@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sales/commands/notes.ts"],
|
|
4
|
-
"sourcesContent": ["import { registerCommand, type CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n buildChanges,\n requireId,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport type { CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { E } from '#generated/entities.ids.generated'\nimport {\n SalesNote,\n SalesOrder,\n SalesQuote,\n SalesInvoice,\n SalesCreditMemo,\n type SalesDocumentKind,\n} from '../data/entities'\nimport {\n noteCreateSchema,\n noteUpdateSchema,\n type NoteCreateInput,\n type NoteUpdateInput,\n} from '../data/validators'\nimport { ensureOrganizationScope, ensureSameScope, ensureTenantScope, extractUndoPayload } from './shared'\n\ntype NoteSnapshot = {\n id: string\n organizationId: string\n tenantId: string\n contextType: SalesDocumentKind\n contextId: string\n orderId: string | null\n quoteId: string | null\n body: string\n authorUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n}\n\ntype NoteUndoPayload = {\n before?: NoteSnapshot | null\n after?: NoteSnapshot | null\n}\n\nconst noteCrudIndexer = {\n entityType: E.sales.sales_note,\n}\n\nconst noteCrudEvents: CrudEventsConfig = {\n module: 'sales',\n entity: 'note',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n }),\n}\n\nasync function loadNoteSnapshot(em: EntityManager, id: string): Promise<NoteSnapshot | null> {\n const note = await em.findOne(SalesNote, { id })\n if (!note) return null\n return {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n contextType: note.contextType,\n contextId: note.contextId,\n orderId: note.order ? (typeof note.order === 'string' ? note.order : note.order.id) : null,\n quoteId: note.quote ? (typeof note.quote === 'string' ? note.quote : note.quote.id) : null,\n body: note.body,\n authorUserId: note.authorUserId ?? null,\n appearanceIcon: note.appearanceIcon ?? null,\n appearanceColor: note.appearanceColor ?? null,\n }\n}\n\nasync function requireContext(\n em: EntityManager,\n contextType: SalesDocumentKind,\n contextId: string,\n organizationId?: string,\n tenantId?: string\n): Promise<{\n organizationId: string\n tenantId: string\n order?: SalesOrder | null\n quote?: SalesQuote | null\n}> {\n if (contextType === 'order') {\n const order = await em.findOne(SalesOrder, { id: contextId })\n if (!order) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(order, organizationId, tenantId)\n }\n return {\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n order,\n quote: null,\n }\n }\n if (contextType === 'quote') {\n const quote = await em.findOne(SalesQuote, { id: contextId })\n if (!quote) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(quote, organizationId, tenantId)\n }\n return {\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n order: null,\n quote,\n }\n }\n const repo = contextType === 'invoice' ? SalesInvoice : SalesCreditMemo\n const entity = await em.findOne(repo, { id: contextId })\n if (!entity) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(entity, organizationId, tenantId)\n }\n return {\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n order: null,\n quote: null,\n }\n}\n\nfunction resolveAuthor(inputAuthor: string | undefined, authSub: string | null): string | null {\n if (inputAuthor) return inputAuthor\n if (!authSub) return null\n const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/\n return uuidRegex.test(authSub) ? authSub : null\n}\n\nconst createNoteCommand: CommandHandler<NoteCreateInput, { noteId: string; authorUserId: string | null }> = {\n id: 'sales.notes.create',\n async execute(rawInput, ctx) {\n const parsed = noteCreateSchema.parse(rawInput ?? {})\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, parsed.contextType, parsed.contextId, parsed.organizationId, parsed.tenantId)\n const authorUserId = resolveAuthor(parsed.authorUserId, ctx.auth?.isApiKey ? null : ctx.auth?.sub ?? null)\n\n const note = em.create(SalesNote, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n contextType: parsed.contextType,\n contextId: parsed.contextId,\n order: context.order ?? null,\n quote: context.quote ?? null,\n authorUserId,\n appearanceIcon: parsed.appearanceIcon ?? null,\n appearanceColor: parsed.appearanceColor ?? null,\n body: parsed.body,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n\n return { noteId: note.id, authorUserId: note.authorUserId ?? null }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadNoteSnapshot(em, result.noteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as NoteSnapshot | undefined\n return {\n actionLabel: translate('sales.audit.notes.create', 'Create note'),\n resourceKind: 'sales.note',\n resourceId: result.noteId,\n parentResourceKind: snapshot?.contextType ? `sales.${snapshot.contextType}` : null,\n parentResourceId: snapshot?.contextId ?? null,\n tenantId: snapshot?.tenantId ?? null,\n organizationId: snapshot?.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const noteId = logEntry?.resourceId ?? null\n if (!noteId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const existing = await em.findOne(SalesNote, { id: noteId })\n if (existing) {\n em.remove(existing)\n await em.flush()\n }\n },\n}\n\nconst updateNoteCommand: CommandHandler<NoteUpdateInput, { noteId: string }> = {\n id: 'sales.notes.update',\n async prepare(rawInput, ctx) {\n const parsed = noteUpdateSchema.parse(rawInput ?? {})\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadNoteSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = noteUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const note = await em.findOne(SalesNote, { id: parsed.id })\n if (!note) throw new CrudHttpError(404, { error: 'sales.notes.not_found' })\n ensureTenantScope(ctx, note.tenantId)\n ensureOrganizationScope(ctx, note.organizationId)\n\n if (parsed.body !== undefined) note.body = parsed.body\n if (parsed.authorUserId !== undefined) note.authorUserId = parsed.authorUserId ?? null\n if (parsed.appearanceIcon !== undefined) note.appearanceIcon = parsed.appearanceIcon ?? null\n if (parsed.appearanceColor !== undefined) note.appearanceColor = parsed.appearanceColor ?? null\n note.updatedAt = new Date()\n\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'updated',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n\n return { noteId: note.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadNoteSnapshot(em, result.noteId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as NoteSnapshot | undefined\n if (!before) return null\n const after = snapshots.after as NoteSnapshot | undefined\n const changes =\n after && before\n ? buildChanges(\n before as unknown as Record<string, unknown>,\n after as unknown as Record<string, unknown>,\n ['body', 'authorUserId', 'appearanceIcon', 'appearanceColor']\n )\n : {}\n return {\n actionLabel: translate('sales.audit.notes.update', 'Update note'),\n resourceKind: 'sales.note',\n resourceId: before.id,\n parentResourceKind: before.contextType ? `sales.${before.contextType}` : null,\n parentResourceId: before.contextId ?? null,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n snapshotAfter: after ?? null,\n changes,\n payload: {\n undo: {\n before,\n after: after ?? null,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<NoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, before.contextType, before.contextId).catch(() => null)\n if (!context) return\n let note = await em.findOne(SalesNote, { id: before.id })\n if (!note) {\n note = em.create(SalesNote, {\n id: before.id,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n contextType: before.contextType,\n contextId: before.contextId,\n order: before.orderId ? context.order ?? null : null,\n quote: before.quoteId ? context.quote ?? null : null,\n body: before.body,\n authorUserId: before.authorUserId,\n appearanceIcon: before.appearanceIcon,\n appearanceColor: before.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n }\n note.organizationId = before.organizationId\n note.tenantId = before.tenantId\n note.contextType = before.contextType\n note.contextId = before.contextId\n note.order = before.orderId ? context.order ?? null : null\n note.quote = before.quoteId ? context.quote ?? null : null\n note.body = before.body\n note.authorUserId = before.authorUserId\n note.appearanceIcon = before.appearanceIcon\n note.appearanceColor = before.appearanceColor\n note.updatedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'updated',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n },\n}\n\nconst deleteNoteCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { noteId: string }> =\n {\n id: 'sales.notes.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Note id required')\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadNoteSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Note id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const note = await em.findOne(SalesNote, { id })\n if (!note) throw new CrudHttpError(404, { error: 'sales.notes.not_found' })\n ensureTenantScope(ctx, note.tenantId)\n ensureOrganizationScope(ctx, note.organizationId)\n em.remove(note)\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'deleted',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n return { noteId: note.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as NoteSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.notes.delete', 'Delete note'),\n resourceKind: 'sales.note',\n resourceId: before.id,\n parentResourceKind: before.contextType ? `sales.${before.contextType}` : null,\n parentResourceId: before.contextId ?? null,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<NoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, before.contextType, before.contextId).catch(() => null)\n if (!context) return\n let note = await em.findOne(SalesNote, { id: before.id })\n if (!note) {\n note = em.create(SalesNote, {\n id: before.id,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n contextType: before.contextType,\n contextId: before.contextId,\n order: before.orderId ? context.order ?? null : null,\n quote: before.quoteId ? context.quote ?? null : null,\n body: before.body,\n authorUserId: before.authorUserId,\n appearanceIcon: before.appearanceIcon,\n appearanceColor: before.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n }\n note.organizationId = before.organizationId\n note.tenantId = before.tenantId\n note.contextType = before.contextType\n note.contextId = before.contextId\n note.order = before.orderId ? context.order ?? null : null\n note.quote = before.quoteId ? context.quote ?? null : null\n note.body = before.body\n note.authorUserId = before.authorUserId\n note.appearanceIcon = before.appearanceIcon\n note.appearanceColor = before.appearanceColor\n note.updatedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'created',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n },\n }\n\nregisterCommand(createNoteCommand)\nregisterCommand(updateNoteCommand)\nregisterCommand(deleteNoteCommand)\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,uBAA4C;AACrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AAEpC,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,yBAAyB,iBAAiB,mBAAmB,0BAA0B;AAqBhG,MAAM,kBAAkB;AAAA,EACtB,YAAY,EAAE,MAAM;AACtB;AAEA,MAAM,iBAAmC;AAAA,EACvC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,cAAc,CAAC,SAAS;AAAA,IACtB,IAAI,IAAI,YAAY;AAAA,IACpB,gBAAgB,IAAI,YAAY;AAAA,IAChC,UAAU,IAAI,YAAY;AAAA,EAC5B;AACF;AAEA,eAAe,iBAAiB,IAAmB,IAA0C;AAC3F,QAAM,OAAO,MAAM,GAAG,QAAQ,WAAW,EAAE,GAAG,CAAC;AAC/C,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO;AAAA,IACL,IAAI,KAAK;AAAA,IACT,gBAAgB,KAAK;AAAA,IACrB,UAAU,KAAK;AAAA,IACf,aAAa,KAAK;AAAA,IAClB,WAAW,KAAK;AAAA,IAChB,SAAS,KAAK,QAAS,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,KAAK,MAAM,KAAM;AAAA,IACtF,SAAS,KAAK,QAAS,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,KAAK,MAAM,KAAM;AAAA,IACtF,MAAM,KAAK;AAAA,IACX,cAAc,KAAK,gBAAgB;AAAA,IACnC,gBAAgB,KAAK,kBAAkB;AAAA,IACvC,iBAAiB,KAAK,mBAAmB;AAAA,EAC3C;AACF;AAEA,eAAe,eACb,IACA,aACA,WACA,gBACA,UAMC;AACD,MAAI,gBAAgB,SAAS;AAC3B,UAAM,QAAQ,MAAM,GAAG,QAAQ,YAAY,EAAE,IAAI,UAAU,CAAC;AAC5D,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,cAAc,KAAK,EAAE,OAAO,gCAAgC,CAAC;AAAA,IACzE;AACA,QAAI,kBAAkB,UAAU;AAC9B,sBAAgB,OAAO,gBAAgB,QAAQ;AAAA,IACjD;AACA,WAAO;AAAA,MACL,gBAAgB,MAAM;AAAA,MACtB,UAAU,MAAM;AAAA,MAChB;AAAA,MACA,OAAO;AAAA,IACT;AAAA,EACF;AACA,MAAI,gBAAgB,SAAS;AAC3B,UAAM,QAAQ,MAAM,GAAG,QAAQ,YAAY,EAAE,IAAI,UAAU,CAAC;AAC5D,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,cAAc,KAAK,EAAE,OAAO,gCAAgC,CAAC;AAAA,IACzE;AACA,QAAI,kBAAkB,UAAU;AAC9B,sBAAgB,OAAO,gBAAgB,QAAQ;AAAA,IACjD;AACA,WAAO;AAAA,MACL,gBAAgB,MAAM;AAAA,MACtB,UAAU,MAAM;AAAA,MAChB,OAAO;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACA,QAAM,OAAO,gBAAgB,YAAY,eAAe;AACxD,QAAM,SAAS,MAAM,GAAG,QAAQ,
|
|
4
|
+
"sourcesContent": ["import { registerCommand, type CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n buildChanges,\n requireId,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport type { CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { E } from '#generated/entities.ids.generated'\nimport {\n SalesNote,\n SalesOrder,\n SalesQuote,\n SalesInvoice,\n SalesCreditMemo,\n type SalesDocumentKind,\n} from '../data/entities'\nimport {\n noteCreateSchema,\n noteUpdateSchema,\n type NoteCreateInput,\n type NoteUpdateInput,\n} from '../data/validators'\nimport { ensureOrganizationScope, ensureSameScope, ensureTenantScope, extractUndoPayload } from './shared'\n\ntype NoteSnapshot = {\n id: string\n organizationId: string\n tenantId: string\n contextType: SalesDocumentKind\n contextId: string\n orderId: string | null\n quoteId: string | null\n body: string\n authorUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n}\n\ntype NoteUndoPayload = {\n before?: NoteSnapshot | null\n after?: NoteSnapshot | null\n}\n\nconst noteCrudIndexer = {\n entityType: E.sales.sales_note,\n}\n\nconst noteCrudEvents: CrudEventsConfig = {\n module: 'sales',\n entity: 'note',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n }),\n}\n\nasync function loadNoteSnapshot(em: EntityManager, id: string): Promise<NoteSnapshot | null> {\n const note = await em.findOne(SalesNote, { id })\n if (!note) return null\n return {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n contextType: note.contextType,\n contextId: note.contextId,\n orderId: note.order ? (typeof note.order === 'string' ? note.order : note.order.id) : null,\n quoteId: note.quote ? (typeof note.quote === 'string' ? note.quote : note.quote.id) : null,\n body: note.body,\n authorUserId: note.authorUserId ?? null,\n appearanceIcon: note.appearanceIcon ?? null,\n appearanceColor: note.appearanceColor ?? null,\n }\n}\n\nasync function requireContext(\n em: EntityManager,\n contextType: SalesDocumentKind,\n contextId: string,\n organizationId?: string,\n tenantId?: string\n): Promise<{\n organizationId: string\n tenantId: string\n order?: SalesOrder | null\n quote?: SalesQuote | null\n}> {\n if (contextType === 'order') {\n const order = await em.findOne(SalesOrder, { id: contextId })\n if (!order) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(order, organizationId, tenantId)\n }\n return {\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n order,\n quote: null,\n }\n }\n if (contextType === 'quote') {\n const quote = await em.findOne(SalesQuote, { id: contextId })\n if (!quote) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(quote, organizationId, tenantId)\n }\n return {\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n order: null,\n quote,\n }\n }\n const repo = contextType === 'invoice' ? SalesInvoice : SalesCreditMemo\n const entity = await em.findOne(repo as any, { id: contextId }) as (SalesInvoice | SalesCreditMemo) | null\n if (!entity) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(entity, organizationId, tenantId)\n }\n return {\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n order: null,\n quote: null,\n }\n}\n\nfunction resolveAuthor(inputAuthor: string | undefined, authSub: string | null): string | null {\n if (inputAuthor) return inputAuthor\n if (!authSub) return null\n const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/\n return uuidRegex.test(authSub) ? authSub : null\n}\n\nconst createNoteCommand: CommandHandler<NoteCreateInput, { noteId: string; authorUserId: string | null }> = {\n id: 'sales.notes.create',\n async execute(rawInput, ctx) {\n const parsed = noteCreateSchema.parse(rawInput ?? {})\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, parsed.contextType, parsed.contextId, parsed.organizationId, parsed.tenantId)\n const authorUserId = resolveAuthor(parsed.authorUserId, ctx.auth?.isApiKey ? null : ctx.auth?.sub ?? null)\n\n const note = em.create(SalesNote, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n contextType: parsed.contextType,\n contextId: parsed.contextId,\n order: context.order ?? null,\n quote: context.quote ?? null,\n authorUserId,\n appearanceIcon: parsed.appearanceIcon ?? null,\n appearanceColor: parsed.appearanceColor ?? null,\n body: parsed.body,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n\n return { noteId: note.id, authorUserId: note.authorUserId ?? null }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadNoteSnapshot(em, result.noteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as NoteSnapshot | undefined\n return {\n actionLabel: translate('sales.audit.notes.create', 'Create note'),\n resourceKind: 'sales.note',\n resourceId: result.noteId,\n parentResourceKind: snapshot?.contextType ? `sales.${snapshot.contextType}` : null,\n parentResourceId: snapshot?.contextId ?? null,\n tenantId: snapshot?.tenantId ?? null,\n organizationId: snapshot?.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const noteId = logEntry?.resourceId ?? null\n if (!noteId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const existing = await em.findOne(SalesNote, { id: noteId })\n if (existing) {\n em.remove(existing)\n await em.flush()\n }\n },\n}\n\nconst updateNoteCommand: CommandHandler<NoteUpdateInput, { noteId: string }> = {\n id: 'sales.notes.update',\n async prepare(rawInput, ctx) {\n const parsed = noteUpdateSchema.parse(rawInput ?? {})\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadNoteSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = noteUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const note = await em.findOne(SalesNote, { id: parsed.id })\n if (!note) throw new CrudHttpError(404, { error: 'sales.notes.not_found' })\n ensureTenantScope(ctx, note.tenantId)\n ensureOrganizationScope(ctx, note.organizationId)\n\n if (parsed.body !== undefined) note.body = parsed.body\n if (parsed.authorUserId !== undefined) note.authorUserId = parsed.authorUserId ?? null\n if (parsed.appearanceIcon !== undefined) note.appearanceIcon = parsed.appearanceIcon ?? null\n if (parsed.appearanceColor !== undefined) note.appearanceColor = parsed.appearanceColor ?? null\n note.updatedAt = new Date()\n\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'updated',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n\n return { noteId: note.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadNoteSnapshot(em, result.noteId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as NoteSnapshot | undefined\n if (!before) return null\n const after = snapshots.after as NoteSnapshot | undefined\n const changes =\n after && before\n ? buildChanges(\n before as unknown as Record<string, unknown>,\n after as unknown as Record<string, unknown>,\n ['body', 'authorUserId', 'appearanceIcon', 'appearanceColor']\n )\n : {}\n return {\n actionLabel: translate('sales.audit.notes.update', 'Update note'),\n resourceKind: 'sales.note',\n resourceId: before.id,\n parentResourceKind: before.contextType ? `sales.${before.contextType}` : null,\n parentResourceId: before.contextId ?? null,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n snapshotAfter: after ?? null,\n changes,\n payload: {\n undo: {\n before,\n after: after ?? null,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<NoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, before.contextType, before.contextId).catch(() => null)\n if (!context) return\n let note = await em.findOne(SalesNote, { id: before.id })\n if (!note) {\n note = em.create(SalesNote, {\n id: before.id,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n contextType: before.contextType,\n contextId: before.contextId,\n order: before.orderId ? context.order ?? null : null,\n quote: before.quoteId ? context.quote ?? null : null,\n body: before.body,\n authorUserId: before.authorUserId,\n appearanceIcon: before.appearanceIcon,\n appearanceColor: before.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n }\n note.organizationId = before.organizationId\n note.tenantId = before.tenantId\n note.contextType = before.contextType\n note.contextId = before.contextId\n note.order = before.orderId ? context.order ?? null : null\n note.quote = before.quoteId ? context.quote ?? null : null\n note.body = before.body\n note.authorUserId = before.authorUserId\n note.appearanceIcon = before.appearanceIcon\n note.appearanceColor = before.appearanceColor\n note.updatedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'updated',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n },\n}\n\nconst deleteNoteCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { noteId: string }> =\n {\n id: 'sales.notes.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Note id required')\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadNoteSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Note id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const note = await em.findOne(SalesNote, { id })\n if (!note) throw new CrudHttpError(404, { error: 'sales.notes.not_found' })\n ensureTenantScope(ctx, note.tenantId)\n ensureOrganizationScope(ctx, note.organizationId)\n em.remove(note)\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'deleted',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n return { noteId: note.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as NoteSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.notes.delete', 'Delete note'),\n resourceKind: 'sales.note',\n resourceId: before.id,\n parentResourceKind: before.contextType ? `sales.${before.contextType}` : null,\n parentResourceId: before.contextId ?? null,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<NoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, before.contextType, before.contextId).catch(() => null)\n if (!context) return\n let note = await em.findOne(SalesNote, { id: before.id })\n if (!note) {\n note = em.create(SalesNote, {\n id: before.id,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n contextType: before.contextType,\n contextId: before.contextId,\n order: before.orderId ? context.order ?? null : null,\n quote: before.quoteId ? context.quote ?? null : null,\n body: before.body,\n authorUserId: before.authorUserId,\n appearanceIcon: before.appearanceIcon,\n appearanceColor: before.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n }\n note.organizationId = before.organizationId\n note.tenantId = before.tenantId\n note.contextType = before.contextType\n note.contextId = before.contextId\n note.order = before.orderId ? context.order ?? null : null\n note.quote = before.quoteId ? context.quote ?? null : null\n note.body = before.body\n note.authorUserId = before.authorUserId\n note.appearanceIcon = before.appearanceIcon\n note.appearanceColor = before.appearanceColor\n note.updatedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'created',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n },\n }\n\nregisterCommand(createNoteCommand)\nregisterCommand(updateNoteCommand)\nregisterCommand(deleteNoteCommand)\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAA4C;AACrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AAEpC,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,yBAAyB,iBAAiB,mBAAmB,0BAA0B;AAqBhG,MAAM,kBAAkB;AAAA,EACtB,YAAY,EAAE,MAAM;AACtB;AAEA,MAAM,iBAAmC;AAAA,EACvC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,cAAc,CAAC,SAAS;AAAA,IACtB,IAAI,IAAI,YAAY;AAAA,IACpB,gBAAgB,IAAI,YAAY;AAAA,IAChC,UAAU,IAAI,YAAY;AAAA,EAC5B;AACF;AAEA,eAAe,iBAAiB,IAAmB,IAA0C;AAC3F,QAAM,OAAO,MAAM,GAAG,QAAQ,WAAW,EAAE,GAAG,CAAC;AAC/C,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO;AAAA,IACL,IAAI,KAAK;AA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OAAO;AACvB,SAAK,cAAc,OAAO;AAC1B,SAAK,YAAY,OAAO;AACxB,SAAK,QAAQ,OAAO,UAAU,QAAQ,SAAS,OAAO;AACtD,SAAK,QAAQ,OAAO,UAAU,QAAQ,SAAS,OAAO;AACtD,SAAK,OAAO,OAAO;AACnB,SAAK,eAAe,OAAO;AAC3B,SAAK,iBAAiB,OAAO;AAC7B,SAAK,kBAAkB,OAAO;AAC9B,SAAK,YAAY,oBAAI,KAAK;AAC1B,UAAM,GAAG,MAAM;AAEf,UAAM,aAAa,IAAI,UAAU,QAAQ,YAAY;AACrD,UAAM,wBAAwB;AAAA,MAC5B;AAAA,MACA,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,aAAa;AAAA,QACX,IAAI,KAAK;AAAA,QACT,gBAAgB,KAAK;AAAA,QACrB,UAAU,KAAK;AAAA,MACjB;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;AAEF,gBAAgB,iBAAiB;AACjC,gBAAgB,iBAAiB;AACjC,gBAAgB,iBAAiB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sales/commands/tags.ts"],
|
|
4
|
-
"sourcesContent": ["// @ts-nocheck\n\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { SalesDocumentTag, SalesDocumentTagAssignment } from '../data/entities'\nimport { ensureTenantScope } from './shared'\nimport {\n salesTagCreateSchema,\n salesTagUpdateSchema,\n type SalesTagCreateInput,\n type SalesTagUpdateInput,\n} from '../data/validators'\n\nconst createTagCommand: CommandHandler<SalesTagCreateInput, { tagId: string }> = {\n id: 'sales.tags.create',\n async execute(rawInput, ctx) {\n const parsed = salesTagCreateSchema.parse(rawInput ?? {})\n ensureTenantScope(ctx, parsed.tenantId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const conflict = await em.findOne(SalesDocumentTag, {\n slug: parsed.slug,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n if (conflict) throw new CrudHttpError(409, { error: 'Tag slug already exists for this scope' })\n const tag = em.create(SalesDocumentTag, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n slug: parsed.slug,\n label: parsed.label,\n color: parsed.color ?? null,\n description: parsed.description ?? null,\n })\n await em.
|
|
5
|
-
"mappings": "AAEA,SAAS,uBAAuB;AAGhC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB,kCAAkC;AAC7D,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,MAAM,mBAA2E;AAAA,EAC/E,IAAI;AAAA,EACJ,MAAM,QAAQ,UAAU,KAAK;AAC3B,UAAM,SAAS,qBAAqB,MAAM,YAAY,CAAC,CAAC;AACxD,sBAAkB,KAAK,OAAO,QAAQ;AACtC,UAAM,KAAM,IAAI,UAAU,QAAQ,IAAI,EAAoB,KAAK;AAC/D,UAAM,WAAW,MAAM,GAAG,QAAQ,kBAAkB;AAAA,MAClD,MAAM,OAAO;AAAA,MACb,gBAAgB,OAAO;AAAA,MACvB,UAAU,OAAO;AAAA,IACnB,CAAC;AACD,QAAI,SAAU,OAAM,IAAI,cAAc,KAAK,EAAE,OAAO,yCAAyC,CAAC;AAC9F,UAAM,MAAM,GAAG,OAAO,kBAAkB;AAAA,MACtC,gBAAgB,OAAO;AAAA,MACvB,UAAU,OAAO;AAAA,MACjB,MAAM,OAAO;AAAA,MACb,OAAO,OAAO;AAAA,MACd,OAAO,OAAO,SAAS;AAAA,MACvB,aAAa,OAAO,eAAe;AAAA,IACrC,CAAC;AACD,UAAM,GAAG,
|
|
4
|
+
"sourcesContent": ["// @ts-nocheck\n\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { SalesDocumentTag, SalesDocumentTagAssignment } from '../data/entities'\nimport { ensureTenantScope } from './shared'\nimport {\n salesTagCreateSchema,\n salesTagUpdateSchema,\n type SalesTagCreateInput,\n type SalesTagUpdateInput,\n} from '../data/validators'\n\nconst createTagCommand: CommandHandler<SalesTagCreateInput, { tagId: string }> = {\n id: 'sales.tags.create',\n async execute(rawInput, ctx) {\n const parsed = salesTagCreateSchema.parse(rawInput ?? {})\n ensureTenantScope(ctx, parsed.tenantId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const conflict = await em.findOne(SalesDocumentTag, {\n slug: parsed.slug,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n if (conflict) throw new CrudHttpError(409, { error: 'Tag slug already exists for this scope' })\n const tag = em.create(SalesDocumentTag, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n slug: parsed.slug,\n label: parsed.label,\n color: parsed.color ?? null,\n description: parsed.description ?? null,\n })\n await em.persist(tag).flush()\n return { tagId: tag.id }\n },\n}\n\nconst updateTagCommand: CommandHandler<SalesTagUpdateInput, { tagId: string }> = {\n id: 'sales.tags.update',\n async execute(rawInput, ctx) {\n const parsed = salesTagUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const tag = await em.findOne(SalesDocumentTag, { id: parsed.id })\n if (!tag) throw new CrudHttpError(404, { error: 'Tag not found' })\n ensureTenantScope(ctx, parsed.tenantId ?? tag.tenantId)\n if (parsed.slug && parsed.slug !== tag.slug) {\n const conflict = await em.findOne(SalesDocumentTag, {\n slug: parsed.slug,\n organizationId: parsed.organizationId ?? tag.organizationId,\n tenantId: parsed.tenantId ?? tag.tenantId,\n })\n if (conflict && conflict.id !== tag.id) {\n throw new CrudHttpError(409, { error: 'Tag slug already exists for this scope' })\n }\n tag.slug = parsed.slug\n }\n if (parsed.label !== undefined) tag.label = parsed.label\n if (parsed.color !== undefined) tag.color = parsed.color ?? null\n if (parsed.description !== undefined) tag.description = parsed.description ?? null\n if (parsed.organizationId) tag.organizationId = parsed.organizationId\n if (parsed.tenantId) tag.tenantId = parsed.tenantId\n await em.flush()\n return { tagId: tag.id }\n },\n}\n\nconst deleteTagCommand: CommandHandler<{ id?: string }, { tagId: string }> = {\n id: 'sales.tags.delete',\n async execute(input, ctx) {\n const id = typeof input?.id === 'string' ? input.id : null\n if (!id) throw new CrudHttpError(400, { error: 'Tag id is required' })\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const tag = await em.findOne(SalesDocumentTag, { id })\n if (!tag) throw new CrudHttpError(404, { error: 'Tag not found' })\n ensureTenantScope(ctx, tag.tenantId)\n await em.nativeDelete(SalesDocumentTagAssignment, { tag: tag.id })\n em.remove(tag)\n await em.flush()\n return { tagId: id }\n },\n}\n\nregisterCommand(createTagCommand)\nregisterCommand(updateTagCommand)\nregisterCommand(deleteTagCommand)\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,uBAAuB;AAGhC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB,kCAAkC;AAC7D,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,MAAM,mBAA2E;AAAA,EAC/E,IAAI;AAAA,EACJ,MAAM,QAAQ,UAAU,KAAK;AAC3B,UAAM,SAAS,qBAAqB,MAAM,YAAY,CAAC,CAAC;AACxD,sBAAkB,KAAK,OAAO,QAAQ;AACtC,UAAM,KAAM,IAAI,UAAU,QAAQ,IAAI,EAAoB,KAAK;AAC/D,UAAM,WAAW,MAAM,GAAG,QAAQ,kBAAkB;AAAA,MAClD,MAAM,OAAO;AAAA,MACb,gBAAgB,OAAO;AAAA,MACvB,UAAU,OAAO;AAAA,IACnB,CAAC;AACD,QAAI,SAAU,OAAM,IAAI,cAAc,K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,OAAO,eAAe;AAC9E,QAAI,OAAO,eAAgB,KAAI,iBAAiB,OAAO;AACvD,QAAI,OAAO,SAAU,KAAI,WAAW,OAAO;AAC3C,UAAM,GAAG,MAAM;AACf,WAAO,EAAE,OAAO,IAAI,GAAG;AAAA,EACzB;AACF;AAEA,MAAM,mBAAuE;AAAA,EAC3E,IAAI;AAAA,EACJ,MAAM,QAAQ,OAAO,KAAK;AACxB,UAAM,KAAK,OAAO,OAAO,OAAO,WAAW,MAAM,KAAK;AACtD,QAAI,CAAC,GAAI,OAAM,IAAI,cAAc,KAAK,EAAE,OAAO,qBAAqB,CAAC;AACrE,UAAM,KAAM,IAAI,UAAU,QAAQ,IAAI,EAAoB,KAAK;AAC/D,UAAM,MAAM,MAAM,GAAG,QAAQ,kBAAkB,EAAE,GAAG,CAAC;AACrD,QAAI,CAAC,IAAK,OAAM,IAAI,cAAc,KAAK,EAAE,OAAO,gBAAgB,CAAC;AACjE,sBAAkB,KAAK,IAAI,QAAQ;AACnC,UAAM,GAAG,aAAa,4BAA4B,EAAE,KAAK,IAAI,GAAG,CAAC;AACjE,OAAG,OAAO,GAAG;AACb,UAAM,GAAG,MAAM;AACf,WAAO,EAAE,OAAO,GAAG;AAAA,EACrB;AACF;AAEA,gBAAgB,gBAAgB;AAChC,gBAAgB,gBAAgB;AAChC,gBAAgB,gBAAgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { buildAttachmentImageUrl } from "../../attachments/lib/imageUrls.js";
|
|
2
|
-
function
|
|
3
|
-
|
|
2
|
+
function getDb(em) {
|
|
3
|
+
const getter = em?.getKysely;
|
|
4
|
+
return typeof getter === "function" ? getter.call(em) : null;
|
|
4
5
|
}
|
|
5
|
-
async function fetchMediaIds(
|
|
6
|
+
async function fetchMediaIds(db, table, ids, organizationId) {
|
|
6
7
|
const map = /* @__PURE__ */ new Map();
|
|
7
8
|
if (ids.size === 0) return map;
|
|
8
|
-
const rows = await
|
|
9
|
+
const rows = await db.selectFrom(table).select(["id", "default_media_id"]).where("id", "in", [...ids]).where("organization_id", "=", organizationId).where("deleted_at", "is", null).execute();
|
|
9
10
|
for (const row of rows) {
|
|
10
11
|
map.set(row.id, row.default_media_id ? buildAttachmentImageUrl(row.default_media_id) : null);
|
|
11
12
|
}
|
|
@@ -45,8 +46,8 @@ function createCatalogImageEnricher(targetEntity) {
|
|
|
45
46
|
},
|
|
46
47
|
async enrichMany(records, context) {
|
|
47
48
|
if (records.length === 0) return records;
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
49
|
+
const db = getDb(context.em);
|
|
50
|
+
if (!db) return records;
|
|
50
51
|
const productIds = /* @__PURE__ */ new Set();
|
|
51
52
|
const variantIds = /* @__PURE__ */ new Set();
|
|
52
53
|
for (const record of records) {
|
|
@@ -55,8 +56,8 @@ function createCatalogImageEnricher(targetEntity) {
|
|
|
55
56
|
}
|
|
56
57
|
if (productIds.size === 0 && variantIds.size === 0) return records;
|
|
57
58
|
const [productMedia, variantMedia] = await Promise.all([
|
|
58
|
-
fetchMediaIds(
|
|
59
|
-
fetchMediaIds(
|
|
59
|
+
fetchMediaIds(db, "catalog_products", productIds, context.organizationId),
|
|
60
|
+
fetchMediaIds(db, "catalog_product_variants", variantIds, context.organizationId)
|
|
60
61
|
]);
|
|
61
62
|
return enrichRecords(records, productMedia, variantMedia);
|
|
62
63
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sales/data/enrichers.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Catalog Image Enricher\n *\n * Overrides the snapshot's `thumbnailUrl` with a freshly built URL from the\n * product/variant's current `defaultMediaId`. This ensures quote/order lines\n * always reflect the latest product image, even when the underlying attachment\n * changes. The snapshot serves as fallback for deleted products.\n *\n * Uses raw
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Catalog Image Enricher\n *\n * Overrides the snapshot's `thumbnailUrl` with a freshly built URL from the\n * product/variant's current `defaultMediaId`. This ensures quote/order lines\n * always reflect the latest product image, even when the underlying attachment\n * changes. The snapshot serves as fallback for deleted products.\n *\n * Uses raw Kysely queries because cross-module ORM entity class references\n * do not resolve correctly at runtime (the imported class does not match the\n * entity registered in MikroORM's metadata by the app bootstrap).\n */\n\nimport type { Kysely } from 'kysely'\nimport type { ResponseEnricher, EnricherContext } from '@open-mercato/shared/lib/crud/response-enricher'\nimport { buildAttachmentImageUrl } from '../../attachments/lib/imageUrls'\n\ntype LineRecord = Record<string, unknown> & { id: string }\n\ntype SnapshotNode = { thumbnailUrl?: string | null; [key: string]: unknown }\ntype CatalogSnapshot = { product?: SnapshotNode; variant?: SnapshotNode; [key: string]: unknown }\n\nfunction getDb(em: unknown): Kysely<any> | null {\n const getter = (em as any)?.getKysely\n return typeof getter === 'function' ? getter.call(em) : null\n}\n\nasync function fetchMediaIds(\n db: Kysely<any>,\n table: string,\n ids: Set<string>,\n organizationId: string,\n): Promise<Map<string, string | null>> {\n const map = new Map<string, string | null>()\n if (ids.size === 0) return map\n\n const rows = await (db as any)\n .selectFrom(table)\n .select(['id', 'default_media_id'])\n .where('id', 'in', [...ids])\n .where('organization_id', '=', organizationId)\n .where('deleted_at', 'is', null)\n .execute() as Array<{ id: string; default_media_id: string | null }>\n\n for (const row of rows) {\n map.set(row.id, row.default_media_id ? buildAttachmentImageUrl(row.default_media_id) : null)\n }\n return map\n}\n\nfunction enrichRecords(\n records: LineRecord[],\n productMedia: Map<string, string | null>,\n variantMedia: Map<string, string | null>,\n): LineRecord[] {\n return records.map((record) => {\n const productId = record['product_id'] as string | undefined\n const variantId = record['product_variant_id'] as string | undefined\n\n const productUrl = productId ? productMedia.get(productId) : undefined\n const variantUrl = variantId ? variantMedia.get(variantId) : undefined\n if (productUrl === undefined && variantUrl === undefined) return record\n\n const snapshot = (record['catalog_snapshot'] as CatalogSnapshot | null | undefined) ?? {}\n const updatedSnapshot = { ...snapshot }\n\n if (productUrl !== undefined) {\n updatedSnapshot.product = { ...snapshot.product, thumbnailUrl: productUrl ?? snapshot.product?.thumbnailUrl }\n }\n if (variantUrl !== undefined) {\n updatedSnapshot.variant = { ...snapshot.variant, thumbnailUrl: variantUrl ?? snapshot.variant?.thumbnailUrl }\n }\n\n const changed =\n updatedSnapshot.product?.thumbnailUrl !== snapshot.product?.thumbnailUrl ||\n updatedSnapshot.variant?.thumbnailUrl !== snapshot.variant?.thumbnailUrl\n if (!changed) return record\n\n return { ...record, catalog_snapshot: updatedSnapshot }\n })\n}\n\nfunction createCatalogImageEnricher(targetEntity: string): ResponseEnricher<LineRecord> {\n return {\n id: `sales.catalog-image:${targetEntity}`,\n targetEntity,\n features: [],\n priority: 5,\n timeout: 1000,\n critical: false,\n fallback: {},\n\n async enrichOne(record, context: EnricherContext) {\n return (await this.enrichMany!([record], context))[0]\n },\n\n async enrichMany(records, context: EnricherContext) {\n if (records.length === 0) return records\n\n const db = getDb(context.em)\n if (!db) return records\n\n const productIds = new Set<string>()\n const variantIds = new Set<string>()\n for (const record of records) {\n if (typeof record['product_id'] === 'string') productIds.add(record['product_id'])\n if (typeof record['product_variant_id'] === 'string') variantIds.add(record['product_variant_id'])\n }\n if (productIds.size === 0 && variantIds.size === 0) return records\n\n const [productMedia, variantMedia] = await Promise.all([\n fetchMediaIds(db, 'catalog_products', productIds, context.organizationId),\n fetchMediaIds(db, 'catalog_product_variants', variantIds, context.organizationId),\n ])\n\n return enrichRecords(records, productMedia, variantMedia)\n },\n }\n}\n\nexport const enrichers: ResponseEnricher[] = [\n createCatalogImageEnricher('sales:sales_quote_line'),\n createCatalogImageEnricher('sales:sales_order_line'),\n]\n"],
|
|
5
|
+
"mappings": "AAeA,SAAS,+BAA+B;AAOxC,SAAS,MAAM,IAAiC;AAC9C,QAAM,SAAU,IAAY;AAC5B,SAAO,OAAO,WAAW,aAAa,OAAO,KAAK,EAAE,IAAI;AAC1D;AAEA,eAAe,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,2BAA2B,cAAoD;AACtF,SAAO;AAAA,IACL,IAAI,uBAAuB,YAAY;AAAA,IACvC;AAAA,IACA,UAAU,CAAC;AAAA,IACX,UAAU;AAAA,IACV,SAAS;AAAA,IACT,UAAU;AAAA,IACV,UAAU,CAAC;AAAA,IAEX,MAAM,UAAU,QAAQ,SAA0B;AAChD,cAAQ,MAAM,KAAK,WAAY,CAAC,MAAM,GAAG,OAAO,GAAG,CAAC;AAAA,IACtD;AAAA,IAEA,MAAM,WAAW,SAAS,SAA0B;AAClD,UAAI,QAAQ,WAAW,EAAG,QAAO;AAEjC,YAAM,KAAK,MAAM,QAAQ,EAAE;AAC3B,UAAI,CAAC,GAAI,QAAO;AAEhB,YAAM,aAAa,oBAAI,IAAY;AACnC,YAAM,aAAa,oBAAI,IAAY;AACnC,iBAAW,UAAU,SAAS;AAC5B,YAAI,OAAO,OAAO,YAAY,MAAM,SAAU,YAAW,IAAI,OAAO,YAAY,CAAC;AACjF,YAAI,OAAO,OAAO,oBAAoB,MAAM,SAAU,YAAW,IAAI,OAAO,oBAAoB,CAAC;AAAA,MACnG;AACA,UAAI,WAAW,SAAS,KAAK,WAAW,SAAS,EAAG,QAAO;AAE3D,YAAM,CAAC,cAAc,YAAY,IAAI,MAAM,QAAQ,IAAI;AAAA,QACrD,cAAc,IAAI,oBAAoB,YAAY,QAAQ,cAAc;AAAA,QACxE,cAAc,IAAI,4BAA4B,YAAY,QAAQ,cAAc;AAAA,MAClF,CAAC;AAED,aAAO,cAAc,SAAS,cAAc,YAAY;AAAA,IAC1D;AAAA,EACF;AACF;AAEO,MAAM,YAAgC;AAAA,EAC3C,2BAA2B,wBAAwB;AAAA,EACnD,2BAA2B,wBAAwB;AACrD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -8,17 +8,8 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
8
8
|
if (kind && result) __defProp(target, key, result);
|
|
9
9
|
return result;
|
|
10
10
|
};
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
Entity,
|
|
14
|
-
Index,
|
|
15
|
-
ManyToOne,
|
|
16
|
-
OneToMany,
|
|
17
|
-
OptionalProps,
|
|
18
|
-
PrimaryKey,
|
|
19
|
-
Property,
|
|
20
|
-
Unique
|
|
21
|
-
} from "@mikro-orm/core";
|
|
11
|
+
import { Collection, OptionalProps } from "@mikro-orm/core";
|
|
12
|
+
import { Entity, Index, ManyToOne, OneToMany, PrimaryKey, Property, Unique } from "@mikro-orm/decorators/legacy";
|
|
22
13
|
import { DEFAULT_ORDER_NUMBER_FORMAT, DEFAULT_QUOTE_NUMBER_FORMAT } from "../lib/documentNumberTokens.js";
|
|
23
14
|
const DEFAULT_SALES_ADJUSTMENT_KINDS = ["discount", "tax", "shipping", "surcharge", "return", "custom"];
|
|
24
15
|
let SalesChannel = class {
|