@open-mercato/core 0.6.6-develop.6256.1.9fc16aedc4 → 0.6.6-develop.6286.1.d985c5c374

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 (234) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/carrier_shipment_idempotency_key/index.js +19 -0
  3. package/dist/generated/entities/carrier_shipment_idempotency_key/index.js.map +7 -0
  4. package/dist/generated/entities.ids.generated.js +2 -1
  5. package/dist/generated/entities.ids.generated.js.map +2 -2
  6. package/dist/generated/entity-fields-registry.js +10 -0
  7. package/dist/generated/entity-fields-registry.js.map +2 -2
  8. package/dist/modules/catalog/lib/productResolution.js +45 -0
  9. package/dist/modules/catalog/lib/productResolution.js.map +7 -0
  10. package/dist/modules/communication_channels/workers/channel-import-history.js +1 -1
  11. package/dist/modules/communication_channels/workers/channel-import-history.js.map +2 -2
  12. package/dist/modules/currencies/api/fetch-configs/route.js +34 -0
  13. package/dist/modules/currencies/api/fetch-configs/route.js.map +2 -2
  14. package/dist/modules/currencies/components/CurrencyFetchingConfig.js +17 -15
  15. package/dist/modules/currencies/components/CurrencyFetchingConfig.js.map +2 -2
  16. package/dist/modules/customers/api/companies/[id]/route.js +176 -161
  17. package/dist/modules/customers/api/companies/[id]/route.js.map +2 -2
  18. package/dist/modules/customers/api/people/[id]/route.js +75 -59
  19. package/dist/modules/customers/api/people/[id]/route.js.map +2 -2
  20. package/dist/modules/customers/backend/config/customers/pipeline-stages/page.js +17 -10
  21. package/dist/modules/customers/backend/config/customers/pipeline-stages/page.js.map +2 -2
  22. package/dist/modules/customers/components/detail/ActivitiesAddNewMenu.js +6 -4
  23. package/dist/modules/customers/components/detail/ActivitiesAddNewMenu.js.map +2 -2
  24. package/dist/modules/customers/components/detail/AiActionChips.js +5 -2
  25. package/dist/modules/customers/components/detail/AiActionChips.js.map +2 -2
  26. package/dist/modules/customers/components/detail/schedule/ParticipantsField.js +19 -21
  27. package/dist/modules/customers/components/detail/schedule/ParticipantsField.js.map +2 -2
  28. package/dist/modules/data_sync/api/runs/[id]/cancel.js +1 -1
  29. package/dist/modules/data_sync/api/runs/[id]/cancel.js.map +2 -2
  30. package/dist/modules/data_sync/backend/data-sync/page.js +9 -45
  31. package/dist/modules/data_sync/backend/data-sync/page.js.map +2 -2
  32. package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js +11 -17
  33. package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js.map +2 -2
  34. package/dist/modules/data_sync/components/IntegrationScheduleTab.js +12 -10
  35. package/dist/modules/data_sync/components/IntegrationScheduleTab.js.map +2 -2
  36. package/dist/modules/data_sync/lib/id-mapping.js +46 -1
  37. package/dist/modules/data_sync/lib/id-mapping.js.map +2 -2
  38. package/dist/modules/data_sync/lib/sync-engine.js +2 -2
  39. package/dist/modules/data_sync/lib/sync-engine.js.map +2 -2
  40. package/dist/modules/data_sync/lib/syncRunStatus.js +30 -0
  41. package/dist/modules/data_sync/lib/syncRunStatus.js.map +7 -0
  42. package/dist/modules/entities/api/records.js +6 -0
  43. package/dist/modules/entities/api/records.js.map +2 -2
  44. package/dist/modules/feature_toggles/api/global/route.js +17 -15
  45. package/dist/modules/feature_toggles/api/global/route.js.map +2 -2
  46. package/dist/modules/feature_toggles/api/openapi.js +2 -2
  47. package/dist/modules/feature_toggles/api/openapi.js.map +2 -2
  48. package/dist/modules/feature_toggles/commands/global.js +14 -0
  49. package/dist/modules/feature_toggles/commands/global.js.map +2 -2
  50. package/dist/modules/inbox_ops/backend/inbox-ops/page.js +6 -0
  51. package/dist/modules/inbox_ops/backend/inbox-ops/page.js.map +2 -2
  52. package/dist/modules/messages/api/[id]/conversation/archive/route.js +25 -7
  53. package/dist/modules/messages/api/[id]/conversation/archive/route.js.map +2 -2
  54. package/dist/modules/messages/api/[id]/conversation/read/route.js +24 -6
  55. package/dist/modules/messages/api/[id]/conversation/read/route.js.map +2 -2
  56. package/dist/modules/messages/api/[id]/route.js +13 -1
  57. package/dist/modules/messages/api/[id]/route.js.map +2 -2
  58. package/dist/modules/messages/api/openapi.js +3 -1
  59. package/dist/modules/messages/api/openapi.js.map +2 -2
  60. package/dist/modules/messages/commands/conversation.js +77 -0
  61. package/dist/modules/messages/commands/conversation.js.map +2 -2
  62. package/dist/modules/messages/components/MessageDetailPageClient.js +16 -4
  63. package/dist/modules/messages/components/MessageDetailPageClient.js.map +2 -2
  64. package/dist/modules/messages/components/message-detail/hooks/useMessageDetails.js +3 -1
  65. package/dist/modules/messages/components/message-detail/hooks/useMessageDetails.js.map +2 -2
  66. package/dist/modules/messages/components/message-detail/hooks/useMessageDetailsActions.js +29 -4
  67. package/dist/modules/messages/components/message-detail/hooks/useMessageDetailsActions.js.map +2 -2
  68. package/dist/modules/messages/components/message-detail/hooks/useMessageDetailsQueries.js +10 -1
  69. package/dist/modules/messages/components/message-detail/hooks/useMessageDetailsQueries.js.map +2 -2
  70. package/dist/modules/messages/components/message-detail/panels/MainMessageHeader.js +13 -11
  71. package/dist/modules/messages/components/message-detail/panels/MainMessageHeader.js.map +2 -2
  72. package/dist/modules/payment_gateways/api/cancel/route.js +5 -0
  73. package/dist/modules/payment_gateways/api/cancel/route.js.map +2 -2
  74. package/dist/modules/payment_gateways/api/capture/route.js +5 -0
  75. package/dist/modules/payment_gateways/api/capture/route.js.map +2 -2
  76. package/dist/modules/payment_gateways/api/refund/route.js +5 -0
  77. package/dist/modules/payment_gateways/api/refund/route.js.map +2 -2
  78. package/dist/modules/payment_gateways/lib/gateway-service.js +52 -25
  79. package/dist/modules/payment_gateways/lib/gateway-service.js.map +2 -2
  80. package/dist/modules/payment_gateways/lib/status-machine.js +13 -0
  81. package/dist/modules/payment_gateways/lib/status-machine.js.map +2 -2
  82. package/dist/modules/perspectives/api/[tableId]/route.js +8 -2
  83. package/dist/modules/perspectives/api/[tableId]/route.js.map +2 -2
  84. package/dist/modules/perspectives/data/entities.js +33 -3
  85. package/dist/modules/perspectives/data/entities.js.map +2 -2
  86. package/dist/modules/perspectives/migrations/Migration20260619120000_perspectives_live_row_uniqueness.js +63 -0
  87. package/dist/modules/perspectives/migrations/Migration20260619120000_perspectives_live_row_uniqueness.js.map +7 -0
  88. package/dist/modules/perspectives/services/perspectiveService.js +17 -0
  89. package/dist/modules/perspectives/services/perspectiveService.js.map +2 -2
  90. package/dist/modules/planner/commands/availability-weekly.js +33 -1
  91. package/dist/modules/planner/commands/availability-weekly.js.map +2 -2
  92. package/dist/modules/planner/components/AvailabilityRulesEditor.js +14 -2
  93. package/dist/modules/planner/components/AvailabilityRulesEditor.js.map +2 -2
  94. package/dist/modules/progress/api/active/route.js +1 -1
  95. package/dist/modules/progress/api/active/route.js.map +2 -2
  96. package/dist/modules/progress/lib/progressService.js.map +1 -1
  97. package/dist/modules/progress/lib/progressServiceImpl.js +33 -8
  98. package/dist/modules/progress/lib/progressServiceImpl.js.map +2 -2
  99. package/dist/modules/query_index/api/status.js +19 -24
  100. package/dist/modules/query_index/api/status.js.map +3 -3
  101. package/dist/modules/query_index/lib/coverage.js +35 -0
  102. package/dist/modules/query_index/lib/coverage.js.map +2 -2
  103. package/dist/modules/query_index/lib/engine.js +11 -6
  104. package/dist/modules/query_index/lib/engine.js.map +2 -2
  105. package/dist/modules/resources/api/resource-types.js +5 -37
  106. package/dist/modules/resources/api/resource-types.js.map +2 -2
  107. package/dist/modules/resources/api/resourceTypeCounts.js +35 -0
  108. package/dist/modules/resources/api/resourceTypeCounts.js.map +7 -0
  109. package/dist/modules/resources/backend/resources/resource-types/[id]/edit/page.js +1 -1
  110. package/dist/modules/resources/backend/resources/resource-types/[id]/edit/page.js.map +1 -1
  111. package/dist/modules/resources/backend/resources/resource-types/page.js +2 -1
  112. package/dist/modules/resources/backend/resources/resource-types/page.js.map +2 -2
  113. package/dist/modules/sales/components/documents/ReturnDialog.js +4 -1
  114. package/dist/modules/sales/components/documents/ReturnDialog.js.map +2 -2
  115. package/dist/modules/sales/components/documents/ShipmentDialog.js +17 -2
  116. package/dist/modules/sales/components/documents/ShipmentDialog.js.map +2 -2
  117. package/dist/modules/sales/di.js +4 -0
  118. package/dist/modules/sales/di.js.map +2 -2
  119. package/dist/modules/sales/services/salesOrderService.js +26 -0
  120. package/dist/modules/sales/services/salesOrderService.js.map +7 -0
  121. package/dist/modules/shipping_carriers/api/shipments/route.js +8 -0
  122. package/dist/modules/shipping_carriers/api/shipments/route.js.map +2 -2
  123. package/dist/modules/shipping_carriers/data/entities.js +38 -0
  124. package/dist/modules/shipping_carriers/data/entities.js.map +2 -2
  125. package/dist/modules/shipping_carriers/data/validators.js +2 -1
  126. package/dist/modules/shipping_carriers/data/validators.js.map +2 -2
  127. package/dist/modules/shipping_carriers/lib/shipment-idempotency.js +76 -0
  128. package/dist/modules/shipping_carriers/lib/shipment-idempotency.js.map +7 -0
  129. package/dist/modules/shipping_carriers/lib/shipment-wizard/hooks/shipmentApi.js +2 -1
  130. package/dist/modules/shipping_carriers/lib/shipment-wizard/hooks/shipmentApi.js.map +2 -2
  131. package/dist/modules/shipping_carriers/lib/shipment-wizard/hooks/useShipmentWizard.js +20 -2
  132. package/dist/modules/shipping_carriers/lib/shipment-wizard/hooks/useShipmentWizard.js.map +2 -2
  133. package/dist/modules/shipping_carriers/lib/shipping-service.js +82 -43
  134. package/dist/modules/shipping_carriers/lib/shipping-service.js.map +2 -2
  135. package/dist/modules/shipping_carriers/migrations/Migration20260618173616_shipping_carriers.js +14 -0
  136. package/dist/modules/shipping_carriers/migrations/Migration20260618173616_shipping_carriers.js.map +7 -0
  137. package/dist/modules/staff/lib/timesheets-ui/ListView.js +15 -6
  138. package/dist/modules/staff/lib/timesheets-ui/ListView.js.map +2 -2
  139. package/dist/modules/translations/components/TranslationManager.js +9 -18
  140. package/dist/modules/translations/components/TranslationManager.js.map +2 -2
  141. package/generated/entities/carrier_shipment_idempotency_key/index.ts +8 -0
  142. package/generated/entities.ids.generated.ts +2 -1
  143. package/generated/entity-fields-registry.ts +10 -0
  144. package/package.json +9 -8
  145. package/src/modules/catalog/lib/productResolution.ts +75 -0
  146. package/src/modules/communication_channels/workers/channel-import-history.ts +1 -1
  147. package/src/modules/currencies/api/fetch-configs/route.ts +36 -0
  148. package/src/modules/currencies/components/CurrencyFetchingConfig.tsx +20 -17
  149. package/src/modules/currencies/i18n/de.json +2 -1
  150. package/src/modules/currencies/i18n/en.json +2 -1
  151. package/src/modules/currencies/i18n/es.json +2 -1
  152. package/src/modules/currencies/i18n/pl.json +2 -1
  153. package/src/modules/customers/api/companies/[id]/route.ts +214 -189
  154. package/src/modules/customers/api/people/[id]/route.ts +106 -80
  155. package/src/modules/customers/backend/config/customers/pipeline-stages/page.tsx +19 -12
  156. package/src/modules/customers/components/detail/ActivitiesAddNewMenu.tsx +8 -6
  157. package/src/modules/customers/components/detail/AiActionChips.tsx +6 -3
  158. package/src/modules/customers/components/detail/schedule/ParticipantsField.tsx +16 -18
  159. package/src/modules/data_sync/api/runs/[id]/cancel.ts +1 -1
  160. package/src/modules/data_sync/backend/data-sync/page.tsx +11 -58
  161. package/src/modules/data_sync/backend/data-sync/runs/[id]/page.tsx +13 -20
  162. package/src/modules/data_sync/components/IntegrationScheduleTab.tsx +10 -8
  163. package/src/modules/data_sync/lib/id-mapping.ts +58 -1
  164. package/src/modules/data_sync/lib/sync-engine.ts +2 -2
  165. package/src/modules/data_sync/lib/syncRunStatus.ts +39 -0
  166. package/src/modules/entities/api/records.ts +14 -0
  167. package/src/modules/feature_toggles/api/global/route.ts +16 -14
  168. package/src/modules/feature_toggles/api/openapi.ts +2 -2
  169. package/src/modules/feature_toggles/commands/global.ts +15 -0
  170. package/src/modules/inbox_ops/backend/inbox-ops/page.tsx +7 -0
  171. package/src/modules/messages/api/[id]/conversation/archive/route.ts +29 -6
  172. package/src/modules/messages/api/[id]/conversation/read/route.ts +29 -6
  173. package/src/modules/messages/api/[id]/route.ts +15 -0
  174. package/src/modules/messages/api/openapi.ts +2 -0
  175. package/src/modules/messages/commands/conversation.ts +87 -0
  176. package/src/modules/messages/components/MessageDetailPageClient.tsx +16 -4
  177. package/src/modules/messages/components/message-detail/hooks/useMessageDetails.ts +2 -0
  178. package/src/modules/messages/components/message-detail/hooks/useMessageDetailsActions.ts +39 -4
  179. package/src/modules/messages/components/message-detail/hooks/useMessageDetailsQueries.ts +15 -1
  180. package/src/modules/messages/components/message-detail/panels/MainMessageHeader.tsx +29 -14
  181. package/src/modules/messages/components/message-detail/types.ts +2 -0
  182. package/src/modules/messages/i18n/de.json +4 -0
  183. package/src/modules/messages/i18n/en.json +4 -0
  184. package/src/modules/messages/i18n/es.json +4 -0
  185. package/src/modules/messages/i18n/pl.json +4 -0
  186. package/src/modules/payment_gateways/api/cancel/route.ts +5 -0
  187. package/src/modules/payment_gateways/api/capture/route.ts +5 -0
  188. package/src/modules/payment_gateways/api/refund/route.ts +5 -0
  189. package/src/modules/payment_gateways/lib/gateway-service.ts +58 -25
  190. package/src/modules/payment_gateways/lib/status-machine.ts +16 -0
  191. package/src/modules/perspectives/api/[tableId]/route.ts +8 -2
  192. package/src/modules/perspectives/data/entities.ts +43 -3
  193. package/src/modules/perspectives/migrations/.snapshot-open-mercato.json +69 -25
  194. package/src/modules/perspectives/migrations/Migration20260619120000_perspectives_live_row_uniqueness.ts +65 -0
  195. package/src/modules/perspectives/services/perspectiveService.ts +17 -0
  196. package/src/modules/planner/commands/availability-weekly.ts +48 -1
  197. package/src/modules/planner/components/AvailabilityRulesEditor.tsx +31 -10
  198. package/src/modules/progress/api/active/route.ts +1 -1
  199. package/src/modules/progress/lib/progressService.ts +2 -2
  200. package/src/modules/progress/lib/progressServiceImpl.ts +33 -8
  201. package/src/modules/query_index/api/status.ts +28 -32
  202. package/src/modules/query_index/lib/coverage.ts +63 -0
  203. package/src/modules/query_index/lib/engine.ts +37 -24
  204. package/src/modules/resources/api/resource-types.ts +4 -44
  205. package/src/modules/resources/api/resourceTypeCounts.ts +74 -0
  206. package/src/modules/resources/backend/resources/resource-types/[id]/edit/page.tsx +1 -1
  207. package/src/modules/resources/backend/resources/resource-types/page.tsx +1 -0
  208. package/src/modules/sales/components/documents/ReturnDialog.tsx +4 -1
  209. package/src/modules/sales/components/documents/ShipmentDialog.tsx +20 -2
  210. package/src/modules/sales/di.ts +6 -0
  211. package/src/modules/sales/services/salesOrderService.ts +38 -0
  212. package/src/modules/shipping_carriers/api/shipments/route.ts +8 -0
  213. package/src/modules/shipping_carriers/data/entities.ts +33 -0
  214. package/src/modules/shipping_carriers/data/validators.ts +1 -0
  215. package/src/modules/shipping_carriers/i18n/de.json +1 -0
  216. package/src/modules/shipping_carriers/i18n/en.json +1 -0
  217. package/src/modules/shipping_carriers/i18n/es.json +1 -0
  218. package/src/modules/shipping_carriers/i18n/pl.json +1 -0
  219. package/src/modules/shipping_carriers/lib/shipment-idempotency.ts +119 -0
  220. package/src/modules/shipping_carriers/lib/shipment-wizard/hooks/shipmentApi.ts +3 -1
  221. package/src/modules/shipping_carriers/lib/shipment-wizard/hooks/useShipmentWizard.ts +24 -2
  222. package/src/modules/shipping_carriers/lib/shipping-service.ts +87 -43
  223. package/src/modules/shipping_carriers/migrations/.snapshot-open-mercato.json +197 -0
  224. package/src/modules/shipping_carriers/migrations/Migration20260618173616_shipping_carriers.ts +14 -0
  225. package/src/modules/staff/i18n/de.json +1 -0
  226. package/src/modules/staff/i18n/en.json +1 -0
  227. package/src/modules/staff/i18n/es.json +1 -0
  228. package/src/modules/staff/i18n/pl.json +1 -0
  229. package/src/modules/staff/lib/timesheets-ui/ListView.tsx +15 -7
  230. package/src/modules/translations/components/TranslationManager.tsx +17 -24
  231. package/src/modules/translations/i18n/de.json +1 -0
  232. package/src/modules/translations/i18n/en.json +1 -0
  233. package/src/modules/translations/i18n/es.json +1 -0
  234. package/src/modules/translations/i18n/pl.json +1 -0
