@open-mercato/core 0.11.1-develop.8541.1.955f210e1d → 0.11.1-develop.8545.1.dd603570fd
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/dist/modules/customer_accounts/api/admin/users/[id].js +10 -9
- package/dist/modules/customer_accounts/api/admin/users/[id].js.map +2 -2
- package/dist/modules/customer_accounts/api/portal/notifications/[id]/dismiss.js +3 -2
- package/dist/modules/customer_accounts/api/portal/notifications/[id]/dismiss.js.map +2 -2
- package/dist/modules/customer_accounts/api/portal/notifications/[id]/read.js +3 -2
- package/dist/modules/customer_accounts/api/portal/notifications/[id]/read.js.map +2 -2
- package/dist/modules/customer_accounts/api/portal/notifications/mark-all-read.js +4 -0
- package/dist/modules/customer_accounts/api/portal/notifications/mark-all-read.js.map +2 -2
- package/dist/modules/customer_accounts/api/portal/notifications/unread-count.js +4 -0
- package/dist/modules/customer_accounts/api/portal/notifications/unread-count.js.map +2 -2
- package/dist/modules/customer_accounts/api/portal/notifications.js +4 -0
- package/dist/modules/customer_accounts/api/portal/notifications.js.map +2 -2
- package/dist/modules/customer_accounts/lib/customerEntityOwnership.js +12 -1
- package/dist/modules/customer_accounts/lib/customerEntityOwnership.js.map +2 -2
- package/dist/modules/customer_accounts/lib/moduleEntityRegistration.js +8 -0
- package/dist/modules/customer_accounts/lib/moduleEntityRegistration.js.map +7 -0
- package/dist/modules/customer_accounts/lib/portalNotificationsAvailability.js +9 -0
- package/dist/modules/customer_accounts/lib/portalNotificationsAvailability.js.map +7 -0
- package/dist/modules/wms/index.js +1 -1
- package/dist/modules/wms/index.js.map +2 -2
- package/dist/modules/wms/setup.js +4 -1
- package/dist/modules/wms/setup.js.map +2 -2
- package/dist/modules/workflows/api/events/route.js +1 -1
- package/dist/modules/workflows/api/events/route.js.map +2 -2
- package/dist/modules/workflows/api/instances/[id]/events/route.js +1 -1
- package/dist/modules/workflows/api/instances/[id]/events/route.js.map +2 -2
- package/dist/modules/workflows/api/instances/[id]/steps/route.js +1 -1
- package/dist/modules/workflows/api/instances/[id]/steps/route.js.map +2 -2
- package/dist/modules/workflows/api/instances/failure-queue/route.js +1 -1
- package/dist/modules/workflows/api/instances/failure-queue/route.js.map +2 -2
- package/dist/modules/workflows/lib/event-logger.js +1 -1
- package/dist/modules/workflows/lib/event-logger.js.map +2 -2
- package/dist/modules/workflows/lib/work-inbox/user-task-source.js +1 -1
- package/dist/modules/workflows/lib/work-inbox/user-task-source.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/customer_accounts/api/admin/users/[id].ts +10 -9
- package/src/modules/customer_accounts/api/portal/notifications/[id]/dismiss.ts +8 -5
- package/src/modules/customer_accounts/api/portal/notifications/[id]/read.ts +8 -5
- package/src/modules/customer_accounts/api/portal/notifications/mark-all-read.ts +4 -0
- package/src/modules/customer_accounts/api/portal/notifications/unread-count.ts +4 -0
- package/src/modules/customer_accounts/api/portal/notifications.ts +4 -0
- package/src/modules/customer_accounts/lib/customerEntityOwnership.ts +13 -1
- package/src/modules/customer_accounts/lib/moduleEntityRegistration.ts +12 -0
- package/src/modules/customer_accounts/lib/portalNotificationsAvailability.ts +7 -0
- package/src/modules/wms/index.ts +1 -1
- package/src/modules/wms/setup.ts +4 -1
- package/src/modules/workflows/api/events/route.ts +1 -1
- package/src/modules/workflows/api/instances/[id]/events/route.ts +1 -1
- package/src/modules/workflows/api/instances/[id]/steps/route.ts +3 -2
- package/src/modules/workflows/api/instances/failure-queue/route.ts +1 -1
- package/src/modules/workflows/lib/event-logger.ts +1 -1
- package/src/modules/workflows/lib/work-inbox/user-task-source.ts +3 -2
|
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
4
|
import { getCustomerAuthFromRequest } from '@open-mercato/core/modules/customer_accounts/lib/customerAuth'
|
|
5
|
+
import { arePortalNotificationsAvailable } from '@open-mercato/core/modules/customer_accounts/lib/portalNotificationsAvailability'
|
|
5
6
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
7
|
import { Notification } from '@open-mercato/core/modules/notifications/data/entities'
|
|
7
8
|
|
|
@@ -16,11 +17,13 @@ export async function PUT(req: Request, { params }: { params: { id: string } })
|
|
|
16
17
|
const container = await createRequestContainer()
|
|
17
18
|
const em = container.resolve('em') as import('@mikro-orm/postgresql').EntityManager
|
|
18
19
|
|
|
19
|
-
const notification =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const notification = arePortalNotificationsAvailable(em)
|
|
21
|
+
? await em.findOne(Notification, {
|
|
22
|
+
id: params.id,
|
|
23
|
+
recipientUserId: auth.sub,
|
|
24
|
+
tenantId: auth.tenantId,
|
|
25
|
+
})
|
|
26
|
+
: null
|
|
24
27
|
|
|
25
28
|
if (!notification) {
|
|
26
29
|
return NextResponse.json({ ok: false, error: 'Notification not found' }, { status: 404 })
|
|
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
4
|
import { getCustomerAuthFromRequest } from '@open-mercato/core/modules/customer_accounts/lib/customerAuth'
|
|
5
|
+
import { arePortalNotificationsAvailable } from '@open-mercato/core/modules/customer_accounts/lib/portalNotificationsAvailability'
|
|
5
6
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
7
|
import { Notification } from '@open-mercato/core/modules/notifications/data/entities'
|
|
7
8
|
|
|
@@ -16,11 +17,13 @@ export async function PUT(req: Request, { params }: { params: { id: string } })
|
|
|
16
17
|
const container = await createRequestContainer()
|
|
17
18
|
const em = container.resolve('em') as import('@mikro-orm/postgresql').EntityManager
|
|
18
19
|
|
|
19
|
-
const notification =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const notification = arePortalNotificationsAvailable(em)
|
|
21
|
+
? await em.findOne(Notification, {
|
|
22
|
+
id: params.id,
|
|
23
|
+
recipientUserId: auth.sub,
|
|
24
|
+
tenantId: auth.tenantId,
|
|
25
|
+
})
|
|
26
|
+
: null
|
|
24
27
|
|
|
25
28
|
if (!notification) {
|
|
26
29
|
return NextResponse.json({ ok: false, error: 'Notification not found' }, { status: 404 })
|
|
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
4
|
import { getCustomerAuthFromRequest } from '@open-mercato/core/modules/customer_accounts/lib/customerAuth'
|
|
5
|
+
import { arePortalNotificationsAvailable } from '@open-mercato/core/modules/customer_accounts/lib/portalNotificationsAvailability'
|
|
5
6
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
7
|
import { Notification } from '@open-mercato/core/modules/notifications/data/entities'
|
|
7
8
|
|
|
@@ -15,6 +16,9 @@ export async function PUT(req: Request) {
|
|
|
15
16
|
|
|
16
17
|
const container = await createRequestContainer()
|
|
17
18
|
const em = container.resolve('em') as import('@mikro-orm/postgresql').EntityManager
|
|
19
|
+
if (!arePortalNotificationsAvailable(em)) {
|
|
20
|
+
return NextResponse.json({ ok: true, count: 0 })
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
const now = new Date()
|
|
20
24
|
const count = await em.nativeUpdate(Notification, {
|
|
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
4
|
import { getCustomerAuthFromRequest } from '@open-mercato/core/modules/customer_accounts/lib/customerAuth'
|
|
5
|
+
import { arePortalNotificationsAvailable } from '@open-mercato/core/modules/customer_accounts/lib/portalNotificationsAvailability'
|
|
5
6
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
7
|
import { Notification } from '@open-mercato/core/modules/notifications/data/entities'
|
|
7
8
|
|
|
@@ -15,6 +16,9 @@ export async function GET(req: Request) {
|
|
|
15
16
|
|
|
16
17
|
const container = await createRequestContainer()
|
|
17
18
|
const em = container.resolve('em') as import('@mikro-orm/postgresql').EntityManager
|
|
19
|
+
if (!arePortalNotificationsAvailable(em)) {
|
|
20
|
+
return NextResponse.json({ ok: true, unreadCount: 0 })
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
const unreadCount = await em.count(Notification, {
|
|
20
24
|
recipientUserId: auth.sub,
|
|
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
4
|
import { getCustomerAuthFromRequest } from '@open-mercato/core/modules/customer_accounts/lib/customerAuth'
|
|
5
|
+
import { arePortalNotificationsAvailable } from '@open-mercato/core/modules/customer_accounts/lib/portalNotificationsAvailability'
|
|
5
6
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
7
|
import { Notification } from '@open-mercato/core/modules/notifications/data/entities'
|
|
7
8
|
import { toNotificationDto } from '@open-mercato/core/modules/notifications/lib/notificationMapper'
|
|
@@ -23,6 +24,9 @@ export async function GET(req: Request) {
|
|
|
23
24
|
|
|
24
25
|
const container = await createRequestContainer()
|
|
25
26
|
const em = container.resolve('em') as import('@mikro-orm/postgresql').EntityManager
|
|
27
|
+
if (!arePortalNotificationsAvailable(em)) {
|
|
28
|
+
return NextResponse.json({ ok: true, items: [], total: 0, page, pageSize })
|
|
29
|
+
}
|
|
26
30
|
|
|
27
31
|
const where: Record<string, unknown> = {
|
|
28
32
|
recipientUserId: auth.sub,
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
2
|
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
3
|
+
import { isRegisteredModuleEntity } from './moduleEntityRegistration'
|
|
3
4
|
|
|
4
5
|
export type CustomerEntityScope = {
|
|
5
6
|
tenantId: string | null | undefined
|
|
6
7
|
organizationId: string | null | undefined
|
|
7
8
|
}
|
|
8
9
|
|
|
10
|
+
async function getRegisteredCustomerEntity(em: EntityManager) {
|
|
11
|
+
const { CustomerEntity } = await import('@open-mercato/core/modules/customers/data/entities')
|
|
12
|
+
return isRegisteredModuleEntity(em, CustomerEntity, 'customers.CustomerEntity') ? CustomerEntity : null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function isCustomerEntityRegistered(em: EntityManager): Promise<boolean> {
|
|
16
|
+
return (await getRegisteredCustomerEntity(em)) !== null
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
/**
|
|
10
20
|
* Confirms that a caller-supplied `customerEntityId` (the CRM company FK linked
|
|
11
21
|
* onto a customer user) exists, is a company, is not soft-deleted, and belongs
|
|
@@ -57,6 +67,7 @@ export async function resolveOwnedCompanyForPerson(
|
|
|
57
67
|
scope: CustomerEntityScope,
|
|
58
68
|
): Promise<string | null> {
|
|
59
69
|
const { CustomerPersonProfile } = await import('@open-mercato/core/modules/customers/data/entities')
|
|
70
|
+
if (!isRegisteredModuleEntity(em, CustomerPersonProfile, 'customers.CustomerPersonProfile')) return null
|
|
60
71
|
const profile = await em.findOne(CustomerPersonProfile as any, {
|
|
61
72
|
entity: personEntityId,
|
|
62
73
|
tenantId: scope.tenantId,
|
|
@@ -87,7 +98,8 @@ async function isOwnedEntityOfKind(
|
|
|
87
98
|
kind: 'company' | 'person',
|
|
88
99
|
scope: CustomerEntityScope,
|
|
89
100
|
): Promise<boolean> {
|
|
90
|
-
const
|
|
101
|
+
const CustomerEntity = await getRegisteredCustomerEntity(em)
|
|
102
|
+
if (!CustomerEntity) return false
|
|
91
103
|
const entity = await findOneWithDecryption(
|
|
92
104
|
em,
|
|
93
105
|
CustomerEntity,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EntityCtor } from '@mikro-orm/core'
|
|
2
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
3
|
+
|
|
4
|
+
export function isRegisteredModuleEntity<Entity>(
|
|
5
|
+
em: EntityManager,
|
|
6
|
+
entity: EntityCtor<Entity>,
|
|
7
|
+
qualifiedName: string,
|
|
8
|
+
): boolean {
|
|
9
|
+
const registeredClass: (EntityCtor<Entity> & { entityName?: string }) | undefined =
|
|
10
|
+
em.getMetadata().find(entity)?.class
|
|
11
|
+
return registeredClass === entity || registeredClass?.entityName === qualifiedName
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
+
import { Notification } from '@open-mercato/core/modules/notifications/data/entities'
|
|
3
|
+
import { isRegisteredModuleEntity } from './moduleEntityRegistration'
|
|
4
|
+
|
|
5
|
+
export function arePortalNotificationsAvailable(em: EntityManager): boolean {
|
|
6
|
+
return isRegisteredModuleEntity(em, Notification, 'notifications.Notification')
|
|
7
|
+
}
|
package/src/modules/wms/index.ts
CHANGED
package/src/modules/wms/setup.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'
|
|
2
2
|
import { ensureRoles } from '@open-mercato/core/modules/auth/lib/setup-app'
|
|
3
|
+
import { FeatureToggle } from '@open-mercato/core/modules/feature_toggles/data/entities'
|
|
3
4
|
import {
|
|
4
5
|
WMS_CUSTOM_ROLE_NAMES,
|
|
5
6
|
WMS_OPERATOR_FEATURES,
|
|
@@ -15,7 +16,9 @@ async function seedWmsRoles(em: Parameters<typeof ensureRoles>[0], tenantId: str
|
|
|
15
16
|
|
|
16
17
|
export const setup: ModuleSetupConfig = {
|
|
17
18
|
seedDefaults: async (ctx) => {
|
|
18
|
-
|
|
19
|
+
if (ctx.em.getMetadata().find(FeatureToggle)) {
|
|
20
|
+
await seedWmsIntegrationToggles(ctx.em)
|
|
21
|
+
}
|
|
19
22
|
await seedWmsRoles(ctx.em, ctx.tenantId)
|
|
20
23
|
},
|
|
21
24
|
defaultRoleFeatures: {
|
|
@@ -90,7 +90,8 @@ export async function GET(request: NextRequest, context: RouteContext) {
|
|
|
90
90
|
|
|
91
91
|
// Ordered by when the step was entered so the Gantt and the overlay read the
|
|
92
92
|
// run in execution order. `createdAt` is the tiebreaker because a step
|
|
93
|
-
// instance is persisted before `enteredAt` is stamped on some paths
|
|
93
|
+
// instance is persisted before `enteredAt` is stamped on some paths, and
|
|
94
|
+
// `id` comes last so steps sharing both timestamps page deterministically.
|
|
94
95
|
const [steps, total] = await em.findAndCount(
|
|
95
96
|
StepInstance,
|
|
96
97
|
{
|
|
@@ -99,7 +100,7 @@ export async function GET(request: NextRequest, context: RouteContext) {
|
|
|
99
100
|
...orgFilter.where,
|
|
100
101
|
},
|
|
101
102
|
{
|
|
102
|
-
orderBy: [{ enteredAt: 'ASC' }, { createdAt: 'ASC' }],
|
|
103
|
+
orderBy: [{ enteredAt: 'ASC' }, { createdAt: 'ASC' }, { id: 'ASC' }],
|
|
103
104
|
limit,
|
|
104
105
|
offset,
|
|
105
106
|
}
|
|
@@ -113,7 +113,7 @@ export async function GET(request: NextRequest) {
|
|
|
113
113
|
// Grouping first, over a bounded scan, so the group counts describe the
|
|
114
114
|
// same set the caller is paging through.
|
|
115
115
|
const scanned = (await em.find(WorkflowInstance, where, {
|
|
116
|
-
orderBy: { createdAt: 'DESC' },
|
|
116
|
+
orderBy: { createdAt: 'DESC', id: 'DESC' },
|
|
117
117
|
limit: FAILURE_GROUP_SCAN_LIMIT,
|
|
118
118
|
})) as WorkflowInstance[]
|
|
119
119
|
const scannedInputs = scanned.map(toTriageInput)
|
|
@@ -196,7 +196,8 @@ export function toUserTaskWorkInboxRow(task: UserTask, now: Date): WorkInboxRow
|
|
|
196
196
|
|
|
197
197
|
/**
|
|
198
198
|
* SQL orders by due date (Postgres puts NULLs last on ASC, which is what the
|
|
199
|
-
* inbox wants)
|
|
199
|
+
* inbox wants), then by recency, then by `id` so the window is a total order
|
|
200
|
+
* and tied rows cannot shift between requests; the canonical priority → due → created
|
|
200
201
|
* ordering is applied by the merge service over the returned window, because
|
|
201
202
|
* `priority` is an authored label with no ordinal column to sort on. Phase 1 is
|
|
202
203
|
* a projection — a persisted sort key belongs with the `Task` entity, which
|
|
@@ -213,7 +214,7 @@ async function listUserTaskWorkItems(
|
|
|
213
214
|
const where = buildUserTaskWorkInboxWhere(query, context.scope, options)
|
|
214
215
|
|
|
215
216
|
const [tasks, total] = await em.findAndCount(UserTask, where, {
|
|
216
|
-
orderBy: [{ dueDate: 'ASC' }, { createdAt: 'DESC' }],
|
|
217
|
+
orderBy: [{ dueDate: 'ASC' }, { createdAt: 'DESC' }, { id: 'ASC' }],
|
|
217
218
|
limit: query.offset + query.limit,
|
|
218
219
|
offset: 0,
|
|
219
220
|
})
|