@open-mercato/core 0.11.1-develop.8538.1.78ea48b6e6 → 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.
Files changed (76) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/customer_accounts/api/admin/users/[id].js +10 -9
  3. package/dist/modules/customer_accounts/api/admin/users/[id].js.map +2 -2
  4. package/dist/modules/customer_accounts/api/portal/notifications/[id]/dismiss.js +3 -2
  5. package/dist/modules/customer_accounts/api/portal/notifications/[id]/dismiss.js.map +2 -2
  6. package/dist/modules/customer_accounts/api/portal/notifications/[id]/read.js +3 -2
  7. package/dist/modules/customer_accounts/api/portal/notifications/[id]/read.js.map +2 -2
  8. package/dist/modules/customer_accounts/api/portal/notifications/mark-all-read.js +4 -0
  9. package/dist/modules/customer_accounts/api/portal/notifications/mark-all-read.js.map +2 -2
  10. package/dist/modules/customer_accounts/api/portal/notifications/unread-count.js +4 -0
  11. package/dist/modules/customer_accounts/api/portal/notifications/unread-count.js.map +2 -2
  12. package/dist/modules/customer_accounts/api/portal/notifications.js +4 -0
  13. package/dist/modules/customer_accounts/api/portal/notifications.js.map +2 -2
  14. package/dist/modules/customer_accounts/lib/customerEntityOwnership.js +12 -1
  15. package/dist/modules/customer_accounts/lib/customerEntityOwnership.js.map +2 -2
  16. package/dist/modules/customer_accounts/lib/moduleEntityRegistration.js +8 -0
  17. package/dist/modules/customer_accounts/lib/moduleEntityRegistration.js.map +7 -0
  18. package/dist/modules/customer_accounts/lib/portalNotificationsAvailability.js +9 -0
  19. package/dist/modules/customer_accounts/lib/portalNotificationsAvailability.js.map +7 -0
  20. package/dist/modules/directory/utils/organizationScope.js +3 -2
  21. package/dist/modules/directory/utils/organizationScope.js.map +2 -2
  22. package/dist/modules/entities/api/records.js +4 -3
  23. package/dist/modules/entities/api/records.js.map +2 -2
  24. package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js +22 -38
  25. package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js.map +2 -2
  26. package/dist/modules/progress/api/active/route.js +11 -3
  27. package/dist/modules/progress/api/active/route.js.map +2 -2
  28. package/dist/modules/progress/api/jobPermissions.js +42 -0
  29. package/dist/modules/progress/api/jobPermissions.js.map +7 -0
  30. package/dist/modules/progress/api/jobs/[id]/route.js +6 -11
  31. package/dist/modules/progress/api/jobs/[id]/route.js.map +2 -2
  32. package/dist/modules/wms/index.js +1 -1
  33. package/dist/modules/wms/index.js.map +2 -2
  34. package/dist/modules/wms/setup.js +4 -1
  35. package/dist/modules/wms/setup.js.map +2 -2
  36. package/dist/modules/workflows/api/events/route.js +1 -1
  37. package/dist/modules/workflows/api/events/route.js.map +2 -2
  38. package/dist/modules/workflows/api/instances/[id]/events/route.js +1 -1
  39. package/dist/modules/workflows/api/instances/[id]/events/route.js.map +2 -2
  40. package/dist/modules/workflows/api/instances/[id]/steps/route.js +1 -1
  41. package/dist/modules/workflows/api/instances/[id]/steps/route.js.map +2 -2
  42. package/dist/modules/workflows/api/instances/failure-queue/route.js +1 -1
  43. package/dist/modules/workflows/api/instances/failure-queue/route.js.map +2 -2
  44. package/dist/modules/workflows/lib/event-logger.js +1 -1
  45. package/dist/modules/workflows/lib/event-logger.js.map +2 -2
  46. package/dist/modules/workflows/lib/work-inbox/user-task-source.js +1 -1
  47. package/dist/modules/workflows/lib/work-inbox/user-task-source.js.map +2 -2
  48. package/package.json +7 -7
  49. package/src/modules/customer_accounts/api/admin/users/[id].ts +10 -9
  50. package/src/modules/customer_accounts/api/portal/notifications/[id]/dismiss.ts +8 -5
  51. package/src/modules/customer_accounts/api/portal/notifications/[id]/read.ts +8 -5
  52. package/src/modules/customer_accounts/api/portal/notifications/mark-all-read.ts +4 -0
  53. package/src/modules/customer_accounts/api/portal/notifications/unread-count.ts +4 -0
  54. package/src/modules/customer_accounts/api/portal/notifications.ts +4 -0
  55. package/src/modules/customer_accounts/lib/customerEntityOwnership.ts +13 -1
  56. package/src/modules/customer_accounts/lib/moduleEntityRegistration.ts +12 -0
  57. package/src/modules/customer_accounts/lib/portalNotificationsAvailability.ts +7 -0
  58. package/src/modules/directory/utils/organizationScope.ts +3 -2
  59. package/src/modules/entities/api/records.ts +4 -3
  60. package/src/modules/entities/backend/entities/user/[entityId]/records/page.tsx +25 -31
  61. package/src/modules/entities/i18n/de.json +20 -1
  62. package/src/modules/entities/i18n/en.json +20 -1
  63. package/src/modules/entities/i18n/es.json +20 -1
  64. package/src/modules/entities/i18n/ko.json +20 -1
  65. package/src/modules/entities/i18n/pl.json +20 -1
  66. package/src/modules/progress/api/active/route.ts +18 -3
  67. package/src/modules/progress/api/jobPermissions.ts +50 -0
  68. package/src/modules/progress/api/jobs/[id]/route.ts +7 -20
  69. package/src/modules/wms/index.ts +1 -1
  70. package/src/modules/wms/setup.ts +4 -1
  71. package/src/modules/workflows/api/events/route.ts +1 -1
  72. package/src/modules/workflows/api/instances/[id]/events/route.ts +1 -1
  73. package/src/modules/workflows/api/instances/[id]/steps/route.ts +3 -2
  74. package/src/modules/workflows/api/instances/failure-queue/route.ts +1 -1
  75. package/src/modules/workflows/lib/event-logger.ts +1 -1
  76. package/src/modules/workflows/lib/work-inbox/user-task-source.ts +3 -2