@@ -335,90 +335,92 @@ async function GET(_req, ctx) {
335
335
  currentUserId: viewerUserId,
336
336
  userFeatures: void 0
337
337
  });
338
- const profile = company.companyProfile ? await findOneWithDecryption(
339
- em,
340
- CustomerCompanyProfile,
341
- {
342
- id: company.companyProfile.id,
343
- tenantId: company.tenantId,
344
- organizationId: company.organizationId
345
- },
346
- {},
347
- companyScope
348
- ) : await findOneWithDecryption(
349
- em,
350
- CustomerCompanyProfile,
351
- {
352
- entity: company,
353
- tenantId: company.tenantId,
354
- organizationId: company.organizationId
355
- },
356
- {},
357
- companyScope
358
- );
359
- const addresses = includeAddresses ? await findWithDecryption(
360
- em,
361
- CustomerAddress,
362
- {
363
- entity: company.id,
364
- tenantId: company.tenantId,
365
- organizationId: company.organizationId
366
- },
367
- { orderBy: { isPrimary: "desc", createdAt: "desc" } },
368
- companyScope
369
- ) : [];
370
- const tagAssignments = await findWithDecryption(
371
- em,
372
- CustomerTagAssignment,
373
- {
374
- entity: company.id,
375
- tenantId: company.tenantId,
376
- organizationId: company.organizationId
377
- },
378
- { populate: ["tag"] },
379
- companyScope
380
- );
381
- const labelAssignments = await findWithDecryption(
382
- em,
383
- CustomerLabelAssignment,
384
- {
385
- entity: company.id,
386
- tenantId: company.tenantId,
387
- organizationId: company.organizationId
388
- },
389
- { populate: ["label"] },
390
- companyScope
391
- );
392
- const comments = includeComments ? await findWithDecryption(
393
- em,
394
- CustomerComment,
395
- {
396
- entity: company.id,
397
- tenantId: company.tenantId,
398
- organizationId: company.organizationId
399
- },
400
- { orderBy: { createdAt: "desc" }, limit: 50 },
401
- companyScope
402
- ) : [];
403
338
  const shouldLoadCanonicalInteractions = includeInteractions || includeActivities || includeTodos;
