@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.
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
-
import type
|
|
2
|
+
import { type Kysely, sql } from 'kysely'
|
|
3
3
|
import { resolveEntityTableName } from '@open-mercato/shared/lib/query/engine'
|
|
4
4
|
import { resolveTenantEncryptionService } from '@open-mercato/shared/lib/encryption/customFieldValues'
|
|
5
5
|
import { decryptIndexDocForSearch, encryptIndexDocForStorage } from '@open-mercato/shared/lib/encryption/indexDoc'
|
|
@@ -41,7 +41,7 @@ const COVERAGE_REFRESH_THROTTLE_MS = 5 * 60 * 1000
|
|
|
41
41
|
const lastCoverageReset = new Map<string, number>()
|
|
42
42
|
|
|
43
43
|
async function cleanupLegacyJobScopes(
|
|
44
|
-
|
|
44
|
+
db: Kysely<any>,
|
|
45
45
|
options: {
|
|
46
46
|
entityType: string
|
|
47
47
|
organizationId: string | null
|
|
@@ -49,12 +49,13 @@ async function cleanupLegacyJobScopes(
|
|
|
49
49
|
activePartitionCount: number | null
|
|
50
50
|
},
|
|
51
51
|
): Promise<void> {
|
|
52
|
-
await
|
|
53
|
-
.
|
|
54
|
-
.
|
|
55
|
-
.
|
|
56
|
-
.
|
|
57
|
-
.
|
|
52
|
+
await db
|
|
53
|
+
.deleteFrom('entity_index_jobs' as any)
|
|
54
|
+
.where('entity_type' as any, '=', options.entityType)
|
|
55
|
+
.where(sql<boolean>`organization_id is not distinct from ${options.organizationId}`)
|
|
56
|
+
.where(sql<boolean>`tenant_id is not distinct from ${options.tenantId}`)
|
|
57
|
+
.where(sql<boolean>`partition_count is distinct from ${options.activePartitionCount}`)
|
|
58
|
+
.execute()
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
function toNumber(value: unknown): number {
|
|
@@ -66,10 +67,15 @@ function toNumber(value: unknown): number {
|
|
|
66
67
|
return 0
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
async function getColumnSet(
|
|
70
|
+
async function getColumnSet(db: Kysely<any>, tableName: string): Promise<Set<string>> {
|
|
70
71
|
try {
|
|
71
|
-
const
|
|
72
|
-
|
|
72
|
+
const rows = await db
|
|
73
|
+
.selectFrom('information_schema.columns' as any)
|
|
74
|
+
.select(['column_name' as any])
|
|
75
|
+
.where(sql<boolean>`table_schema = current_schema()`)
|
|
76
|
+
.where('table_name' as any, '=', tableName)
|
|
77
|
+
.execute() as Array<{ column_name: string }>
|
|
78
|
+
return new Set(rows.map((row) => String(row.column_name).toLowerCase()))
|
|
73
79
|
} catch {
|
|
74
80
|
return new Set<string>()
|
|
75
81
|
}
|
|
@@ -111,7 +117,7 @@ export async function reindexEntity(
|
|
|
111
117
|
: null
|
|
112
118
|
const resetCoverage = options?.resetCoverage ?? (!usingPartitions || partitionIndex === 0)
|
|
113
119
|
|
|
114
|
-
const
|
|
120
|
+
const db = (em as any).getKysely() as Kysely<any>
|
|
115
121
|
const table = resolveEntityTableName(em, entityType)
|
|
116
122
|
if (entityType === 'query_index:search_token' || table === 'search_tokens') {
|
|
117
123
|
return {
|
|
@@ -121,7 +127,7 @@ export async function reindexEntity(
|
|
|
121
127
|
scopes: [],
|
|
122
128
|
}
|
|
123
129
|
}
|
|
124
|
-
const columns = await getColumnSet(
|
|
130
|
+
const columns = await getColumnSet(db, table)
|
|
125
131
|
const hasOrgCol = columns.has('organization_id')
|
|
126
132
|
const hasTenantCol = columns.has('tenant_id')
|
|
127
133
|
const hasDeletedCol = columns.has('deleted_at')
|
|
@@ -135,16 +141,16 @@ export async function reindexEntity(
|
|
|
135
141
|
}
|
|
136
142
|
|
|
137
143
|
if (!force) {
|
|
138
|
-
const activeJob = await
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
const activeJob = await db
|
|
145
|
+
.selectFrom('entity_index_jobs' as any)
|
|
146
|
+
.select(['id' as any])
|
|
147
|
+
.where('entity_type' as any, '=', entityType)
|
|
148
|
+
.where('finished_at' as any, 'is', null as any)
|
|
149
|
+
.where(sql<boolean>`organization_id is not distinct from ${null}`)
|
|
150
|
+
.where(sql<boolean>`tenant_id is not distinct from ${tenantId ?? null}`)
|
|
151
|
+
.where(sql<boolean>`partition_index is not distinct from ${partitionIndex}`)
|
|
152
|
+
.where(sql<boolean>`partition_count is not distinct from ${usingPartitions ? partitionCountRaw : null}`)
|
|
153
|
+
.executeTakeFirst()
|
|
148
154
|
if (activeJob) {
|
|
149
155
|
return {
|
|
150
156
|
processed: 0,
|
|
@@ -156,7 +162,7 @@ export async function reindexEntity(
|
|
|
156
162
|
}
|
|
157
163
|
|
|
158
164
|
if (resetCoverage) {
|
|
159
|
-
await cleanupLegacyJobScopes(
|
|
165
|
+
await cleanupLegacyJobScopes(db, {
|
|
160
166
|
entityType,
|
|
161
167
|
organizationId: jobScope.organizationId ?? null,
|
|
162
168
|
tenantId: jobScope.tenantId ?? null,
|
|
@@ -165,19 +171,24 @@ export async function reindexEntity(
|
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
const scopeKey = (tenantValue: string | null, orgValue: string | null) => `${tenantValue ?? '__null__'}|${orgValue ?? '__null__'}`
|
|
168
|
-
|
|
169
|
-
|
|
174
|
+
|
|
175
|
+
const applyBaseWhere = <QB extends { where: (...args: any[]) => QB }>(q: QB): QB => {
|
|
176
|
+
let chain = q
|
|
177
|
+
if (hasDeletedCol) chain = chain.where('b.deleted_at' as any, 'is', null as any)
|
|
170
178
|
if (tenantId !== undefined && hasTenantCol) {
|
|
171
|
-
|
|
172
|
-
|
|
179
|
+
chain = tenantId === null
|
|
180
|
+
? chain.where('b.tenant_id' as any, 'is', null as any)
|
|
181
|
+
: chain.where('b.tenant_id' as any, '=', tenantId)
|
|
173
182
|
}
|
|
174
183
|
if (organizationId !== undefined && hasOrgCol) {
|
|
175
|
-
|
|
176
|
-
|
|
184
|
+
chain = organizationId === null
|
|
185
|
+
? chain.where('b.organization_id' as any, 'is', null as any)
|
|
186
|
+
: chain.where('b.organization_id' as any, '=', organizationId)
|
|
177
187
|
}
|
|
178
188
|
if (usingPartitions && partitionIndex !== null) {
|
|
179
|
-
|
|
189
|
+
chain = chain.where(sql<boolean>`mod(abs(hashtext(b.id::text)), ${partitionCountRaw}) = ${partitionIndex}`)
|
|
180
190
|
}
|
|
191
|
+
return chain
|
|
181
192
|
}
|
|
182
193
|
|
|
183
194
|
type ScopeStats = { tenantId: string | null; organizationId: string | null; count: number }
|
|
@@ -191,17 +202,16 @@ export async function reindexEntity(
|
|
|
191
202
|
const groupByOrg = hasOrgCol && organizationId === undefined
|
|
192
203
|
|
|
193
204
|
if (groupByTenant || groupByOrg) {
|
|
194
|
-
|
|
195
|
-
.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
})
|
|
205
|
+
let groupQuery = applyBaseWhere(
|
|
206
|
+
db.selectFrom(`${table} as b` as any).select(sql<number>`count(*)`.as('count')),
|
|
207
|
+
)
|
|
208
|
+
if (groupByTenant) {
|
|
209
|
+
groupQuery = groupQuery.select('b.tenant_id as tenant_id' as any).groupBy('b.tenant_id' as any)
|
|
210
|
+
}
|
|
211
|
+
if (groupByOrg) {
|
|
212
|
+
groupQuery = groupQuery.select('b.organization_id as organization_id' as any).groupBy('b.organization_id' as any)
|
|
213
|
+
}
|
|
214
|
+
const rows = await groupQuery.execute() as Array<Record<string, unknown>>
|
|
205
215
|
for (const row of rows) {
|
|
206
216
|
const bucketTenant = groupByTenant
|
|
207
217
|
? ((row as any)?.tenant_id ?? null)
|
|
@@ -212,25 +222,26 @@ export async function reindexEntity(
|
|
|
212
222
|
registerBaseCount(bucketTenant, bucketOrg, toNumber((row as any)?.count))
|
|
213
223
|
}
|
|
214
224
|
} else {
|
|
215
|
-
const row = await
|
|
216
|
-
.
|
|
217
|
-
|
|
218
|
-
.first()
|
|
225
|
+
const row = await applyBaseWhere(
|
|
226
|
+
db.selectFrom(`${table} as b` as any).select(sql<number>`count(*)`.as('count')),
|
|
227
|
+
).executeTakeFirst() as { count: unknown } | undefined
|
|
219
228
|
const bucketTenant = tenantId === undefined ? null : tenantId ?? null
|
|
220
229
|
const bucketOrg = organizationId === undefined ? null : organizationId ?? null
|
|
221
230
|
registerBaseCount(bucketTenant, bucketOrg, toNumber(row?.count))
|
|
222
231
|
}
|
|
223
232
|
|
|
224
233
|
const total = Array.from(baseCounts.values()).reduce((acc, value) => acc + (Number.isFinite(value.count) ? value.count : 0), 0)
|
|
225
|
-
await prepareJob(
|
|
226
|
-
const jobRow = await
|
|
227
|
-
.
|
|
228
|
-
.
|
|
229
|
-
.
|
|
230
|
-
.
|
|
231
|
-
.
|
|
232
|
-
.
|
|
233
|
-
.
|
|
234
|
+
await prepareJob(db, jobScope, 'reindexing', { totalCount: total })
|
|
235
|
+
const jobRow = await db
|
|
236
|
+
.selectFrom('entity_index_jobs' as any)
|
|
237
|
+
.select(['started_at' as any])
|
|
238
|
+
.where('entity_type' as any, '=', entityType)
|
|
239
|
+
.where('organization_id' as any, 'is', null as any)
|
|
240
|
+
.where(sql<boolean>`tenant_id is not distinct from ${tenantId ?? null}`)
|
|
241
|
+
.where(sql<boolean>`partition_index is not distinct from ${partitionIndex}`)
|
|
242
|
+
.where(sql<boolean>`partition_count is not distinct from ${usingPartitions ? partitionCountRaw : null}`)
|
|
243
|
+
.orderBy('started_at' as any, 'desc')
|
|
244
|
+
.executeTakeFirst() as { started_at: Date | string } | undefined
|
|
234
245
|
const jobStartedAt = jobRow?.started_at ? new Date(jobRow.started_at) : new Date()
|
|
235
246
|
const deriveOrg = deriveOrgFromId.has(entityType)
|
|
236
247
|
? (row: AnyRow) => String(row.id)
|
|
@@ -259,25 +270,25 @@ export async function reindexEntity(
|
|
|
259
270
|
|
|
260
271
|
if (resetCoverage) {
|
|
261
272
|
if (force) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
})
|
|
273
|
+
try {
|
|
274
|
+
let purgeQuery = db
|
|
275
|
+
.deleteFrom('entity_indexes' as any)
|
|
276
|
+
.where('entity_type' as any, '=', entityType)
|
|
277
|
+
if (tenantId !== undefined) {
|
|
278
|
+
purgeQuery = purgeQuery.where(sql<boolean>`tenant_id is not distinct from ${tenantId ?? null}`)
|
|
279
|
+
}
|
|
280
|
+
if (organizationId !== undefined) {
|
|
281
|
+
purgeQuery = purgeQuery.where(sql<boolean>`organization_id is not distinct from ${organizationId ?? null}`)
|
|
282
|
+
}
|
|
283
|
+
await purgeQuery.execute()
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.warn('[HybridQueryEngine] Failed to purge index rows before force reindex', {
|
|
286
|
+
entityType,
|
|
287
|
+
tenantId: tenantId ?? null,
|
|
288
|
+
organizationId: organizationId ?? null,
|
|
289
|
+
error: error instanceof Error ? error.message : error,
|
|
280
290
|
})
|
|
291
|
+
}
|
|
281
292
|
|
|
282
293
|
if (emitVectorize && eventBus) {
|
|
283
294
|
if (tenantId !== undefined) {
|
|
@@ -326,15 +337,17 @@ export async function reindexEntity(
|
|
|
326
337
|
|
|
327
338
|
try {
|
|
328
339
|
while (true) {
|
|
329
|
-
let query =
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
340
|
+
let query = applyBaseWhere(
|
|
341
|
+
db
|
|
342
|
+
.selectFrom(`${table} as b` as any)
|
|
343
|
+
.selectAll('b' as any)
|
|
344
|
+
.orderBy('b.id' as any, 'asc')
|
|
345
|
+
.limit(batchSize),
|
|
346
|
+
)
|
|
334
347
|
if (lastId !== null) {
|
|
335
|
-
query = query.where('b.id', '>', lastId)
|
|
348
|
+
query = query.where('b.id' as any, '>', lastId)
|
|
336
349
|
}
|
|
337
|
-
const rows = await query as AnyRow[]
|
|
350
|
+
const rows = await query.execute() as AnyRow[]
|
|
338
351
|
if (!rows.length) break
|
|
339
352
|
|
|
340
353
|
const encryption = resolveTenantEncryptionService(em as any)
|
|
@@ -380,7 +393,7 @@ export async function reindexEntity(
|
|
|
380
393
|
return result
|
|
381
394
|
}
|
|
382
395
|
|
|
383
|
-
await upsertIndexBatch(
|
|
396
|
+
await upsertIndexBatch(db, entityType, rows, scopeOverrides, { deriveOrganizationId: deriveOrg, encryptDoc, decryptDoc })
|
|
384
397
|
|
|
385
398
|
const coverageDeltas = new Map<string, { tenantId: string | null; organizationId: string | null; delta: number }>()
|
|
386
399
|
for (const row of rows) {
|
|
@@ -439,10 +452,10 @@ export async function reindexEntity(
|
|
|
439
452
|
processed += rows.length
|
|
440
453
|
lastId = String(rows[rows.length - 1]!.id)
|
|
441
454
|
options?.onProgress?.({ processed, total, chunkSize: rows.length })
|
|
442
|
-
await updateJobProgress(
|
|
455
|
+
await updateJobProgress(db, jobScope, rows.length)
|
|
443
456
|
}
|
|
444
457
|
|
|
445
|
-
await purgeOrphans(
|
|
458
|
+
await purgeOrphans(db, {
|
|
446
459
|
entityType,
|
|
447
460
|
tenantId,
|
|
448
461
|
organizationId,
|
|
@@ -481,7 +494,7 @@ export async function reindexEntity(
|
|
|
481
494
|
)
|
|
482
495
|
}
|
|
483
496
|
} finally {
|
|
484
|
-
await finalizeJob(
|
|
497
|
+
await finalizeJob(db, jobScope)
|
|
485
498
|
}
|
|
486
499
|
|
|
487
500
|
return {
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Kysely, sql } from 'kysely'
|
|
2
2
|
import { resolveSearchConfig, type SearchConfig } from '@open-mercato/shared/lib/search/config'
|
|
3
3
|
import { tokenizeText } from '@open-mercato/shared/lib/search/tokenize'
|
|
4
4
|
import { parseBooleanToken } from '@open-mercato/shared/lib/boolean'
|
|
5
5
|
|
|
6
|
+
const INSERT_BATCH_SIZE = 500
|
|
7
|
+
|
|
8
|
+
function chunk<T>(items: T[], size: number): T[][] {
|
|
9
|
+
if (size <= 0) return [items]
|
|
10
|
+
const out: T[][] = []
|
|
11
|
+
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size))
|
|
12
|
+
return out
|
|
13
|
+
}
|
|
14
|
+
|
|
6
15
|
export type SearchTokenRow = {
|
|
7
16
|
entity_type: string
|
|
8
17
|
entity_id: string
|
|
@@ -130,7 +139,7 @@ function buildFieldPairs(recordId: string, doc?: Record<string, unknown> | null)
|
|
|
130
139
|
}
|
|
131
140
|
|
|
132
141
|
export async function replaceSearchTokensForRecord(
|
|
133
|
-
|
|
142
|
+
db: Kysely<any>,
|
|
134
143
|
params: BuildTokenOptions
|
|
135
144
|
): Promise<void> {
|
|
136
145
|
const rows = buildSearchTokenRows(params)
|
|
@@ -140,38 +149,48 @@ export async function replaceSearchTokensForRecord(
|
|
|
140
149
|
const tenantId = params.tenantId ?? null
|
|
141
150
|
const fieldPairs = buildFieldPairs(String(params.recordId), params.doc)
|
|
142
151
|
|
|
143
|
-
await
|
|
144
|
-
|
|
145
|
-
.
|
|
146
|
-
.
|
|
147
|
-
.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
await db.transaction().execute(async (trx) => {
|
|
153
|
+
let deleteQuery = trx
|
|
154
|
+
.deleteFrom('search_tokens' as any)
|
|
155
|
+
.where('entity_type' as any, '=', params.entityType)
|
|
156
|
+
.where(sql<boolean>`organization_id is not distinct from ${organizationId}`)
|
|
157
|
+
.where(sql<boolean>`tenant_id is not distinct from ${tenantId}`)
|
|
158
|
+
if (fieldPairs.length) {
|
|
159
|
+
deleteQuery = deleteQuery.where((eb: any) => eb.or(
|
|
160
|
+
fieldPairs.map(([rid, field]) => eb.and([
|
|
161
|
+
eb('entity_id' as any, '=', rid),
|
|
162
|
+
eb('field' as any, '=', field),
|
|
163
|
+
])),
|
|
164
|
+
))
|
|
165
|
+
} else {
|
|
166
|
+
deleteQuery = deleteQuery.where('entity_id' as any, '=', String(params.recordId))
|
|
167
|
+
}
|
|
168
|
+
await deleteQuery.execute()
|
|
151
169
|
if (!rows.length) return
|
|
152
|
-
const payloads = rows.map((row) => ({
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
await trx.batchInsert('search_tokens', payloads, 500)
|
|
170
|
+
const payloads = rows.map((row) => ({ ...row, created_at: sql`now()` }))
|
|
171
|
+
for (const batch of chunk(payloads, INSERT_BATCH_SIZE)) {
|
|
172
|
+
await trx.insertInto('search_tokens' as any).values(batch as any).execute()
|
|
173
|
+
}
|
|
157
174
|
})
|
|
158
175
|
}
|
|
159
176
|
|
|
160
177
|
export async function deleteSearchTokensForRecord(
|
|
161
|
-
|
|
178
|
+
db: Kysely<any>,
|
|
162
179
|
params: { entityType: string; recordId: string; organizationId?: string | null; tenantId?: string | null }
|
|
163
180
|
): Promise<void> {
|
|
164
181
|
const organizationId = params.organizationId ?? null
|
|
165
182
|
const tenantId = params.tenantId ?? null
|
|
166
|
-
await
|
|
167
|
-
.
|
|
168
|
-
.
|
|
169
|
-
.
|
|
170
|
-
.
|
|
183
|
+
await db
|
|
184
|
+
.deleteFrom('search_tokens' as any)
|
|
185
|
+
.where('entity_type' as any, '=', params.entityType)
|
|
186
|
+
.where('entity_id' as any, '=', String(params.recordId))
|
|
187
|
+
.where(sql<boolean>`organization_id is not distinct from ${organizationId}`)
|
|
188
|
+
.where(sql<boolean>`tenant_id is not distinct from ${tenantId}`)
|
|
189
|
+
.execute()
|
|
171
190
|
}
|
|
172
191
|
|
|
173
192
|
export async function replaceSearchTokensForBatch(
|
|
174
|
-
|
|
193
|
+
db: Kysely<any>,
|
|
175
194
|
payloads: Array<BuildTokenOptions & { doc: Record<string, unknown> }>
|
|
176
195
|
): Promise<void> {
|
|
177
196
|
if (!payloads.length) return
|
|
@@ -183,7 +202,11 @@ export async function replaceSearchTokensForBatch(
|
|
|
183
202
|
const entityType = payloads[0]?.entityType
|
|
184
203
|
if (!entityType) return
|
|
185
204
|
const ids = payloads.map((p) => String(p.recordId))
|
|
186
|
-
await
|
|
205
|
+
await db
|
|
206
|
+
.deleteFrom('search_tokens' as any)
|
|
207
|
+
.where('entity_type' as any, '=', entityType)
|
|
208
|
+
.where('entity_id' as any, 'in', ids)
|
|
209
|
+
.execute()
|
|
187
210
|
return
|
|
188
211
|
}
|
|
189
212
|
|
|
@@ -218,21 +241,29 @@ export async function replaceSearchTokensForBatch(
|
|
|
218
241
|
seenPairsByScope.set(key, seen)
|
|
219
242
|
}
|
|
220
243
|
|
|
221
|
-
await
|
|
244
|
+
await db.transaction().execute(async (trx) => {
|
|
222
245
|
for (const [key, bucket] of scopeBuckets.entries()) {
|
|
223
246
|
const pairs = fieldPairsByScope.get(key) ?? []
|
|
224
|
-
|
|
225
|
-
.
|
|
226
|
-
.
|
|
227
|
-
.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
247
|
+
let deleteQuery = trx
|
|
248
|
+
.deleteFrom('search_tokens' as any)
|
|
249
|
+
.where('entity_type' as any, '=', payloads[0].entityType)
|
|
250
|
+
.where(sql<boolean>`organization_id is not distinct from ${bucket.organizationId}`)
|
|
251
|
+
.where(sql<boolean>`tenant_id is not distinct from ${bucket.tenantId}`)
|
|
252
|
+
if (pairs.length) {
|
|
253
|
+
deleteQuery = deleteQuery.where((eb: any) => eb.or(
|
|
254
|
+
pairs.map(([rid, field]) => eb.and([
|
|
255
|
+
eb('entity_id' as any, '=', rid),
|
|
256
|
+
eb('field' as any, '=', field),
|
|
257
|
+
])),
|
|
258
|
+
))
|
|
259
|
+
} else {
|
|
260
|
+
deleteQuery = deleteQuery.where('entity_id' as any, 'in', Array.from(bucket.ids))
|
|
261
|
+
}
|
|
262
|
+
await deleteQuery.execute()
|
|
263
|
+
}
|
|
264
|
+
const payloadWithTimestamps = rows.map((row) => ({ ...row, created_at: sql`now()` }))
|
|
265
|
+
for (const batch of chunk(payloadWithTimestamps, INSERT_BATCH_SIZE)) {
|
|
266
|
+
await trx.insertInto('search_tokens' as any).values(batch as any).execute()
|
|
231
267
|
}
|
|
232
|
-
const payloadWithTimestamps = rows.map((row) => ({
|
|
233
|
-
...row,
|
|
234
|
-
created_at: trx.fn.now(),
|
|
235
|
-
}))
|
|
236
|
-
await trx.batchInsert('search_tokens', payloadWithTimestamps, 500)
|
|
237
268
|
})
|
|
238
269
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Kysely, sql } from 'kysely'
|
|
2
2
|
|
|
3
3
|
type PurgeOrphansOptions = {
|
|
4
4
|
entityType: string
|
|
@@ -10,23 +10,20 @@ type PurgeOrphansOptions = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export async function purgeOrphans(
|
|
13
|
-
|
|
13
|
+
db: Kysely<any>,
|
|
14
14
|
options: PurgeOrphansOptions,
|
|
15
15
|
): Promise<void> {
|
|
16
16
|
const { entityType, tenantId, partitionIndex, partitionCount, startedAt } = options
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
.andWhere('updated_at', '<', startedAt)
|
|
31
|
-
.del()
|
|
17
|
+
let q = db.deleteFrom('entity_indexes' as any).where('entity_type' as any, '=', entityType)
|
|
18
|
+
if (tenantId !== undefined) {
|
|
19
|
+
q = q.where(sql<boolean>`tenant_id is not distinct from ${tenantId ?? null}`)
|
|
20
|
+
}
|
|
21
|
+
if (options.organizationId !== undefined) {
|
|
22
|
+
q = q.where(sql<boolean>`organization_id is not distinct from ${options.organizationId ?? null}`)
|
|
23
|
+
}
|
|
24
|
+
if (partitionIndex != null && partitionCount != null) {
|
|
25
|
+
q = q.where(sql<boolean>`mod(abs(hashtext(entity_id::text)), ${partitionCount}) = ${partitionIndex}`)
|
|
26
|
+
}
|
|
27
|
+
q = q.where('updated_at' as any, '<', startedAt as any)
|
|
28
|
+
await q.execute()
|
|
32
29
|
}
|
|
@@ -32,12 +32,13 @@ export async function loadQueryIndexRowScope(
|
|
|
32
32
|
entityType: string,
|
|
33
33
|
recordId: string
|
|
34
34
|
): Promise<QueryIndexScope | null> {
|
|
35
|
-
const
|
|
35
|
+
const db = em.getKysely<any>()
|
|
36
36
|
const table = resolveEntityTableName(em, entityType)
|
|
37
|
-
const row = await
|
|
38
|
-
.
|
|
39
|
-
.
|
|
40
|
-
.
|
|
37
|
+
const row = await db
|
|
38
|
+
.selectFrom(table as any)
|
|
39
|
+
.select(['organization_id' as any, 'tenant_id' as any])
|
|
40
|
+
.where('id' as any, '=', recordId)
|
|
41
|
+
.executeTakeFirst() as { organization_id: string | null; tenant_id: string | null } | undefined
|
|
41
42
|
|
|
42
43
|
if (!row) {
|
|
43
44
|
return null
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { recordIndexerError } from '@open-mercato/shared/lib/indexers/error-log'
|
|
2
2
|
import { resolveEntityTableName } from '@open-mercato/shared/lib/query/engine'
|
|
3
|
+
import { sql } from 'kysely'
|
|
3
4
|
import { markDeleted } from '../lib/indexer'
|
|
4
5
|
import { applyCoverageAdjustments, createCoverageAdjustments } from '../lib/coverage'
|
|
5
6
|
import { loadQueryIndexRowScope, resolveQueryIndexRecordScope } from '../lib/subscriber-scope'
|
|
@@ -33,13 +34,15 @@ export default async function handle(payload: any, ctx: { resolve: <T=any>(name:
|
|
|
33
34
|
let baseDelta = 0
|
|
34
35
|
let baseCheckSucceeded = false
|
|
35
36
|
try {
|
|
36
|
-
const
|
|
37
|
+
const db = (em as any).getKysely()
|
|
37
38
|
const table = resolveEntityTableName(em, entityType)
|
|
38
|
-
const row = await
|
|
39
|
-
.
|
|
40
|
-
.
|
|
41
|
-
.
|
|
42
|
-
.
|
|
39
|
+
const row = await db
|
|
40
|
+
.selectFrom(table as any)
|
|
41
|
+
.select(['deleted_at' as any])
|
|
42
|
+
.where('id' as any, '=', recordId)
|
|
43
|
+
.where('organization_id' as any, organizationId === null ? 'is' : '=', organizationId as any)
|
|
44
|
+
.where(sql`tenant_id is not distinct from ${tenantId}`)
|
|
45
|
+
.executeTakeFirst() as { deleted_at: Date | null } | undefined
|
|
43
46
|
const baseMissing = !row
|
|
44
47
|
const baseDeleted = baseMissing || (row && row.deleted_at != null)
|
|
45
48
|
baseCheckSucceeded = true
|
|
@@ -140,7 +140,7 @@ const unassignResourceTagCommand: CommandHandler<ResourcesResourceTagAssignmentI
|
|
|
140
140
|
organizationId: parsed.organizationId,
|
|
141
141
|
})
|
|
142
142
|
if (!existing) throw new CrudHttpError(404, { error: 'Tag assignment not found.' })
|
|
143
|
-
await em.remove(existing)
|
|
143
|
+
await em.remove(existing).flush()
|
|
144
144
|
await em.flush()
|
|
145
145
|
|
|
146
146
|
const dataEngine = (ctx.container.resolve('dataEngine') as DataEngine)
|
|
@@ -40,7 +40,7 @@ const createTagCommand: CommandHandler<ResourcesResourceTagCreateInput, { tagId:
|
|
|
40
40
|
createdAt: new Date(),
|
|
41
41
|
updatedAt: new Date(),
|
|
42
42
|
})
|
|
43
|
-
await em.
|
|
43
|
+
await em.persist(tag).flush()
|
|
44
44
|
return { tagId: tag.id }
|
|
45
45
|
},
|
|
46
46
|
buildLog: async ({ input, result, ctx }) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection } from '@mikro-orm/core'
|
|
2
|
+
import { Entity, Index, ManyToOne, OneToMany, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
|
|
2
3
|
|
|
3
4
|
@Entity({ tableName: 'resources_resource_types' })
|
|
4
5
|
@Index({ name: 'resources_resource_types_tenant_org_idx', properties: ['tenantId', 'organizationId'] })
|
|
@@ -87,7 +87,7 @@ const createDocumentAddress: CommandHandler<DocumentAddressCreateInput, { id: st
|
|
|
87
87
|
order: input.documentKind === 'order' ? (document as SalesOrder) : null,
|
|
88
88
|
quote: input.documentKind === 'quote' ? (document as SalesQuote) : null,
|
|
89
89
|
})
|
|
90
|
-
await em.
|
|
90
|
+
await em.persist(entity).flush()
|
|
91
91
|
return { id: entity.id }
|
|
92
92
|
},
|
|
93
93
|
}
|
|
@@ -158,7 +158,7 @@ const deleteDocumentAddress: CommandHandler<
|
|
|
158
158
|
status: (document as SalesOrder).status ?? null,
|
|
159
159
|
})
|
|
160
160
|
}
|
|
161
|
-
await em.
|
|
161
|
+
await em.remove(entity).flush()
|
|
162
162
|
return { ok: true }
|
|
163
163
|
},
|
|
164
164
|
}
|
|
@@ -122,7 +122,7 @@ async function requireContext(
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
const repo = contextType === 'invoice' ? SalesInvoice : SalesCreditMemo
|
|
125
|
-
const entity = await em.findOne(repo, { id: contextId })
|
|
125
|
+
const entity = await em.findOne(repo as any, { id: contextId }) as (SalesInvoice | SalesCreditMemo) | null
|
|
126
126
|
if (!entity) {
|
|
127
127
|
throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })
|
|
128
128
|
}
|
|
@@ -33,7 +33,7 @@ const createTagCommand: CommandHandler<SalesTagCreateInput, { tagId: string }> =
|
|
|
33
33
|
color: parsed.color ?? null,
|
|
34
34
|
description: parsed.description ?? null,
|
|
35
35
|
})
|
|
36
|
-
await em.
|
|
36
|
+
await em.persist(tag).flush()
|
|
37
37
|
return { tagId: tag.id }
|
|
38
38
|
},
|
|
39
39
|
}
|