@open-mercato/core 0.4.2-canary-10c7a8bf2a → 0.4.2-canary-c84cff7ed5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/entities/notification/index.js +57 -0
- package/dist/generated/entities/notification/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +5 -1
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +2 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/api_docs/frontend/docs/api/page.js +3 -2
- package/dist/modules/api_docs/frontend/docs/api/page.js.map +2 -2
- package/dist/modules/api_keys/backend/api-keys/page.js +1 -1
- package/dist/modules/api_keys/backend/api-keys/page.js.map +2 -2
- package/dist/modules/attachments/components/AttachmentLibrary.js +4 -0
- package/dist/modules/attachments/components/AttachmentLibrary.js.map +2 -2
- package/dist/modules/attachments/components/AttachmentPartitionSettings.js +2 -0
- package/dist/modules/attachments/components/AttachmentPartitionSettings.js.map +2 -2
- package/dist/modules/auth/api/admin/nav.js +4 -3
- package/dist/modules/auth/api/admin/nav.js.map +2 -2
- package/dist/modules/auth/api/profile/route.js +157 -0
- package/dist/modules/auth/api/profile/route.js.map +7 -0
- package/dist/modules/auth/api/reset/confirm.js +25 -2
- package/dist/modules/auth/api/reset/confirm.js.map +2 -2
- package/dist/modules/auth/api/reset.js +23 -0
- package/dist/modules/auth/api/reset.js.map +2 -2
- package/dist/modules/auth/api/sidebar/preferences/route.js +14 -9
- package/dist/modules/auth/api/sidebar/preferences/route.js.map +2 -2
- package/dist/modules/auth/api/users/route.js +4 -2
- package/dist/modules/auth/api/users/route.js.map +2 -2
- package/dist/modules/auth/backend/auth/profile/page.js +141 -0
- package/dist/modules/auth/backend/auth/profile/page.js.map +7 -0
- package/dist/modules/auth/backend/auth/profile/page.meta.js +13 -0
- package/dist/modules/auth/backend/auth/profile/page.meta.js.map +7 -0
- package/dist/modules/auth/backend/roles/page.js +3 -3
- package/dist/modules/auth/backend/roles/page.js.map +2 -2
- package/dist/modules/auth/backend/users/[id]/edit/page.js +14 -2
- package/dist/modules/auth/backend/users/[id]/edit/page.js.map +2 -2
- package/dist/modules/auth/backend/users/create/page.js +15 -2
- package/dist/modules/auth/backend/users/create/page.js.map +2 -2
- package/dist/modules/auth/backend/users/page.js +3 -3
- package/dist/modules/auth/backend/users/page.js.map +2 -2
- package/dist/modules/auth/cli.js +13 -0
- package/dist/modules/auth/cli.js.map +2 -2
- package/dist/modules/auth/commands/users.js +59 -2
- package/dist/modules/auth/commands/users.js.map +2 -2
- package/dist/modules/auth/data/validators.js +4 -2
- package/dist/modules/auth/data/validators.js.map +2 -2
- package/dist/modules/auth/frontend/reset/[token]/page.js +20 -10
- package/dist/modules/auth/frontend/reset/[token]/page.js.map +2 -2
- package/dist/modules/auth/lib/setup-app.js +3 -0
- package/dist/modules/auth/lib/setup-app.js.map +2 -2
- package/dist/modules/auth/notifications.js +112 -0
- package/dist/modules/auth/notifications.js.map +7 -0
- package/dist/modules/auth/services/authService.js +3 -3
- package/dist/modules/auth/services/authService.js.map +2 -2
- package/dist/modules/business_rules/backend/rules/page.js +4 -0
- package/dist/modules/business_rules/backend/rules/page.js.map +2 -2
- package/dist/modules/business_rules/backend/sets/page.js +3 -0
- package/dist/modules/business_rules/backend/sets/page.js.map +2 -2
- package/dist/modules/business_rules/notifications.js +28 -0
- package/dist/modules/business_rules/notifications.js.map +7 -0
- package/dist/modules/business_rules/subscribers/rule-execution-failed-notification.js +37 -0
- package/dist/modules/business_rules/subscribers/rule-execution-failed-notification.js.map +7 -0
- package/dist/modules/catalog/analytics.js +27 -0
- package/dist/modules/catalog/analytics.js.map +7 -0
- package/dist/modules/catalog/components/PriceKindSettings.js +2 -0
- package/dist/modules/catalog/components/PriceKindSettings.js.map +2 -2
- package/dist/modules/catalog/components/categories/CategoriesDataTable.js +2 -2
- package/dist/modules/catalog/components/categories/CategoriesDataTable.js.map +2 -2
- package/dist/modules/catalog/components/products/ProductsDataTable.js +2 -0
- package/dist/modules/catalog/components/products/ProductsDataTable.js.map +2 -2
- package/dist/modules/catalog/notifications.js +28 -0
- package/dist/modules/catalog/notifications.js.map +7 -0
- package/dist/modules/catalog/subscribers/low-stock-notification.js +38 -0
- package/dist/modules/catalog/subscribers/low-stock-notification.js.map +7 -0
- package/dist/modules/configs/cli.js +6 -0
- package/dist/modules/configs/cli.js.map +2 -2
- package/dist/modules/configs/lib/upgrade-actions.js +18 -0
- package/dist/modules/configs/lib/upgrade-actions.js.map +2 -2
- package/dist/modules/currencies/backend/currencies/page.js +3 -0
- package/dist/modules/currencies/backend/currencies/page.js.map +2 -2
- package/dist/modules/currencies/backend/exchange-rates/page.js +2 -0
- package/dist/modules/currencies/backend/exchange-rates/page.js.map +2 -2
- package/dist/modules/customers/analytics.js +50 -0
- package/dist/modules/customers/analytics.js.map +7 -0
- package/dist/modules/customers/backend/customers/companies/page.js +3 -0
- package/dist/modules/customers/backend/customers/companies/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/page.js +3 -0
- package/dist/modules/customers/backend/customers/deals/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/people/page.js +3 -0
- package/dist/modules/customers/backend/customers/people/page.js.map +2 -2
- package/dist/modules/customers/commands/deals.js +31 -0
- package/dist/modules/customers/commands/deals.js.map +2 -2
- package/dist/modules/customers/components/CustomerTodosTable.js +1 -0
- package/dist/modules/customers/components/CustomerTodosTable.js.map +2 -2
- package/dist/modules/customers/notifications.js +48 -0
- package/dist/modules/customers/notifications.js.map +7 -0
- package/dist/modules/dashboards/acl.js +2 -1
- package/dist/modules/dashboards/acl.js.map +2 -2
- package/dist/modules/dashboards/api/widgets/data/route.js +187 -0
- package/dist/modules/dashboards/api/widgets/data/route.js.map +7 -0
- package/dist/modules/dashboards/cli.js +173 -1
- package/dist/modules/dashboards/cli.js.map +2 -2
- package/dist/modules/dashboards/di.js +11 -0
- package/dist/modules/dashboards/di.js.map +7 -0
- package/dist/modules/dashboards/lib/aggregations.js +162 -0
- package/dist/modules/dashboards/lib/aggregations.js.map +7 -0
- package/dist/modules/dashboards/lib/formatters.js +34 -0
- package/dist/modules/dashboards/lib/formatters.js.map +7 -0
- package/dist/modules/dashboards/lib/role-widgets.js +58 -0
- package/dist/modules/dashboards/lib/role-widgets.js.map +7 -0
- package/dist/modules/dashboards/seed/analytics.js +383 -0
- package/dist/modules/dashboards/seed/analytics.js.map +7 -0
- package/dist/modules/dashboards/services/analyticsRegistry.js +52 -0
- package/dist/modules/dashboards/services/analyticsRegistry.js.map +7 -0
- package/dist/modules/dashboards/services/widgetDataService.js +207 -0
- package/dist/modules/dashboards/services/widgetDataService.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/aov-kpi/config.js +18 -0
- package/dist/modules/dashboards/widgets/dashboard/aov-kpi/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/aov-kpi/widget.client.js +128 -0
- package/dist/modules/dashboards/widgets/dashboard/aov-kpi/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/aov-kpi/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/aov-kpi/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/new-customers-kpi/config.js +18 -0
- package/dist/modules/dashboards/widgets/dashboard/new-customers-kpi/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.client.js +126 -0
- package/dist/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-by-status/config.js +18 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-by-status/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-by-status/widget.client.js +151 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-by-status/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-by-status/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-by-status/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-kpi/config.js +18 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-kpi/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-kpi/widget.client.js +126 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-kpi/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-kpi/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/orders-kpi/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/config.js +16 -0
- package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/widget.client.js +123 -0
- package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-kpi/config.js +18 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-kpi/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-kpi/widget.client.js +128 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-kpi/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-kpi/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-kpi/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-trend/config.js +21 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-trend/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-trend/widget.client.js +211 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-trend/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-trend/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/revenue-trend/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/sales-by-region/config.js +19 -0
- package/dist/modules/dashboards/widgets/dashboard/sales-by-region/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/sales-by-region/widget.client.js +131 -0
- package/dist/modules/dashboards/widgets/dashboard/sales-by-region/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/sales-by-region/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/sales-by-region/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/top-customers/config.js +19 -0
- package/dist/modules/dashboards/widgets/dashboard/top-customers/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/top-customers/widget.client.js +153 -0
- package/dist/modules/dashboards/widgets/dashboard/top-customers/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/top-customers/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/top-customers/widget.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/top-products/config.js +22 -0
- package/dist/modules/dashboards/widgets/dashboard/top-products/config.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/top-products/widget.client.js +180 -0
- package/dist/modules/dashboards/widgets/dashboard/top-products/widget.client.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/top-products/widget.js +25 -0
- package/dist/modules/dashboards/widgets/dashboard/top-products/widget.js.map +7 -0
- package/dist/modules/dictionaries/components/DictionaryTable.js +2 -0
- package/dist/modules/dictionaries/components/DictionaryTable.js.map +2 -2
- package/dist/modules/directory/backend/directory/organizations/page.js +2 -2
- package/dist/modules/directory/backend/directory/organizations/page.js.map +2 -2
- package/dist/modules/directory/backend/directory/tenants/page.js +2 -2
- package/dist/modules/directory/backend/directory/tenants/page.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js.map +2 -2
- package/dist/modules/entities/components/SystemEntitiesTable.js +1 -1
- package/dist/modules/entities/components/SystemEntitiesTable.js.map +2 -2
- package/dist/modules/entities/components/UserEntitiesTable.js +2 -2
- package/dist/modules/entities/components/UserEntitiesTable.js.map +2 -2
- package/dist/modules/feature_toggles/components/FeatureTogglesTable.js +3 -3
- package/dist/modules/feature_toggles/components/FeatureTogglesTable.js.map +2 -2
- package/dist/modules/feature_toggles/components/OverridesTable.js +1 -1
- package/dist/modules/feature_toggles/components/OverridesTable.js.map +2 -2
- package/dist/modules/notifications/acl.js +11 -0
- package/dist/modules/notifications/acl.js.map +7 -0
- package/dist/modules/notifications/api/[id]/action/route.js +74 -0
- package/dist/modules/notifications/api/[id]/action/route.js.map +7 -0
- package/dist/modules/notifications/api/[id]/dismiss/route.js +15 -0
- package/dist/modules/notifications/api/[id]/dismiss/route.js.map +7 -0
- package/dist/modules/notifications/api/[id]/read/route.js +15 -0
- package/dist/modules/notifications/api/[id]/read/route.js.map +7 -0
- package/dist/modules/notifications/api/[id]/restore/route.js +53 -0
- package/dist/modules/notifications/api/[id]/restore/route.js.map +7 -0
- package/dist/modules/notifications/api/batch/route.js +17 -0
- package/dist/modules/notifications/api/batch/route.js.map +7 -0
- package/dist/modules/notifications/api/feature/route.js +17 -0
- package/dist/modules/notifications/api/feature/route.js.map +7 -0
- package/dist/modules/notifications/api/mark-all-read/route.js +35 -0
- package/dist/modules/notifications/api/mark-all-read/route.js.map +7 -0
- package/dist/modules/notifications/api/openapi.js +76 -0
- package/dist/modules/notifications/api/openapi.js.map +7 -0
- package/dist/modules/notifications/api/role/route.js +17 -0
- package/dist/modules/notifications/api/role/route.js.map +7 -0
- package/dist/modules/notifications/api/route.js +85 -0
- package/dist/modules/notifications/api/route.js.map +7 -0
- package/dist/modules/notifications/api/settings/route.js +155 -0
- package/dist/modules/notifications/api/settings/route.js.map +7 -0
- package/dist/modules/notifications/api/unread-count/route.js +38 -0
- package/dist/modules/notifications/api/unread-count/route.js.map +7 -0
- package/dist/modules/notifications/backend/config/notifications/page.js +10 -0
- package/dist/modules/notifications/backend/config/notifications/page.js.map +7 -0
- package/dist/modules/notifications/backend/config/notifications/page.meta.js +24 -0
- package/dist/modules/notifications/backend/config/notifications/page.meta.js.map +7 -0
- package/dist/modules/notifications/cli.js +16 -0
- package/dist/modules/notifications/cli.js.map +7 -0
- package/dist/modules/notifications/data/entities.js +112 -0
- package/dist/modules/notifications/data/entities.js.map +7 -0
- package/dist/modules/notifications/data/validators.js +94 -0
- package/dist/modules/notifications/data/validators.js.map +7 -0
- package/dist/modules/notifications/di.js +13 -0
- package/dist/modules/notifications/di.js.map +7 -0
- package/dist/modules/notifications/emails/NotificationEmail.js +58 -0
- package/dist/modules/notifications/emails/NotificationEmail.js.map +7 -0
- package/dist/modules/notifications/frontend/NotificationInboxPageClient.js +44 -0
- package/dist/modules/notifications/frontend/NotificationInboxPageClient.js.map +7 -0
- package/dist/modules/notifications/frontend/NotificationSettingsPageClient.js +219 -0
- package/dist/modules/notifications/frontend/NotificationSettingsPageClient.js.map +7 -0
- package/dist/modules/notifications/index.js +14 -0
- package/dist/modules/notifications/index.js.map +7 -0
- package/dist/modules/notifications/lib/deliveryConfig.js +105 -0
- package/dist/modules/notifications/lib/deliveryConfig.js.map +7 -0
- package/dist/modules/notifications/lib/events.js +12 -0
- package/dist/modules/notifications/lib/events.js.map +7 -0
- package/dist/modules/notifications/lib/notificationBuilder.js +66 -0
- package/dist/modules/notifications/lib/notificationBuilder.js.map +7 -0
- package/dist/modules/notifications/lib/notificationFactory.js +54 -0
- package/dist/modules/notifications/lib/notificationFactory.js.map +7 -0
- package/dist/modules/notifications/lib/notificationMapper.js +34 -0
- package/dist/modules/notifications/lib/notificationMapper.js.map +7 -0
- package/dist/modules/notifications/lib/notificationRecipients.js +35 -0
- package/dist/modules/notifications/lib/notificationRecipients.js.map +7 -0
- package/dist/modules/notifications/lib/notificationService.js +279 -0
- package/dist/modules/notifications/lib/notificationService.js.map +7 -0
- package/dist/modules/notifications/lib/routeHelpers.js +101 -0
- package/dist/modules/notifications/lib/routeHelpers.js.map +7 -0
- package/dist/modules/notifications/lib/safeHref.js +24 -0
- package/dist/modules/notifications/lib/safeHref.js.map +7 -0
- package/dist/modules/notifications/migrations/Migration20260123000001.js +70 -0
- package/dist/modules/notifications/migrations/Migration20260123000001.js.map +7 -0
- package/dist/modules/notifications/migrations/Migration20260126150000.js +37 -0
- package/dist/modules/notifications/migrations/Migration20260126150000.js.map +7 -0
- package/dist/modules/notifications/subscribers/deliver-notification.js +139 -0
- package/dist/modules/notifications/subscribers/deliver-notification.js.map +7 -0
- package/dist/modules/notifications/workers/create-notification.worker.js +70 -0
- package/dist/modules/notifications/workers/create-notification.worker.js.map +7 -0
- package/dist/modules/planner/backend/planner/availability-rulesets/page.js +2 -2
- package/dist/modules/planner/backend/planner/availability-rulesets/page.js.map +2 -2
- package/dist/modules/query_index/components/QueryIndexesTable.js +7 -1
- package/dist/modules/query_index/components/QueryIndexesTable.js.map +2 -2
- package/dist/modules/resources/backend/resources/resource-types/page.js +2 -2
- package/dist/modules/resources/backend/resources/resource-types/page.js.map +2 -2
- package/dist/modules/resources/backend/resources/resources/page.js +2 -2
- package/dist/modules/resources/backend/resources/resources/page.js.map +2 -2
- package/dist/modules/sales/analytics.js +67 -0
- package/dist/modules/sales/analytics.js.map +7 -0
- package/dist/modules/sales/backend/sales/channels/offers/page.js +2 -0
- package/dist/modules/sales/backend/sales/channels/offers/page.js.map +2 -2
- package/dist/modules/sales/backend/sales/channels/page.js +2 -0
- package/dist/modules/sales/backend/sales/channels/page.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +53 -0
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/commands/payments.js +26 -0
- package/dist/modules/sales/commands/payments.js.map +2 -2
- package/dist/modules/sales/components/AdjustmentKindSettings.js +2 -2
- package/dist/modules/sales/components/AdjustmentKindSettings.js.map +2 -2
- package/dist/modules/sales/components/PaymentMethodsSettings.js +2 -2
- package/dist/modules/sales/components/PaymentMethodsSettings.js.map +2 -2
- package/dist/modules/sales/components/ShippingMethodsSettings.js +2 -2
- package/dist/modules/sales/components/ShippingMethodsSettings.js.map +2 -2
- package/dist/modules/sales/components/TaxRatesSettings.js +2 -2
- package/dist/modules/sales/components/TaxRatesSettings.js.map +2 -2
- package/dist/modules/sales/components/channels/SalesChannelOffersPanel.js +2 -0
- package/dist/modules/sales/components/channels/SalesChannelOffersPanel.js.map +2 -2
- package/dist/modules/sales/components/documents/AdjustmentsSection.js +2 -0
- package/dist/modules/sales/components/documents/AdjustmentsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/PaymentsSection.js +2 -1
- package/dist/modules/sales/components/documents/PaymentsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/SalesDocumentsTable.js +2 -0
- package/dist/modules/sales/components/documents/SalesDocumentsTable.js.map +2 -2
- package/dist/modules/sales/notifications.client.js +51 -0
- package/dist/modules/sales/notifications.client.js.map +7 -0
- package/dist/modules/sales/notifications.js +88 -0
- package/dist/modules/sales/notifications.js.map +7 -0
- package/dist/modules/sales/subscribers/quote-expiring-notification.js +38 -0
- package/dist/modules/sales/subscribers/quote-expiring-notification.js.map +7 -0
- package/dist/modules/sales/widgets/notifications/SalesOrderCreatedRenderer.js +137 -0
- package/dist/modules/sales/widgets/notifications/SalesOrderCreatedRenderer.js.map +7 -0
- package/dist/modules/sales/widgets/notifications/SalesQuoteCreatedRenderer.js +137 -0
- package/dist/modules/sales/widgets/notifications/SalesQuoteCreatedRenderer.js.map +7 -0
- package/dist/modules/sales/widgets/notifications/index.js +7 -0
- package/dist/modules/sales/widgets/notifications/index.js.map +7 -0
- package/dist/modules/sales/widgets/notifications/useSalesDocumentTotals.js +60 -0
- package/dist/modules/sales/widgets/notifications/useSalesDocumentTotals.js.map +7 -0
- package/dist/modules/staff/backend/staff/team-members/page.js +1 -1
- package/dist/modules/staff/backend/staff/team-members/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/team-roles/page.js +2 -2
- package/dist/modules/staff/backend/staff/team-roles/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/teams/[id]/edit/page.js +2 -2
- package/dist/modules/staff/backend/staff/teams/[id]/edit/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/teams/page.js +2 -2
- package/dist/modules/staff/backend/staff/teams/page.js.map +2 -2
- package/dist/modules/staff/commands/leave-requests.js +79 -0
- package/dist/modules/staff/commands/leave-requests.js.map +2 -2
- package/dist/modules/staff/notifications.js +75 -0
- package/dist/modules/staff/notifications.js.map +7 -0
- package/dist/modules/workflows/backend/definitions/page.js +5 -0
- package/dist/modules/workflows/backend/definitions/page.js.map +2 -2
- package/dist/modules/workflows/backend/instances/page.js +3 -0
- package/dist/modules/workflows/backend/instances/page.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/page.js +3 -0
- package/dist/modules/workflows/backend/tasks/page.js.map +2 -2
- package/dist/modules/workflows/notifications.js +28 -0
- package/dist/modules/workflows/notifications.js.map +7 -0
- package/dist/modules/workflows/subscribers/task-assigned-notification.js +38 -0
- package/dist/modules/workflows/subscribers/task-assigned-notification.js.map +7 -0
- package/generated/entities/notification/index.ts +27 -0
- package/generated/entities.ids.generated.ts +5 -1
- package/generated/entity-fields-registry.ts +2 -0
- package/package.json +2 -2
- package/src/modules/api_docs/frontend/docs/api/page.tsx +3 -2
- package/src/modules/api_keys/backend/api-keys/page.tsx +1 -1
- package/src/modules/attachments/components/AttachmentLibrary.tsx +4 -0
- package/src/modules/attachments/components/AttachmentPartitionSettings.tsx +2 -0
- package/src/modules/auth/api/admin/nav.ts +10 -6
- package/src/modules/auth/api/profile/route.ts +163 -0
- package/src/modules/auth/api/reset/confirm.ts +25 -2
- package/src/modules/auth/api/reset.ts +23 -0
- package/src/modules/auth/api/sidebar/preferences/route.ts +21 -12
- package/src/modules/auth/api/users/route.ts +5 -2
- package/src/modules/auth/backend/auth/profile/page.meta.ts +9 -0
- package/src/modules/auth/backend/auth/profile/page.tsx +174 -0
- package/src/modules/auth/backend/roles/page.tsx +3 -3
- package/src/modules/auth/backend/users/[id]/edit/page.tsx +18 -2
- package/src/modules/auth/backend/users/create/page.tsx +19 -2
- package/src/modules/auth/backend/users/page.tsx +3 -3
- package/src/modules/auth/cli.ts +14 -0
- package/src/modules/auth/commands/users.ts +73 -2
- package/src/modules/auth/data/validators.ts +5 -2
- package/src/modules/auth/frontend/reset/[token]/page.tsx +24 -11
- package/src/modules/auth/i18n/de.json +43 -1
- package/src/modules/auth/i18n/en.json +43 -1
- package/src/modules/auth/i18n/es.json +43 -1
- package/src/modules/auth/i18n/pl.json +43 -1
- package/src/modules/auth/lib/setup-app.ts +3 -0
- package/src/modules/auth/notifications.ts +109 -0
- package/src/modules/auth/services/authService.ts +4 -4
- package/src/modules/business_rules/backend/rules/page.tsx +4 -0
- package/src/modules/business_rules/backend/sets/page.tsx +3 -0
- package/src/modules/business_rules/i18n/en.json +3 -1
- package/src/modules/business_rules/notifications.ts +25 -0
- package/src/modules/business_rules/subscribers/rule-execution-failed-notification.ts +50 -0
- package/src/modules/catalog/analytics.ts +24 -0
- package/src/modules/catalog/components/PriceKindSettings.tsx +2 -0
- package/src/modules/catalog/components/categories/CategoriesDataTable.tsx +2 -2
- package/src/modules/catalog/components/products/ProductsDataTable.tsx +2 -0
- package/src/modules/catalog/i18n/en.json +3 -1
- package/src/modules/catalog/notifications.ts +25 -0
- package/src/modules/catalog/subscribers/low-stock-notification.ts +52 -0
- package/src/modules/configs/cli.ts +6 -0
- package/src/modules/configs/lib/upgrade-actions.ts +18 -0
- package/src/modules/currencies/backend/currencies/page.tsx +3 -0
- package/src/modules/currencies/backend/exchange-rates/page.tsx +2 -0
- package/src/modules/customers/analytics.ts +47 -0
- package/src/modules/customers/backend/customers/companies/page.tsx +3 -0
- package/src/modules/customers/backend/customers/deals/page.tsx +3 -0
- package/src/modules/customers/backend/customers/people/page.tsx +3 -0
- package/src/modules/customers/commands/deals.ts +39 -0
- package/src/modules/customers/components/CustomerTodosTable.tsx +1 -0
- package/src/modules/customers/i18n/en.json +5 -1
- package/src/modules/customers/notifications.ts +44 -0
- package/src/modules/dashboards/acl.ts +1 -0
- package/src/modules/dashboards/api/widgets/data/route.ts +221 -0
- package/src/modules/dashboards/cli.ts +204 -1
- package/src/modules/dashboards/di.ts +9 -0
- package/src/modules/dashboards/i18n/de.json +115 -1
- package/src/modules/dashboards/i18n/en.json +115 -1
- package/src/modules/dashboards/i18n/es.json +115 -1
- package/src/modules/dashboards/i18n/pl.json +115 -1
- package/src/modules/dashboards/lib/__tests__/aggregations.test.ts +327 -0
- package/src/modules/dashboards/lib/__tests__/formatters.test.ts +128 -0
- package/src/modules/dashboards/lib/aggregations.ts +225 -0
- package/src/modules/dashboards/lib/formatters.ts +36 -0
- package/src/modules/dashboards/lib/role-widgets.ts +80 -0
- package/src/modules/dashboards/seed/analytics.ts +405 -0
- package/src/modules/dashboards/services/analyticsRegistry.ts +79 -0
- package/src/modules/dashboards/services/widgetDataService.ts +329 -0
- package/src/modules/dashboards/widgets/dashboard/aov-kpi/config.ts +20 -0
- package/src/modules/dashboards/widgets/dashboard/aov-kpi/widget.client.tsx +135 -0
- package/src/modules/dashboards/widgets/dashboard/aov-kpi/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/new-customers-kpi/config.ts +20 -0
- package/src/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.client.tsx +133 -0
- package/src/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/orders-by-status/config.ts +20 -0
- package/src/modules/dashboards/widgets/dashboard/orders-by-status/widget.client.tsx +154 -0
- package/src/modules/dashboards/widgets/dashboard/orders-by-status/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/orders-kpi/config.ts +20 -0
- package/src/modules/dashboards/widgets/dashboard/orders-kpi/widget.client.tsx +133 -0
- package/src/modules/dashboards/widgets/dashboard/orders-kpi/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/pipeline-summary/config.ts +17 -0
- package/src/modules/dashboards/widgets/dashboard/pipeline-summary/widget.client.tsx +137 -0
- package/src/modules/dashboards/widgets/dashboard/pipeline-summary/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/revenue-kpi/config.ts +20 -0
- package/src/modules/dashboards/widgets/dashboard/revenue-kpi/widget.client.tsx +135 -0
- package/src/modules/dashboards/widgets/dashboard/revenue-kpi/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/revenue-trend/config.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/revenue-trend/widget.client.tsx +220 -0
- package/src/modules/dashboards/widgets/dashboard/revenue-trend/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/sales-by-region/config.ts +21 -0
- package/src/modules/dashboards/widgets/dashboard/sales-by-region/widget.client.tsx +131 -0
- package/src/modules/dashboards/widgets/dashboard/sales-by-region/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/top-customers/config.ts +21 -0
- package/src/modules/dashboards/widgets/dashboard/top-customers/widget.client.tsx +161 -0
- package/src/modules/dashboards/widgets/dashboard/top-customers/widget.ts +24 -0
- package/src/modules/dashboards/widgets/dashboard/top-products/config.ts +27 -0
- package/src/modules/dashboards/widgets/dashboard/top-products/widget.client.tsx +181 -0
- package/src/modules/dashboards/widgets/dashboard/top-products/widget.ts +24 -0
- package/src/modules/dictionaries/components/DictionaryTable.tsx +2 -0
- package/src/modules/directory/backend/directory/organizations/page.tsx +2 -2
- package/src/modules/directory/backend/directory/tenants/page.tsx +2 -2
- package/src/modules/entities/backend/entities/user/[entityId]/records/page.tsx +2 -2
- package/src/modules/entities/components/SystemEntitiesTable.tsx +1 -1
- package/src/modules/entities/components/UserEntitiesTable.tsx +2 -2
- package/src/modules/feature_toggles/components/FeatureTogglesTable.tsx +3 -4
- package/src/modules/feature_toggles/components/OverridesTable.tsx +1 -1
- package/src/modules/notifications/acl.ts +7 -0
- package/src/modules/notifications/api/[id]/action/route.ts +75 -0
- package/src/modules/notifications/api/[id]/dismiss/route.ts +12 -0
- package/src/modules/notifications/api/[id]/read/route.ts +12 -0
- package/src/modules/notifications/api/[id]/restore/route.ts +53 -0
- package/src/modules/notifications/api/batch/route.ts +14 -0
- package/src/modules/notifications/api/feature/route.ts +14 -0
- package/src/modules/notifications/api/mark-all-read/route.ts +34 -0
- package/src/modules/notifications/api/openapi.ts +76 -0
- package/src/modules/notifications/api/role/route.ts +14 -0
- package/src/modules/notifications/api/route.ts +92 -0
- package/src/modules/notifications/api/settings/route.ts +157 -0
- package/src/modules/notifications/api/unread-count/route.ts +38 -0
- package/src/modules/notifications/backend/config/notifications/page.meta.ts +22 -0
- package/src/modules/notifications/backend/config/notifications/page.tsx +12 -0
- package/src/modules/notifications/cli.ts +18 -0
- package/src/modules/notifications/data/entities.ts +99 -0
- package/src/modules/notifications/data/validators.ts +110 -0
- package/src/modules/notifications/di.ts +11 -0
- package/src/modules/notifications/emails/NotificationEmail.tsx +98 -0
- package/src/modules/notifications/frontend/NotificationInboxPageClient.tsx +42 -0
- package/src/modules/notifications/frontend/NotificationSettingsPageClient.tsx +231 -0
- package/src/modules/notifications/i18n/de.json +50 -0
- package/src/modules/notifications/i18n/en.json +50 -0
- package/src/modules/notifications/i18n/es.json +50 -0
- package/src/modules/notifications/i18n/pl.json +50 -0
- package/src/modules/notifications/index.ts +12 -0
- package/src/modules/notifications/lib/deliveryConfig.ts +145 -0
- package/src/modules/notifications/lib/events.ts +48 -0
- package/src/modules/notifications/lib/notificationBuilder.ts +121 -0
- package/src/modules/notifications/lib/notificationFactory.ts +76 -0
- package/src/modules/notifications/lib/notificationMapper.ts +33 -0
- package/src/modules/notifications/lib/notificationRecipients.ts +83 -0
- package/src/modules/notifications/lib/notificationService.ts +414 -0
- package/src/modules/notifications/lib/routeHelpers.ts +151 -0
- package/src/modules/notifications/lib/safeHref.ts +29 -0
- package/src/modules/notifications/migrations/.snapshot-open-mercato.json +300 -0
- package/src/modules/notifications/migrations/Migration20260123000001.ts +73 -0
- package/src/modules/notifications/migrations/Migration20260126150000.ts +39 -0
- package/src/modules/notifications/subscribers/deliver-notification.ts +175 -0
- package/src/modules/notifications/workers/create-notification.worker.ts +122 -0
- package/src/modules/planner/backend/planner/availability-rulesets/page.tsx +2 -2
- package/src/modules/query_index/components/QueryIndexesTable.tsx +8 -2
- package/src/modules/resources/backend/resources/resource-types/page.tsx +2 -2
- package/src/modules/resources/backend/resources/resources/page.tsx +2 -2
- package/src/modules/sales/analytics.ts +64 -0
- package/src/modules/sales/backend/sales/channels/offers/page.tsx +2 -0
- package/src/modules/sales/backend/sales/channels/page.tsx +2 -0
- package/src/modules/sales/commands/documents.ts +65 -0
- package/src/modules/sales/commands/payments.ts +33 -0
- package/src/modules/sales/components/AdjustmentKindSettings.tsx +2 -2
- package/src/modules/sales/components/PaymentMethodsSettings.tsx +2 -2
- package/src/modules/sales/components/ShippingMethodsSettings.tsx +2 -2
- package/src/modules/sales/components/TaxRatesSettings.tsx +2 -2
- package/src/modules/sales/components/channels/SalesChannelOffersPanel.tsx +2 -0
- package/src/modules/sales/components/documents/AdjustmentsSection.tsx +2 -0
- package/src/modules/sales/components/documents/PaymentsSection.tsx +2 -1
- package/src/modules/sales/components/documents/SalesDocumentsTable.tsx +2 -0
- package/src/modules/sales/i18n/de.json +20 -0
- package/src/modules/sales/i18n/en.json +25 -1
- package/src/modules/sales/i18n/es.json +20 -0
- package/src/modules/sales/i18n/pl.json +20 -0
- package/src/modules/sales/notifications.client.ts +65 -0
- package/src/modules/sales/notifications.ts +82 -0
- package/src/modules/sales/subscribers/quote-expiring-notification.ts +53 -0
- package/src/modules/sales/widgets/notifications/SalesOrderCreatedRenderer.tsx +156 -0
- package/src/modules/sales/widgets/notifications/SalesQuoteCreatedRenderer.tsx +156 -0
- package/src/modules/sales/widgets/notifications/index.ts +2 -0
- package/src/modules/sales/widgets/notifications/useSalesDocumentTotals.ts +81 -0
- package/src/modules/staff/backend/staff/team-members/page.tsx +1 -1
- package/src/modules/staff/backend/staff/team-roles/page.tsx +2 -2
- package/src/modules/staff/backend/staff/teams/[id]/edit/page.tsx +2 -2
- package/src/modules/staff/backend/staff/teams/page.tsx +2 -2
- package/src/modules/staff/commands/leave-requests.ts +94 -0
- package/src/modules/staff/i18n/de.json +4 -0
- package/src/modules/staff/i18n/en.json +9 -1
- package/src/modules/staff/i18n/es.json +4 -0
- package/src/modules/staff/i18n/pl.json +4 -0
- package/src/modules/staff/notifications.ts +71 -0
- package/src/modules/workflows/backend/definitions/page.tsx +5 -0
- package/src/modules/workflows/backend/instances/page.tsx +4 -1
- package/src/modules/workflows/backend/tasks/page.tsx +4 -1
- package/src/modules/workflows/i18n/en.json +3 -1
- package/src/modules/workflows/notifications.ts +25 -0
- package/src/modules/workflows/subscribers/task-assigned-notification.ts +53 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function mapActions(actions) {
|
|
2
|
+
if (!actions || actions.length === 0) return void 0;
|
|
3
|
+
return actions.map((action) => ({
|
|
4
|
+
id: action.id,
|
|
5
|
+
label: action.labelKey,
|
|
6
|
+
labelKey: action.labelKey,
|
|
7
|
+
variant: action.variant,
|
|
8
|
+
icon: action.icon,
|
|
9
|
+
commandId: action.commandId,
|
|
10
|
+
href: action.href,
|
|
11
|
+
confirmRequired: action.confirmRequired,
|
|
12
|
+
confirmMessage: action.confirmMessageKey
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
function buildBaseNotificationFields(typeDef, options) {
|
|
16
|
+
return {
|
|
17
|
+
type: typeDef.type,
|
|
18
|
+
titleKey: typeDef.titleKey,
|
|
19
|
+
bodyKey: typeDef.bodyKey,
|
|
20
|
+
titleVariables: options.titleVariables,
|
|
21
|
+
bodyVariables: options.bodyVariables,
|
|
22
|
+
title: typeDef.titleKey,
|
|
23
|
+
body: typeDef.bodyKey,
|
|
24
|
+
icon: typeDef.icon,
|
|
25
|
+
severity: typeDef.severity,
|
|
26
|
+
actions: mapActions(typeDef.actions),
|
|
27
|
+
primaryActionId: typeDef.primaryActionId,
|
|
28
|
+
sourceModule: typeDef.module,
|
|
29
|
+
sourceEntityType: options.sourceEntityType,
|
|
30
|
+
sourceEntityId: options.sourceEntityId,
|
|
31
|
+
linkHref: options.linkHref ?? typeDef.linkHref,
|
|
32
|
+
groupKey: options.groupKey,
|
|
33
|
+
expiresAt: options.expiresAt ?? (typeDef.expiresAfterHours ? new Date(Date.now() + typeDef.expiresAfterHours * 60 * 60 * 1e3).toISOString() : void 0)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function buildNotificationFromType(typeDef, options) {
|
|
37
|
+
return {
|
|
38
|
+
recipientUserId: options.recipientUserId,
|
|
39
|
+
...buildBaseNotificationFields(typeDef, options)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function buildBatchNotificationFromType(typeDef, options) {
|
|
43
|
+
return {
|
|
44
|
+
recipientUserIds: options.recipientUserIds,
|
|
45
|
+
...buildBaseNotificationFields(typeDef, options)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function buildRoleNotificationFromType(typeDef, options) {
|
|
49
|
+
return {
|
|
50
|
+
roleId: options.roleId,
|
|
51
|
+
...buildBaseNotificationFields(typeDef, options)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function buildFeatureNotificationFromType(typeDef, options) {
|
|
55
|
+
return {
|
|
56
|
+
requiredFeature: options.requiredFeature,
|
|
57
|
+
...buildBaseNotificationFields(typeDef, options)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
buildBatchNotificationFromType,
|
|
62
|
+
buildFeatureNotificationFromType,
|
|
63
|
+
buildNotificationFromType,
|
|
64
|
+
buildRoleNotificationFromType
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=notificationBuilder.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/notifications/lib/notificationBuilder.ts"],
|
|
4
|
+
"sourcesContent": ["import type { NotificationTypeDefinition, NotificationTypeAction } from '@open-mercato/shared/modules/notifications/types'\nimport type { CreateNotificationInput, CreateBatchNotificationInput, CreateRoleNotificationInput, CreateFeatureNotificationInput } from '../data/validators'\n\n/**\n * Transform type definition actions to API input actions.\n * Type definitions use labelKey (i18n-first), while API input uses label with optional labelKey.\n */\nfunction mapActions(actions: NotificationTypeAction[] | undefined) {\n if (!actions || actions.length === 0) return undefined\n return actions.map((action) => ({\n id: action.id,\n label: action.labelKey,\n labelKey: action.labelKey,\n variant: action.variant,\n icon: action.icon,\n commandId: action.commandId,\n href: action.href,\n confirmRequired: action.confirmRequired,\n confirmMessage: action.confirmMessageKey,\n }))\n}\n\n/**\n * Common options for building notifications from type definitions\n */\ninterface CommonBuildOptions {\n titleVariables?: Record<string, string>\n bodyVariables?: Record<string, string>\n sourceEntityType?: string\n sourceEntityId?: string\n linkHref?: string\n groupKey?: string\n expiresAt?: string\n}\n\n/**\n * Build base notification fields from a type definition.\n * Shared logic used by all notification builder functions.\n */\nfunction buildBaseNotificationFields(\n typeDef: NotificationTypeDefinition,\n options: CommonBuildOptions\n) {\n return {\n type: typeDef.type,\n titleKey: typeDef.titleKey,\n bodyKey: typeDef.bodyKey,\n titleVariables: options.titleVariables,\n bodyVariables: options.bodyVariables,\n title: typeDef.titleKey,\n body: typeDef.bodyKey,\n icon: typeDef.icon,\n severity: typeDef.severity,\n actions: mapActions(typeDef.actions),\n primaryActionId: typeDef.primaryActionId,\n sourceModule: typeDef.module,\n sourceEntityType: options.sourceEntityType,\n sourceEntityId: options.sourceEntityId,\n linkHref: options.linkHref ?? typeDef.linkHref,\n groupKey: options.groupKey,\n expiresAt: options.expiresAt ?? (\n typeDef.expiresAfterHours\n ? new Date(Date.now() + typeDef.expiresAfterHours * 60 * 60 * 1000).toISOString()\n : undefined\n ),\n }\n}\n\n/**\n * Build a notification input from a type definition with i18n support.\n * This is the recommended way to create notifications - use type definitions from notifications.ts\n * to ensure i18n-first approach.\n */\nexport function buildNotificationFromType(\n typeDef: NotificationTypeDefinition,\n options: CommonBuildOptions & { recipientUserId: string }\n): CreateNotificationInput {\n return {\n recipientUserId: options.recipientUserId,\n ...buildBaseNotificationFields(typeDef, options),\n }\n}\n\n/**\n * Build a batch notification input from a type definition\n */\nexport function buildBatchNotificationFromType(\n typeDef: NotificationTypeDefinition,\n options: CommonBuildOptions & { recipientUserIds: string[] }\n): CreateBatchNotificationInput {\n return {\n recipientUserIds: options.recipientUserIds,\n ...buildBaseNotificationFields(typeDef, options),\n }\n}\n\n/**\n * Build a role notification input from a type definition\n */\nexport function buildRoleNotificationFromType(\n typeDef: NotificationTypeDefinition,\n options: CommonBuildOptions & { roleId: string }\n): CreateRoleNotificationInput {\n return {\n roleId: options.roleId,\n ...buildBaseNotificationFields(typeDef, options),\n }\n}\n\n/**\n * Build a feature-based notification input from a type definition\n */\nexport function buildFeatureNotificationFromType(\n typeDef: NotificationTypeDefinition,\n options: CommonBuildOptions & { requiredFeature: string }\n): CreateFeatureNotificationInput {\n return {\n requiredFeature: options.requiredFeature,\n ...buildBaseNotificationFields(typeDef, options),\n }\n}\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,WAAW,SAA+C;AACjE,MAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,QAAO;AAC7C,SAAO,QAAQ,IAAI,CAAC,YAAY;AAAA,IAC9B,IAAI,OAAO;AAAA,IACX,OAAO,OAAO;AAAA,IACd,UAAU,OAAO;AAAA,IACjB,SAAS,OAAO;AAAA,IAChB,MAAM,OAAO;AAAA,IACb,WAAW,OAAO;AAAA,IAClB,MAAM,OAAO;AAAA,IACb,iBAAiB,OAAO;AAAA,IACxB,gBAAgB,OAAO;AAAA,EACzB,EAAE;AACJ;AAmBA,SAAS,4BACP,SACA,SACA;AACA,SAAO;AAAA,IACL,MAAM,QAAQ;AAAA,IACd,UAAU,QAAQ;AAAA,IAClB,SAAS,QAAQ;AAAA,IACjB,gBAAgB,QAAQ;AAAA,IACxB,eAAe,QAAQ;AAAA,IACvB,OAAO,QAAQ;AAAA,IACf,MAAM,QAAQ;AAAA,IACd,MAAM,QAAQ;AAAA,IACd,UAAU,QAAQ;AAAA,IAClB,SAAS,WAAW,QAAQ,OAAO;AAAA,IACnC,iBAAiB,QAAQ;AAAA,IACzB,cAAc,QAAQ;AAAA,IACtB,kBAAkB,QAAQ;AAAA,IAC1B,gBAAgB,QAAQ;AAAA,IACxB,UAAU,QAAQ,YAAY,QAAQ;AAAA,IACtC,UAAU,QAAQ;AAAA,IAClB,WAAW,QAAQ,cACjB,QAAQ,oBACJ,IAAI,KAAK,KAAK,IAAI,IAAI,QAAQ,oBAAoB,KAAK,KAAK,GAAI,EAAE,YAAY,IAC9E;AAAA,EAER;AACF;AAOO,SAAS,0BACd,SACA,SACyB;AACzB,SAAO;AAAA,IACL,iBAAiB,QAAQ;AAAA,IACzB,GAAG,4BAA4B,SAAS,OAAO;AAAA,EACjD;AACF;AAKO,SAAS,+BACd,SACA,SAC8B;AAC9B,SAAO;AAAA,IACL,kBAAkB,QAAQ;AAAA,IAC1B,GAAG,4BAA4B,SAAS,OAAO;AAAA,EACjD;AACF;AAKO,SAAS,8BACd,SACA,SAC6B;AAC7B,SAAO;AAAA,IACL,QAAQ,QAAQ;AAAA,IAChB,GAAG,4BAA4B,SAAS,OAAO;AAAA,EACjD;AACF;AAKO,SAAS,iCACd,SACA,SACgC;AAChC,SAAO;AAAA,IACL,iBAAiB,QAAQ;AAAA,IACzB,GAAG,4BAA4B,SAAS,OAAO;AAAA,EACjD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Notification } from "../data/entities.js";
|
|
2
|
+
import { NOTIFICATION_EVENTS } from "./events.js";
|
|
3
|
+
import { assertSafeNotificationHref, sanitizeNotificationActions } from "./safeHref.js";
|
|
4
|
+
function buildNotificationEntity(em, input, recipientUserId, ctx) {
|
|
5
|
+
const actions = sanitizeNotificationActions(input.actions);
|
|
6
|
+
const linkHref = assertSafeNotificationHref(input.linkHref);
|
|
7
|
+
return em.create(Notification, {
|
|
8
|
+
recipientUserId,
|
|
9
|
+
type: input.type,
|
|
10
|
+
// i18n-first: store keys and variables for translation at display time
|
|
11
|
+
titleKey: input.titleKey,
|
|
12
|
+
bodyKey: input.bodyKey,
|
|
13
|
+
titleVariables: input.titleVariables,
|
|
14
|
+
bodyVariables: input.bodyVariables,
|
|
15
|
+
// Fallback text (required for backward compatibility)
|
|
16
|
+
title: input.title || input.titleKey || "",
|
|
17
|
+
body: input.body,
|
|
18
|
+
icon: input.icon,
|
|
19
|
+
severity: input.severity ?? "info",
|
|
20
|
+
actionData: actions ? {
|
|
21
|
+
actions,
|
|
22
|
+
primaryActionId: input.primaryActionId
|
|
23
|
+
} : null,
|
|
24
|
+
sourceModule: input.sourceModule,
|
|
25
|
+
sourceEntityType: input.sourceEntityType,
|
|
26
|
+
sourceEntityId: input.sourceEntityId,
|
|
27
|
+
linkHref,
|
|
28
|
+
groupKey: input.groupKey,
|
|
29
|
+
expiresAt: input.expiresAt ? new Date(input.expiresAt) : null,
|
|
30
|
+
tenantId: ctx.tenantId,
|
|
31
|
+
organizationId: ctx.organizationId
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async function emitNotificationCreated(eventBus, notification, ctx) {
|
|
35
|
+
await eventBus.emit(NOTIFICATION_EVENTS.CREATED, {
|
|
36
|
+
notificationId: notification.id,
|
|
37
|
+
recipientUserId: notification.recipientUserId,
|
|
38
|
+
type: notification.type,
|
|
39
|
+
title: notification.title,
|
|
40
|
+
tenantId: ctx.tenantId,
|
|
41
|
+
organizationId: ctx.organizationId
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function emitNotificationCreatedBatch(eventBus, notifications, ctx) {
|
|
45
|
+
for (const notification of notifications) {
|
|
46
|
+
await emitNotificationCreated(eventBus, notification, ctx);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
buildNotificationEntity,
|
|
51
|
+
emitNotificationCreated,
|
|
52
|
+
emitNotificationCreatedBatch
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=notificationFactory.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/notifications/lib/notificationFactory.ts"],
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/core'\nimport { Notification } from '../data/entities'\nimport type { CreateNotificationInput } from '../data/validators'\nimport { NOTIFICATION_EVENTS } from './events'\nimport { assertSafeNotificationHref, sanitizeNotificationActions } from './safeHref'\n\nexport type NotificationContentInput = Omit<CreateNotificationInput, 'recipientUserId'>\n\nexport type NotificationTenantContext = {\n tenantId: string\n organizationId?: string | null\n}\n\nexport function buildNotificationEntity(\n em: EntityManager,\n input: NotificationContentInput,\n recipientUserId: string,\n ctx: NotificationTenantContext\n): Notification {\n const actions = sanitizeNotificationActions(input.actions)\n const linkHref = assertSafeNotificationHref(input.linkHref)\n\n return em.create(Notification, {\n recipientUserId,\n type: input.type,\n // i18n-first: store keys and variables for translation at display time\n titleKey: input.titleKey,\n bodyKey: input.bodyKey,\n titleVariables: input.titleVariables,\n bodyVariables: input.bodyVariables,\n // Fallback text (required for backward compatibility)\n title: input.title || input.titleKey || '',\n body: input.body,\n icon: input.icon,\n severity: input.severity ?? 'info',\n actionData: actions\n ? {\n actions,\n primaryActionId: input.primaryActionId,\n }\n : null,\n sourceModule: input.sourceModule,\n sourceEntityType: input.sourceEntityType,\n sourceEntityId: input.sourceEntityId,\n linkHref,\n groupKey: input.groupKey,\n expiresAt: input.expiresAt ? new Date(input.expiresAt) : null,\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n })\n}\n\nexport async function emitNotificationCreated(\n eventBus: { emit: (event: string, payload: unknown) => Promise<void> },\n notification: Notification,\n ctx: NotificationTenantContext\n): Promise<void> {\n await eventBus.emit(NOTIFICATION_EVENTS.CREATED, {\n notificationId: notification.id,\n recipientUserId: notification.recipientUserId,\n type: notification.type,\n title: notification.title,\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n })\n}\n\nexport async function emitNotificationCreatedBatch(\n eventBus: { emit: (event: string, payload: unknown) => Promise<void> },\n notifications: Notification[],\n ctx: NotificationTenantContext\n): Promise<void> {\n for (const notification of notifications) {\n await emitNotificationCreated(eventBus, notification, ctx)\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,oBAAoB;AAE7B,SAAS,2BAA2B;AACpC,SAAS,4BAA4B,mCAAmC;AASjE,SAAS,wBACd,IACA,OACA,iBACA,KACc;AACd,QAAM,UAAU,4BAA4B,MAAM,OAAO;AACzD,QAAM,WAAW,2BAA2B,MAAM,QAAQ;AAE1D,SAAO,GAAG,OAAO,cAAc;AAAA,IAC7B;AAAA,IACA,MAAM,MAAM;AAAA;AAAA,IAEZ,UAAU,MAAM;AAAA,IAChB,SAAS,MAAM;AAAA,IACf,gBAAgB,MAAM;AAAA,IACtB,eAAe,MAAM;AAAA;AAAA,IAErB,OAAO,MAAM,SAAS,MAAM,YAAY;AAAA,IACxC,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM,YAAY;AAAA,IAC5B,YAAY,UACR;AAAA,MACE;AAAA,MACA,iBAAiB,MAAM;AAAA,IACzB,IACA;AAAA,IACJ,cAAc,MAAM;AAAA,IACpB,kBAAkB,MAAM;AAAA,IACxB,gBAAgB,MAAM;AAAA,IACtB;AAAA,IACA,UAAU,MAAM;AAAA,IAChB,WAAW,MAAM,YAAY,IAAI,KAAK,MAAM,SAAS,IAAI;AAAA,IACzD,UAAU,IAAI;AAAA,IACd,gBAAgB,IAAI;AAAA,EACtB,CAAC;AACH;AAEA,eAAsB,wBACpB,UACA,cACA,KACe;AACf,QAAM,SAAS,KAAK,oBAAoB,SAAS;AAAA,IAC/C,gBAAgB,aAAa;AAAA,IAC7B,iBAAiB,aAAa;AAAA,IAC9B,MAAM,aAAa;AAAA,IACnB,OAAO,aAAa;AAAA,IACpB,UAAU,IAAI;AAAA,IACd,gBAAgB,IAAI;AAAA,EACtB,CAAC;AACH;AAEA,eAAsB,6BACpB,UACA,eACA,KACe;AACf,aAAW,gBAAgB,eAAe;AACxC,UAAM,wBAAwB,UAAU,cAAc,GAAG;AAAA,EAC3D;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function toNotificationDto(notification) {
|
|
2
|
+
return {
|
|
3
|
+
id: notification.id,
|
|
4
|
+
type: notification.type,
|
|
5
|
+
title: notification.title,
|
|
6
|
+
body: notification.body,
|
|
7
|
+
titleKey: notification.titleKey,
|
|
8
|
+
bodyKey: notification.bodyKey,
|
|
9
|
+
titleVariables: notification.titleVariables,
|
|
10
|
+
bodyVariables: notification.bodyVariables,
|
|
11
|
+
icon: notification.icon,
|
|
12
|
+
severity: notification.severity,
|
|
13
|
+
status: notification.status,
|
|
14
|
+
actions: notification.actionData?.actions?.map((action) => ({
|
|
15
|
+
id: action.id,
|
|
16
|
+
label: action.label,
|
|
17
|
+
labelKey: action.labelKey,
|
|
18
|
+
variant: action.variant,
|
|
19
|
+
icon: action.icon
|
|
20
|
+
})) ?? [],
|
|
21
|
+
primaryActionId: notification.actionData?.primaryActionId,
|
|
22
|
+
sourceModule: notification.sourceModule,
|
|
23
|
+
sourceEntityType: notification.sourceEntityType,
|
|
24
|
+
sourceEntityId: notification.sourceEntityId,
|
|
25
|
+
linkHref: notification.linkHref,
|
|
26
|
+
createdAt: notification.createdAt.toISOString(),
|
|
27
|
+
readAt: notification.readAt?.toISOString() ?? null,
|
|
28
|
+
actionTaken: notification.actionTaken
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
toNotificationDto
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=notificationMapper.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/notifications/lib/notificationMapper.ts"],
|
|
4
|
+
"sourcesContent": ["import type { NotificationDto } from '@open-mercato/shared/modules/notifications/types'\nimport { Notification } from '../data/entities'\n\nexport function toNotificationDto(notification: Notification): NotificationDto {\n return {\n id: notification.id,\n type: notification.type,\n title: notification.title,\n body: notification.body,\n titleKey: notification.titleKey,\n bodyKey: notification.bodyKey,\n titleVariables: notification.titleVariables,\n bodyVariables: notification.bodyVariables,\n icon: notification.icon,\n severity: notification.severity,\n status: notification.status,\n actions: notification.actionData?.actions?.map((action) => ({\n id: action.id,\n label: action.label,\n labelKey: action.labelKey,\n variant: action.variant,\n icon: action.icon,\n })) ?? [],\n primaryActionId: notification.actionData?.primaryActionId,\n sourceModule: notification.sourceModule,\n sourceEntityType: notification.sourceEntityType,\n sourceEntityId: notification.sourceEntityId,\n linkHref: notification.linkHref,\n createdAt: notification.createdAt.toISOString(),\n readAt: notification.readAt?.toISOString() ?? null,\n actionTaken: notification.actionTaken,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAGO,SAAS,kBAAkB,cAA6C;AAC7E,SAAO;AAAA,IACL,IAAI,aAAa;AAAA,IACjB,MAAM,aAAa;AAAA,IACnB,OAAO,aAAa;AAAA,IACpB,MAAM,aAAa;AAAA,IACnB,UAAU,aAAa;AAAA,IACvB,SAAS,aAAa;AAAA,IACtB,gBAAgB,aAAa;AAAA,IAC7B,eAAe,aAAa;AAAA,IAC5B,MAAM,aAAa;AAAA,IACnB,UAAU,aAAa;AAAA,IACvB,QAAQ,aAAa;AAAA,IACrB,SAAS,aAAa,YAAY,SAAS,IAAI,CAAC,YAAY;AAAA,MAC1D,IAAI,OAAO;AAAA,MACX,OAAO,OAAO;AAAA,MACd,UAAU,OAAO;AAAA,MACjB,SAAS,OAAO;AAAA,MAChB,MAAM,OAAO;AAAA,IACf,EAAE,KAAK,CAAC;AAAA,IACR,iBAAiB,aAAa,YAAY;AAAA,IAC1C,cAAc,aAAa;AAAA,IAC3B,kBAAkB,aAAa;AAAA,IAC/B,gBAAgB,aAAa;AAAA,IAC7B,UAAU,aAAa;AAAA,IACvB,WAAW,aAAa,UAAU,YAAY;AAAA,IAC9C,QAAQ,aAAa,QAAQ,YAAY,KAAK;AAAA,IAC9C,aAAa,aAAa;AAAA,EAC5B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { hasFeature } from "@open-mercato/shared/security/features";
|
|
2
|
+
function normalizeFeatures(features) {
|
|
3
|
+
if (!Array.isArray(features)) return void 0;
|
|
4
|
+
const normalized = features.filter((feature) => typeof feature === "string");
|
|
5
|
+
return normalized.length ? normalized : void 0;
|
|
6
|
+
}
|
|
7
|
+
function collectUsersWithFeature(userIdsSet, rows, requiredFeature) {
|
|
8
|
+
for (const row of rows) {
|
|
9
|
+
if (row.is_super_admin) {
|
|
10
|
+
userIdsSet.add(row.user_id);
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const features = normalizeFeatures(row.features_json);
|
|
14
|
+
if (features && hasFeature(features, requiredFeature)) {
|
|
15
|
+
userIdsSet.add(row.user_id);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function getRecipientUserIdsForRole(knex, tenantId, roleId) {
|
|
20
|
+
const userRoles = await knex("user_roles").join("users", "user_roles.user_id", "users.id").where("user_roles.role_id", roleId).whereNull("user_roles.deleted_at").whereNull("users.deleted_at").where("users.tenant_id", tenantId).select("users.id as user_id");
|
|
21
|
+
return userRoles.map((row) => row.user_id);
|
|
22
|
+
}
|
|
23
|
+
async function getRecipientUserIdsForFeature(knex, tenantId, requiredFeature) {
|
|
24
|
+
const userIdsSet = /* @__PURE__ */ new Set();
|
|
25
|
+
const userAcls = await knex("user_acls").join("users", "user_acls.user_id", "users.id").where("user_acls.tenant_id", tenantId).whereNull("user_acls.deleted_at").whereNull("users.deleted_at").where("users.tenant_id", tenantId).select("users.id as user_id", "user_acls.features_json", "user_acls.is_super_admin");
|
|
26
|
+
collectUsersWithFeature(userIdsSet, userAcls, requiredFeature);
|
|
27
|
+
const roleAcls = await knex("role_acls").join("user_roles", "role_acls.role_id", "user_roles.role_id").join("users", "user_roles.user_id", "users.id").where("role_acls.tenant_id", tenantId).whereNull("role_acls.deleted_at").whereNull("user_roles.deleted_at").whereNull("users.deleted_at").where("users.tenant_id", tenantId).select("users.id as user_id", "role_acls.features_json", "role_acls.is_super_admin");
|
|
28
|
+
collectUsersWithFeature(userIdsSet, roleAcls, requiredFeature);
|
|
29
|
+
return Array.from(userIdsSet);
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
getRecipientUserIdsForFeature,
|
|
33
|
+
getRecipientUserIdsForRole
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=notificationRecipients.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/notifications/lib/notificationRecipients.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Knex } from 'knex'\nimport { hasFeature } from '@open-mercato/shared/security/features'\n\ninterface AclRow {\n user_id: string\n features_json: unknown\n is_super_admin: boolean\n}\n\nfunction normalizeFeatures(features: unknown): string[] | undefined {\n if (!Array.isArray(features)) return undefined\n const normalized = features.filter((feature): feature is string => typeof feature === 'string')\n return normalized.length ? normalized : undefined\n}\n\n/**\n * Extract user IDs from ACL rows that have the required feature or are super admins.\n */\nfunction collectUsersWithFeature(\n userIdsSet: Set<string>,\n rows: AclRow[],\n requiredFeature: string\n): void {\n for (const row of rows) {\n if (row.is_super_admin) {\n userIdsSet.add(row.user_id)\n continue\n }\n\n const features = normalizeFeatures(row.features_json)\n if (features && hasFeature(features, requiredFeature)) {\n userIdsSet.add(row.user_id)\n }\n }\n}\n\nexport async function getRecipientUserIdsForRole(\n knex: Knex,\n tenantId: string,\n roleId: string\n): Promise<string[]> {\n const userRoles = await knex('user_roles')\n .join('users', 'user_roles.user_id', 'users.id')\n .where('user_roles.role_id', roleId)\n .whereNull('user_roles.deleted_at')\n .whereNull('users.deleted_at')\n .where('users.tenant_id', tenantId)\n .select('users.id as user_id')\n\n return userRoles.map((row: { user_id: string }) => row.user_id)\n}\n\nexport async function getRecipientUserIdsForFeature(\n knex: Knex,\n tenantId: string,\n requiredFeature: string\n): Promise<string[]> {\n const userIdsSet = new Set<string>()\n\n const userAcls = await knex('user_acls')\n .join('users', 'user_acls.user_id', 'users.id')\n .where('user_acls.tenant_id', tenantId)\n .whereNull('user_acls.deleted_at')\n .whereNull('users.deleted_at')\n .where('users.tenant_id', tenantId)\n .select('users.id as user_id', 'user_acls.features_json', 'user_acls.is_super_admin')\n\n collectUsersWithFeature(userIdsSet, userAcls, requiredFeature)\n\n const roleAcls = await knex('role_acls')\n .join('user_roles', 'role_acls.role_id', 'user_roles.role_id')\n .join('users', 'user_roles.user_id', 'users.id')\n .where('role_acls.tenant_id', tenantId)\n .whereNull('role_acls.deleted_at')\n .whereNull('user_roles.deleted_at')\n .whereNull('users.deleted_at')\n .where('users.tenant_id', tenantId)\n .select('users.id as user_id', 'role_acls.features_json', 'role_acls.is_super_admin')\n\n collectUsersWithFeature(userIdsSet, roleAcls, requiredFeature)\n\n return Array.from(userIdsSet)\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,kBAAkB;AAQ3B,SAAS,kBAAkB,UAAyC;AAClE,MAAI,CAAC,MAAM,QAAQ,QAAQ,EAAG,QAAO;AACrC,QAAM,aAAa,SAAS,OAAO,CAAC,YAA+B,OAAO,YAAY,QAAQ;AAC9F,SAAO,WAAW,SAAS,aAAa;AAC1C;AAKA,SAAS,wBACP,YACA,MACA,iBACM;AACN,aAAW,OAAO,MAAM;AACtB,QAAI,IAAI,gBAAgB;AACtB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} from "./events.js";
|
|
3
|
+
import { buildNotificationEntity, emitNotificationCreated, emitNotificationCreatedBatch } from "./notificationFactory.js";
|
|
4
|
+
import { toNotificationDto } from "./notificationMapper.js";
|
|
5
|
+
import { getRecipientUserIdsForFeature, getRecipientUserIdsForRole } from "./notificationRecipients.js";
|
|
6
|
+
const DEBUG = process.env.NOTIFICATIONS_DEBUG === "true";
|
|
7
|
+
function debug(...args) {
|
|
8
|
+
if (DEBUG) {
|
|
9
|
+
console.log("[notifications]", ...args);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function getKnex(em) {
|
|
13
|
+
return em.getConnection().getKnex();
|
|
14
|
+
}
|
|
15
|
+
function createNotificationService(deps) {
|
|
16
|
+
const { em: rootEm, eventBus, commandBus, container } = deps;
|
|
17
|
+
return {
|
|
18
|
+
async create(input, ctx) {
|
|
19
|
+
const em = rootEm.fork();
|
|
20
|
+
const { recipientUserId, ...content } = input;
|
|
21
|
+
const notification = buildNotificationEntity(em, content, recipientUserId, ctx);
|
|
22
|
+
await em.persistAndFlush(notification);
|
|
23
|
+
await emitNotificationCreated(eventBus, notification, ctx);
|
|
24
|
+
return notification;
|
|
25
|
+
},
|
|
26
|
+
async createBatch(input, ctx) {
|
|
27
|
+
const em = rootEm.fork();
|
|
28
|
+
const { recipientUserIds, ...content } = input;
|
|
29
|
+
const notifications = [];
|
|
30
|
+
for (const recipientUserId of recipientUserIds) {
|
|
31
|
+
const notification = buildNotificationEntity(em, content, recipientUserId, ctx);
|
|
32
|
+
notifications.push(notification);
|
|
33
|
+
}
|
|
34
|
+
await em.persistAndFlush(notifications);
|
|
35
|
+
await emitNotificationCreatedBatch(eventBus, notifications, ctx);
|
|
36
|
+
return notifications;
|
|
37
|
+
},
|
|
38
|
+
async createForRole(input, ctx) {
|
|
39
|
+
const em = rootEm.fork();
|
|
40
|
+
const knex = getKnex(em);
|
|
41
|
+
const recipientUserIds = await getRecipientUserIdsForRole(knex, ctx.tenantId, input.roleId);
|
|
42
|
+
if (recipientUserIds.length === 0) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const { roleId: _roleId, ...content } = input;
|
|
46
|
+
const notifications = [];
|
|
47
|
+
for (const recipientUserId of recipientUserIds) {
|
|
48
|
+
const notification = buildNotificationEntity(em, content, recipientUserId, ctx);
|
|
49
|
+
notifications.push(notification);
|
|
50
|
+
}
|
|
51
|
+
await em.persistAndFlush(notifications);
|
|
52
|
+
await emitNotificationCreatedBatch(eventBus, notifications, ctx);
|
|
53
|
+
return notifications;
|
|
54
|
+
},
|
|
55
|
+
async createForFeature(input, ctx) {
|
|
56
|
+
const em = rootEm.fork();
|
|
57
|
+
const knex = getKnex(em);
|
|
58
|
+
const recipientUserIds = await getRecipientUserIdsForFeature(knex, ctx.tenantId, input.requiredFeature);
|
|
59
|
+
if (recipientUserIds.length === 0) {
|
|
60
|
+
debug("No users found with feature:", input.requiredFeature, "in tenant:", ctx.tenantId);
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
debug("Creating notifications for", recipientUserIds.length, "user(s) with feature:", input.requiredFeature);
|
|
64
|
+
const { requiredFeature: _requiredFeature, ...content } = input;
|
|
65
|
+
const notifications = [];
|
|
66
|
+
for (const recipientUserId of recipientUserIds) {
|
|
67
|
+
const notification = buildNotificationEntity(em, content, recipientUserId, ctx);
|
|
68
|
+
notifications.push(notification);
|
|
69
|
+
}
|
|
70
|
+
await em.persistAndFlush(notifications);
|
|
71
|
+
await emitNotificationCreatedBatch(eventBus, notifications, ctx);
|
|
72
|
+
return notifications;
|
|
73
|
+
},
|
|
74
|
+
async markAsRead(notificationId, ctx) {
|
|
75
|
+
const em = rootEm.fork();
|
|
76
|
+
const notification = await em.findOneOrFail(Notification, {
|
|
77
|
+
id: notificationId,
|
|
78
|
+
recipientUserId: ctx.userId,
|
|
79
|
+
tenantId: ctx.tenantId
|
|
80
|
+
});
|
|
81
|
+
if (notification.status === "unread") {
|
|
82
|
+
notification.status = "read";
|
|
83
|
+
notification.readAt = /* @__PURE__ */ new Date();
|
|
84
|
+
await em.flush();
|
|
85
|
+
await eventBus.emit(NOTIFICATION_EVENTS.READ, {
|
|
86
|
+
notificationId: notification.id,
|
|
87
|
+
userId: ctx.userId,
|
|
88
|
+
tenantId: ctx.tenantId
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return notification;
|
|
92
|
+
},
|
|
93
|
+
async markAllAsRead(ctx) {
|
|
94
|
+
const em = rootEm.fork();
|
|
95
|
+
const knex = getKnex(em);
|
|
96
|
+
const result = await knex("notifications").where({
|
|
97
|
+
recipient_user_id: ctx.userId,
|
|
98
|
+
tenant_id: ctx.tenantId,
|
|
99
|
+
status: "unread"
|
|
100
|
+
}).update({
|
|
101
|
+
status: "read",
|
|
102
|
+
read_at: knex.fn.now()
|
|
103
|
+
});
|
|
104
|
+
return result;
|
|
105
|
+
},
|
|
106
|
+
async dismiss(notificationId, ctx) {
|
|
107
|
+
const em = rootEm.fork();
|
|
108
|
+
const notification = await em.findOneOrFail(Notification, {
|
|
109
|
+
id: notificationId,
|
|
110
|
+
recipientUserId: ctx.userId,
|
|
111
|
+
tenantId: ctx.tenantId
|
|
112
|
+
});
|
|
113
|
+
notification.status = "dismissed";
|
|
114
|
+
notification.dismissedAt = /* @__PURE__ */ new Date();
|
|
115
|
+
await em.flush();
|
|
116
|
+
await eventBus.emit(NOTIFICATION_EVENTS.DISMISSED, {
|
|
117
|
+
notificationId: notification.id,
|
|
118
|
+
userId: ctx.userId,
|
|
119
|
+
tenantId: ctx.tenantId
|
|
120
|
+
});
|
|
121
|
+
return notification;
|
|
122
|
+
},
|
|
123
|
+
async restoreDismissed(notificationId, status, ctx) {
|
|
124
|
+
const em = rootEm.fork();
|
|
125
|
+
const notification = await em.findOneOrFail(Notification, {
|
|
126
|
+
id: notificationId,
|
|
127
|
+
recipientUserId: ctx.userId,
|
|
128
|
+
tenantId: ctx.tenantId
|
|
129
|
+
});
|
|
130
|
+
if (notification.status !== "dismissed") {
|
|
131
|
+
return notification;
|
|
132
|
+
}
|
|
133
|
+
const targetStatus = status ?? "read";
|
|
134
|
+
notification.status = targetStatus;
|
|
135
|
+
notification.dismissedAt = null;
|
|
136
|
+
if (targetStatus === "unread") {
|
|
137
|
+
notification.readAt = null;
|
|
138
|
+
} else if (!notification.readAt) {
|
|
139
|
+
notification.readAt = /* @__PURE__ */ new Date();
|
|
140
|
+
}
|
|
141
|
+
await em.flush();
|
|
142
|
+
await eventBus.emit(NOTIFICATION_EVENTS.RESTORED, {
|
|
143
|
+
notificationId: notification.id,
|
|
144
|
+
userId: ctx.userId,
|
|
145
|
+
tenantId: ctx.tenantId,
|
|
146
|
+
status: targetStatus
|
|
147
|
+
});
|
|
148
|
+
return notification;
|
|
149
|
+
},
|
|
150
|
+
async executeAction(notificationId, input, ctx) {
|
|
151
|
+
const em = rootEm.fork();
|
|
152
|
+
const notification = await em.findOneOrFail(Notification, {
|
|
153
|
+
id: notificationId,
|
|
154
|
+
recipientUserId: ctx.userId,
|
|
155
|
+
tenantId: ctx.tenantId
|
|
156
|
+
});
|
|
157
|
+
const actionData = notification.actionData;
|
|
158
|
+
const action = actionData?.actions?.find((a) => a.id === input.actionId);
|
|
159
|
+
if (!action) {
|
|
160
|
+
throw new Error("Action not found");
|
|
161
|
+
}
|
|
162
|
+
let result = null;
|
|
163
|
+
if (action.commandId && commandBus && container) {
|
|
164
|
+
const commandInput = {
|
|
165
|
+
id: notification.sourceEntityId,
|
|
166
|
+
...input.payload
|
|
167
|
+
};
|
|
168
|
+
const commandCtx = {
|
|
169
|
+
container,
|
|
170
|
+
auth: {
|
|
171
|
+
sub: ctx.userId,
|
|
172
|
+
tenantId: ctx.tenantId,
|
|
173
|
+
orgId: ctx.organizationId
|
|
174
|
+
},
|
|
175
|
+
organizationScope: null,
|
|
176
|
+
selectedOrganizationId: ctx.organizationId ?? null,
|
|
177
|
+
organizationIds: ctx.organizationId ? [ctx.organizationId] : null
|
|
178
|
+
};
|
|
179
|
+
const commandResult = await commandBus.execute(action.commandId, {
|
|
180
|
+
input: commandInput,
|
|
181
|
+
ctx: commandCtx,
|
|
182
|
+
metadata: {
|
|
183
|
+
tenantId: ctx.tenantId,
|
|
184
|
+
organizationId: ctx.organizationId,
|
|
185
|
+
resourceKind: "notifications"
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
result = commandResult.result;
|
|
189
|
+
}
|
|
190
|
+
notification.status = "actioned";
|
|
191
|
+
notification.actionedAt = /* @__PURE__ */ new Date();
|
|
192
|
+
notification.actionTaken = input.actionId;
|
|
193
|
+
notification.actionResult = result;
|
|
194
|
+
if (!notification.readAt) {
|
|
195
|
+
notification.readAt = /* @__PURE__ */ new Date();
|
|
196
|
+
}
|
|
197
|
+
await em.flush();
|
|
198
|
+
await eventBus.emit(NOTIFICATION_EVENTS.ACTIONED, {
|
|
199
|
+
notificationId: notification.id,
|
|
200
|
+
actionId: input.actionId,
|
|
201
|
+
userId: ctx.userId,
|
|
202
|
+
tenantId: ctx.tenantId
|
|
203
|
+
});
|
|
204
|
+
return { notification, result };
|
|
205
|
+
},
|
|
206
|
+
async getUnreadCount(ctx) {
|
|
207
|
+
const em = rootEm.fork();
|
|
208
|
+
return em.count(Notification, {
|
|
209
|
+
recipientUserId: ctx.userId,
|
|
210
|
+
tenantId: ctx.tenantId,
|
|
211
|
+
status: "unread"
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
async getPollData(ctx, since) {
|
|
215
|
+
const em = rootEm.fork();
|
|
216
|
+
const filters = {
|
|
217
|
+
recipientUserId: ctx.userId,
|
|
218
|
+
tenantId: ctx.tenantId
|
|
219
|
+
};
|
|
220
|
+
if (since) {
|
|
221
|
+
filters.createdAt = { $gt: new Date(since) };
|
|
222
|
+
}
|
|
223
|
+
const [notifications, unreadCount] = await Promise.all([
|
|
224
|
+
em.find(Notification, filters, {
|
|
225
|
+
orderBy: { createdAt: "desc" },
|
|
226
|
+
limit: 50
|
|
227
|
+
}),
|
|
228
|
+
em.count(Notification, {
|
|
229
|
+
recipientUserId: ctx.userId,
|
|
230
|
+
tenantId: ctx.tenantId,
|
|
231
|
+
status: "unread"
|
|
232
|
+
})
|
|
233
|
+
]);
|
|
234
|
+
const recent = notifications.map(toNotificationDto);
|
|
235
|
+
const hasNew = since ? recent.length > 0 : false;
|
|
236
|
+
return {
|
|
237
|
+
unreadCount,
|
|
238
|
+
recent,
|
|
239
|
+
hasNew,
|
|
240
|
+
lastId: recent[0]?.id
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
async cleanupExpired() {
|
|
244
|
+
const em = rootEm.fork();
|
|
245
|
+
const knex = getKnex(em);
|
|
246
|
+
const result = await knex("notifications").where("expires_at", "<", knex.fn.now()).whereNotIn("status", ["actioned", "dismissed"]).update({
|
|
247
|
+
status: "dismissed",
|
|
248
|
+
dismissed_at: knex.fn.now()
|
|
249
|
+
});
|
|
250
|
+
return result;
|
|
251
|
+
},
|
|
252
|
+
async deleteBySource(sourceEntityType, sourceEntityId, ctx) {
|
|
253
|
+
const em = rootEm.fork();
|
|
254
|
+
const knex = getKnex(em);
|
|
255
|
+
const result = await knex("notifications").where({
|
|
256
|
+
source_entity_type: sourceEntityType,
|
|
257
|
+
source_entity_id: sourceEntityId,
|
|
258
|
+
tenant_id: ctx.tenantId
|
|
259
|
+
}).delete();
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function resolveNotificationService(container) {
|
|
265
|
+
const em = container.resolve("em");
|
|
266
|
+
const eventBus = container.resolve("eventBus");
|
|
267
|
+
let commandBus;
|
|
268
|
+
try {
|
|
269
|
+
commandBus = container.resolve("commandBus");
|
|
270
|
+
} catch {
|
|
271
|
+
commandBus = void 0;
|
|
272
|
+
}
|
|
273
|
+
return createNotificationService({ em, eventBus, commandBus, container });
|
|
274
|
+
}
|
|
275
|
+
export {
|
|
276
|
+
createNotificationService,
|
|
277
|
+
resolveNotificationService
|
|
278
|
+
};
|
|
279
|
+
//# sourceMappingURL=notificationService.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/notifications/lib/notificationService.ts"],
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/core'\nimport type { Knex } from 'knex'\nimport { Notification } from '../data/entities'\nimport type { CreateNotificationInput, CreateBatchNotificationInput, CreateRoleNotificationInput, CreateFeatureNotificationInput, ExecuteActionInput } from '../data/validators'\nimport type { NotificationPollData } from '@open-mercato/shared/modules/notifications/types'\nimport { NOTIFICATION_EVENTS } from './events'\nimport { buildNotificationEntity, emitNotificationCreated, emitNotificationCreatedBatch } from './notificationFactory'\nimport { toNotificationDto } from './notificationMapper'\nimport { getRecipientUserIdsForFeature, getRecipientUserIdsForRole } from './notificationRecipients'\n\nconst DEBUG = process.env.NOTIFICATIONS_DEBUG === 'true'\n\nfunction debug(...args: unknown[]): void {\n if (DEBUG) {\n console.log('[notifications]', ...args)\n }\n}\n\nfunction getKnex(em: EntityManager): Knex {\n return (em.getConnection() as unknown as { getKnex: () => Knex }).getKnex()\n}\n\nexport interface NotificationServiceContext {\n tenantId: string\n organizationId?: string | null\n userId?: string | null\n}\n\nexport interface NotificationService {\n create(input: CreateNotificationInput, ctx: NotificationServiceContext): Promise<Notification>\n createBatch(input: CreateBatchNotificationInput, ctx: NotificationServiceContext): Promise<Notification[]>\n createForRole(input: CreateRoleNotificationInput, ctx: NotificationServiceContext): Promise<Notification[]>\n createForFeature(input: CreateFeatureNotificationInput, ctx: NotificationServiceContext): Promise<Notification[]>\n markAsRead(notificationId: string, ctx: NotificationServiceContext): Promise<Notification>\n markAllAsRead(ctx: NotificationServiceContext): Promise<number>\n dismiss(notificationId: string, ctx: NotificationServiceContext): Promise<Notification>\n restoreDismissed(\n notificationId: string,\n status: 'read' | 'unread' | undefined,\n ctx: NotificationServiceContext\n ): Promise<Notification>\n executeAction(\n notificationId: string,\n input: ExecuteActionInput,\n ctx: NotificationServiceContext\n ): Promise<{ notification: Notification; result: unknown }>\n getUnreadCount(ctx: NotificationServiceContext): Promise<number>\n getPollData(ctx: NotificationServiceContext, since?: string): Promise<NotificationPollData>\n cleanupExpired(): Promise<number>\n deleteBySource(\n sourceEntityType: string,\n sourceEntityId: string,\n ctx: NotificationServiceContext\n ): Promise<number>\n}\n\nexport interface NotificationServiceDeps {\n em: EntityManager\n eventBus: { emit: (event: string, payload: unknown) => Promise<void> }\n commandBus?: {\n execute: (\n commandId: string,\n options: { input: unknown; ctx: unknown; metadata?: unknown }\n ) => Promise<{ result: unknown }>\n }\n container?: { resolve: (name: string) => unknown }\n}\n\nexport function createNotificationService(deps: NotificationServiceDeps): NotificationService {\n const { em: rootEm, eventBus, commandBus, container } = deps\n\n return {\n async create(input, ctx) {\n const em = rootEm.fork()\n const { recipientUserId, ...content } = input\n const notification = buildNotificationEntity(em, content, recipientUserId, ctx)\n\n await em.persistAndFlush(notification)\n\n await emitNotificationCreated(eventBus, notification, ctx)\n\n return notification\n },\n\n async createBatch(input, ctx) {\n const em = rootEm.fork()\n const { recipientUserIds, ...content } = input\n const notifications: Notification[] = []\n\n for (const recipientUserId of recipientUserIds) {\n const notification = buildNotificationEntity(em, content, recipientUserId, ctx)\n notifications.push(notification)\n }\n\n await em.persistAndFlush(notifications)\n\n await emitNotificationCreatedBatch(eventBus, notifications, ctx)\n\n return notifications\n },\n\n async createForRole(input, ctx) {\n const em = rootEm.fork()\n\n const knex = getKnex(em)\n const recipientUserIds = await getRecipientUserIdsForRole(knex, ctx.tenantId, input.roleId)\n if (recipientUserIds.length === 0) {\n return []\n }\n\n const { roleId: _roleId, ...content } = input\n const notifications: Notification[] = []\n\n for (const recipientUserId of recipientUserIds) {\n const notification = buildNotificationEntity(em, content, recipientUserId, ctx)\n notifications.push(notification)\n }\n\n await em.persistAndFlush(notifications)\n\n await emitNotificationCreatedBatch(eventBus, notifications, ctx)\n\n return notifications\n },\n\n async createForFeature(input, ctx) {\n const em = rootEm.fork()\n const knex = getKnex(em)\n const recipientUserIds = await getRecipientUserIdsForFeature(knex, ctx.tenantId, input.requiredFeature)\n\n if (recipientUserIds.length === 0) {\n debug('No users found with feature:', input.requiredFeature, 'in tenant:', ctx.tenantId)\n return []\n }\n\n debug('Creating notifications for', recipientUserIds.length, 'user(s) with feature:', input.requiredFeature)\n\n const { requiredFeature: _requiredFeature, ...content } = input\n const notifications: Notification[] = []\n\n for (const recipientUserId of recipientUserIds) {\n const notification = buildNotificationEntity(em, content, recipientUserId, ctx)\n notifications.push(notification)\n }\n\n await em.persistAndFlush(notifications)\n\n await emitNotificationCreatedBatch(eventBus, notifications, ctx)\n\n return notifications\n },\n\n async markAsRead(notificationId, ctx) {\n const em = rootEm.fork()\n const notification = await em.findOneOrFail(Notification, {\n id: notificationId,\n recipientUserId: ctx.userId,\n tenantId: ctx.tenantId,\n })\n\n if (notification.status === 'unread') {\n notification.status = 'read'\n notification.readAt = new Date()\n await em.flush()\n\n await eventBus.emit(NOTIFICATION_EVENTS.READ, {\n notificationId: notification.id,\n userId: ctx.userId,\n tenantId: ctx.tenantId,\n })\n }\n\n return notification\n },\n\n async markAllAsRead(ctx) {\n const em = rootEm.fork()\n const knex = getKnex(em)\n\n const result = await knex('notifications')\n .where({\n recipient_user_id: ctx.userId,\n tenant_id: ctx.tenantId,\n status: 'unread',\n })\n .update({\n status: 'read',\n read_at: knex.fn.now(),\n })\n\n return result\n },\n\n async dismiss(notificationId, ctx) {\n const em = rootEm.fork()\n const notification = await em.findOneOrFail(Notification, {\n id: notificationId,\n recipientUserId: ctx.userId,\n tenantId: ctx.tenantId,\n })\n\n notification.status = 'dismissed'\n notification.dismissedAt = new Date()\n await em.flush()\n\n await eventBus.emit(NOTIFICATION_EVENTS.DISMISSED, {\n notificationId: notification.id,\n userId: ctx.userId,\n tenantId: ctx.tenantId,\n })\n\n return notification\n },\n\n async restoreDismissed(notificationId, status, ctx) {\n const em = rootEm.fork()\n const notification = await em.findOneOrFail(Notification, {\n id: notificationId,\n recipientUserId: ctx.userId,\n tenantId: ctx.tenantId,\n })\n\n if (notification.status !== 'dismissed') {\n return notification\n }\n\n const targetStatus = status ?? 'read'\n notification.status = targetStatus\n notification.dismissedAt = null\n\n if (targetStatus === 'unread') {\n notification.readAt = null\n } else if (!notification.readAt) {\n notification.readAt = new Date()\n }\n\n await em.flush()\n\n await eventBus.emit(NOTIFICATION_EVENTS.RESTORED, {\n notificationId: notification.id,\n userId: ctx.userId,\n tenantId: ctx.tenantId,\n status: targetStatus,\n })\n\n return notification\n },\n\n async executeAction(notificationId, input, ctx) {\n const em = rootEm.fork()\n const notification = await em.findOneOrFail(Notification, {\n id: notificationId,\n recipientUserId: ctx.userId,\n tenantId: ctx.tenantId,\n })\n\n const actionData = notification.actionData\n const action = actionData?.actions?.find((a) => a.id === input.actionId)\n\n if (!action) {\n throw new Error('Action not found')\n }\n\n let result: unknown = null\n\n if (action.commandId && commandBus && container) {\n const commandInput = {\n id: notification.sourceEntityId,\n ...input.payload,\n }\n\n // Build a CommandRuntimeContext from the notification service context\n const commandCtx = {\n container,\n auth: {\n sub: ctx.userId,\n tenantId: ctx.tenantId,\n orgId: ctx.organizationId,\n },\n organizationScope: null,\n selectedOrganizationId: ctx.organizationId ?? null,\n organizationIds: ctx.organizationId ? [ctx.organizationId] : null,\n }\n\n const commandResult = await commandBus.execute(action.commandId, {\n input: commandInput,\n ctx: commandCtx,\n metadata: {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n resourceKind: 'notifications',\n },\n })\n\n result = commandResult.result\n }\n\n notification.status = 'actioned'\n notification.actionedAt = new Date()\n notification.actionTaken = input.actionId\n notification.actionResult = result as Record<string, unknown>\n\n if (!notification.readAt) {\n notification.readAt = new Date()\n }\n\n await em.flush()\n\n await eventBus.emit(NOTIFICATION_EVENTS.ACTIONED, {\n notificationId: notification.id,\n actionId: input.actionId,\n userId: ctx.userId,\n tenantId: ctx.tenantId,\n })\n\n return { notification, result }\n },\n\n async getUnreadCount(ctx) {\n const em = rootEm.fork()\n return em.count(Notification, {\n recipientUserId: ctx.userId,\n tenantId: ctx.tenantId,\n status: 'unread',\n })\n },\n\n async getPollData(ctx, since) {\n const em = rootEm.fork()\n const filters: Record<string, unknown> = {\n recipientUserId: ctx.userId,\n tenantId: ctx.tenantId,\n }\n\n if (since) {\n filters.createdAt = { $gt: new Date(since) }\n }\n\n const [notifications, unreadCount] = await Promise.all([\n em.find(Notification, filters, {\n orderBy: { createdAt: 'desc' },\n limit: 50,\n }),\n em.count(Notification, {\n recipientUserId: ctx.userId,\n tenantId: ctx.tenantId,\n status: 'unread',\n }),\n ])\n\n const recent = notifications.map(toNotificationDto)\n const hasNew = since ? recent.length > 0 : false\n\n return {\n unreadCount,\n recent,\n hasNew,\n lastId: recent[0]?.id,\n }\n },\n\n async cleanupExpired() {\n const em = rootEm.fork()\n const knex = getKnex(em)\n\n const result = await knex('notifications')\n .where('expires_at', '<', knex.fn.now())\n .whereNotIn('status', ['actioned', 'dismissed'])\n .update({\n status: 'dismissed',\n dismissed_at: knex.fn.now(),\n })\n\n return result\n },\n\n async deleteBySource(sourceEntityType, sourceEntityId, ctx) {\n const em = rootEm.fork()\n const knex = getKnex(em)\n\n const result = await knex('notifications')\n .where({\n source_entity_type: sourceEntityType,\n source_entity_id: sourceEntityId,\n tenant_id: ctx.tenantId,\n })\n .delete()\n\n return result\n },\n }\n}\n\n/**\n * Helper to create notification service from a DI container.\n * Use this in API routes and commands to avoid DI resolution issues.\n */\nexport function resolveNotificationService(container: {\n resolve: (name: string) => unknown\n}): NotificationService {\n const em = container.resolve('em') as EntityManager\n const eventBus = container.resolve('eventBus') as { emit: (event: string, payload: unknown) => Promise<void> }\n\n // commandBus may not be registered in all contexts, so resolve it safely\n let commandBus: NotificationServiceDeps['commandBus']\n try {\n commandBus = container.resolve('commandBus') as typeof commandBus\n } catch {\n // commandBus not available - actions with commandId won't work\n commandBus = undefined\n }\n\n return createNotificationService({ em, eventBus,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