404
- const canonicalInteractionRows = shouldLoadCanonicalInteractions ? await findWithDecryption(
405
- em,
406
- CustomerInteraction,
407
- interactionFlags.unified ? {
408
- entity: company.id,
409
- tenantId: company.tenantId,
410
- organizationId: company.organizationId,
411
- deletedAt: null,
412
- ...emailVisibilityFilter
413
- } : {
414
- entity: company.id,
415
- tenantId: company.tenantId,
416
- organizationId: company.organizationId,
417
- ...emailVisibilityFilter
418
- },
419
- { orderBy: { scheduledAt: "asc", createdAt: "desc" }, limit: 100 },
420
- companyScope
421
- ) : [];
339
+ const [profile, addresses, tagAssignments, labelAssignments, comments, canonicalInteractionRows] = await Promise.all([
340
+ company.companyProfile ? findOneWithDecryption(
341
+ em,
342
+ CustomerCompanyProfile,
343
+ {
344
+ id: company.companyProfile.id,
345
+ tenantId: company.tenantId,
346
+ organizationId: company.organizationId
347
+ },
348
+ {},
349
+ companyScope
350
+ ) : findOneWithDecryption(
351
+ em,
352
+ CustomerCompanyProfile,
353
+ {
354
+ entity: company,
355
+ tenantId: company.tenantId,
356
+ organizationId: company.organizationId
357
+ },
358
+ {},
359
+ companyScope
360
+ ),
361
+ includeAddresses ? findWithDecryption(
362
+ em,
363
+ CustomerAddress,
364
+ {
365
+ entity: company.id,
366
+ tenantId: company.tenantId,
367
+ organizationId: company.organizationId
368
+ },
369
+ { orderBy: { isPrimary: "desc", createdAt: "desc" } },
370
+ companyScope
371
+ ) : Promise.resolve([]),
372
+ findWithDecryption(
373
+ em,
374
+ CustomerTagAssignment,
375
+ {
376
+ entity: company.id,
377
+ tenantId: company.tenantId,
378
+ organizationId: company.organizationId
379
+ },
380
+ { populate: ["tag"] },
381
+ companyScope
382
+ ),
383
+ findWithDecryption(
384
+ em,
385
+ CustomerLabelAssignment,
386
+ {
387
+ entity: company.id,
388
+ tenantId: company.tenantId,
389
+ organizationId: company.organizationId
390
+ },
391
+ { populate: ["label"] },
392
+ companyScope
393
+ ),
394
+ includeComments ? findWithDecryption(
395
+ em,
396
+ CustomerComment,
397
+ {
398
+ entity: company.id,
399
+ tenantId: company.tenantId,
400
+ organizationId: company.organizationId
401
+ },
402
+ { orderBy: { createdAt: "desc" }, limit: 50 },
403
+ companyScope
404
+ ) : Promise.resolve([]),
405
+ shouldLoadCanonicalInteractions ? findWithDecryption(
406
+ em,
407
+ CustomerInteraction,
408
+ interactionFlags.unified ? {
409
+ entity: company.id,
410
+ tenantId: company.tenantId,
411
+ organizationId: company.organizationId,
412
+ deletedAt: null,
413
+ ...emailVisibilityFilter
414
+ } : {
415
+ entity: company.id,
416
+ tenantId: company.tenantId,
417
+ organizationId: company.organizationId,
418
+ ...emailVisibilityFilter
419
+ },
420
+ { orderBy: { scheduledAt: "asc", createdAt: "desc" }, limit: 100 },
421
+ companyScope
422
+ ) : Promise.resolve([])
423
+ ]);
422
424
  const canonicalActiveInteractions = canonicalInteractionRows.filter((interaction) => !interaction.deletedAt);
