@open-mercato/core 0.6.5-develop.5337.1.534b781eac → 0.6.5
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/.turbo/turbo-build.log +1 -1
- package/AGENTS.md +1 -1
- package/dist/bootstrap.js +46 -6
- package/dist/bootstrap.js.map +2 -2
- package/dist/generated/entities/organization/index.js +2 -0
- package/dist/generated/entities/organization/index.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +1 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/helpers/integration/crmFixtures.js +4 -0
- package/dist/helpers/integration/crmFixtures.js.map +2 -2
- package/dist/modules/attachments/api/library/route.js +2 -2
- package/dist/modules/attachments/api/library/route.js.map +2 -2
- package/dist/modules/attachments/api/route.js +2 -0
- package/dist/modules/attachments/api/route.js.map +2 -2
- package/dist/modules/attachments/components/AttachmentContentPreview.js +9 -5
- package/dist/modules/attachments/components/AttachmentContentPreview.js.map +2 -2
- package/dist/modules/attachments/lib/access.js +18 -0
- package/dist/modules/attachments/lib/access.js.map +2 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/redo/route.js +3 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/redo/route.js.map +2 -2
- package/dist/modules/audit_logs/data/entities.js +2 -1
- package/dist/modules/audit_logs/data/entities.js.map +2 -2
- package/dist/modules/audit_logs/migrations/Migration20260611104500.js +13 -0
- package/dist/modules/audit_logs/migrations/Migration20260611104500.js.map +7 -0
- package/dist/modules/audit_logs/services/accessLogService.js +10 -0
- package/dist/modules/audit_logs/services/accessLogService.js.map +2 -2
- package/dist/modules/auth/api/admin/nav.js +9 -0
- package/dist/modules/auth/api/admin/nav.js.map +2 -2
- package/dist/modules/auth/api/login.js +4 -13
- package/dist/modules/auth/api/login.js.map +2 -2
- package/dist/modules/auth/commands/users.js +20 -14
- package/dist/modules/auth/commands/users.js.map +2 -2
- package/dist/modules/auth/data/entities.js +4 -2
- package/dist/modules/auth/data/entities.js.map +2 -2
- package/dist/modules/auth/lib/backendChrome.js +35 -2
- package/dist/modules/auth/lib/backendChrome.js.map +2 -2
- package/dist/modules/auth/lib/consentIntegrity.js +3 -3
- package/dist/modules/auth/lib/consentIntegrity.js.map +2 -2
- package/dist/modules/auth/migrations/Migration20260610120000.js +30 -0
- package/dist/modules/auth/migrations/Migration20260610120000.js.map +7 -0
- package/dist/modules/auth/migrations/Migration20260611103000.js +15 -0
- package/dist/modules/auth/migrations/Migration20260611103000.js.map +7 -0
- package/dist/modules/auth/services/authService.js +5 -3
- package/dist/modules/auth/services/authService.js.map +2 -2
- package/dist/modules/auth/services/rbacService.js +3 -2
- package/dist/modules/auth/services/rbacService.js.map +2 -2
- package/dist/modules/catalog/ai-tools/configuration-pack.js.map +1 -1
- package/dist/modules/catalog/ai-tools/prices-offers-pack.js.map +1 -1
- package/dist/modules/catalog/ai-tools/products-pack.js.map +1 -1
- package/dist/modules/catalog/ai-tools/variants-pack.js.map +1 -1
- package/dist/modules/communication_channels/data/entities.js.map +1 -1
- package/dist/modules/communication_channels/encryption.js.map +1 -1
- package/dist/modules/communication_channels/lib/thread-matcher.js.map +1 -1
- package/dist/modules/communication_channels/lib/thread-token.js.map +1 -1
- package/dist/modules/currencies/api/currencies/route.js +4 -3
- package/dist/modules/currencies/api/currencies/route.js.map +2 -2
- package/dist/modules/customer_accounts/api/admin/roles.js +2 -1
- package/dist/modules/customer_accounts/api/admin/roles.js.map +2 -2
- package/dist/modules/customer_accounts/backend/customer_accounts/settings/domain/components/Diagnostics.js +0 -3
- package/dist/modules/customer_accounts/backend/customer_accounts/settings/domain/components/Diagnostics.js.map +2 -2
- package/dist/modules/customer_accounts/events.js +1 -1
- package/dist/modules/customer_accounts/events.js.map +1 -1
- package/dist/modules/customer_accounts/lib/resolveTenantContext.js.map +1 -1
- package/dist/modules/customers/acl.js +1 -1
- package/dist/modules/customers/acl.js.map +1 -1
- package/dist/modules/customers/ai-tools/companies-pack.js.map +1 -1
- package/dist/modules/customers/ai-tools/deals-pack.js.map +1 -1
- package/dist/modules/customers/ai-tools/people-pack.js.map +1 -1
- package/dist/modules/customers/api/companies/route.js +4 -4
- package/dist/modules/customers/api/companies/route.js.map +2 -2
- package/dist/modules/customers/api/deals/route.js +43 -2
- package/dist/modules/customers/api/deals/route.js.map +2 -2
- package/dist/modules/customers/api/deals/summary/route.js +402 -0
- package/dist/modules/customers/api/deals/summary/route.js.map +7 -0
- package/dist/modules/customers/api/people/route.js +4 -4
- package/dist/modules/customers/api/people/route.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/[id]/hooks/useDealActivities.js +16 -5
- package/dist/modules/customers/backend/customers/deals/[id]/hooks/useDealActivities.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/[id]/hooks/useDealData.js +22 -5
- package/dist/modules/customers/backend/customers/deals/[id]/hooks/useDealData.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/[id]/page.js +12 -2
- package/dist/modules/customers/backend/customers/deals/[id]/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/page.js +221 -56
- package/dist/modules/customers/backend/customers/deals/page.js.map +3 -3
- package/dist/modules/customers/backend/customers/deals/pipeline/page.js +1 -1
- package/dist/modules/customers/backend/customers/deals/pipeline/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/people-v2/[id]/page.js +18 -0
- package/dist/modules/customers/backend/customers/people-v2/[id]/page.js.map +2 -2
- package/dist/modules/customers/cli.js +15 -9
- package/dist/modules/customers/cli.js.map +2 -2
- package/dist/modules/customers/commands/addresses.js +5 -5
- package/dist/modules/customers/commands/addresses.js.map +2 -2
- package/dist/modules/customers/commands/comments.js +5 -5
- package/dist/modules/customers/commands/comments.js.map +2 -2
- package/dist/modules/customers/commands/deals.js +2 -2
- package/dist/modules/customers/commands/deals.js.map +2 -2
- package/dist/modules/customers/commands/entity-roles.js +2 -1
- package/dist/modules/customers/commands/entity-roles.js.map +2 -2
- package/dist/modules/customers/commands/interactions.js +8 -5
- package/dist/modules/customers/commands/interactions.js.map +2 -2
- package/dist/modules/customers/commands/shared.js +21 -6
- package/dist/modules/customers/commands/shared.js.map +2 -2
- package/dist/modules/customers/commands/tags.js +3 -3
- package/dist/modules/customers/commands/tags.js.map +2 -2
- package/dist/modules/customers/components/DealsKpiStrip.js +282 -0
- package/dist/modules/customers/components/DealsKpiStrip.js.map +7 -0
- package/dist/modules/customers/components/detail/ConfirmDealLostDialog.js +0 -1
- package/dist/modules/customers/components/detail/ConfirmDealLostDialog.js.map +2 -2
- package/dist/modules/customers/components/detail/DealForm.js +100 -17
- package/dist/modules/customers/components/detail/DealForm.js.map +2 -2
- package/dist/modules/customers/components/detail/PersonDetailTabs.js +11 -3
- package/dist/modules/customers/components/detail/PersonDetailTabs.js.map +2 -2
- package/dist/modules/customers/components/detail/ScheduleActivityDialog.js +1 -2
- package/dist/modules/customers/components/detail/ScheduleActivityDialog.js.map +2 -2
- package/dist/modules/customers/components/detail/assignableStaff.js +21 -8
- package/dist/modules/customers/components/detail/assignableStaff.js.map +2 -2
- package/dist/modules/customers/components/kpi/PipelineStageBar.js +63 -0
- package/dist/modules/customers/components/kpi/PipelineStageBar.js.map +7 -0
- package/dist/modules/customers/lib/dealsMetrics.js +82 -0
- package/dist/modules/customers/lib/dealsMetrics.js.map +7 -0
- package/dist/modules/customers/migrations/Migration20260519120000_pipeline_stage_color_tones.js.map +1 -1
- package/dist/modules/data_sync/api/run.js +1 -1
- package/dist/modules/data_sync/api/run.js.map +2 -2
- package/dist/modules/directory/api/organization-branding/route.js +214 -0
- package/dist/modules/directory/api/organization-branding/route.js.map +7 -0
- package/dist/modules/directory/api/organizations/route.js +7 -0
- package/dist/modules/directory/api/organizations/route.js.map +3 -3
- package/dist/modules/directory/backend/directory/branding/page.js +214 -0
- package/dist/modules/directory/backend/directory/branding/page.js.map +7 -0
- package/dist/modules/directory/backend/directory/branding/page.meta.js +26 -0
- package/dist/modules/directory/backend/directory/branding/page.meta.js.map +7 -0
- package/dist/modules/directory/commands/organizations.js +8 -1
- package/dist/modules/directory/commands/organizations.js.map +2 -2
- package/dist/modules/directory/data/entities.js +3 -0
- package/dist/modules/directory/data/entities.js.map +2 -2
- package/dist/modules/directory/data/validators.js +9 -0
- package/dist/modules/directory/data/validators.js.map +2 -2
- package/dist/modules/directory/migrations/Migration20260607222259_directory.js +13 -0
- package/dist/modules/directory/migrations/Migration20260607222259_directory.js.map +7 -0
- package/dist/modules/directory/subscribers/invalidateOrgScopeCache.js +2 -1
- package/dist/modules/directory/subscribers/invalidateOrgScopeCache.js.map +2 -2
- package/dist/modules/directory/utils/organizationScope.js +59 -27
- package/dist/modules/directory/utils/organizationScope.js.map +2 -2
- package/dist/modules/entities/api/definitions.batch.js +2 -1
- package/dist/modules/entities/api/definitions.batch.js.map +2 -2
- package/dist/modules/entities/api/entities.js +7 -0
- package/dist/modules/entities/api/entities.js.map +2 -2
- package/dist/modules/entities/api/records.js +26 -15
- package/dist/modules/entities/api/records.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/records/[recordId]/page.js +14 -0
- package/dist/modules/entities/backend/entities/user/[entityId]/records/[recordId]/page.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/records/create/page.js +14 -0
- package/dist/modules/entities/backend/entities/user/[entityId]/records/create/page.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js +12 -0
- package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js.map +2 -2
- package/dist/modules/entities/components/useRecordsEntityGuard.js +30 -0
- package/dist/modules/entities/components/useRecordsEntityGuard.js.map +7 -0
- package/dist/modules/payment_gateways/api/transactions/route.js +2 -4
- package/dist/modules/payment_gateways/api/transactions/route.js.map +2 -2
- package/dist/modules/progress/api/jobs/[id]/route.js +7 -2
- package/dist/modules/progress/api/jobs/[id]/route.js.map +2 -2
- package/dist/modules/progress/api/jobs/route.js +1 -1
- package/dist/modules/progress/api/jobs/route.js.map +2 -2
- package/dist/modules/progress/lib/progressServiceImpl.js +8 -2
- package/dist/modules/progress/lib/progressServiceImpl.js.map +2 -2
- package/dist/modules/query_index/data/entities.js +2 -1
- package/dist/modules/query_index/data/entities.js.map +2 -2
- package/dist/modules/query_index/lib/engine.js +4 -2
- package/dist/modules/query_index/lib/engine.js.map +2 -2
- package/dist/modules/query_index/migrations/Migration20260611103000_query_index.js +16 -0
- package/dist/modules/query_index/migrations/Migration20260611103000_query_index.js.map +7 -0
- package/dist/modules/resources/api/resources.js +2 -3
- package/dist/modules/resources/api/resources.js.map +2 -2
- package/dist/modules/sales/api/documents/factory.js +2 -2
- package/dist/modules/sales/api/documents/factory.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +7 -5
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/components/documents/SalesDocumentsTable.js +2 -1
- package/dist/modules/sales/components/documents/SalesDocumentsTable.js.map +2 -2
- package/dist/modules/sales/components/documents/salesDocumentsColumns.js +10 -0
- package/dist/modules/sales/components/documents/salesDocumentsColumns.js.map +7 -0
- package/dist/modules/staff/api/team-members.js +9 -2
- package/dist/modules/staff/api/team-members.js.map +2 -2
- package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js +24 -1
- package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js.map +2 -2
- package/dist/modules/staff/backend/staff/team-members/[id]/page.js +11 -6
- package/dist/modules/staff/backend/staff/team-members/[id]/page.js.map +2 -2
- package/dist/modules/staff/commands/team-members.js +1 -1
- package/dist/modules/staff/commands/team-members.js.map +2 -2
- package/dist/modules/staff/components/TeamMemberForm.js +1 -1
- package/dist/modules/staff/components/TeamMemberForm.js.map +2 -2
- package/dist/modules/staff/lib/scheduleSwitch.js +23 -0
- package/dist/modules/staff/lib/scheduleSwitch.js.map +7 -0
- package/dist/modules/sync_excel/api/import/route.js +1 -1
- package/dist/modules/sync_excel/api/import/route.js.map +2 -2
- package/dist/modules/workflows/api/definitions/route.js +3 -2
- package/dist/modules/workflows/api/definitions/route.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/create/page.js +1 -2
- package/dist/modules/workflows/backend/definitions/create/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/visual-editor/page.js +1 -2
- package/dist/modules/workflows/backend/definitions/visual-editor/page.js.map +2 -2
- package/dist/modules/workflows/components/DefinitionTriggersEditor.js +1 -2
- package/dist/modules/workflows/components/DefinitionTriggersEditor.js.map +2 -2
- package/dist/modules/workflows/components/NodeEditDialog.js +4 -13
- package/dist/modules/workflows/components/NodeEditDialog.js.map +2 -2
- package/dist/modules/workflows/components/NodeEditDialogCrudForm.js +4 -13
- package/dist/modules/workflows/components/NodeEditDialogCrudForm.js.map +2 -2
- package/dist/modules/workflows/components/WorkflowGraphImpl.js +1 -4
- package/dist/modules/workflows/components/WorkflowGraphImpl.js.map +2 -2
- package/dist/modules/workflows/components/fields/FormFieldArrayEditor.js +2 -5
- package/dist/modules/workflows/components/fields/FormFieldArrayEditor.js.map +2 -2
- package/generated/entities/organization/index.ts +1 -0
- package/generated/entity-fields-registry.ts +1 -0
- package/package.json +11 -12
- package/src/bootstrap.ts +65 -7
- package/src/helpers/integration/crmFixtures.ts +21 -1
- package/src/modules/attachments/AGENTS.md +79 -0
- package/src/modules/attachments/api/library/route.ts +2 -2
- package/src/modules/attachments/api/route.ts +2 -0
- package/src/modules/attachments/components/AttachmentContentPreview.tsx +6 -6
- package/src/modules/attachments/lib/access.ts +36 -0
- package/src/modules/audit_logs/api/audit-logs/actions/redo/route.ts +14 -2
- package/src/modules/audit_logs/data/entities.ts +1 -0
- package/src/modules/audit_logs/migrations/.snapshot-open-mercato.json +10 -0
- package/src/modules/audit_logs/migrations/Migration20260611104500.ts +13 -0
- package/src/modules/audit_logs/services/accessLogService.ts +15 -0
- package/src/modules/auth/api/admin/nav.ts +9 -0
- package/src/modules/auth/api/login.ts +13 -13
- package/src/modules/auth/commands/users.ts +32 -15
- package/src/modules/auth/data/entities.ts +13 -1
- package/src/modules/auth/i18n/de.json +0 -1
- package/src/modules/auth/i18n/en.json +0 -1
- package/src/modules/auth/i18n/es.json +0 -1
- package/src/modules/auth/i18n/pl.json +0 -1
- package/src/modules/auth/lib/backendChrome.tsx +37 -1
- package/src/modules/auth/lib/consentIntegrity.ts +6 -3
- package/src/modules/auth/migrations/.snapshot-open-mercato.json +20 -10
- package/src/modules/auth/migrations/Migration20260610120000.ts +53 -0
- package/src/modules/auth/migrations/Migration20260611103000.ts +21 -0
- package/src/modules/auth/services/authService.ts +24 -4
- package/src/modules/auth/services/rbacService.ts +11 -2
- package/src/modules/catalog/ai-tools/configuration-pack.ts +1 -1
- package/src/modules/catalog/ai-tools/prices-offers-pack.ts +1 -1
- package/src/modules/catalog/ai-tools/products-pack.ts +1 -1
- package/src/modules/catalog/ai-tools/variants-pack.ts +1 -1
- package/src/modules/communication_channels/data/entities.ts +2 -2
- package/src/modules/communication_channels/encryption.ts +1 -1
- package/src/modules/communication_channels/lib/adapter.ts +1 -1
- package/src/modules/communication_channels/lib/thread-matcher.ts +1 -1
- package/src/modules/communication_channels/lib/thread-token.ts +1 -1
- package/src/modules/currencies/api/currencies/route.ts +4 -3
- package/src/modules/customer_accounts/api/admin/roles.ts +2 -1
- package/src/modules/customer_accounts/backend/customer_accounts/settings/domain/components/Diagnostics.tsx +0 -3
- package/src/modules/customer_accounts/events.ts +1 -1
- package/src/modules/customer_accounts/lib/resolveTenantContext.ts +2 -2
- package/src/modules/customers/acl.ts +1 -1
- package/src/modules/customers/ai-tools/companies-pack.ts +1 -1
- package/src/modules/customers/ai-tools/deals-pack.ts +1 -1
- package/src/modules/customers/ai-tools/people-pack.ts +1 -1
- package/src/modules/customers/api/companies/route.ts +4 -4
- package/src/modules/customers/api/deals/route.ts +51 -2
- package/src/modules/customers/api/deals/summary/route.ts +496 -0
- package/src/modules/customers/api/people/route.ts +4 -4
- package/src/modules/customers/backend/customers/deals/[id]/hooks/useDealActivities.ts +28 -6
- package/src/modules/customers/backend/customers/deals/[id]/hooks/useDealData.ts +33 -6
- package/src/modules/customers/backend/customers/deals/[id]/page.tsx +17 -2
- package/src/modules/customers/backend/customers/deals/page.tsx +254 -66
- package/src/modules/customers/backend/customers/deals/pipeline/page.tsx +1 -2
- package/src/modules/customers/backend/customers/people-v2/[id]/page.tsx +18 -0
- package/src/modules/customers/cli.ts +15 -15
- package/src/modules/customers/commands/addresses.ts +5 -5
- package/src/modules/customers/commands/comments.ts +5 -5
- package/src/modules/customers/commands/deals.ts +2 -2
- package/src/modules/customers/commands/entity-roles.ts +2 -1
- package/src/modules/customers/commands/interactions.ts +8 -5
- package/src/modules/customers/commands/shared.ts +26 -4
- package/src/modules/customers/commands/tags.ts +3 -3
- package/src/modules/customers/components/DealsKpiStrip.tsx +389 -0
- package/src/modules/customers/components/detail/ConfirmDealLostDialog.tsx +0 -1
- package/src/modules/customers/components/detail/DealForm.tsx +121 -19
- package/src/modules/customers/components/detail/PersonDetailTabs.tsx +12 -2
- package/src/modules/customers/components/detail/ScheduleActivityDialog.tsx +1 -2
- package/src/modules/customers/components/detail/assignableStaff.ts +32 -8
- package/src/modules/customers/components/kpi/PipelineStageBar.tsx +77 -0
- package/src/modules/customers/i18n/de.json +43 -0
- package/src/modules/customers/i18n/en.json +43 -0
- package/src/modules/customers/i18n/es.json +43 -0
- package/src/modules/customers/i18n/pl.json +43 -0
- package/src/modules/customers/lib/dealsMetrics.ts +159 -0
- package/src/modules/customers/migrations/Migration20260519120000_pipeline_stage_color_tones.ts +1 -1
- package/src/modules/data_sync/api/run.ts +1 -1
- package/src/modules/directory/api/organization-branding/route.ts +238 -0
- package/src/modules/directory/api/organizations/route.ts +7 -0
- package/src/modules/directory/backend/directory/branding/page.meta.ts +24 -0
- package/src/modules/directory/backend/directory/branding/page.tsx +248 -0
- package/src/modules/directory/commands/organizations.ts +9 -1
- package/src/modules/directory/data/entities.ts +3 -0
- package/src/modules/directory/data/validators.ts +12 -0
- package/src/modules/directory/i18n/de.json +21 -0
- package/src/modules/directory/i18n/en.json +21 -0
- package/src/modules/directory/i18n/es.json +21 -0
- package/src/modules/directory/i18n/pl.json +21 -0
- package/src/modules/directory/migrations/.snapshot-open-mercato.json +40 -0
- package/src/modules/directory/migrations/Migration20260607222259_directory.ts +13 -0
- package/src/modules/directory/subscribers/invalidateOrgScopeCache.ts +3 -1
- package/src/modules/directory/utils/organizationScope.ts +85 -30
- package/src/modules/entities/api/definitions.batch.ts +11 -7
- package/src/modules/entities/api/entities.ts +11 -0
- package/src/modules/entities/api/records.ts +46 -25
- package/src/modules/entities/backend/entities/user/[entityId]/records/[recordId]/page.tsx +15 -0
- package/src/modules/entities/backend/entities/user/[entityId]/records/create/page.tsx +15 -0
- package/src/modules/entities/backend/entities/user/[entityId]/records/page.tsx +23 -0
- package/src/modules/entities/components/useRecordsEntityGuard.ts +41 -0
- package/src/modules/entities/i18n/de.json +1 -0
- package/src/modules/entities/i18n/en.json +1 -0
- package/src/modules/entities/i18n/es.json +1 -0
- package/src/modules/entities/i18n/pl.json +1 -0
- package/src/modules/payment_gateways/api/transactions/route.ts +2 -5
- package/src/modules/progress/api/jobs/[id]/route.ts +6 -1
- package/src/modules/progress/api/jobs/route.ts +1 -1
- package/src/modules/progress/lib/progressServiceImpl.ts +7 -1
- package/src/modules/query_index/data/entities.ts +1 -0
- package/src/modules/query_index/lib/engine.ts +11 -5
- package/src/modules/query_index/migrations/.snapshot-open-mercato.json +11 -0
- package/src/modules/query_index/migrations/Migration20260611103000_query_index.ts +29 -0
- package/src/modules/resources/api/resources.ts +2 -3
- package/src/modules/sales/api/documents/factory.ts +2 -2
- package/src/modules/sales/commands/documents.ts +7 -5
- package/src/modules/sales/components/documents/SalesDocumentsTable.tsx +2 -1
- package/src/modules/sales/components/documents/salesDocumentsColumns.ts +6 -0
- package/src/modules/staff/AGENTS.md +1 -1
- package/src/modules/staff/api/team-members.ts +9 -2
- package/src/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.ts +31 -1
- package/src/modules/staff/backend/staff/team-members/[id]/page.tsx +18 -8
- package/src/modules/staff/commands/team-members.ts +5 -2
- package/src/modules/staff/components/TeamMemberForm.tsx +4 -1
- package/src/modules/staff/i18n/de.json +1 -0
- package/src/modules/staff/i18n/en.json +1 -0
- package/src/modules/staff/i18n/es.json +1 -0
- package/src/modules/staff/i18n/pl.json +1 -0
- package/src/modules/staff/lib/scheduleSwitch.ts +46 -0
- package/src/modules/sync_excel/api/import/route.ts +1 -1
- package/src/modules/workflows/api/definitions/route.ts +3 -2
- package/src/modules/workflows/backend/definitions/create/page.tsx +1 -2
- package/src/modules/workflows/backend/definitions/visual-editor/page.tsx +1 -2
- package/src/modules/workflows/components/DefinitionTriggersEditor.tsx +1 -2
- package/src/modules/workflows/components/NodeEditDialog.tsx +1 -4
- package/src/modules/workflows/components/NodeEditDialogCrudForm.tsx +4 -7
- package/src/modules/workflows/components/WorkflowGraphImpl.tsx +1 -2
- package/src/modules/workflows/components/fields/FormFieldArrayEditor.tsx +2 -3
|
@@ -4,13 +4,11 @@ import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
|
4
4
|
import { GatewayTransaction } from "../../data/entities.js";
|
|
5
5
|
import { listTransactionsQuerySchema } from "../../data/validators.js";
|
|
6
6
|
import { paymentGatewaysTag } from "../openapi.js";
|
|
7
|
+
import { buildIlikeTerm } from "@open-mercato/shared/lib/db/buildIlikeTerm";
|
|
7
8
|
const metadata = {
|
|
8
9
|
path: "/payment_gateways/transactions",
|
|
9
10
|
GET: { requireAuth: true, requireFeatures: ["payment_gateways.view"] }
|
|
10
11
|
};
|
|
11
|
-
function escapeLikePattern(value) {
|
|
12
|
-
return value.replace(/[\\%_]/g, "\\$&");
|
|
13
|
-
}
|
|
14
12
|
function formatDateValue(value) {
|
|
15
13
|
if (!value) return null;
|
|
16
14
|
if (value instanceof Date) return value.toISOString();
|
|
@@ -49,7 +47,7 @@ async function GET(req) {
|
|
|
49
47
|
qb.andWhere({ unifiedStatus: status });
|
|
50
48
|
}
|
|
51
49
|
if (search) {
|
|
52
|
-
const pattern =
|
|
50
|
+
const pattern = buildIlikeTerm(search);
|
|
53
51
|
qb.andWhere(`(
|
|
54
52
|
cast(gt.id as text) ilike ?
|
|
55
53
|
or cast(gt.payment_id as text) ilike ?
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/payment_gateways/api/transactions/route.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { GatewayTransaction } from '../../data/entities'\nimport { listTransactionsQuerySchema } from '../../data/validators'\nimport { paymentGatewaysTag } from '../openapi'\n\nexport const metadata = {\n path: '/payment_gateways/transactions',\n GET: { requireAuth: true, requireFeatures: ['payment_gateways.view'] },\n}\n\nfunction
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAC5C,SAAS,0BAA0B;
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { GatewayTransaction } from '../../data/entities'\nimport { listTransactionsQuerySchema } from '../../data/validators'\nimport { paymentGatewaysTag } from '../openapi'\nimport { buildIlikeTerm } from '@open-mercato/shared/lib/db/buildIlikeTerm'\n\nexport const metadata = {\n path: '/payment_gateways/transactions',\n GET: { requireAuth: true, requireFeatures: ['payment_gateways.view'] },\n}\n\nfunction formatDateValue(value: unknown): string | null {\n if (!value) return null\n if (value instanceof Date) return value.toISOString()\n if (typeof value === 'string') {\n const parsed = new Date(value)\n if (!Number.isNaN(parsed.getTime())) return parsed.toISOString()\n return value\n }\n const fallback = new Date(value as string | number)\n return Number.isNaN(fallback.getTime()) ? null : fallback.toISOString()\n}\n\nexport async function GET(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const url = new URL(req.url)\n const parsed = listTransactionsQuerySchema.safeParse(Object.fromEntries(url.searchParams.entries()))\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid query', details: parsed.error.flatten() }, { status: 400 })\n }\n\n const { page, pageSize, search, providerKey, status } = parsed.data\n const offset = (page - 1) * pageSize\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n const qb = em.createQueryBuilder(GatewayTransaction, 'gt')\n\n qb.where({\n organizationId: auth.orgId,\n tenantId: auth.tenantId,\n deletedAt: null,\n })\n\n if (providerKey) {\n qb.andWhere({ providerKey })\n }\n if (status) {\n qb.andWhere({ unifiedStatus: status })\n }\n if (search) {\n const pattern = buildIlikeTerm(search)\n qb.andWhere(`(\n cast(gt.id as text) ilike ?\n or cast(gt.payment_id as text) ilike ?\n or coalesce(gt.provider_key, '') ilike ?\n or coalesce(gt.provider_session_id, '') ilike ?\n or coalesce(gt.gateway_payment_id, '') ilike ?\n or coalesce(gt.gateway_refund_id, '') ilike ?\n ) escape '\\\\'`, [pattern, pattern, pattern, pattern, pattern, pattern])\n }\n\n const countQb = qb.clone()\n qb.orderBy({ createdAt: 'desc' })\n qb.limit(pageSize).offset(offset)\n\n const [items, total] = await Promise.all([\n qb.getResultList(),\n countQb.getCount('gt.id', true),\n ])\n\n return NextResponse.json({\n items: items.map((item) => ({\n id: item.id,\n paymentId: item.paymentId,\n providerKey: item.providerKey,\n providerSessionId: item.providerSessionId ?? null,\n gatewayPaymentId: item.gatewayPaymentId ?? null,\n gatewayRefundId: item.gatewayRefundId ?? null,\n unifiedStatus: item.unifiedStatus,\n gatewayStatus: item.gatewayStatus ?? null,\n amount: item.amount,\n currencyCode: item.currencyCode,\n redirectUrl: item.redirectUrl ?? null,\n lastWebhookAt: formatDateValue(item.lastWebhookAt),\n lastPolledAt: formatDateValue(item.lastPolledAt),\n createdAt: formatDateValue(item.createdAt),\n updatedAt: formatDateValue(item.updatedAt),\n })),\n total,\n page,\n pageSize,\n totalPages: Math.max(1, Math.ceil(Number(total) / pageSize)),\n })\n}\n\nexport const openApi = {\n tags: [paymentGatewaysTag],\n summary: 'List payment transactions',\n methods: {\n GET: {\n summary: 'List payment transactions',\n tags: [paymentGatewaysTag],\n responses: [\n { status: 200, description: 'Payment transaction list' },\n ],\n },\n },\n}\n\nexport default GET\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAC5C,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAExB,MAAM,WAAW;AAAA,EACtB,MAAM;AAAA,EACN,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,uBAAuB,EAAE;AACvE;AAEA,SAAS,gBAAgB,OAA+B;AACtD,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,iBAAiB,KAAM,QAAO,MAAM,YAAY;AACpD,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,SAAS,IAAI,KAAK,KAAK;AAC7B,QAAI,CAAC,OAAO,MAAM,OAAO,QAAQ,CAAC,EAAG,QAAO,OAAO,YAAY;AAC/D,WAAO;AAAA,EACT;AACA,QAAM,WAAW,IAAI,KAAK,KAAwB;AAClD,SAAO,OAAO,MAAM,SAAS,QAAQ,CAAC,IAAI,OAAO,SAAS,YAAY;AACxE;AAEA,eAAsB,IAAI,KAAc;AACtC,QAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,MAAI,CAAC,MAAM,YAAY,CAAC,KAAK,OAAO;AAClC,WAAO,aAAa,KAAK,EAAE,OAAO,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AA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MAC1B,IAAI,KAAK;AAAA,MACT,WAAW,KAAK;AAAA,MAChB,aAAa,KAAK;AAAA,MAClB,mBAAmB,KAAK,qBAAqB;AAAA,MAC7C,kBAAkB,KAAK,oBAAoB;AAAA,MAC3C,iBAAiB,KAAK,mBAAmB;AAAA,MACzC,eAAe,KAAK;AAAA,MACpB,eAAe,KAAK,iBAAiB;AAAA,MACrC,QAAQ,KAAK;AAAA,MACb,cAAc,KAAK;AAAA,MACnB,aAAa,KAAK,eAAe;AAAA,MACjC,eAAe,gBAAgB,KAAK,aAAa;AAAA,MACjD,cAAc,gBAAgB,KAAK,YAAY;AAAA,MAC/C,WAAW,gBAAgB,KAAK,SAAS;AAAA,MACzC,WAAW,gBAAgB,KAAK,SAAS;AAAA,IAC3C,EAAE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,KAAK,IAAI,GAAG,KAAK,KAAK,OAAO,KAAK,IAAI,QAAQ,CAAC;AAAA,EAC7D,CAAC;AACH;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,kBAAkB;AAAA,EACzB,SAAS;AAAA,EACT,SAAS;AAAA,IACP,KAAK;AAAA,MACH,SAAS;AAAA,MACT,MAAM,CAAC,kBAAkB;AAAA,MACzB,WAAW;AAAA,QACT,EAAE,QAAQ,KAAK,aAAa,2BAA2B;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,7 +18,8 @@ async function GET(req, { params }) {
|
|
|
18
18
|
const em = container.resolve("em");
|
|
19
19
|
const job = await em.findOne(ProgressJob, {
|
|
20
20
|
id: params.id,
|
|
21
|
-
tenantId: auth.tenantId
|
|
21
|
+
tenantId: auth.tenantId,
|
|
22
|
+
...auth.orgId ? { organizationId: auth.orgId } : {}
|
|
22
23
|
});
|
|
23
24
|
if (!job) {
|
|
24
25
|
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
|
@@ -62,7 +63,11 @@ async function PUT(req, { params }) {
|
|
|
62
63
|
}
|
|
63
64
|
const container = await createRequestContainer();
|
|
64
65
|
const em = container.resolve("em");
|
|
65
|
-
const existing = await em.findOne(ProgressJob, {
|
|
66
|
+
const existing = await em.findOne(ProgressJob, {
|
|
67
|
+
id: params.id,
|
|
68
|
+
tenantId: auth.tenantId,
|
|
69
|
+
...auth.orgId ? { organizationId: auth.orgId } : {}
|
|
70
|
+
});
|
|
66
71
|
if (!existing) {
|
|
67
72
|
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
|
68
73
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/progress/api/jobs/%5Bid%5D/route.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { ProgressJob } from '../../../data/entities'\nimport { updateProgressSchema } from '../../../data/validators'\nimport type { ProgressService } from '../../../lib/progressService'\n\nconst routeMetadata = {\n GET: { requireAuth: true },\n PUT: { requireAuth: true, requireFeatures: ['progress.update'] },\n DELETE: { requireAuth: true, requireFeatures: ['progress.cancel'] },\n}\n\nexport const metadata = routeMetadata\n\nexport async function GET(req: Request, { params }: { params: { id: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const container = await createRequestContainer()\n const em = container.resolve('em') as EntityManager\n\n const job = await em.findOne(ProgressJob, {\n id: params.id,\n tenantId: auth.tenantId,\n })\n\n if (!job) {\n return NextResponse.json({ error: 'Not found' }, { status: 404 })\n }\n\n return NextResponse.json({\n id: job.id,\n jobType: job.jobType,\n name: job.name,\n description: job.description,\n status: job.status,\n progressPercent: job.progressPercent,\n processedCount: job.processedCount,\n totalCount: job.totalCount,\n etaSeconds: job.etaSeconds,\n cancellable: job.cancellable,\n meta: job.meta,\n resultSummary: job.resultSummary,\n errorMessage: job.errorMessage,\n startedByUserId: job.startedByUserId,\n startedAt: job.startedAt?.toISOString() ?? null,\n heartbeatAt: job.heartbeatAt?.toISOString() ?? null,\n finishedAt: job.finishedAt?.toISOString() ?? null,\n parentJobId: job.parentJobId,\n partitionIndex: job.partitionIndex,\n partitionCount: job.partitionCount,\n createdAt: job.createdAt.toISOString(),\n updatedAt: job.updatedAt.toISOString(),\n tenantId: job.tenantId,\n organizationId: job.organizationId,\n })\n}\n\nexport async function PUT(req: Request, { params }: { params: { id: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const body = await req.json()\n const parsed = updateProgressSchema.safeParse(body)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid input', details: parsed.error.flatten() }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const em = container.resolve('em') as EntityManager\n const existing = await em.findOne(ProgressJob, {
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAEvC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAGrC,MAAM,gBAAgB;AAAA,EACpB,KAAK,EAAE,aAAa,KAAK;AAAA,EACzB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,iBAAiB,EAAE;AAAA,EAC/D,QAAQ,EAAE,aAAa,MAAM,iBAAiB,CAAC,iBAAiB,EAAE;AACpE;AAEO,MAAM,WAAW;AAExB,eAAsB,IAAI,KAAc,EAAE,OAAO,GAA+B;AAC9E,QAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,MAAI,CAAC,QAAQ,CAAC,KAAK,UAAU;AAC3B,WAAO,aAAa,KAAK,EAAE,OAAO,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACrE;AAEA,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,KAAK,UAAU,QAAQ,IAAI;AAEjC,QAAM,MAAM,MAAM,GAAG,QAAQ,aAAa;AAAA,IACxC,IAAI,OAAO;AAAA,IACX,UAAU,KAAK;AAAA,
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { ProgressJob } from '../../../data/entities'\nimport { updateProgressSchema } from '../../../data/validators'\nimport type { ProgressService } from '../../../lib/progressService'\n\nconst routeMetadata = {\n GET: { requireAuth: true },\n PUT: { requireAuth: true, requireFeatures: ['progress.update'] },\n DELETE: { requireAuth: true, requireFeatures: ['progress.cancel'] },\n}\n\nexport const metadata = routeMetadata\n\nexport async function GET(req: Request, { params }: { params: { id: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const container = await createRequestContainer()\n const em = container.resolve('em') as EntityManager\n\n const job = await em.findOne(ProgressJob, {\n id: params.id,\n tenantId: auth.tenantId,\n ...(auth.orgId ? { organizationId: auth.orgId } : {}),\n })\n\n if (!job) {\n return NextResponse.json({ error: 'Not found' }, { status: 404 })\n }\n\n return NextResponse.json({\n id: job.id,\n jobType: job.jobType,\n name: job.name,\n description: job.description,\n status: job.status,\n progressPercent: job.progressPercent,\n processedCount: job.processedCount,\n totalCount: job.totalCount,\n etaSeconds: job.etaSeconds,\n cancellable: job.cancellable,\n meta: job.meta,\n resultSummary: job.resultSummary,\n errorMessage: job.errorMessage,\n startedByUserId: job.startedByUserId,\n startedAt: job.startedAt?.toISOString() ?? null,\n heartbeatAt: job.heartbeatAt?.toISOString() ?? null,\n finishedAt: job.finishedAt?.toISOString() ?? null,\n parentJobId: job.parentJobId,\n partitionIndex: job.partitionIndex,\n partitionCount: job.partitionCount,\n createdAt: job.createdAt.toISOString(),\n updatedAt: job.updatedAt.toISOString(),\n tenantId: job.tenantId,\n organizationId: job.organizationId,\n })\n}\n\nexport async function PUT(req: Request, { params }: { params: { id: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const body = await req.json()\n const parsed = updateProgressSchema.safeParse(body)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid input', details: parsed.error.flatten() }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const em = container.resolve('em') as EntityManager\n const existing = await em.findOne(ProgressJob, {\n id: params.id,\n tenantId: auth.tenantId,\n ...(auth.orgId ? { organizationId: auth.orgId } : {}),\n })\n if (!existing) {\n return NextResponse.json({ error: 'Not found' }, { status: 404 })\n }\n\n const progressService = container.resolve('progressService') as ProgressService\n\n const job = await progressService.updateProgress(params.id, parsed.data, {\n tenantId: auth.tenantId,\n organizationId: auth.orgId,\n userId: auth.sub,\n })\n\n return NextResponse.json({ ok: true, progressPercent: job.progressPercent })\n}\n\nexport async function DELETE(req: Request, { params }: { params: { id: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const container = await createRequestContainer()\n const progressService = container.resolve('progressService') as ProgressService\n\n try {\n await progressService.cancelJob(params.id, {\n tenantId: auth.tenantId,\n organizationId: auth.orgId,\n userId: auth.sub,\n })\n return NextResponse.json({ ok: true })\n } catch {\n return NextResponse.json({ error: 'Cannot cancel this job' }, { status: 400 })\n }\n}\n\nexport const openApi = {\n GET: {\n summary: 'Get progress job details',\n description: 'Returns full details of a specific progress job by ID.',\n tags: ['Progress'],\n responses: {\n 200: { description: 'Progress job details' },\n 404: { description: 'Job not found' },\n },\n },\n PUT: {\n summary: 'Update progress job',\n description: 'Updates progress metrics and heartbeat for a running job.',\n tags: ['Progress'],\n responses: {\n 200: { description: 'Progress updated' },\n 400: { description: 'Invalid input' },\n 404: { description: 'Job not found' },\n },\n },\n DELETE: {\n summary: 'Cancel progress job',\n description: 'Requests cancellation of a running or pending job.',\n tags: ['Progress'],\n responses: {\n 200: { description: 'Cancellation requested' },\n 400: { description: 'Cannot cancel this job' },\n },\n },\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAEvC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAGrC,MAAM,gBAAgB;AAAA,EACpB,KAAK,EAAE,aAAa,KAAK;AAAA,EACzB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,iBAAiB,EAAE;AAAA,EAC/D,QAAQ,EAAE,aAAa,MAAM,iBAAiB,CAAC,iBAAiB,EAAE;AACpE;AAEO,MAAM,WAAW;AAExB,eAAsB,IAAI,KAAc,EAAE,OAAO,GAA+B;AAC9E,QAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,MAAI,CAAC,QAAQ,CAAC,KAAK,UAAU;AAC3B,WAAO,aAAa,KAAK,EAAE,OAAO,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACrE;AAEA,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,KAAK,UAAU,QAAQ,IAAI;AAEjC,QAAM,MAAM,MAAM,GAAG,QAAQ,aAAa;AAAA,IACxC,IAAI,OAAO;AAAA,IACX,UAAU,KAAK;AAAA,IACf,GAAI,KAAK,QAAQ,EAAE,gBAAgB,KAAK,MAAM,IAAI,CAAC;AAAA,EACrD,CAAC;AAED,MAAI,CAAC,KAAK;AACR,WAAO,aAAa,KAAK,EAAE,OAAO,YAAY,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAClE;AAEA,SAAO,aAAa,KAAK;AAAA,IACvB,IAAI,IAAI;AAAA,IACR,SAAS,IAAI;AAAA,IACb,MAAM,IAAI;AA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gBAAgB;AAAA,IACtC;AAAA,EACF;AAAA,EACA,KAAK;AAAA,IACH,SAAS;AAAA,IACT,aAAa;AAAA,IACb,MAAM,CAAC,UAAU;AAAA,IACjB,WAAW;AAAA,MACT,KAAK,EAAE,aAAa,mBAAmB;AAAA,MACvC,KAAK,EAAE,aAAa,gBAAgB;AAAA,MACpC,KAAK,EAAE,aAAa,gBAAgB;AAAA,IACtC;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,SAAS;AAAA,IACT,aAAa;AAAA,IACb,MAAM,CAAC,UAAU;AAAA,IACjB,WAAW;AAAA,MACT,KAAK,EAAE,aAAa,yBAAyB;AAAA,MAC7C,KAAK,EAAE,aAAa,yBAAyB;AAAA,IAC/C;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -124,7 +124,7 @@ async function POST(req) {
|
|
|
124
124
|
const stack = error instanceof Error ? error.stack : void 0;
|
|
125
125
|
console.error("[progress.jobs.create] unhandled error", { message, stack });
|
|
126
126
|
return NextResponse.json(
|
|
127
|
-
{ error: "Failed to create progress job."
|
|
127
|
+
{ error: "Failed to create progress job." },
|
|
128
128
|
{ status: 500 }
|
|
129
129
|
);
|
|
130
130
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/progress/api/jobs/route.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { FilterQuery } from '@mikro-orm/core'\nimport { escapeLikePattern } from '@open-mercato/shared/lib/db/escapeLikePattern'\nimport { ProgressJob } from '../../data/entities'\nimport { createProgressJobSchema, listProgressJobsSchema } from '../../data/validators'\nimport {\n createProgressCrudOpenApi,\n createPagedListResponseSchema,\n} from '../openapi'\n\nconst routeMetadata = {\n GET: { requireAuth: true },\n POST: { requireAuth: true, requireFeatures: ['progress.create'] },\n}\n\nexport const metadata = routeMetadata\n\nconst listQuerySchema = listProgressJobsSchema\n\ntype JobRow = {\n id: string\n jobType: string\n name: string\n description: string | null\n status: string\n progressPercent: number\n processedCount: number\n totalCount: number | null\n etaSeconds: number | null\n cancellable: boolean\n startedAt: string | null\n finishedAt: string | null\n errorMessage: string | null\n createdAt: string | null\n tenantId: string\n organizationId: string | null\n}\n\nconst toRow = (job: ProgressJob): JobRow => ({\n id: String(job.id),\n jobType: String(job.jobType),\n name: String(job.name),\n description: job.description ?? null,\n status: job.status,\n progressPercent: job.progressPercent,\n processedCount: job.processedCount,\n totalCount: job.totalCount ?? null,\n etaSeconds: job.etaSeconds ?? null,\n cancellable: !!job.cancellable,\n startedAt: job.startedAt ? job.startedAt.toISOString() : null,\n finishedAt: job.finishedAt ? job.finishedAt.toISOString() : null,\n errorMessage: job.errorMessage ?? null,\n createdAt: job.createdAt ? job.createdAt.toISOString() : null,\n tenantId: String(job.tenantId),\n organizationId: job.organizationId ? String(job.organizationId) : null,\n})\n\nexport async function GET(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ items: [], total: 0, page: 1, pageSize: 20, totalPages: 1 }, { status: 401 })\n }\n\n const url = new URL(req.url)\n const parsed = listQuerySchema.safeParse({\n status: url.searchParams.get('status') ?? undefined,\n jobType: url.searchParams.get('jobType') ?? undefined,\n parentJobId: url.searchParams.get('parentJobId') ?? undefined,\n includeCompleted: url.searchParams.get('includeCompleted') ?? undefined,\n completedSince: url.searchParams.get('completedSince') ?? undefined,\n page: url.searchParams.get('page') ?? undefined,\n pageSize: url.searchParams.get('pageSize') ?? undefined,\n search: url.searchParams.get('search') ?? undefined,\n sortField: url.searchParams.get('sortField') ?? undefined,\n sortDir: url.searchParams.get('sortDir') ?? undefined,\n })\n if (!parsed.success) {\n return NextResponse.json({ items: [], total: 0, page: 1, pageSize: 20, totalPages: 1 }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const em = container.resolve('em') as EntityManager\n\n const { status, jobType, parentJobId, includeCompleted, completedSince, page, pageSize, search, sortField, sortDir } = parsed.data\n const filter: FilterQuery<ProgressJob> = {\n tenantId: auth.tenantId,\n }\n\n if (auth.orgId) {\n filter.organizationId = auth.orgId\n }\n\n if (status) {\n const statusValues = status.split(',')\n filter.status = statusValues.length > 1 ? { $in: statusValues as never } : status as never\n } else if (includeCompleted !== 'true') {\n filter.status = { $in: ['pending', 'running'] }\n }\n\n if (jobType) filter.jobType = jobType\n if (parentJobId) filter.parentJobId = parentJobId\n if (completedSince) filter.finishedAt = { $gte: new Date(completedSince) }\n\n if (search) {\n const escaped = escapeLikePattern(search)\n filter.$or = [\n { name: { $ilike: `%${escaped}%` } },\n { jobType: { $ilike: `%${escaped}%` } },\n ]\n }\n\n const fieldMap: Record<string, string> = {\n createdAt: 'createdAt',\n startedAt: 'startedAt',\n finishedAt: 'finishedAt',\n }\n const orderBy: Record<string, 'ASC' | 'DESC'> = {}\n if (sortField) {\n const mapped = fieldMap[sortField] || 'createdAt'\n orderBy[mapped] = sortDir === 'asc' ? 'ASC' : 'DESC'\n } else {\n orderBy.createdAt = 'DESC'\n }\n\n const [rows, total] = await em.findAndCount(ProgressJob, filter, {\n orderBy,\n limit: pageSize,\n offset: (page - 1) * pageSize,\n })\n const items = rows.map(toRow)\n const totalPages = Math.max(1, Math.ceil(total / pageSize))\n\n return NextResponse.json({ items, total, page, pageSize, totalPages })\n}\n\nexport async function POST(req: Request) {\n try {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const body = await req.json()\n const parsed = createProgressJobSchema.safeParse(body)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid input', details: parsed.error.flatten() }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const progressService = container.resolve('progressService') as import('../../lib/progressService').ProgressService\n\n const job = await progressService.createJob(parsed.data, {\n tenantId: auth.tenantId,\n organizationId: auth.orgId,\n userId: auth.sub,\n })\n\n return NextResponse.json({ id: job.id }, { status: 201 })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const stack = error instanceof Error ? error.stack : undefined\n console.error('[progress.jobs.create] unhandled error', { message, stack })\n return NextResponse.json(\n { error: 'Failed to create progress job.'
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAGvC,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB,8BAA8B;AAChE;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,gBAAgB;AAAA,EACpB,KAAK,EAAE,aAAa,KAAK;AAAA,EACzB,MAAM,EAAE,aAAa,MAAM,iBAAiB,CAAC,iBAAiB,EAAE;AAClE;AAEO,MAAM,WAAW;AAExB,MAAM,kBAAkB;AAqBxB,MAAM,QAAQ,CAAC,SAA8B;AAAA,EAC3C,IAAI,OAAO,IAAI,EAAE;AAAA,EACjB,SAAS,OAAO,IAAI,OAAO;AAAA,EAC3B,MAAM,OAAO,IAAI,IAAI;AAAA,EACrB,aAAa,IAAI,eAAe;AAAA,EAChC,QAAQ,IAAI;AAAA,EACZ,iBAAiB,IAAI;AAAA,EACrB,gBAAgB,IAAI;AAAA,EACpB,YAAY,IAAI,cAAc;AAAA,EAC9B,YAAY,IAAI,cAAc;AAAA,EAC9B,aAAa,CAAC,CAAC,IAAI;AAAA,EACnB,WAAW,IAAI,YAAY,IAAI,UAAU,YAAY,IAAI;AAAA,EACzD,YAAY,IAAI,aAAa,IAAI,WAAW,YAAY,IAAI;AAAA,EAC5D,cAAc,IAAI,gBAAgB;AAAA,EAClC,WAAW,IAAI,YAAY,IAAI,UAAU,YAAY,IAAI;AAAA,EACzD,UAAU,OAAO,IAAI,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,EAAE,OAAO,OAAO,MAAM,UAAU,WAAW,CAAC;AACvE;AAEA,eAAsB,KAAK,KAAc;AACvC,MAAI;AACF,UAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,QAAI,CAAC,QAAQ,CAAC,KAAK,UAAU;AAC3B,aAAO,aAAa,KAAK,EAAE,OAAO,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IACrE;AAEA,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,SAAS,wBAAwB,UAAU,IAAI;AACrD,QAAI,CAAC,OAAO,SAAS;AACnB,aAAO,aAAa,KAAK,EAAE,OAAO,iBAAiB,SAAS,OAAO,MAAM,QAAQ,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IACvG;AAEA,UAAM,YAAY,MAAM,uBAAuB;AAC/C,UAAM,kBAAkB,UAAU,QAAQ,iBAAiB;AAE3D,UAAM,MAAM,MAAM,gBAAgB,UAAU,OAAO,MAAM;AAAA,MACvD,UAAU,KAAK;AAAA,MACf,gBAAgB,KAAK;AAAA,MACrB,QAAQ,KAAK;AAAA,IACf,CAAC;AAED,WAAO,aAAa,KAAK,EAAE,IAAI,IAAI,GAAG,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC1D,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAM,QAAQ,iBAAiB,QAAQ,MAAM,QAAQ;AACrD,YAAQ,MAAM,0CAA0C,EAAE,SAAS,MAAM,CAAC;AAC1E,WAAO,aAAa;AAAA,MAClB,EAAE,OAAO,
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { FilterQuery } from '@mikro-orm/core'\nimport { escapeLikePattern } from '@open-mercato/shared/lib/db/escapeLikePattern'\nimport { ProgressJob } from '../../data/entities'\nimport { createProgressJobSchema, listProgressJobsSchema } from '../../data/validators'\nimport {\n createProgressCrudOpenApi,\n createPagedListResponseSchema,\n} from '../openapi'\n\nconst routeMetadata = {\n GET: { requireAuth: true },\n POST: { requireAuth: true, requireFeatures: ['progress.create'] },\n}\n\nexport const metadata = routeMetadata\n\nconst listQuerySchema = listProgressJobsSchema\n\ntype JobRow = {\n id: string\n jobType: string\n name: string\n description: string | null\n status: string\n progressPercent: number\n processedCount: number\n totalCount: number | null\n etaSeconds: number | null\n cancellable: boolean\n startedAt: string | null\n finishedAt: string | null\n errorMessage: string | null\n createdAt: string | null\n tenantId: string\n organizationId: string | null\n}\n\nconst toRow = (job: ProgressJob): JobRow => ({\n id: String(job.id),\n jobType: String(job.jobType),\n name: String(job.name),\n description: job.description ?? null,\n status: job.status,\n progressPercent: job.progressPercent,\n processedCount: job.processedCount,\n totalCount: job.totalCount ?? null,\n etaSeconds: job.etaSeconds ?? null,\n cancellable: !!job.cancellable,\n startedAt: job.startedAt ? job.startedAt.toISOString() : null,\n finishedAt: job.finishedAt ? job.finishedAt.toISOString() : null,\n errorMessage: job.errorMessage ?? null,\n createdAt: job.createdAt ? job.createdAt.toISOString() : null,\n tenantId: String(job.tenantId),\n organizationId: job.organizationId ? String(job.organizationId) : null,\n})\n\nexport async function GET(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ items: [], total: 0, page: 1, pageSize: 20, totalPages: 1 }, { status: 401 })\n }\n\n const url = new URL(req.url)\n const parsed = listQuerySchema.safeParse({\n status: url.searchParams.get('status') ?? undefined,\n jobType: url.searchParams.get('jobType') ?? undefined,\n parentJobId: url.searchParams.get('parentJobId') ?? undefined,\n includeCompleted: url.searchParams.get('includeCompleted') ?? undefined,\n completedSince: url.searchParams.get('completedSince') ?? undefined,\n page: url.searchParams.get('page') ?? undefined,\n pageSize: url.searchParams.get('pageSize') ?? undefined,\n search: url.searchParams.get('search') ?? undefined,\n sortField: url.searchParams.get('sortField') ?? undefined,\n sortDir: url.searchParams.get('sortDir') ?? undefined,\n })\n if (!parsed.success) {\n return NextResponse.json({ items: [], total: 0, page: 1, pageSize: 20, totalPages: 1 }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const em = container.resolve('em') as EntityManager\n\n const { status, jobType, parentJobId, includeCompleted, completedSince, page, pageSize, search, sortField, sortDir } = parsed.data\n const filter: FilterQuery<ProgressJob> = {\n tenantId: auth.tenantId,\n }\n\n if (auth.orgId) {\n filter.organizationId = auth.orgId\n }\n\n if (status) {\n const statusValues = status.split(',')\n filter.status = statusValues.length > 1 ? { $in: statusValues as never } : status as never\n } else if (includeCompleted !== 'true') {\n filter.status = { $in: ['pending', 'running'] }\n }\n\n if (jobType) filter.jobType = jobType\n if (parentJobId) filter.parentJobId = parentJobId\n if (completedSince) filter.finishedAt = { $gte: new Date(completedSince) }\n\n if (search) {\n const escaped = escapeLikePattern(search)\n filter.$or = [\n { name: { $ilike: `%${escaped}%` } },\n { jobType: { $ilike: `%${escaped}%` } },\n ]\n }\n\n const fieldMap: Record<string, string> = {\n createdAt: 'createdAt',\n startedAt: 'startedAt',\n finishedAt: 'finishedAt',\n }\n const orderBy: Record<string, 'ASC' | 'DESC'> = {}\n if (sortField) {\n const mapped = fieldMap[sortField] || 'createdAt'\n orderBy[mapped] = sortDir === 'asc' ? 'ASC' : 'DESC'\n } else {\n orderBy.createdAt = 'DESC'\n }\n\n const [rows, total] = await em.findAndCount(ProgressJob, filter, {\n orderBy,\n limit: pageSize,\n offset: (page - 1) * pageSize,\n })\n const items = rows.map(toRow)\n const totalPages = Math.max(1, Math.ceil(total / pageSize))\n\n return NextResponse.json({ items, total, page, pageSize, totalPages })\n}\n\nexport async function POST(req: Request) {\n try {\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const body = await req.json()\n const parsed = createProgressJobSchema.safeParse(body)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid input', details: parsed.error.flatten() }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const progressService = container.resolve('progressService') as import('../../lib/progressService').ProgressService\n\n const job = await progressService.createJob(parsed.data, {\n tenantId: auth.tenantId,\n organizationId: auth.orgId,\n userId: auth.sub,\n })\n\n return NextResponse.json({ id: job.id }, { status: 201 })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const stack = error instanceof Error ? error.stack : undefined\n console.error('[progress.jobs.create] unhandled error', { message, stack })\n return NextResponse.json(\n { error: 'Failed to create progress job.' },\n { status: 500 },\n )\n }\n}\n\nconst jobListItemSchema = z.object({\n id: z.string().uuid(),\n jobType: z.string(),\n name: z.string(),\n description: z.string().nullable(),\n status: z.string(),\n progressPercent: z.number(),\n processedCount: z.number(),\n totalCount: z.number().nullable(),\n etaSeconds: z.number().nullable(),\n cancellable: z.boolean(),\n startedAt: z.string().nullable(),\n finishedAt: z.string().nullable(),\n errorMessage: z.string().nullable(),\n createdAt: z.string().nullable(),\n tenantId: z.string().uuid(),\n organizationId: z.string().uuid().nullable(),\n})\n\nexport const openApi = createProgressCrudOpenApi({\n resourceName: 'ProgressJob',\n pluralName: 'ProgressJobs',\n querySchema: listQuerySchema,\n listResponseSchema: createPagedListResponseSchema(jobListItemSchema),\n create: {\n schema: createProgressJobSchema,\n description: 'Creates a new progress job for tracking a long-running operation.',\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAGvC,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB,8BAA8B;AAChE;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,gBAAgB;AAAA,EACpB,KAAK,EAAE,aAAa,KAAK;AAAA,EACzB,MAAM,EAAE,aAAa,MAAM,iBAAiB,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a;AAAA,EACb,oBAAoB,8BAA8B,iBAAiB;AAAA,EACnE,QAAQ;AAAA,IACN,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AACF,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -62,7 +62,11 @@ function createProgressService(em, eventBus) {
|
|
|
62
62
|
return job;
|
|
63
63
|
},
|
|
64
64
|
async updateProgress(jobId, input, ctx) {
|
|
65
|
-
const job = await em.findOneOrFail(ProgressJob, {
|
|
65
|
+
const job = await em.findOneOrFail(ProgressJob, {
|
|
66
|
+
id: jobId,
|
|
67
|
+
tenantId: ctx.tenantId,
|
|
68
|
+
...ctx.organizationId ? { organizationId: ctx.organizationId } : {}
|
|
69
|
+
});
|
|
66
70
|
if (job.status === "completed" || job.status === "failed" || job.status === "cancelled") {
|
|
67
71
|
return job;
|
|
68
72
|
}
|
|
@@ -160,6 +164,7 @@ function createProgressService(em, eventBus) {
|
|
|
160
164
|
const job = await em.findOneOrFail(ProgressJob, {
|
|
161
165
|
id: jobId,
|
|
162
166
|
tenantId: ctx.tenantId,
|
|
167
|
+
...ctx.organizationId ? { organizationId: ctx.organizationId } : {},
|
|
163
168
|
cancellable: true,
|
|
164
169
|
status: { $in: ["pending", "running"] }
|
|
165
170
|
});
|
|
@@ -227,7 +232,8 @@ function createProgressService(em, eventBus) {
|
|
|
227
232
|
async getJob(jobId, ctx) {
|
|
228
233
|
return em.findOne(ProgressJob, {
|
|
229
234
|
id: jobId,
|
|
230
|
-
tenantId: ctx.tenantId
|
|
235
|
+
tenantId: ctx.tenantId,
|
|
236
|
+
...ctx.organizationId ? { organizationId: ctx.organizationId } : {}
|
|
231
237
|
});
|
|
232
238
|
},
|
|
233
239
|
async markStaleJobsFailed(tenantId, timeoutSeconds = STALE_JOB_TIMEOUT_SECONDS) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/progress/lib/progressServiceImpl.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { ProgressJob } from '../data/entities'\nimport type { ProgressService } from './progressService'\nimport { calculateEta, calculateProgressPercent, STALE_JOB_TIMEOUT_SECONDS } from './progressService'\nimport { PROGRESS_EVENTS } from './events'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\n\nfunction buildJobPayload(job: ProgressJob): Record<string, unknown> {\n return {\n jobId: job.id,\n jobType: job.jobType,\n name: job.name,\n description: job.description ?? null,\n status: job.status,\n progressPercent: job.progressPercent,\n processedCount: job.processedCount,\n totalCount: job.totalCount ?? null,\n etaSeconds: job.etaSeconds ?? null,\n cancellable: job.cancellable,\n meta: job.meta ?? null,\n startedAt: job.startedAt?.toISOString() ?? null,\n finishedAt: job.finishedAt?.toISOString() ?? null,\n }\n}\n\nexport function createProgressService(em: EntityManager, eventBus: { emit: (event: string, payload: Record<string, unknown>) => Promise<void> }): ProgressService {\n return {\n async createJob(input, ctx) {\n const job = em.create(ProgressJob, {\n jobType: input.jobType,\n name: input.name,\n description: input.description,\n totalCount: input.totalCount,\n cancellable: input.cancellable ?? false,\n meta: input.meta,\n parentJobId: input.parentJobId,\n partitionIndex: input.partitionIndex,\n partitionCount: input.partitionCount,\n startedByUserId: ctx.userId,\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n status: 'pending',\n })\n\n await em.persist(job).flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_CREATED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n })\n\n return job\n },\n\n async startJob(jobId, ctx) {\n const job = await em.findOneOrFail(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (job.status === 'cancelled') {\n return job\n }\n\n job.status = 'running'\n job.startedAt = new Date()\n job.heartbeatAt = new Date()\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_STARTED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async updateProgress(jobId, input, ctx) {\n const job = await em.findOneOrFail(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (job.status === 'completed' || job.status === 'failed' || job.status === 'cancelled') {\n return job\n }\n\n if (input.processedCount !== undefined) {\n job.processedCount = input.processedCount\n }\n if (input.totalCount !== undefined) {\n job.totalCount = input.totalCount\n }\n if (input.meta !== undefined) {\n job.meta = { ...job.meta, ...input.meta }\n }\n\n if (input.progressPercent !== undefined) {\n job.progressPercent = input.progressPercent\n } else if (job.totalCount) {\n job.progressPercent = calculateProgressPercent(job.processedCount, job.totalCount)\n }\n\n if (input.etaSeconds !== undefined) {\n job.etaSeconds = input.etaSeconds\n } else if (job.startedAt && job.totalCount) {\n job.etaSeconds = calculateEta(job.processedCount, job.totalCount, job.startedAt)\n }\n\n job.heartbeatAt = new Date()\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_UPDATED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async incrementProgress(jobId, delta, ctx) {\n const job = await em.findOneOrFail(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (job.status === 'completed' || job.status === 'failed' || job.status === 'cancelled') {\n return job\n }\n\n job.processedCount += delta\n job.heartbeatAt = new Date()\n\n if (job.totalCount) {\n job.progressPercent = calculateProgressPercent(job.processedCount, job.totalCount)\n if (job.startedAt) {\n job.etaSeconds = calculateEta(job.processedCount, job.totalCount, job.startedAt)\n }\n }\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_UPDATED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async completeJob(jobId, input, ctx) {\n const job = await em.findOne(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (!job) throw new Error(`Job ${jobId} not found`)\n if (job.status === 'cancelled') {\n return job\n }\n\n job.status = 'completed'\n job.finishedAt = new Date()\n job.progressPercent = 100\n job.etaSeconds = 0\n if (input?.resultSummary) {\n job.resultSummary = input.resultSummary\n }\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_COMPLETED, {\n ...buildJobPayload(job),\n resultSummary: job.resultSummary,\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async failJob(jobId, input, ctx) {\n const job = await em.findOne(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (!job) throw new Error(`Job ${jobId} not found`)\n if (job.status === 'cancelled') {\n return job\n }\n\n job.status = 'failed'\n job.finishedAt = new Date()\n job.errorMessage = input.errorMessage\n job.errorStack = input.errorStack\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_FAILED, {\n ...buildJobPayload(job),\n errorMessage: job.errorMessage,\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async cancelJob(jobId, ctx) {\n const job = await em.findOneOrFail(ProgressJob, {\n id: jobId,\n tenantId: ctx.tenantId,\n cancellable: true,\n status: { $in: ['pending', 'running'] },\n })\n\n job.cancelRequestedAt = new Date()\n job.cancelledByUserId = ctx.userId\n\n if (job.status === 'pending') {\n job.status = 'cancelled'\n job.finishedAt = new Date()\n }\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_CANCELLED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async markCancelled(jobId, ctx) {\n const job = await em.findOne(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (!job) throw new Error(`Job ${jobId} not found`)\n if (job.status === 'cancelled') {\n return job\n }\n\n job.cancelRequestedAt = job.cancelRequestedAt ?? new Date()\n job.cancelledByUserId = ctx.userId\n job.status = 'cancelled'\n job.finishedAt = job.finishedAt ?? new Date()\n job.etaSeconds = 0\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_CANCELLED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async isCancellationRequested(jobId, tenantId) {\n const job = await findOneWithDecryption(em, ProgressJob, { id: jobId, tenantId })\n return job?.cancelRequestedAt != null\n },\n\n async getActiveJobs(ctx) {\n return em.find(ProgressJob, {\n tenantId: ctx.tenantId,\n ...(ctx.organizationId ? { organizationId: ctx.organizationId } : {}),\n status: { $in: ['pending', 'running'] },\n parentJobId: null,\n }, {\n orderBy: { createdAt: 'DESC' },\n limit: 50,\n })\n },\n\n async getRecentlyCompletedJobs(ctx, sinceSeconds = 30) {\n const cutoff = new Date(Date.now() - sinceSeconds * 1000)\n return em.find(ProgressJob, {\n tenantId: ctx.tenantId,\n ...(ctx.organizationId ? { organizationId: ctx.organizationId } : {}),\n status: { $in: ['completed', 'failed'] },\n finishedAt: { $gte: cutoff },\n parentJobId: null,\n }, {\n orderBy: { finishedAt: 'DESC' },\n limit: 10,\n })\n },\n\n async getJob(jobId, ctx) {\n return em.findOne(ProgressJob, {\n id: jobId,\n tenantId: ctx.tenantId,\n })\n },\n\n async markStaleJobsFailed(tenantId: string, timeoutSeconds = STALE_JOB_TIMEOUT_SECONDS) {\n const cutoff = new Date(Date.now() - timeoutSeconds * 1000)\n\n const staleJobs = await em.find(ProgressJob, {\n tenantId,\n status: 'running',\n $or: [\n { heartbeatAt: { $lt: cutoff } },\n {\n heartbeatAt: null,\n startedAt: { $lt: cutoff },\n },\n ],\n })\n\n for (const job of staleJobs) {\n job.status = 'failed'\n job.finishedAt = new Date()\n job.errorMessage = `Job stale: no heartbeat for ${timeoutSeconds} seconds`\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_FAILED, {\n ...buildJobPayload(job),\n errorMessage: job.errorMessage,\n tenantId: job.tenantId,\n stale: true,\n organizationId: job.organizationId ?? null,\n })\n }\n\n await em.flush()\n return staleJobs.length\n },\n }\n}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,MAAM,SAAS,OAAO,KAAK;AACzB,YAAM,MAAM,MAAM,GAAG,cAAc,aAAa,EAAE,IAAI,OAAO,UAAU,IAAI,SAAS,CAAC;AACrF,UAAI,IAAI,WAAW,aAAa;AAC9B,eAAO;AAAA,MACT;AAEA,UAAI,SAAS;AACb,UAAI,YAAY,oBAAI,KAAK;AACzB,UAAI,cAAc,oBAAI,KAAK;AAE3B,YAAM,GAAG,MAAM;AAEf,YAAM,SAAS,KAAK,gBAAgB,aAAa;AAAA,QAC/C,GAAG,gBAAgB,GAAG;AAAA,QACtB,UAAU,IAAI;AAAA,QACd,gBAAgB,IAAI,kBAAkB;AAAA,MACxC,CAAC;AAED,aAAO;AAAA,IACT;AAAA,IAEA,MAAM,eAAe,OAAO,OAAO,KAAK;AACtC,YAAM,MAAM,MAAM,GAAG,cAAc,aAAa,
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { ProgressJob } from '../data/entities'\nimport type { ProgressService } from './progressService'\nimport { calculateEta, calculateProgressPercent, STALE_JOB_TIMEOUT_SECONDS } from './progressService'\nimport { PROGRESS_EVENTS } from './events'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\n\nfunction buildJobPayload(job: ProgressJob): Record<string, unknown> {\n return {\n jobId: job.id,\n jobType: job.jobType,\n name: job.name,\n description: job.description ?? null,\n status: job.status,\n progressPercent: job.progressPercent,\n processedCount: job.processedCount,\n totalCount: job.totalCount ?? null,\n etaSeconds: job.etaSeconds ?? null,\n cancellable: job.cancellable,\n meta: job.meta ?? null,\n startedAt: job.startedAt?.toISOString() ?? null,\n finishedAt: job.finishedAt?.toISOString() ?? null,\n }\n}\n\nexport function createProgressService(em: EntityManager, eventBus: { emit: (event: string, payload: Record<string, unknown>) => Promise<void> }): ProgressService {\n return {\n async createJob(input, ctx) {\n const job = em.create(ProgressJob, {\n jobType: input.jobType,\n name: input.name,\n description: input.description,\n totalCount: input.totalCount,\n cancellable: input.cancellable ?? false,\n meta: input.meta,\n parentJobId: input.parentJobId,\n partitionIndex: input.partitionIndex,\n partitionCount: input.partitionCount,\n startedByUserId: ctx.userId,\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n status: 'pending',\n })\n\n await em.persist(job).flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_CREATED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n })\n\n return job\n },\n\n async startJob(jobId, ctx) {\n const job = await em.findOneOrFail(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (job.status === 'cancelled') {\n return job\n }\n\n job.status = 'running'\n job.startedAt = new Date()\n job.heartbeatAt = new Date()\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_STARTED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async updateProgress(jobId, input, ctx) {\n const job = await em.findOneOrFail(ProgressJob, {\n id: jobId,\n tenantId: ctx.tenantId,\n ...(ctx.organizationId ? { organizationId: ctx.organizationId } : {}),\n })\n if (job.status === 'completed' || job.status === 'failed' || job.status === 'cancelled') {\n return job\n }\n\n if (input.processedCount !== undefined) {\n job.processedCount = input.processedCount\n }\n if (input.totalCount !== undefined) {\n job.totalCount = input.totalCount\n }\n if (input.meta !== undefined) {\n job.meta = { ...job.meta, ...input.meta }\n }\n\n if (input.progressPercent !== undefined) {\n job.progressPercent = input.progressPercent\n } else if (job.totalCount) {\n job.progressPercent = calculateProgressPercent(job.processedCount, job.totalCount)\n }\n\n if (input.etaSeconds !== undefined) {\n job.etaSeconds = input.etaSeconds\n } else if (job.startedAt && job.totalCount) {\n job.etaSeconds = calculateEta(job.processedCount, job.totalCount, job.startedAt)\n }\n\n job.heartbeatAt = new Date()\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_UPDATED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async incrementProgress(jobId, delta, ctx) {\n const job = await em.findOneOrFail(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (job.status === 'completed' || job.status === 'failed' || job.status === 'cancelled') {\n return job\n }\n\n job.processedCount += delta\n job.heartbeatAt = new Date()\n\n if (job.totalCount) {\n job.progressPercent = calculateProgressPercent(job.processedCount, job.totalCount)\n if (job.startedAt) {\n job.etaSeconds = calculateEta(job.processedCount, job.totalCount, job.startedAt)\n }\n }\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_UPDATED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async completeJob(jobId, input, ctx) {\n const job = await em.findOne(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (!job) throw new Error(`Job ${jobId} not found`)\n if (job.status === 'cancelled') {\n return job\n }\n\n job.status = 'completed'\n job.finishedAt = new Date()\n job.progressPercent = 100\n job.etaSeconds = 0\n if (input?.resultSummary) {\n job.resultSummary = input.resultSummary\n }\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_COMPLETED, {\n ...buildJobPayload(job),\n resultSummary: job.resultSummary,\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async failJob(jobId, input, ctx) {\n const job = await em.findOne(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (!job) throw new Error(`Job ${jobId} not found`)\n if (job.status === 'cancelled') {\n return job\n }\n\n job.status = 'failed'\n job.finishedAt = new Date()\n job.errorMessage = input.errorMessage\n job.errorStack = input.errorStack\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_FAILED, {\n ...buildJobPayload(job),\n errorMessage: job.errorMessage,\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async cancelJob(jobId, ctx) {\n const job = await em.findOneOrFail(ProgressJob, {\n id: jobId,\n tenantId: ctx.tenantId,\n ...(ctx.organizationId ? { organizationId: ctx.organizationId } : {}),\n cancellable: true,\n status: { $in: ['pending', 'running'] },\n })\n\n job.cancelRequestedAt = new Date()\n job.cancelledByUserId = ctx.userId\n\n if (job.status === 'pending') {\n job.status = 'cancelled'\n job.finishedAt = new Date()\n }\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_CANCELLED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async markCancelled(jobId, ctx) {\n const job = await em.findOne(ProgressJob, { id: jobId, tenantId: ctx.tenantId })\n if (!job) throw new Error(`Job ${jobId} not found`)\n if (job.status === 'cancelled') {\n return job\n }\n\n job.cancelRequestedAt = job.cancelRequestedAt ?? new Date()\n job.cancelledByUserId = ctx.userId\n job.status = 'cancelled'\n job.finishedAt = job.finishedAt ?? new Date()\n job.etaSeconds = 0\n\n await em.flush()\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_CANCELLED, {\n ...buildJobPayload(job),\n tenantId: ctx.tenantId,\n organizationId: job.organizationId ?? null,\n })\n\n return job\n },\n\n async isCancellationRequested(jobId, tenantId) {\n const job = await findOneWithDecryption(em, ProgressJob, { id: jobId, tenantId })\n return job?.cancelRequestedAt != null\n },\n\n async getActiveJobs(ctx) {\n return em.find(ProgressJob, {\n tenantId: ctx.tenantId,\n ...(ctx.organizationId ? { organizationId: ctx.organizationId } : {}),\n status: { $in: ['pending', 'running'] },\n parentJobId: null,\n }, {\n orderBy: { createdAt: 'DESC' },\n limit: 50,\n })\n },\n\n async getRecentlyCompletedJobs(ctx, sinceSeconds = 30) {\n const cutoff = new Date(Date.now() - sinceSeconds * 1000)\n return em.find(ProgressJob, {\n tenantId: ctx.tenantId,\n ...(ctx.organizationId ? { organizationId: ctx.organizationId } : {}),\n status: { $in: ['completed', 'failed'] },\n finishedAt: { $gte: cutoff },\n parentJobId: null,\n }, {\n orderBy: { finishedAt: 'DESC' },\n limit: 10,\n })\n },\n\n async getJob(jobId, ctx) {\n return em.findOne(ProgressJob, {\n id: jobId,\n tenantId: ctx.tenantId,\n ...(ctx.organizationId ? { organizationId: ctx.organizationId } : {}),\n })\n },\n\n async markStaleJobsFailed(tenantId: string, timeoutSeconds = STALE_JOB_TIMEOUT_SECONDS) {\n const cutoff = new Date(Date.now() - timeoutSeconds * 1000)\n\n const staleJobs = await em.find(ProgressJob, {\n tenantId,\n status: 'running',\n $or: [\n { heartbeatAt: { $lt: cutoff } },\n {\n heartbeatAt: null,\n startedAt: { $lt: cutoff },\n },\n ],\n })\n\n for (const job of staleJobs) {\n job.status = 'failed'\n job.finishedAt = new Date()\n job.errorMessage = `Job stale: no heartbeat for ${timeoutSeconds} seconds`\n\n await eventBus.emit(PROGRESS_EVENTS.JOB_FAILED, {\n ...buildJobPayload(job),\n errorMessage: job.errorMessage,\n tenantId: job.tenantId,\n stale: true,\n organizationId: job.organizationId ?? null,\n })\n }\n\n await em.flush()\n return staleJobs.length\n },\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,mBAAmB;AAE5B,SAAS,cAAc,0BAA0B,iCAAiC;AAClF,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AAEtC,SAAS,gBAAgB,KAA2C;AAClE,SAAO;AAAA,IACL,OAAO,IAAI;AAAA,IACX,SAAS,IAAI;AAAA,IACb,MAAM,IAAI;AAAA,IACV,aAAa,IAAI,eAAe;AAAA,IAChC,QAAQ,IAAI;AAAA,IACZ,iBAAiB,IAAI;AAAA,IACrB,gBAAgB,IAAI;AAAA,IACpB,YAAY,IAAI,cAAc;AAAA,IAC9B,YAAY,IAAI,cAAc;AAAA,IAC9B,aAAa,IAAI;AAAA,IACjB,MAAM,IAAI,QAAQ;AAAA,IAClB,WAAW,IAAI,WAAW,YAAY,KAAK;AAAA,IAC3C,YAAY,IAAI,YAAY,YAAY,KAAK;AAAA,EAC/C;AACF;AAEO,SAAS,sBAAsB,IAAm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MAAM,OAAO,OAAO,KAAK;AACvB,aAAO,GAAG,QAAQ,aAAa;AAAA,QAC7B,IAAI;AAAA,QACJ,UAAU,IAAI;AAAA,QACd,GAAI,IAAI,iBAAiB,EAAE,gBAAgB,IAAI,eAAe,IAAI,CAAC;AAAA,MACrE,CAAC;AAAA,IACH;AAAA,IAEA,MAAM,oBAAoB,UAAkB,iBAAiB,2BAA2B;AACtF,YAAM,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,iBAAiB,GAAI;AAE1D,YAAM,YAAY,MAAM,GAAG,KAAK,aAAa;AAAA,QAC3C;AAAA,QACA,QAAQ;AAAA,QACR,KAAK;AAAA,UACH,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE;AAAA,UAC/B;AAAA,YACE,aAAa;AAAA,YACb,WAAW,EAAE,KAAK,OAAO;AAAA,UAC3B;AAAA,QACF;AAAA,MACF,CAAC;AAED,iBAAW,OAAO,WAAW;AAC3B,YAAI,SAAS;AACb,YAAI,aAAa,oBAAI,KAAK;AAC1B,YAAI,eAAe,+BAA+B,cAAc;AAEhE,cAAM,SAAS,KAAK,gBAAgB,YAAY;AAAA,UAC9C,GAAG,gBAAgB,GAAG;AAAA,UACtB,cAAc,IAAI;AAAA,UAClB,UAAU,IAAI;AAAA,UACd,OAAO;AAAA,UACP,gBAAgB,IAAI,kBAAkB;AAAA,QACxC,CAAC;AAAA,MACH;AAEA,YAAM,GAAG,MAAM;AACf,aAAO,UAAU;AAAA,IACnB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -307,7 +307,8 @@ __decorateClass([
|
|
|
307
307
|
SearchToken = __decorateClass([
|
|
308
308
|
Entity({ tableName: "search_tokens" }),
|
|
309
309
|
Index({ name: "search_tokens_lookup_idx", properties: ["entityType", "field", "tokenHash", "tenantId", "organizationId"] }),
|
|
310
|
-
Index({ name: "search_tokens_entity_idx", properties: ["entityType", "entityId"] })
|
|
310
|
+
Index({ name: "search_tokens_entity_idx", properties: ["entityType", "entityId"] }),
|
|
311
|
+
Index({ name: "search_tokens_tenant_token_hash_idx", properties: ["tenantId", "tokenHash"] })
|
|
311
312
|
], SearchToken);
|
|
312
313
|
export {
|
|
313
314
|
EntityIndexCoverage,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/query_index/data/entities.ts"],
|
|
4
|
-
"sourcesContent": ["import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\n\n// Generic JSONB-backed index rows for any entity ('<module>:<entity>')\n@Entity({ tableName: 'entity_indexes' })\n@Index({\n name: 'entity_indexes_customer_entity_doc_idx',\n expression:\n `create index \"entity_indexes_customer_entity_doc_idx\" on \"entity_indexes\" (\"entity_id\", \"organization_id\", \"tenant_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_entity' and organization_id is not null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_person_profile_doc_idx',\n expression:\n `create index \"entity_indexes_customer_person_profile_doc_idx\" on \"entity_indexes\" (\"entity_id\", \"organization_id\", \"tenant_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_person_profile' and organization_id is not null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_company_profile_doc_idx',\n expression:\n `create index \"entity_indexes_customer_company_profile_doc_idx\" on \"entity_indexes\" (\"entity_id\", \"organization_id\", \"tenant_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_company_profile' and organization_id is not null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_entity_tenant_doc_idx',\n expression:\n `create index \"entity_indexes_customer_entity_tenant_doc_idx\" on \"entity_indexes\" (\"tenant_id\", \"entity_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_entity' and organization_id is null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_person_profile_tenant_doc_idx',\n expression:\n `create index \"entity_indexes_customer_person_profile_tenant_doc_idx\" on \"entity_indexes\" (\"tenant_id\", \"entity_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_person_profile' and organization_id is null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_company_profile_tenant_doc_idx',\n expression:\n `create index \"entity_indexes_customer_company_profile_tenant_doc_idx\" on \"entity_indexes\" (\"tenant_id\", \"entity_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_company_profile' and organization_id is null and tenant_id is not null`,\n})\n@Index({ name: 'entity_indexes_type_tenant_idx', properties: ['entityType', 'tenantId'] })\n@Unique({\n name: 'entity_indexes_type_entity_org_coalesced_unique',\n properties: ['entityType', 'entityId', 'organizationIdCoalesced'],\n})\nexport class EntityIndexRow {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n // Entity identifier: '<module>:<entity>'\n @Property({ name: 'entity_type', type: 'text' })\n @Index({ name: 'entity_indexes_type_idx' })\n entityType!: string\n\n // Record id as text for compatibility with uuid/int\n @Property({ name: 'entity_id', type: 'text' })\n @Index({ name: 'entity_indexes_entity_idx' })\n entityId!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n @Index({ name: 'entity_indexes_org_idx' })\n organizationId?: string | null\n\n @Property({\n name: 'organization_id_coalesced',\n type: 'uuid',\n generated: (cols) => `(coalesce(${cols.organizationId}, '00000000-0000-0000-0000-000000000000'::uuid)) stored`,\n hidden: true,\n })\n organizationIdCoalesced!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n // Flattened document of base fields and custom fields\n @Property({ name: 'doc', type: 'json' })\n doc!: any\n\n // Optional embedding vector or metadata produced by secondary indexers\n @Property({ name: 'embedding', type: 'json', nullable: true })\n embedding?: any | null\n\n @Property({ name: 'index_version', type: 'int', default: 1 })\n indexVersion: number = 1\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// Track long-running index jobs (reindex/purge) per entity and org scope\n@Entity({ tableName: 'entity_index_jobs' })\n// Coalesced-scope unique index so prepareJob can upsert atomically and two\n// concurrent schedulers cannot insert duplicate rows for the same scope (#2739).\n// Declared via @Unique with a raw expression (not properties) because the scope\n// columns are nullable and NULLs must collapse to one bucket via coalesce; mirrors\n// the entity_indexes coalesced uniqueness and the domain_mappings expression unique.\n@Unique({\n name: 'entity_index_jobs_scope_unique',\n expression:\n `create unique index \"entity_index_jobs_scope_unique\" on \"entity_index_jobs\" (\"entity_type\", coalesce(\"organization_id\", '00000000-0000-0000-0000-000000000000'::uuid), coalesce(\"tenant_id\", '00000000-0000-0000-0000-000000000000'::uuid), coalesce(\"partition_index\", -1), coalesce(\"partition_count\", -1))`,\n})\nexport class EntityIndexJob {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'entity_type', type: 'text' })\n @Index({ name: 'entity_index_jobs_type_idx' })\n entityType!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n @Index({ name: 'entity_index_jobs_org_idx' })\n organizationId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'partition_index', type: 'int', nullable: true })\n partitionIndex?: number | null\n\n @Property({ name: 'partition_count', type: 'int', nullable: true })\n partitionCount?: number | null\n\n @Property({ name: 'processed_count', type: 'int', nullable: true })\n processedCount?: number | null\n\n @Property({ name: 'total_count', type: 'int', nullable: true })\n totalCount?: number | null\n\n @Property({ name: 'heartbeat_at', type: Date, nullable: true })\n heartbeatAt?: Date | null\n\n // 'reindexing' | 'purging'\n @Property({ name: 'status', type: 'text' })\n status!: string\n\n @Property({ name: 'started_at', type: Date, onCreate: () => new Date() })\n startedAt: Date = new Date()\n\n @Property({ name: 'finished_at', type: Date, nullable: true })\n finishedAt?: Date | null\n}\n\n// Snapshot counts for coverage checks (per entity / tenant / org / withDeleted scope)\n@Entity({ tableName: 'entity_index_coverage' })\n@Unique({\n name: 'entity_index_coverage_scope_idx',\n properties: ['entityType', 'tenantId', 'organizationId', 'withDeleted'],\n})\nexport class EntityIndexCoverage {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'entity_type', type: 'text' })\n entityType!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'with_deleted', type: 'boolean', default: false })\n withDeleted: boolean = false\n\n @Property({ name: 'base_count', type: 'int', unsigned: true, default: 0 })\n baseCount: number = 0\n\n @Property({ name: 'indexed_count', type: 'int', unsigned: true, default: 0 })\n indexedCount: number = 0\n\n @Property({ name: 'vector_indexed_count', type: 'int', unsigned: true, default: 0 })\n vectorIndexedCount: number = 0\n\n @Property({ name: 'refreshed_at', type: Date, onCreate: () => new Date(), onUpdate: () => new Date() })\n refreshedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'indexer_error_logs' })\n@Index({ name: 'indexer_error_logs_source_idx', properties: ['source'] })\n@Index({ name: 'indexer_error_logs_occurred_idx', properties: ['occurredAt'] })\nexport class IndexerErrorLog {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'source', type: 'text' })\n source!: string\n\n @Property({ name: 'handler', type: 'text' })\n handler!: string\n\n @Property({ name: 'entity_type', type: 'text', nullable: true })\n entityType?: string | null\n\n @Property({ name: 'record_id', type: 'text', nullable: true })\n recordId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'payload', type: 'json', nullable: true })\n payload?: any | null\n\n @Property({ name: 'message', type: 'text' })\n message!: string\n\n @Property({ name: 'stack', type: 'text', nullable: true })\n stack?: string | null\n\n@Property({ name: 'occurred_at', type: Date, onCreate: () => new Date() })\n occurredAt: Date = new Date()\n}\n\n@Entity({ tableName: 'indexer_status_logs' })\n@Index({ name: 'indexer_status_logs_source_idx', properties: ['source'] })\n@Index({ name: 'indexer_status_logs_occurred_idx', properties: ['occurredAt'] })\nexport class IndexerStatusLog {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'source', type: 'text' })\n source!: string\n\n @Property({ name: 'handler', type: 'text' })\n handler!: string\n\n @Property({ name: 'level', type: 'text' })\n level: string = 'info'\n\n @Property({ name: 'entity_type', type: 'text', nullable: true })\n entityType?: string | null\n\n @Property({ name: 'record_id', type: 'text', nullable: true })\n recordId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'message', type: 'text' })\n message!: string\n\n @Property({ name: 'details', type: 'json', nullable: true })\n details?: any | null\n\n @Property({ name: 'occurred_at', type: Date, onCreate: () => new Date() })\n occurredAt: Date = new Date()\n}\n\n@Entity({ tableName: 'search_tokens' })\n@Index({ name: 'search_tokens_lookup_idx', properties: ['entityType', 'field', 'tokenHash', 'tenantId', 'organizationId'] })\n@Index({ name: 'search_tokens_entity_idx', properties: ['entityType', 'entityId'] })\nexport class SearchToken {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'entity_type', type: 'text' })\n entityType!: string\n\n @Property({ name: 'entity_id', type: 'text' })\n entityId!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'field', type: 'text' })\n field!: string\n\n @Property({ name: 'token_hash', type: 'text' })\n tokenHash!: string\n\n @Property({ name: 'token', type: 'text', nullable: true })\n token?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;AAAA,SAAS,QAAQ,OAAO,YAAY,UAAU,cAAc;AAuCrD,IAAM,iBAAN,MAAqB;AAAA,EAArB;AAsCL,wBAAuB;AAGvB,qBAAkB,oBAAI,KAAK;AAG3B,qBAAkB,oBAAI,KAAK;AAAA;AAI7B;AA9CE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GADlD,eAEX;AAKA;AAAA,EAFC,SAAS,EAAE,MAAM,eAAe,MAAM,OAAO,CAAC;AAAA,EAC9C,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAAA,GAN/B,eAOX;AAKA;AAAA,EAFC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,EAC5C,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAAA,GAXjC,eAYX;AAIA;AAAA,EAFC,SAAS,EAAE,MAAM,mBAAmB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,EAClE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAAA,GAf9B,eAgBX;AAQA;AAAA,EANC,SAAS;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,IACN,WAAW,CAAC,SAAS,aAAa,KAAK,cAAc;AAAA,IACrD,QAAQ;AAAA,EACV,CAAC;AAAA,GAvBU,eAwBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GA1BlD,eA2BX;AAIA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,MAAM,OAAO,CAAC;AAAA,GA9B5B,eA+BX;AAIA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,QAAQ,UAAU,K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BAAsB,CAAC;AAAA,EAC3C,MAAM,EAAE,MAAM,kCAAkC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAAA,EACxE,MAAM,EAAE,MAAM,oCAAoC,YAAY,CAAC,YAAY,EAAE,CAAC;AAAA,GAClE;
|
|
4
|
+
"sourcesContent": ["import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\n\n// Generic JSONB-backed index rows for any entity ('<module>:<entity>')\n@Entity({ tableName: 'entity_indexes' })\n@Index({\n name: 'entity_indexes_customer_entity_doc_idx',\n expression:\n `create index \"entity_indexes_customer_entity_doc_idx\" on \"entity_indexes\" (\"entity_id\", \"organization_id\", \"tenant_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_entity' and organization_id is not null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_person_profile_doc_idx',\n expression:\n `create index \"entity_indexes_customer_person_profile_doc_idx\" on \"entity_indexes\" (\"entity_id\", \"organization_id\", \"tenant_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_person_profile' and organization_id is not null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_company_profile_doc_idx',\n expression:\n `create index \"entity_indexes_customer_company_profile_doc_idx\" on \"entity_indexes\" (\"entity_id\", \"organization_id\", \"tenant_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_company_profile' and organization_id is not null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_entity_tenant_doc_idx',\n expression:\n `create index \"entity_indexes_customer_entity_tenant_doc_idx\" on \"entity_indexes\" (\"tenant_id\", \"entity_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_entity' and organization_id is null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_person_profile_tenant_doc_idx',\n expression:\n `create index \"entity_indexes_customer_person_profile_tenant_doc_idx\" on \"entity_indexes\" (\"tenant_id\", \"entity_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_person_profile' and organization_id is null and tenant_id is not null`,\n})\n@Index({\n name: 'entity_indexes_customer_company_profile_tenant_doc_idx',\n expression:\n `create index \"entity_indexes_customer_company_profile_tenant_doc_idx\" on \"entity_indexes\" (\"tenant_id\", \"entity_id\") include (\"doc\") where deleted_at is null and entity_type = 'customers:customer_company_profile' and organization_id is null and tenant_id is not null`,\n})\n@Index({ name: 'entity_indexes_type_tenant_idx', properties: ['entityType', 'tenantId'] })\n@Unique({\n name: 'entity_indexes_type_entity_org_coalesced_unique',\n properties: ['entityType', 'entityId', 'organizationIdCoalesced'],\n})\nexport class EntityIndexRow {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n // Entity identifier: '<module>:<entity>'\n @Property({ name: 'entity_type', type: 'text' })\n @Index({ name: 'entity_indexes_type_idx' })\n entityType!: string\n\n // Record id as text for compatibility with uuid/int\n @Property({ name: 'entity_id', type: 'text' })\n @Index({ name: 'entity_indexes_entity_idx' })\n entityId!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n @Index({ name: 'entity_indexes_org_idx' })\n organizationId?: string | null\n\n @Property({\n name: 'organization_id_coalesced',\n type: 'uuid',\n generated: (cols) => `(coalesce(${cols.organizationId}, '00000000-0000-0000-0000-000000000000'::uuid)) stored`,\n hidden: true,\n })\n organizationIdCoalesced!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n // Flattened document of base fields and custom fields\n @Property({ name: 'doc', type: 'json' })\n doc!: any\n\n // Optional embedding vector or metadata produced by secondary indexers\n @Property({ name: 'embedding', type: 'json', nullable: true })\n embedding?: any | null\n\n @Property({ name: 'index_version', type: 'int', default: 1 })\n indexVersion: number = 1\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// Track long-running index jobs (reindex/purge) per entity and org scope\n@Entity({ tableName: 'entity_index_jobs' })\n// Coalesced-scope unique index so prepareJob can upsert atomically and two\n// concurrent schedulers cannot insert duplicate rows for the same scope (#2739).\n// Declared via @Unique with a raw expression (not properties) because the scope\n// columns are nullable and NULLs must collapse to one bucket via coalesce; mirrors\n// the entity_indexes coalesced uniqueness and the domain_mappings expression unique.\n@Unique({\n name: 'entity_index_jobs_scope_unique',\n expression:\n `create unique index \"entity_index_jobs_scope_unique\" on \"entity_index_jobs\" (\"entity_type\", coalesce(\"organization_id\", '00000000-0000-0000-0000-000000000000'::uuid), coalesce(\"tenant_id\", '00000000-0000-0000-0000-000000000000'::uuid), coalesce(\"partition_index\", -1), coalesce(\"partition_count\", -1))`,\n})\nexport class EntityIndexJob {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'entity_type', type: 'text' })\n @Index({ name: 'entity_index_jobs_type_idx' })\n entityType!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n @Index({ name: 'entity_index_jobs_org_idx' })\n organizationId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'partition_index', type: 'int', nullable: true })\n partitionIndex?: number | null\n\n @Property({ name: 'partition_count', type: 'int', nullable: true })\n partitionCount?: number | null\n\n @Property({ name: 'processed_count', type: 'int', nullable: true })\n processedCount?: number | null\n\n @Property({ name: 'total_count', type: 'int', nullable: true })\n totalCount?: number | null\n\n @Property({ name: 'heartbeat_at', type: Date, nullable: true })\n heartbeatAt?: Date | null\n\n // 'reindexing' | 'purging'\n @Property({ name: 'status', type: 'text' })\n status!: string\n\n @Property({ name: 'started_at', type: Date, onCreate: () => new Date() })\n startedAt: Date = new Date()\n\n @Property({ name: 'finished_at', type: Date, nullable: true })\n finishedAt?: Date | null\n}\n\n// Snapshot counts for coverage checks (per entity / tenant / org / withDeleted scope)\n@Entity({ tableName: 'entity_index_coverage' })\n@Unique({\n name: 'entity_index_coverage_scope_idx',\n properties: ['entityType', 'tenantId', 'organizationId', 'withDeleted'],\n})\nexport class EntityIndexCoverage {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'entity_type', type: 'text' })\n entityType!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'with_deleted', type: 'boolean', default: false })\n withDeleted: boolean = false\n\n @Property({ name: 'base_count', type: 'int', unsigned: true, default: 0 })\n baseCount: number = 0\n\n @Property({ name: 'indexed_count', type: 'int', unsigned: true, default: 0 })\n indexedCount: number = 0\n\n @Property({ name: 'vector_indexed_count', type: 'int', unsigned: true, default: 0 })\n vectorIndexedCount: number = 0\n\n @Property({ name: 'refreshed_at', type: Date, onCreate: () => new Date(), onUpdate: () => new Date() })\n refreshedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'indexer_error_logs' })\n@Index({ name: 'indexer_error_logs_source_idx', properties: ['source'] })\n@Index({ name: 'indexer_error_logs_occurred_idx', properties: ['occurredAt'] })\nexport class IndexerErrorLog {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'source', type: 'text' })\n source!: string\n\n @Property({ name: 'handler', type: 'text' })\n handler!: string\n\n @Property({ name: 'entity_type', type: 'text', nullable: true })\n entityType?: string | null\n\n @Property({ name: 'record_id', type: 'text', nullable: true })\n recordId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'payload', type: 'json', nullable: true })\n payload?: any | null\n\n @Property({ name: 'message', type: 'text' })\n message!: string\n\n @Property({ name: 'stack', type: 'text', nullable: true })\n stack?: string | null\n\n@Property({ name: 'occurred_at', type: Date, onCreate: () => new Date() })\n occurredAt: Date = new Date()\n}\n\n@Entity({ tableName: 'indexer_status_logs' })\n@Index({ name: 'indexer_status_logs_source_idx', properties: ['source'] })\n@Index({ name: 'indexer_status_logs_occurred_idx', properties: ['occurredAt'] })\nexport class IndexerStatusLog {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'source', type: 'text' })\n source!: string\n\n @Property({ name: 'handler', type: 'text' })\n handler!: string\n\n @Property({ name: 'level', type: 'text' })\n level: string = 'info'\n\n @Property({ name: 'entity_type', type: 'text', nullable: true })\n entityType?: string | null\n\n @Property({ name: 'record_id', type: 'text', nullable: true })\n recordId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'message', type: 'text' })\n message!: string\n\n @Property({ name: 'details', type: 'json', nullable: true })\n details?: any | null\n\n @Property({ name: 'occurred_at', type: Date, onCreate: () => new Date() })\n occurredAt: Date = new Date()\n}\n\n@Entity({ tableName: 'search_tokens' })\n@Index({ name: 'search_tokens_lookup_idx', properties: ['entityType', 'field', 'tokenHash', 'tenantId', 'organizationId'] })\n@Index({ name: 'search_tokens_entity_idx', properties: ['entityType', 'entityId'] })\n@Index({ name: 'search_tokens_tenant_token_hash_idx', properties: ['tenantId', 'tokenHash'] })\nexport class SearchToken {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'entity_type', type: 'text' })\n entityType!: string\n\n @Property({ name: 'entity_id', type: 'text' })\n entityId!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'field', type: 'text' })\n field!: string\n\n @Property({ name: 'token_hash', type: 'text' })\n tokenHash!: string\n\n @Property({ name: 'token', type: 'text', nullable: true })\n token?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAAA,SAAS,QAAQ,OAAO,YAAY,UAAU,cAAc;AAuCrD,IAAM,iBAAN,MAAqB;AAAA,EAArB;AAsCL,wBAAuB;AAGvB,qBAAkB,oBAAI,KAAK;AAG3B,qBAAkB,oBAAI,KAAK;AAAA;AAI7B;AA9CE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GADlD,eAEX;AAKA;AAAA,EAFC,SAAS,EAAE,MAAM,eAAe,MAAM,OAAO,CAAC;AAAA,EAC9C,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAAA,GAN/B,eAOX;AAKA;AAAA,EAFC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,EAC5C,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAAA,GAXjC,eAYX;AAIA;AAAA,EAFC,SAAS,EAAE,MAAM,mBAAmB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,EAClE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAAA,GAf9B,eAgBX;AAQA;AAAA,EANC,SAAS;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,IACN,WAAW,CAAC,SAAS,aAAa,KAAK,cAAc;AAAA,IACrD,QAAQ;AAAA,EACV,CAAC;AAAA,GAvBU,eAwBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GA1BlD,eA2BX;AAIA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,MAAM,OAAO,CAAC;AAAA,GA9B5B,eA+BX;AAIA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAlClD,eAmCX;AAGA;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,EAClF,MAAM,EAAE,MAAM,uCAAuC,YAAY,CAAC,YAAY,WAAW,EAAE,CAAC;AAAA,GAChF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SortDir } from "@open-mercato/shared/lib/query/types";
|
|
2
|
-
import { resolveEntityTableName } from "@open-mercato/shared/lib/query/engine";
|
|
2
|
+
import { resolveEntityTableName, resolveRegisteredEntityTableName } from "@open-mercato/shared/lib/query/engine";
|
|
3
3
|
import { sql } from "kysely";
|
|
4
4
|
import { readCoverageSnapshot, refreshCoverageSnapshot } from "./coverage.js";
|
|
5
5
|
import { createProfiler, shouldEnableProfiler } from "@open-mercato/shared/lib/profiler";
|
|
@@ -144,7 +144,7 @@ class HybridQueryEngine {
|
|
|
144
144
|
try {
|
|
145
145
|
const debugEnabled = this.isDebugVerbosity();
|
|
146
146
|
if (debugEnabled) this.debug("query:start", { entity });
|
|
147
|
-
const isCustom = await this.isCustomEntity(entity);
|
|
147
|
+
const isCustom = opts.forceCustomEntityStorage === true || await this.isCustomEntity(entity);
|
|
148
148
|
if (isCustom) {
|
|
149
149
|
if (debugEnabled) this.debug("query:custom-entity", { entity });
|
|
150
150
|
const section = profiler.section("custom_entity");
|
|
@@ -861,6 +861,8 @@ class HybridQueryEngine {
|
|
|
861
861
|
const row = await db.selectFrom("custom_entities").select("id").where("entity_id", "=", entity).where("is_active", "=", true).executeTakeFirst();
|
|
862
862
|
if (row) {
|
|
863
863
|
result = true;
|
|
864
|
+
} else if (resolveRegisteredEntityTableName(this.em, entity) !== null) {
|
|
865
|
+
result = false;
|
|
864
866
|
} else {
|
|
865
867
|
result = await this.hasCustomEntityStorageRows(entity);
|
|
866
868
|
}
|