@@ -1,12 +1,10 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import { z } from 'zod'
3
- import { getAuthFromRequest, type AuthContext } from '@open-mercato/shared/lib/auth/server'
3
+ import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
4
4
  import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
5
- import type { AwilixContainer } from 'awilix'
6
- import type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'
7
5
  import { updateProgressSchema } from '../../../data/validators'
8
- import type { ProgressJob } from '../../../data/entities'
9
6
  import type { ProgressService } from '../../../lib/progressService'
7
+ import { createProgressJobMutationPolicy, progressCancelFeatures } from '../../jobPermissions'
10
8
  import {
11
9
  hasReadableProgressScope,
12
10
  hasWritableProgressScope,
@@ -16,26 +14,13 @@ import {
16
14
  const routeMetadata = {
17
15
  GET: { requireAuth: true, requireFeatures: ['progress.view'] },
18
16
  PUT: { requireAuth: true, requireFeatures: ['progress.update'] },
19
- DELETE: { requireAuth: true, requireFeatures: ['progress.cancel'] },
17
+ DELETE: { requireAuth: true, requireFeatures: progressCancelFeatures },
20
18
  }
21
19
 
22
20
  export const metadata = routeMetadata
23
21
 
24
22
  const jobIdSchema = z.guid()
25
23
 
26
- async function canMutateProgressJob(
27
- container: AwilixContainer,
28
- auth: NonNullable<AuthContext>,
29
- job: Pick<ProgressJob, 'startedByUserId' | 'organizationId'>,
30
- ): Promise<boolean> {
31
- if (job.startedByUserId === auth.sub) return true
32
- const rbacService = container.resolve('rbacService') as RbacService
33
- return rbacService.userHasAllFeatures(auth.sub, ['progress.manage'], {
34
- tenantId: auth.tenantId ?? null,
35
- organizationId: job.organizationId ?? null,
36
- })
37
- }
38
-
39
24
  function cannotCancelJobResponse() {
40
25
  return NextResponse.json({ error: 'Cannot cancel this job' }, { status: 400 })
41
26
  }
@@ -118,7 +103,8 @@ export async function PUT(req: Request, { params }: { params: { id: string } })
118
103
  const existing = jobIdSchema.safeParse(params.id).success
119
104
  ? await progressService.getJob(params.id, progressContext)
120
105
  : null
121
- if (!existing || !(await canMutateProgressJob(container, auth, existing))) {
106
+ const canMutateJob = createProgressJobMutationPolicy(container, auth)
107
+ if (!existing || !(await canMutateJob(existing))) {
122
108
  return NextResponse.json({ error: 'Not found' }, { status: 404 })
123
109
  }
124
110
 
@@ -147,7 +133,8 @@ export async function DELETE(req: Request, { params }: { params: { id: string }
147
133
  }
148
134
  try {
149
135
  const existing = await progressService.getJob(params.id, progressContext)
150
- if (!existing || !(await canMutateProgressJob(container, auth, existing))) {
136
+ const canMutateJob = createProgressJobMutationPolicy(container, auth)
137
+ if (!existing || !(await canMutateJob(existing))) {
151
138
  return cannotCancelJobResponse()
152
139
  }
153
140
  await progressService.cancelJob(params.id, progressContext)
@@ -9,7 +9,7 @@ export const metadata: ModuleInfo = {
9
9
  author: 'Open Mercato Team',
10
10
  license: 'MIT',
11
11
  ejectable: true,
12
- requires: ['catalog', 'customers', 'sales', 'feature_toggles'],
12
+ requires: ['catalog', 'sales'],
13
13
  }
14
14
 
15
15
  export { features } from './acl'
@@ -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
- await seedWmsIntegrationToggles(ctx.em)
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: {
@@ -123,7 +123,7 @@ export async function GET(request: NextRequest) {
123
123
  WorkflowEvent,
124
124
  where,
125
125
  {
126
- orderBy: { [sortField]: sortDir },
126
+ orderBy: { [sortField]: sortDir, id: sortDir },
127
127
  limit: pageSize,
128
128
  offset,
129
129
  }
@@ -100,7 +100,7 @@ export async function GET(
100
100
  WorkflowEvent,
101
101
  where,
102
102
  {
103
- orderBy: { occurredAt: 'DESC' },
103
+ orderBy: { occurredAt: 'DESC', id: 'DESC' },
104
104
  limit,
105
105
  offset,
106
106
  }
@@ -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)
@@ -246,7 +246,7 @@ export async function getWorkflowEvents(
246
246
  WorkflowEvent,
247
247
  where,
248
248
  {
249
- orderBy: { occurredAt: 'ASC' },
249
+ orderBy: { occurredAt: 'ASC', id: 'ASC' },
250
250
  limit: options?.limit,
251
251
  offset: options?.offset,
252
252
  }
@@ -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) and then by recency; the canonical priority → due → created
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
  })