@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
@@ -1,6 +1,7 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import { z } from 'zod'
3
3
  import type { EntityManager } from '@mikro-orm/postgresql'
4
+ import { sql } from 'kysely'
4
5
  import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
5
6
  import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
6
7
  import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
@@ -93,47 +94,49 @@ export async function GET(req: Request) {
93
94
 
94
95
  const checkUserId = query.userId ?? auth.userId
95
96
  const em = (container.resolve('em') as EntityManager).fork()
96
- const knex = em.getKnex()
97
+ const kysely = em.getKysely<any>()
97
98
 
98
- const baseQuery = knex('customer_interactions')
99
- .where('tenant_id', auth.tenantId)
100
- .where('status', 'planned')
101
- .whereNotNull('scheduled_at')
102
- .whereNull('deleted_at')
99
+ let baseQuery = (kysely as any)
100
+ .selectFrom('customer_interactions')
101
+ .select(['id', 'scheduled_at', 'duration_minutes', 'interaction_type'])
102
+ .where('tenant_id', '=', auth.tenantId)
103
+ .where('status', '=', 'planned')
104
+ .where('scheduled_at', 'is not', null)
105
+ .where('deleted_at', 'is', null)
103
106
 
104
107
  if (organizationIds.length === 1) {
105
- baseQuery.where('organization_id', organizationIds[0])
108
+ baseQuery = baseQuery.where('organization_id', '=', organizationIds[0])
106
109
  } else if (organizationIds.length > 1) {
107
- baseQuery.whereIn('organization_id', organizationIds)
110
+ baseQuery = baseQuery.where('organization_id', 'in', organizationIds)
108
111
  }
109
112
 
110
113
  if (checkUserId) {
111
- baseQuery.where(function () {
112
- this.where('author_user_id', checkUserId).orWhere('owner_user_id', checkUserId)
113
- })
114
+ baseQuery = baseQuery.where((eb: any) =>
115
+ eb.or([
116
+ eb('author_user_id', '=', checkUserId),
117
+ eb('owner_user_id', '=', checkUserId),
118
+ ])
119
+ )
114
120
  }
115
121
 
116
122
  if (query.excludeId) {
117
- baseQuery.whereNot('id', query.excludeId)
123
+ baseQuery = baseQuery.where('id', '!=', query.excludeId)
118
124
  }
119
125
 
120
126
  // Overlap condition: existing.start < windowEnd AND existing.end > windowStart
121
127
  // end = scheduled_at + duration_minutes (default 30 if null)
122
- baseQuery.where(function () {
123
- this.where('scheduled_at', '<', windowEnd.toISOString())
124
- .andWhere(
125
- knex.raw(
126
- '(scheduled_at + make_interval(mins => COALESCE(duration_minutes, 30))) > ?',
127
- [windowStart.toISOString()],
128
- ),
129
- )
130
- })
128
+ baseQuery = baseQuery.where((eb: any) =>
129
+ eb.and([
130
+ eb('scheduled_at', '<', windowEnd.toISOString()),
131
+ eb(sql`(scheduled_at + make_interval(mins => COALESCE(duration_minutes, 30)))`, '>', windowStart.toISOString()),
132
+ ])
133
+ )
131
134
 
132
135
  // Raw SELECT: reads only unencrypted columns (id, scheduled_at, duration_minutes, interaction_type); title is excluded to avoid ciphertext leakage and is resolved below via findWithDecryption.
133
136
  const rows = await baseQuery
134
- .select('id', 'scheduled_at', 'duration_minutes', 'interaction_type')
135
137
  .orderBy('scheduled_at', 'asc')
136
- .limit(10) as Array<{
138
+ .limit(10)
139
+ .execute() as Array<{
137
140
  id: string
138
141
  scheduled_at: string | Date
139
142
  duration_minutes: number | null
@@ -1,6 +1,7 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import { z } from 'zod'
3
3
  import type { EntityManager } from '@mikro-orm/postgresql'
4
+ import { sql } from 'kysely'
4
5
  import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
5
6
  import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
6
7
  import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
@@ -67,28 +68,29 @@ export async function GET(req: Request) {
67
68
  ? [auth.orgId]
68
69
  : []
69
70
  const em = (container.resolve('em') as EntityManager).fork()
70
- const knex = em.getKnex()
71
+ const kysely = em.getKysely<any>()
71
72
 
72
- const baseQuery = knex('customer_interactions')
73
- .where('entity_id', query.entityId)
74
- .where('tenant_id', auth.tenantId)
75
- .whereNull('deleted_at')
73
+ let baseQuery = (kysely as any)
74
+ .selectFrom('customer_interactions')
75
+ .where('entity_id', '=', query.entityId)
76
+ .where('tenant_id', '=', auth.tenantId)
77
+ .where('deleted_at', 'is', null)
76
78
 
77
79
  if (organizationIds.length === 1) {
78
- baseQuery.where('organization_id', organizationIds[0])
80
+ baseQuery = baseQuery.where('organization_id', '=', organizationIds[0])
79
81
  } else if (organizationIds.length > 1) {
80
- baseQuery.whereIn('organization_id', organizationIds)
82
+ baseQuery = baseQuery.where('organization_id', 'in', organizationIds)
81
83
  }
82
84
 
83
85
  if (query.status) {
84
- baseQuery.where('status', query.status)
86
+ baseQuery = baseQuery.where('status', '=', query.status)
85
87
  }
86
88
 
87
89
  // Raw SELECT: reads only unencrypted columns (id, interaction_type); title/notes are excluded to avoid ciphertext leakage.
88
90
  const rows = await baseQuery
89
- .select('interaction_type')
90
- .count('* as count')
91
- .groupBy('interaction_type') as Array<{ interaction_type: string; count: string | number }>
91
+ .select(['interaction_type', sql<string>`count(*)`.as('count')])
92
+ .groupBy('interaction_type')
93
+ .execute() as Array<{ interaction_type: string; count: string | number }>
92
94
 
93
95
  const counts: Record<string, number> = { call: 0, email: 0, meeting: 0, note: 0 }
94
96
  let total = 0
@@ -1,6 +1,7 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import { z } from 'zod'
3
3
  import type { EntityManager } from '@mikro-orm/postgresql'
4
+ import { sql } from 'kysely'
4
5
  import { makeCrudRoute } from '@open-mercato/shared/lib/crud/factory'
5
6
  import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
6
7
  import { loadCustomFieldValues } from '@open-mercato/shared/lib/crud/custom-fields'
@@ -314,7 +315,7 @@ export async function GET(req: Request) {
314
315
  : []
315
316
  const selectedOrganizationId = scope?.selectedId ?? auth.orgId ?? organizationIds[0] ?? null
316
317
  const em = (container.resolve('em') as EntityManager).fork()
317
- const knex = em.getKnex()
318
+ const db = em.getKysely<any>() as any
318
319
 
319
320
  const requestedSortField = query.sortField ?? 'scheduledAt'
320
321
  const sortConfig = interactionSortConfig[requestedSortField]
@@ -327,8 +328,9 @@ export async function GET(req: Request) {
327
328
  })
328
329
  }
329
330
 
330
- const rowsQuery = knex('customer_interactions')
331
- .select<InteractionListRow[]>([
331
+ let rowsQuery = db
332
+ .selectFrom('customer_interactions')
333
+ .select([
332
334
  'id',
333
335
  'entity_id',
334
336
  'deal_id',
@@ -359,72 +361,58 @@ export async function GET(req: Request) {
359
361
  'tenant_id',
360
362
  'created_at',
361
363
  'updated_at',
362
- knex.raw(`${sortSql} as __sort_value`),
364
+ sql`${sql.raw(sortSql)}`.as('__sort_value'),
363
365
  ])
364
- .whereNull('deleted_at')
365
- .andWhere('tenant_id', auth.tenantId)
366
+ .where('deleted_at', 'is', null)
367
+ .where('tenant_id', '=', auth.tenantId)
366
368
  .limit(query.limit + 1)
367
369
 
368
370
  if (organizationIds.length > 0) {
369
- rowsQuery.whereIn('organization_id', organizationIds)
370
- }
371
- if (query.entityId) {
372
- rowsQuery.andWhere('entity_id', query.entityId)
373
- }
374
- if (query.dealId) {
375
- rowsQuery.andWhere('deal_id', query.dealId)
376
- }
377
- if (query.status) {
378
- rowsQuery.andWhere('status', query.status)
379
- }
380
- if (query.interactionType) {
381
- rowsQuery.andWhere('interaction_type', query.interactionType)
371
+ rowsQuery = rowsQuery.where('organization_id', 'in', organizationIds)
382
372
  }
373
+ if (query.entityId) rowsQuery = rowsQuery.where('entity_id', '=', query.entityId)
374
+ if (query.dealId) rowsQuery = rowsQuery.where('deal_id', '=', query.dealId)
375
+ if (query.status) rowsQuery = rowsQuery.where('status', '=', query.status)
376
+ if (query.interactionType) rowsQuery = rowsQuery.where('interaction_type', '=', query.interactionType)
383
377
  if (query.type) {
384
378
  const types = query.type.split(',').map((t) => t.trim()).filter(Boolean)
385
379
  if (types.length > 0) {
386
- rowsQuery.whereIn('interaction_type', types)
380
+ rowsQuery = rowsQuery.where('interaction_type', 'in', types)
387
381
  }
388
382
  }
389
383
  if (query.pinned === 'true') {
390
- rowsQuery.andWhere('pinned', true)
384
+ rowsQuery = rowsQuery.where('pinned', '=', true)
391
385
  } else if (query.pinned === 'false') {
392
- rowsQuery.andWhere('pinned', false)
393
- }
394
- if (query.excludeInteractionType) {
395
- rowsQuery.andWhereNot('interaction_type', query.excludeInteractionType)
386
+ rowsQuery = rowsQuery.where('pinned', '=', false)
396
387
  }
388
+ if (query.excludeInteractionType) rowsQuery = rowsQuery.where('interaction_type', '!=', query.excludeInteractionType)
397
389
  if (query.search) {
398
390
  const searchTerm = `%${query.search}%`
399
- rowsQuery.andWhere(function applySearch() {
400
- this.whereRaw("coalesce(title, '') ilike ?", [searchTerm]).orWhereRaw("coalesce(body, '') ilike ?", [searchTerm])
401
- })
391
+ rowsQuery = rowsQuery.where(sql<boolean>`coalesce(title, '') ilike ${searchTerm} or coalesce(body, '') ilike ${searchTerm}`)
402
392
  }
403
393
  if (query.from) {
404
- rowsQuery.andWhereRaw(
405
- "coalesce(occurred_at, scheduled_at, created_at) >= ?",
406
- [new Date(query.from)],
407
- )
394
+ rowsQuery = rowsQuery.where(sql<boolean>`coalesce(occurred_at, scheduled_at, created_at) >= ${new Date(query.from)}`)
408
395
  }
409
396
  if (query.to) {
410
- rowsQuery.andWhereRaw(
411
- "coalesce(occurred_at, scheduled_at, created_at) <= ?",
412
- [new Date(query.to)],
413
- )
397
+ rowsQuery = rowsQuery.where(sql<boolean>`coalesce(occurred_at, scheduled_at, created_at) <= ${new Date(query.to)}`)
414
398
  }
399
+
415
400
  if (cursor) {
416
401
  const op = sortDir === 'asc' ? '>' : '<'
417
- rowsQuery.andWhere(function applyCursor() {
418
- this.whereRaw(`${sortSql} ${op} ?`, [cursor.sortValue]).orWhere(function applyTieBreaker() {
419
- this.whereRaw(`${sortSql} = ?`, [cursor.sortValue]).andWhere('id', op, cursor.id)
420
- })
421
- })
402
+ const opRaw = sql.raw(op)
403
+ const sortRaw = sql.raw(sortSql)
404
+ rowsQuery = rowsQuery.where((eb: any) => eb.or([
405
+ sql<boolean>`${sortRaw} ${opRaw} ${cursor.sortValue}`,
406
+ eb.and([
407
+ sql<boolean>`${sortRaw} = ${cursor.sortValue}`,
408
+ eb('id', op, cursor.id),
409
+ ]),
410
+ ]))
422
411
  }
423
412
 
424
- rowsQuery.orderByRaw(`${sortSql} ${sortDir}`)
425
- rowsQuery.orderBy('id', sortDir)
413
+ rowsQuery = rowsQuery.orderBy(sql`${sql.raw(sortSql)} ${sql.raw(sortDir)}`).orderBy('id', sortDir)
426
414
 
427
- const rows = await rowsQuery
415
+ const rows = await rowsQuery.execute() as InteractionListRow[]
428
416
  const pageRows = rows.slice(0, query.limit)
429
417
  const hasMore = rows.length > query.limit
430
418
 
@@ -1,5 +1,6 @@
1
1
  import { createScopedApiHelpers } from '@open-mercato/shared/lib/api/scoped'
2
2
  import type { EntityManager } from '@mikro-orm/postgresql'
3
+ import { sql } from 'kysely'
3
4
  import type { CrudCtx } from '@open-mercato/shared/lib/crud/factory'
4
5
  import type { EntityId } from '@open-mercato/shared/modules/entities'
5
6
  import type { QueryCustomFieldSource, QueryJoinEdge, QueryEngine } from '@open-mercato/shared/lib/query/types'
@@ -50,28 +51,33 @@ async function enrichSearchSourcesWithCustomFieldTokens(
50
51
  if (!entityTypes.length) return sources
51
52
 
52
53
  const em = ctx.container.resolve('em') as EntityManager
53
- const knex = (em as any).getConnection().getKnex()
54
- let defsQuery = knex('custom_field_defs')
55
- .select('entity_id', 'key', 'kind')
56
- .whereIn('entity_id', entityTypes)
57
- .andWhere('is_active', true)
58
-
59
- defsQuery = defsQuery.andWhere((builder: any) => {
60
- builder.where({ tenant_id: ctx.auth?.tenantId ?? null }).orWhereNull('tenant_id')
61
- })
54
+ const db = em.getKysely<any>() as any
55
+ let defsQuery = db
56
+ .selectFrom('custom_field_defs')
57
+ .select(['entity_id', 'key', 'kind'])
58
+ .where('entity_id', 'in', entityTypes)
59
+ .where('is_active', '=', true)
60
+
61
+ const tenantScope = ctx.auth?.tenantId ?? null
62
+ defsQuery = defsQuery.where((eb: any) => eb.or([
63
+ eb('tenant_id', '=', tenantScope),
64
+ eb('tenant_id', 'is', null),
65
+ ]))
62
66
 
63
67
  if (ctx.selectedOrganizationId) {
64
- defsQuery = defsQuery.andWhere((builder: any) => {
65
- builder.where({ organization_id: ctx.selectedOrganizationId }).orWhereNull('organization_id')
66
- })
68
+ defsQuery = defsQuery.where((eb: any) => eb.or([
69
+ eb('organization_id', '=', ctx.selectedOrganizationId),
70
+ eb('organization_id', 'is', null),
71
+ ]))
67
72
  } else if (Array.isArray(ctx.organizationIds) && ctx.organizationIds.length > 0) {
68
- defsQuery = defsQuery.andWhere((builder: any) => {
69
- builder.whereIn('organization_id', ctx.organizationIds).orWhereNull('organization_id')
70
- })
73
+ defsQuery = defsQuery.where((eb: any) => eb.or([
74
+ eb('organization_id', 'in', ctx.organizationIds),
75
+ eb('organization_id', 'is', null),
76
+ ]))
71
77
  }
72
78
 
73
79
  const customFieldKeysByEntity = new Map<string, Set<string>>()
74
- const rows = await defsQuery
80
+ const rows = await defsQuery.execute()
75
81
  for (const row of rows as Array<{ entity_id?: unknown; key?: unknown; kind?: unknown }>) {
76
82
  if (row.kind === 'attachment') continue
77
83
  const entityType = typeof row.entity_id === 'string' ? row.entity_id : null
@@ -108,28 +114,29 @@ async function findSearchTokenEntityIds({
108
114
  if (!tokens.hashes.length) return []
109
115
 
110
116
  const em = ctx.container.resolve('em') as EntityManager
111
- const knex = (em as any).getConnection().getKnex()
112
- let searchQuery = knex('search_tokens')
117
+ const db = em.getKysely<any>() as any
118
+ let searchQuery = db
119
+ .selectFrom('search_tokens')
113
120
  .select('entity_id')
114
- .where('entity_type', entityType)
115
- .whereIn('field', fields)
116
- .whereIn('token_hash', tokens.hashes)
121
+ .where('entity_type', '=', entityType)
122
+ .where('field', 'in', fields)
123
+ .where('token_hash', 'in', tokens.hashes)
117
124
  .groupBy('entity_id')
118
- .havingRaw('count(distinct token_hash) >= ?', [tokens.hashes.length])
125
+ .having(sql<boolean>`count(distinct token_hash) >= ${tokens.hashes.length}`)
119
126
 
120
127
  if (ctx.auth?.tenantId !== undefined) {
121
- searchQuery = searchQuery.whereRaw('tenant_id is not distinct from ?', [ctx.auth?.tenantId ?? null])
128
+ searchQuery = searchQuery.where(sql<boolean>`tenant_id is not distinct from ${ctx.auth?.tenantId ?? null}`)
122
129
  }
123
130
  if (ctx.selectedOrganizationId) {
124
- searchQuery = searchQuery.where('organization_id', ctx.selectedOrganizationId)
131
+ searchQuery = searchQuery.where('organization_id', '=', ctx.selectedOrganizationId)
125
132
  } else if (Array.isArray(ctx.organizationIds) && ctx.organizationIds.length > 0) {
126
- searchQuery = searchQuery.whereIn('organization_id', ctx.organizationIds)
133
+ searchQuery = searchQuery.where('organization_id', 'in', ctx.organizationIds)
127
134
  }
128
135
 
129
- const rows = await searchQuery
136
+ const rows = await searchQuery.execute() as Array<{ entity_id?: unknown }>
130
137
  return rows
131
- .map((row: { entity_id?: unknown }) => (typeof row.entity_id === 'string' ? row.entity_id : null))
132
- .filter((id: string | null): id is string => typeof id === 'string' && id.length > 0)
138
+ .map((row) => (typeof row.entity_id === 'string' ? row.entity_id : null))
139
+ .filter((id): id is string => typeof id === 'string' && id.length > 0)
133
140
  }
134
141
 
135
142
  async function mapScopedEntityIds({
@@ -144,31 +151,32 @@ async function mapScopedEntityIds({
144
151
  if (!ids.length) return []
145
152
 
146
153
  const em = ctx.container.resolve('em') as EntityManager
147
- const knex = (em as any).getConnection().getKnex()
154
+ const db = em.getKysely<any>() as any
148
155
  const sourceColumn = config.sourceColumn ?? 'id'
149
156
  const tenantColumn = config.tenantColumn ?? 'tenant_id'
150
157
  const organizationColumn = config.organizationColumn ?? 'organization_id'
151
158
 
152
- let mapQuery = knex(config.table)
159
+ let mapQuery = db
160
+ .selectFrom(config.table)
153
161
  .select(config.targetColumn)
154
- .whereIn(sourceColumn, ids)
162
+ .where(sourceColumn, 'in', ids)
155
163
 
156
164
  if (ctx.auth?.tenantId !== undefined) {
157
- mapQuery = mapQuery.whereRaw('?? is not distinct from ?', [tenantColumn, ctx.auth?.tenantId ?? null])
165
+ mapQuery = mapQuery.where(sql<boolean>`${sql.ref(tenantColumn)} is not distinct from ${ctx.auth?.tenantId ?? null}`)
158
166
  }
159
167
  if (ctx.selectedOrganizationId) {
160
- mapQuery = mapQuery.where(organizationColumn, ctx.selectedOrganizationId)
168
+ mapQuery = mapQuery.where(organizationColumn, '=', ctx.selectedOrganizationId)
161
169
  } else if (Array.isArray(ctx.organizationIds) && ctx.organizationIds.length > 0) {
162
- mapQuery = mapQuery.whereIn(organizationColumn, ctx.organizationIds)
170
+ mapQuery = mapQuery.where(organizationColumn, 'in', ctx.organizationIds)
163
171
  }
164
172
 
165
- const rows = await mapQuery
173
+ const rows = await mapQuery.execute() as Array<Record<string, unknown>>
166
174
  return rows
167
- .map((row: Record<string, unknown>) => {
175
+ .map((row) => {
168
176
  const value = row[config.targetColumn]
169
177
  return typeof value === 'string' ? value : null
170
178
  })
171
- .filter((id: string | null): id is string => typeof id === 'string' && id.length > 0)
179
+ .filter((id): id is string => typeof id === 'string' && id.length > 0)
172
180
  }
173
181
 
174
182
  export async function findMatchingEntityIdsBySearchTokensAcrossSources({