@open-mercato/core 0.5.1-develop.2691.d8a0934b37 → 0.5.1-develop.2694.732417c5ec
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/api_keys/data/entities.js +1 -1
- package/dist/modules/api_keys/data/entities.js.map +1 -1
- package/dist/modules/api_keys/services/apiKeyService.js +5 -5
- package/dist/modules/api_keys/services/apiKeyService.js.map +2 -2
- package/dist/modules/attachments/api/library/[id]/route.js +1 -1
- package/dist/modules/attachments/api/library/[id]/route.js.map +2 -2
- package/dist/modules/attachments/api/library/route.js +7 -9
- package/dist/modules/attachments/api/library/route.js.map +2 -2
- package/dist/modules/attachments/api/partitions/route.js +3 -3
- package/dist/modules/attachments/api/partitions/route.js.map +2 -2
- package/dist/modules/attachments/api/route.js +6 -5
- package/dist/modules/attachments/api/route.js.map +2 -2
- package/dist/modules/attachments/api/transfer/route.js +1 -1
- package/dist/modules/attachments/api/transfer/route.js.map +2 -2
- package/dist/modules/attachments/data/entities.js +2 -1
- package/dist/modules/attachments/data/entities.js.map +2 -2
- package/dist/modules/attachments/lib/ocrQueue.js +1 -1
- package/dist/modules/attachments/lib/ocrQueue.js.map +2 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/export/route.js.map +2 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/route.js.map +2 -2
- package/dist/modules/audit_logs/data/entities.js +1 -1
- package/dist/modules/audit_logs/data/entities.js.map +1 -1
- package/dist/modules/audit_logs/services/actionLogService.js +77 -70
- package/dist/modules/audit_logs/services/actionLogService.js.map +2 -2
- package/dist/modules/auth/api/roles/acl/route.js +1 -1
- package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
- package/dist/modules/auth/api/users/acl/route.js +2 -2
- package/dist/modules/auth/api/users/acl/route.js.map +2 -2
- package/dist/modules/auth/api/users/resend-invite/route.js +1 -1
- package/dist/modules/auth/api/users/resend-invite/route.js.map +2 -2
- package/dist/modules/auth/cli.js +12 -6
- package/dist/modules/auth/cli.js.map +2 -2
- package/dist/modules/auth/commands/users.js +1 -1
- package/dist/modules/auth/commands/users.js.map +2 -2
- package/dist/modules/auth/data/entities.js +1 -1
- package/dist/modules/auth/data/entities.js.map +2 -2
- package/dist/modules/auth/lib/setup-app.js +3 -3
- package/dist/modules/auth/lib/setup-app.js.map +2 -2
- package/dist/modules/auth/services/authService.js +2 -2
- package/dist/modules/auth/services/authService.js.map +2 -2
- package/dist/modules/business_rules/api/rules/route.js +3 -3
- package/dist/modules/business_rules/api/rules/route.js.map +2 -2
- package/dist/modules/business_rules/api/sets/[id]/members/route.js +7 -4
- package/dist/modules/business_rules/api/sets/[id]/members/route.js.map +2 -2
- package/dist/modules/business_rules/api/sets/route.js +3 -3
- package/dist/modules/business_rules/api/sets/route.js.map +2 -2
- package/dist/modules/business_rules/cli.js +1 -1
- package/dist/modules/business_rules/cli.js.map +2 -2
- package/dist/modules/business_rules/data/entities.js +2 -9
- package/dist/modules/business_rules/data/entities.js.map +2 -2
- package/dist/modules/business_rules/lib/rule-engine.js +1 -1
- package/dist/modules/business_rules/lib/rule-engine.js.map +2 -2
- package/dist/modules/catalog/api/option-schemas/route.js +0 -1
- package/dist/modules/catalog/api/option-schemas/route.js.map +2 -2
- package/dist/modules/catalog/data/entities.js +2 -11
- package/dist/modules/catalog/data/entities.js.map +2 -2
- package/dist/modules/configs/data/entities.js +2 -1
- package/dist/modules/configs/data/entities.js.map +2 -2
- package/dist/modules/currencies/commands/fetch-configs.js +3 -3
- package/dist/modules/currencies/commands/fetch-configs.js.map +2 -2
- package/dist/modules/currencies/data/entities.js +1 -1
- package/dist/modules/currencies/data/entities.js.map +2 -2
- package/dist/modules/customer_accounts/api/signup.js +1 -1
- package/dist/modules/customer_accounts/api/signup.js.map +2 -2
- package/dist/modules/customer_accounts/data/entities.js +1 -1
- package/dist/modules/customer_accounts/data/entities.js.map +2 -2
- package/dist/modules/customer_accounts/services/customerInvitationService.js +1 -1
- package/dist/modules/customer_accounts/services/customerInvitationService.js.map +2 -2
- package/dist/modules/customer_accounts/services/customerSessionService.js +1 -1
- package/dist/modules/customer_accounts/services/customerSessionService.js.map +2 -2
- package/dist/modules/customer_accounts/services/customerTokenService.js +12 -7
- package/dist/modules/customer_accounts/services/customerTokenService.js.map +2 -2
- package/dist/modules/customers/api/interactions/conflicts/route.js +19 -17
- package/dist/modules/customers/api/interactions/conflicts/route.js.map +2 -2
- package/dist/modules/customers/api/interactions/counts/route.js +7 -6
- package/dist/modules/customers/api/interactions/counts/route.js.map +2 -2
- package/dist/modules/customers/api/interactions/route.js +28 -42
- package/dist/modules/customers/api/interactions/route.js.map +2 -2
- package/dist/modules/customers/api/utils.js +29 -24
- package/dist/modules/customers/api/utils.js.map +2 -2
- package/dist/modules/customers/cli.js +45 -40
- package/dist/modules/customers/cli.js.map +2 -2
- package/dist/modules/customers/commands/dictionaries.js +1 -1
- package/dist/modules/customers/commands/dictionaries.js.map +2 -2
- package/dist/modules/customers/commands/tags.js +1 -1
- package/dist/modules/customers/commands/tags.js.map +2 -2
- package/dist/modules/customers/data/entities.js +2 -12
- package/dist/modules/customers/data/entities.js.map +2 -2
- package/dist/modules/customers/lib/interactionProjection.js +18 -15
- package/dist/modules/customers/lib/interactionProjection.js.map +2 -2
- package/dist/modules/customers/lib/personCompanyLinkTable.js +6 -8
- package/dist/modules/customers/lib/personCompanyLinkTable.js.map +2 -2
- package/dist/modules/dashboards/api/roles/widgets/route.js +1 -1
- package/dist/modules/dashboards/api/roles/widgets/route.js.map +2 -2
- package/dist/modules/dashboards/api/users/widgets/route.js +1 -1
- package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
- package/dist/modules/dashboards/data/entities.js +1 -1
- package/dist/modules/dashboards/data/entities.js.map +1 -1
- package/dist/modules/data_sync/api/mappings/route.js +1 -1
- package/dist/modules/data_sync/api/mappings/route.js.map +2 -2
- package/dist/modules/data_sync/data/entities.js +2 -1
- package/dist/modules/data_sync/data/entities.js.map +2 -2
- package/dist/modules/data_sync/lib/id-mapping.js +1 -1
- package/dist/modules/data_sync/lib/id-mapping.js.map +2 -2
- package/dist/modules/data_sync/lib/sync-run-service.js +1 -1
- package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
- package/dist/modules/dictionaries/commands/factory.js +1 -1
- package/dist/modules/dictionaries/commands/factory.js.map +2 -2
- package/dist/modules/dictionaries/data/entities.js +2 -9
- package/dist/modules/dictionaries/data/entities.js.map +2 -2
- package/dist/modules/directory/commands/organizations.js +4 -4
- package/dist/modules/directory/commands/organizations.js.map +2 -2
- package/dist/modules/directory/data/entities.js +2 -1
- package/dist/modules/directory/data/entities.js.map +2 -2
- package/dist/modules/entities/api/definitions.js +2 -2
- package/dist/modules/entities/api/definitions.js.map +2 -2
- package/dist/modules/entities/api/encryption.js +2 -2
- package/dist/modules/entities/api/encryption.js.map +2 -2
- package/dist/modules/entities/api/relations/options.js +2 -2
- package/dist/modules/entities/api/relations/options.js.map +2 -2
- package/dist/modules/entities/cli.js +4 -4
- package/dist/modules/entities/cli.js.map +2 -2
- package/dist/modules/entities/data/entities.js +1 -1
- package/dist/modules/entities/data/entities.js.map +2 -2
- package/dist/modules/entities/lib/field-definitions.js +2 -2
- package/dist/modules/entities/lib/field-definitions.js.map +2 -2
- package/dist/modules/entities/lib/register.js +1 -1
- package/dist/modules/entities/lib/register.js.map +2 -2
- package/dist/modules/feature_toggles/data/entities.js +2 -9
- package/dist/modules/feature_toggles/data/entities.js.map +2 -2
- package/dist/modules/inbox_ops/api/proposals/counts/route.js +3 -6
- package/dist/modules/inbox_ops/api/proposals/counts/route.js.map +2 -2
- package/dist/modules/inbox_ops/data/entities.js +2 -8
- package/dist/modules/inbox_ops/data/entities.js.map +2 -2
- package/dist/modules/inbox_ops/lib/messagesIntegration.js +6 -6
- package/dist/modules/inbox_ops/lib/messagesIntegration.js.map +2 -2
- package/dist/modules/integrations/data/entities.js +2 -1
- package/dist/modules/integrations/data/entities.js.map +2 -2
- package/dist/modules/integrations/lib/credentials-service.js +1 -1
- package/dist/modules/integrations/lib/credentials-service.js.map +2 -2
- package/dist/modules/integrations/lib/log-service.js +1 -1
- package/dist/modules/integrations/lib/log-service.js.map +2 -2
- package/dist/modules/integrations/lib/state-service.js +1 -1
- package/dist/modules/integrations/lib/state-service.js.map +2 -2
- package/dist/modules/messages/api/route.js +90 -93
- package/dist/modules/messages/api/route.js.map +2 -2
- package/dist/modules/messages/api/unread-count/route.js +8 -7
- package/dist/modules/messages/api/unread-count/route.js.map +2 -2
- package/dist/modules/messages/commands/confirmations.js +1 -1
- package/dist/modules/messages/commands/confirmations.js.map +2 -2
- package/dist/modules/messages/commands/messages.js +3 -3
- package/dist/modules/messages/commands/messages.js.map +2 -2
- package/dist/modules/messages/data/entities.js +2 -1
- package/dist/modules/messages/data/entities.js.map +2 -2
- package/dist/modules/messages/lib/email-sender.js +1 -1
- package/dist/modules/messages/lib/email-sender.js.map +2 -2
- package/dist/modules/messages/lib/searchLookup.js +8 -8
- package/dist/modules/messages/lib/searchLookup.js.map +2 -2
- package/dist/modules/messages/lib/tokenConsumption.js +9 -4
- package/dist/modules/messages/lib/tokenConsumption.js.map +2 -2
- package/dist/modules/notifications/data/entities.js +2 -1
- package/dist/modules/notifications/data/entities.js.map +2 -2
- package/dist/modules/notifications/lib/notificationRecipients.js +15 -5
- package/dist/modules/notifications/lib/notificationRecipients.js.map +2 -2
- package/dist/modules/notifications/lib/notificationService.js +39 -34
- package/dist/modules/notifications/lib/notificationService.js.map +2 -2
- package/dist/modules/notifications/workers/create-notification.worker.js +14 -13
- package/dist/modules/notifications/workers/create-notification.worker.js.map +2 -2
- package/dist/modules/payment_gateways/api/transactions/route.js +2 -2
- package/dist/modules/payment_gateways/api/transactions/route.js.map +2 -2
- package/dist/modules/payment_gateways/data/entities.js +2 -1
- package/dist/modules/payment_gateways/data/entities.js.map +2 -2
- package/dist/modules/payment_gateways/lib/gateway-service.js +1 -1
- package/dist/modules/payment_gateways/lib/gateway-service.js.map +2 -2
- package/dist/modules/payment_gateways/lib/webhook-utils.js +2 -2
- package/dist/modules/payment_gateways/lib/webhook-utils.js.map +2 -2
- package/dist/modules/perspectives/data/entities.js +1 -1
- package/dist/modules/perspectives/data/entities.js.map +2 -2
- package/dist/modules/planner/data/entities.js +1 -1
- package/dist/modules/planner/data/entities.js.map +2 -2
- package/dist/modules/progress/data/entities.js +2 -1
- package/dist/modules/progress/data/entities.js.map +2 -2
- package/dist/modules/progress/lib/progressServiceImpl.js +1 -1
- package/dist/modules/progress/lib/progressServiceImpl.js.map +2 -2
- package/dist/modules/query_index/api/status.js +66 -57
- package/dist/modules/query_index/api/status.js.map +2 -2
- package/dist/modules/query_index/cli.js +39 -24
- package/dist/modules/query_index/cli.js.map +2 -2
- package/dist/modules/query_index/data/entities.js +1 -1
- package/dist/modules/query_index/data/entities.js.map +2 -2
- package/dist/modules/query_index/di.js +25 -13
- package/dist/modules/query_index/di.js.map +2 -2
- package/dist/modules/query_index/lib/batch.js +31 -33
- package/dist/modules/query_index/lib/batch.js.map +2 -2
- package/dist/modules/query_index/lib/coverage.js +63 -50
- package/dist/modules/query_index/lib/coverage.js.map +2 -2
- package/dist/modules/query_index/lib/engine.js +592 -588
- package/dist/modules/query_index/lib/engine.js.map +2 -2
- package/dist/modules/query_index/lib/indexer.js +74 -47
- package/dist/modules/query_index/lib/indexer.js.map +2 -2
- package/dist/modules/query_index/lib/jobs.js +37 -24
- package/dist/modules/query_index/lib/jobs.js.map +2 -2
- package/dist/modules/query_index/lib/purge.js +19 -11
- package/dist/modules/query_index/lib/purge.js.map +2 -2
- package/dist/modules/query_index/lib/reindexer.js +47 -44
- package/dist/modules/query_index/lib/reindexer.js.map +2 -2
- package/dist/modules/query_index/lib/search-tokens.js +47 -25
- package/dist/modules/query_index/lib/search-tokens.js.map +2 -2
- package/dist/modules/query_index/lib/stale.js +14 -12
- package/dist/modules/query_index/lib/stale.js.map +2 -2
- package/dist/modules/query_index/lib/subscriber-scope.js +2 -2
- package/dist/modules/query_index/lib/subscriber-scope.js.map +2 -2
- package/dist/modules/query_index/subscribers/delete_one.js +3 -2
- package/dist/modules/query_index/subscribers/delete_one.js.map +2 -2
- package/dist/modules/resources/commands/tag-assignments.js +1 -1
- package/dist/modules/resources/commands/tag-assignments.js.map +2 -2
- package/dist/modules/resources/commands/tags.js +1 -1
- package/dist/modules/resources/commands/tags.js.map +2 -2
- package/dist/modules/resources/data/entities.js +2 -1
- package/dist/modules/resources/data/entities.js.map +2 -2
- package/dist/modules/sales/commands/documentAddresses.js +2 -2
- package/dist/modules/sales/commands/documentAddresses.js.map +2 -2
- package/dist/modules/sales/commands/notes.js.map +2 -2
- package/dist/modules/sales/commands/tags.js +1 -1
- package/dist/modules/sales/commands/tags.js.map +2 -2
- package/dist/modules/sales/data/enrichers.js +9 -8
- package/dist/modules/sales/data/enrichers.js.map +2 -2
- package/dist/modules/sales/data/entities.js +2 -11
- package/dist/modules/sales/data/entities.js.map +2 -2
- package/dist/modules/shipping_carriers/data/entities.js +2 -1
- package/dist/modules/shipping_carriers/data/entities.js.map +2 -2
- package/dist/modules/shipping_carriers/lib/shipping-service.js +1 -1
- package/dist/modules/shipping_carriers/lib/shipping-service.js.map +2 -2
- package/dist/modules/shipping_carriers/lib/webhook-utils.js +2 -2
- package/dist/modules/shipping_carriers/lib/webhook-utils.js.map +2 -2
- package/dist/modules/staff/data/entities.js +1 -1
- package/dist/modules/staff/data/entities.js.map +2 -2
- package/dist/modules/translations/api/[entityType]/[entityId]/route.js +3 -5
- package/dist/modules/translations/api/[entityType]/[entityId]/route.js.map +2 -2
- package/dist/modules/translations/api/context.js +2 -2
- package/dist/modules/translations/api/context.js.map +2 -2
- package/dist/modules/translations/commands/translations.js +46 -39
- package/dist/modules/translations/commands/translations.js.map +2 -2
- package/dist/modules/translations/components/TranslationManager.js +19 -10
- package/dist/modules/translations/components/TranslationManager.js.map +2 -2
- package/dist/modules/translations/data/entities.js +1 -1
- package/dist/modules/translations/data/entities.js.map +2 -2
- package/dist/modules/translations/lib/apply.js +4 -4
- package/dist/modules/translations/lib/apply.js.map +2 -2
- package/dist/modules/translations/lib/batch.js +3 -2
- package/dist/modules/translations/lib/batch.js.map +2 -2
- package/dist/modules/translations/subscribers/cleanup.js +3 -5
- package/dist/modules/translations/subscribers/cleanup.js.map +2 -2
- package/dist/modules/workflows/api/definitions/route.js +1 -1
- package/dist/modules/workflows/api/definitions/route.js.map +2 -2
- package/dist/modules/workflows/cli.js +5 -5
- package/dist/modules/workflows/cli.js.map +2 -2
- package/dist/modules/workflows/data/entities.js +2 -1
- package/dist/modules/workflows/data/entities.js.map +2 -2
- package/dist/modules/workflows/lib/event-logger.js +2 -2
- package/dist/modules/workflows/lib/event-logger.js.map +2 -2
- package/dist/modules/workflows/lib/seeds.js +16 -1
- package/dist/modules/workflows/lib/seeds.js.map +2 -2
- package/dist/modules/workflows/lib/step-handler.js +3 -3
- package/dist/modules/workflows/lib/step-handler.js.map +2 -2
- package/dist/modules/workflows/lib/task-handler.js +1 -1
- package/dist/modules/workflows/lib/task-handler.js.map +2 -2
- package/dist/modules/workflows/lib/transition-handler.js +1 -1
- package/dist/modules/workflows/lib/transition-handler.js.map +2 -2
- package/dist/modules/workflows/lib/workflow-executor.js +2 -2
- package/dist/modules/workflows/lib/workflow-executor.js.map +2 -2
- package/jest.config.cjs +4 -2
- package/package.json +3 -3
- package/src/modules/api_keys/data/entities.ts +1 -1
- package/src/modules/api_keys/services/apiKeyService.ts +5 -5
- package/src/modules/attachments/api/library/[id]/route.ts +1 -1
- package/src/modules/attachments/api/library/route.ts +10 -12
- package/src/modules/attachments/api/partitions/route.ts +3 -3
- package/src/modules/attachments/api/route.ts +10 -8
- package/src/modules/attachments/api/transfer/route.ts +1 -1
- package/src/modules/attachments/data/entities.ts +2 -1
- package/src/modules/attachments/lib/ocrQueue.ts +1 -1
- package/src/modules/audit_logs/api/audit-logs/actions/export/route.ts +4 -4
- package/src/modules/audit_logs/api/audit-logs/actions/route.ts +4 -4
- package/src/modules/audit_logs/data/entities.ts +1 -1
- package/src/modules/audit_logs/services/actionLogService.ts +96 -87
- package/src/modules/auth/api/roles/acl/route.ts +1 -1
- package/src/modules/auth/api/users/acl/route.ts +2 -2
- package/src/modules/auth/api/users/resend-invite/route.ts +1 -1
- package/src/modules/auth/cli.ts +46 -40
- package/src/modules/auth/commands/users.ts +1 -1
- package/src/modules/auth/data/entities.ts +1 -1
- package/src/modules/auth/lib/setup-app.ts +3 -3
- package/src/modules/auth/services/authService.ts +2 -2
- package/src/modules/business_rules/api/rules/route.ts +3 -3
- package/src/modules/business_rules/api/sets/[id]/members/route.ts +7 -4
- package/src/modules/business_rules/api/sets/route.ts +3 -3
- package/src/modules/business_rules/cli.ts +1 -1
- package/src/modules/business_rules/data/entities.ts +2 -9
- package/src/modules/business_rules/lib/rule-engine.ts +1 -1
- package/src/modules/catalog/api/option-schemas/route.ts +0 -1
- package/src/modules/catalog/data/entities.ts +2 -11
- package/src/modules/configs/data/entities.ts +2 -1
- package/src/modules/currencies/commands/fetch-configs.ts +3 -3
- package/src/modules/currencies/data/entities.ts +1 -1
- package/src/modules/customer_accounts/api/signup.ts +1 -1
- package/src/modules/customer_accounts/data/entities.ts +1 -1
- package/src/modules/customer_accounts/services/customerInvitationService.ts +1 -1
- package/src/modules/customer_accounts/services/customerSessionService.ts +1 -1
- package/src/modules/customer_accounts/services/customerTokenService.ts +26 -15
- package/src/modules/customers/api/interactions/conflicts/route.ts +26 -23
- package/src/modules/customers/api/interactions/counts/route.ts +13 -11
- package/src/modules/customers/api/interactions/route.ts +32 -44
- package/src/modules/customers/api/utils.ts +45 -37
- package/src/modules/customers/cli.ts +88 -67
- package/src/modules/customers/commands/dictionaries.ts +1 -1
- package/src/modules/customers/commands/tags.ts +1 -1
- package/src/modules/customers/data/entities.ts +2 -12
- package/src/modules/customers/lib/interactionProjection.ts +36 -25
- package/src/modules/customers/lib/personCompanyLinkTable.ts +13 -18
- package/src/modules/dashboards/api/roles/widgets/route.ts +1 -1
- package/src/modules/dashboards/api/users/widgets/route.ts +1 -1
- package/src/modules/dashboards/data/entities.ts +1 -1
- package/src/modules/data_sync/api/mappings/route.ts +1 -1
- package/src/modules/data_sync/data/entities.ts +2 -1
- package/src/modules/data_sync/lib/id-mapping.ts +1 -1
- package/src/modules/data_sync/lib/sync-run-service.ts +1 -1
- package/src/modules/dictionaries/commands/factory.ts +1 -1
- package/src/modules/dictionaries/data/entities.ts +2 -9
- package/src/modules/directory/commands/organizations.ts +4 -4
- package/src/modules/directory/data/entities.ts +2 -1
- package/src/modules/entities/api/definitions.ts +2 -2
- package/src/modules/entities/api/encryption.ts +2 -2
- package/src/modules/entities/api/relations/options.ts +8 -3
- package/src/modules/entities/cli.ts +4 -4
- package/src/modules/entities/data/entities.ts +1 -1
- package/src/modules/entities/lib/field-definitions.ts +2 -2
- package/src/modules/entities/lib/register.ts +1 -1
- package/src/modules/feature_toggles/data/entities.ts +2 -9
- package/src/modules/inbox_ops/api/proposals/counts/route.ts +10 -10
- package/src/modules/inbox_ops/data/entities.ts +2 -8
- package/src/modules/inbox_ops/lib/messagesIntegration.ts +12 -11
- package/src/modules/integrations/data/entities.ts +2 -1
- package/src/modules/integrations/lib/credentials-service.ts +1 -1
- package/src/modules/integrations/lib/log-service.ts +1 -1
- package/src/modules/integrations/lib/state-service.ts +1 -1
- package/src/modules/messages/api/route.ts +134 -123
- package/src/modules/messages/api/unread-count/route.ts +19 -16
- package/src/modules/messages/commands/confirmations.ts +1 -1
- package/src/modules/messages/commands/messages.ts +3 -3
- package/src/modules/messages/data/entities.ts +2 -1
- package/src/modules/messages/lib/email-sender.ts +1 -1
- package/src/modules/messages/lib/searchLookup.ts +16 -13
- package/src/modules/messages/lib/tokenConsumption.ts +16 -8
- package/src/modules/notifications/data/entities.ts +2 -1
- package/src/modules/notifications/lib/notificationRecipients.ts +42 -26
- package/src/modules/notifications/lib/notificationService.ts +53 -42
- package/src/modules/notifications/workers/create-notification.worker.ts +20 -17
- package/src/modules/payment_gateways/api/transactions/route.ts +2 -2
- package/src/modules/payment_gateways/data/entities.ts +2 -1
- package/src/modules/payment_gateways/lib/gateway-service.ts +1 -1
- package/src/modules/payment_gateways/lib/webhook-utils.ts +2 -2
- package/src/modules/perspectives/data/entities.ts +1 -1
- package/src/modules/planner/data/entities.ts +1 -1
- package/src/modules/progress/data/entities.ts +2 -1
- package/src/modules/progress/lib/progressServiceImpl.ts +1 -1
- package/src/modules/query_index/api/status.ts +85 -71
- package/src/modules/query_index/cli.ts +51 -31
- package/src/modules/query_index/data/entities.ts +1 -1
- package/src/modules/query_index/di.ts +41 -16
- package/src/modules/query_index/lib/batch.ts +68 -55
- package/src/modules/query_index/lib/coverage.ts +115 -88
- package/src/modules/query_index/lib/engine.ts +1036 -1096
- package/src/modules/query_index/lib/indexer.ts +115 -79
- package/src/modules/query_index/lib/jobs.ts +51 -31
- package/src/modules/query_index/lib/purge.ts +25 -19
- package/src/modules/query_index/lib/reindexer.ts +97 -84
- package/src/modules/query_index/lib/search-tokens.ts +67 -36
- package/src/modules/query_index/lib/stale.ts +14 -17
- package/src/modules/query_index/lib/subscriber-scope.ts +6 -5
- package/src/modules/query_index/subscribers/delete_one.ts +9 -6
- package/src/modules/resources/commands/tag-assignments.ts +1 -1
- package/src/modules/resources/commands/tags.ts +1 -1
- package/src/modules/resources/data/entities.ts +2 -1
- package/src/modules/sales/commands/documentAddresses.ts +2 -2
- package/src/modules/sales/commands/notes.ts +1 -1
- package/src/modules/sales/commands/tags.ts +1 -1
- package/src/modules/sales/data/enrichers.ts +17 -13
- package/src/modules/sales/data/entities.ts +2 -11
- package/src/modules/shipping_carriers/data/entities.ts +2 -1
- package/src/modules/shipping_carriers/lib/shipping-service.ts +1 -1
- package/src/modules/shipping_carriers/lib/webhook-utils.ts +2 -2
- package/src/modules/staff/data/entities.ts +1 -1
- package/src/modules/translations/api/[entityType]/[entityId]/route.ts +14 -11
- package/src/modules/translations/api/context.ts +4 -4
- package/src/modules/translations/commands/translations.ts +116 -81
- package/src/modules/translations/components/TranslationManager.tsx +23 -14
- package/src/modules/translations/data/entities.ts +1 -1
- package/src/modules/translations/i18n/de.json +1 -0
- package/src/modules/translations/i18n/en.json +1 -0
- package/src/modules/translations/i18n/es.json +1 -0
- package/src/modules/translations/i18n/pl.json +1 -0
- package/src/modules/translations/lib/apply.ts +6 -6
- package/src/modules/translations/lib/batch.ts +9 -7
- package/src/modules/translations/subscribers/cleanup.ts +10 -11
- package/src/modules/workflows/api/definitions/route.ts +1 -1
- package/src/modules/workflows/cli.ts +5 -5
- package/src/modules/workflows/data/entities.ts +2 -1
- package/src/modules/workflows/lib/event-logger.ts +2 -2
- package/src/modules/workflows/lib/seeds.ts +16 -1
- package/src/modules/workflows/lib/step-handler.ts +3 -3
- package/src/modules/workflows/lib/task-handler.ts +1 -1
- package/src/modules/workflows/lib/transition-handler.ts +1 -1
- 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
|
|
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
|
-
|
|
123
|
-
.
|
|
124
|
-
.
|
|
125
|
-
.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
148
|
-
.
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
382
|
-
.
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
418
|
-
.
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
|
|
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
|
|
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(
|
|
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
|
|
243
|
-
|
|
244
|
-
|
|
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
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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(
|
|
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(
|
|
302
|
+
async function getColumnSet(db: Kysely<any>, tableName: string): Promise<Set<string>> {
|
|
288
303
|
try {
|
|
289
|
-
const
|
|
290
|
-
|
|
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
|
|
359
|
+
const db = em.getKysely<any>()
|
|
340
360
|
const tableName = resolveEntityTableName(em, entity)
|
|
341
|
-
const columns = await getColumnSet(
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
504
|
+
db,
|
|
485
505
|
entityType: entity,
|
|
486
506
|
tableName,
|
|
487
507
|
orgOverride: orgId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entity, PrimaryKey, Property,
|
|
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
|
|
75
|
+
const db = (em as any).getKysely()
|
|
76
76
|
const table = resolveEntityTableName(em, entityType)
|
|
77
|
-
const row = await
|
|
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
|
|
85
|
-
|
|
86
|
-
.
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
|
127
|
+
const db = (em as any).getKysely()
|
|
111
128
|
const table = resolveEntityTableName(em, entityType)
|
|
112
|
-
const row = await
|
|
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
|
|
147
|
+
const db = (em as any).getKysely()
|
|
127
148
|
const cfEntityIds: string[] = []
|
|
128
|
-
|
|
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
|
})
|