423
425
  const canonicalInteractions = shouldLoadCanonicalInteractions ? await hydrateCanonicalInteractions({
424
426
  em,
@@ -624,20 +626,19 @@ async function GET(_req, ctx) {
624
626
  });
625
627
  relatedPeople = Array.from(relatedPeopleById.values());
626
628
  }
627
- const entityCustomFieldValues = await loadCustomFieldValues({
628
- em,
629
- entityId: E.customers.customer_entity,
630
- recordIds: [company.id],
631
- tenantIdByRecord: { [company.id]: company.tenantId ?? null },
632
- organizationIdByRecord: { [company.id]: company.organizationId ?? null },
633
- tenantFallbacks: [
634
- company.tenantId ?? auth.tenantId ?? null
635
- ].filter((v) => !!v)
636
- });
637
- let profileCustomFieldValues = {};
638
629
  const profileId = profile?.id ?? null;
639
- if (profileId) {
640
- profileCustomFieldValues = await loadCustomFieldValues({
630
+ const [entityCustomFieldValues, profileCustomFieldValues, routing] = await Promise.all([
631
+ loadCustomFieldValues({
632
+ em,
633
+ entityId: E.customers.customer_entity,
634
+ recordIds: [company.id],
635
+ tenantIdByRecord: { [company.id]: company.tenantId ?? null },
636
+ organizationIdByRecord: { [company.id]: company.organizationId ?? null },
637
+ tenantFallbacks: [
638
+ company.tenantId ?? auth.tenantId ?? null
639
+ ].filter((v) => !!v)
640
+ }),
641
+ profileId ? loadCustomFieldValues({
641
642
  em,
642
643
  entityId: E.customers.customer_company_profile,
643
644
  recordIds: [profileId],
@@ -646,9 +647,9 @@ async function GET(_req, ctx) {
646
647
  tenantFallbacks: [
647
648
  profile?.tenantId ?? company.tenantId ?? auth.tenantId ?? null
648
649
  ].filter((v) => !!v)
649
- });
650
- }
651
- const routing = await resolveCompanyCustomFieldRouting(em, company.tenantId ?? null, company.organizationId ?? null);
650
+ }) : Promise.resolve({}),
651
+ resolveCompanyCustomFieldRouting(em, company.tenantId ?? null, company.organizationId ?? null)
652
+ ]);
652
653
  const customFields = normalizeCustomerDetailCustomFields(
653
654
  mergeCompanyCustomFieldValues(
654
655
  routing,
@@ -656,75 +657,89 @@ async function GET(_req, ctx) {
656
657
  profileId ? profileCustomFieldValues?.[profileId] ?? {} : {}
657
658
  )
658
659
  );
659
- const activityCount = await em.count(CustomerInteraction, {
660
- entity: company.id,
661
- organizationId: company.organizationId,
662
- tenantId: company.tenantId,
663
- deletedAt: null,
664
- interactionType: { $ne: "task" },
665
- ...emailVisibilityFilter
666
- });
667
- const interactionCount = await em.count(CustomerInteraction, {
668
- entity: company.id,
669
- organizationId: company.organizationId,
670
- tenantId: company.tenantId,
671
- deletedAt: null,
672
- ...emailVisibilityFilter
673
- });
674
- const todoCount = interactionFlags.unified ? await em.count(CustomerInteraction, {
675
- entity: company.id,
676
- organizationId: company.organizationId,
677
- tenantId: company.tenantId,
678
- deletedAt: null,
679
- interactionType: "task"
680
- }) : await em.count(CustomerTodoLink, {
681
- entity: company.id,
682
- organizationId: company.organizationId,
683
- tenantId: company.tenantId
684
- });
685
- const commentsCount = includeComments ? comments.length : await em.count(CustomerComment, {
686
- entity: company.id,
687
- organizationId: company.organizationId,
688
- tenantId: company.tenantId
689
- });
690
- const addressesCount = includeAddresses ? addresses.length : await em.count(CustomerAddress, {
691
- entity: company.id,
692
- organizationId: company.organizationId,
693
- tenantId: company.tenantId
694
- });
695
- const peopleCount = includePeople ? relatedPeople.length : filterActivePersonCompanyLinks(
696
- await findWithDecryption(
660
+ const peopleCountQuery = includePeople ? Promise.resolve(relatedPeople.length) : (async () => {
661
+ const peopleLinkWhere = await withActiveCustomerPersonCompanyLinkFilter(
697
662
  em,
698
- CustomerPersonCompanyLink,
699
- await withActiveCustomerPersonCompanyLinkFilter(
663
+ {
664
+ company: company.id,
665
+ organizationId: company.organizationId,
666
+ tenantId: company.tenantId
667
+ },
668
+ "customers.companies.GET"
669
+ );
670
+ return filterActivePersonCompanyLinks(
671
+ await findWithDecryption(
700
672
  em,
701
- {
702
- company: company.id,
703
- organizationId: company.organizationId,
704
- tenantId: company.tenantId
705
- },
706
- "customers.companies.GET"
707
- ),
708
- {},
709
- { tenantId: company.tenantId, organizationId: company.organizationId }
710
- )
711
- ).length;
712
- const kpiInteractionRows = canonicalActiveInteractions.length ? canonicalActiveInteractions : await findWithDecryption(
713
- em,
714
- CustomerInteraction,
715
- {
673
+ CustomerPersonCompanyLink,
674
+ peopleLinkWhere,
675
+ {},
676
+ { tenantId: company.tenantId, organizationId: company.organizationId }
677
+ )
678
+ ).length;
679
+ })();
680
+ const [
681
+ activityCount,
682
+ interactionCount,
683
+ todoCount,
684
+ commentsCount,
685
+ addressesCount,
686
+ peopleCount,
687
+ kpiInteractionRows
688
+ ] = await Promise.all([
689
+ em.count(CustomerInteraction, {
716
690
  entity: company.id,
717
691
  organizationId: company.organizationId,
718
692
  tenantId: company.tenantId,
719
693
  deletedAt: null,
694
+ interactionType: { $ne: "task" },
720
695
  ...emailVisibilityFilter
721
- },
722
- {
723
- fields: ["id", "occurredAt", "scheduledAt", "createdAt"],
724
- orderBy: { createdAt: "DESC" }
725
- },
726
- { tenantId: company.tenantId, organizationId: company.organizationId }
727
- );
696
+ }),
697
+ em.count(CustomerInteraction, {
698
+ entity: company.id,
699
+ organizationId: company.organizationId,
700
+ tenantId: company.tenantId,
701
+ deletedAt: null,
702
+ ...emailVisibilityFilter
703
+ }),
704
+ interactionFlags.unified ? em.count(CustomerInteraction, {
705
+ entity: company.id,
706
+ organizationId: company.organizationId,
707
+ tenantId: company.tenantId,
708
+ deletedAt: null,
709
+ interactionType: "task"
710
+ }) : em.count(CustomerTodoLink, {
711
+ entity: company.id,
712
+ organizationId: company.organizationId,
713
+ tenantId: company.tenantId
714
+ }),
715
+ includeComments ? Promise.resolve(comments.length) : em.count(CustomerComment, {
716
+ entity: company.id,
717
+ organizationId: company.organizationId,
718
+ tenantId: company.tenantId
719
+ }),
720
+ includeAddresses ? Promise.resolve(addresses.length) : em.count(CustomerAddress, {
721
+ entity: company.id,
722
+ organizationId: company.organizationId,
723
+ tenantId: company.tenantId
724
+ }),
725
+ peopleCountQuery,
726
+ canonicalActiveInteractions.length ? Promise.resolve(canonicalActiveInteractions) : findWithDecryption(
727
+ em,
728
+ CustomerInteraction,
729
+ {
730
+ entity: company.id,
731
+ organizationId: company.organizationId,
732
+ tenantId: company.tenantId,
733
+ deletedAt: null,
734
+ ...emailVisibilityFilter
735
+ },
736
+ {
737
+ fields: ["id", "occurredAt", "scheduledAt", "createdAt"],
738
+ orderBy: { createdAt: "DESC" }
739
+ },
740
+ { tenantId: company.tenantId, organizationId: company.organizationId }
741
+ )
742
+ ]);
728
743
  const activityTrend = computeActivityTrend(
729
744
  kpiInteractionRows.map((interaction) => interaction.occurredAt ?? interaction.scheduledAt ?? interaction.createdAt).map((value) => value instanceof Date ? value.toISOString() : typeof value === "string" ? value : "").filter((value) => value.length > 0)
730
745
  );