@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.
- 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/directory/utils/organizationScope.js +3 -2
- package/dist/modules/directory/utils/organizationScope.js.map +2 -2
- package/dist/modules/entities/api/records.js +4 -3
- package/dist/modules/entities/api/records.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js +22 -38
- package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js.map +2 -2
- package/dist/modules/progress/api/active/route.js +11 -3
- package/dist/modules/progress/api/active/route.js.map +2 -2
- package/dist/modules/progress/api/jobPermissions.js +42 -0
- package/dist/modules/progress/api/jobPermissions.js.map +7 -0
- package/dist/modules/progress/api/jobs/[id]/route.js +6 -11
- package/dist/modules/progress/api/jobs/[id]/route.js.map +2 -2
- 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/directory/utils/organizationScope.ts +3 -2
- package/src/modules/entities/api/records.ts +4 -3
- package/src/modules/entities/backend/entities/user/[entityId]/records/page.tsx +25 -31
- package/src/modules/entities/i18n/de.json +20 -1
- package/src/modules/entities/i18n/en.json +20 -1
- package/src/modules/entities/i18n/es.json +20 -1
- package/src/modules/entities/i18n/ko.json +20 -1
- package/src/modules/entities/i18n/pl.json +20 -1
- package/src/modules/progress/api/active/route.ts +18 -3
- package/src/modules/progress/api/jobPermissions.ts +50 -0
- package/src/modules/progress/api/jobs/[id]/route.ts +7 -20
- 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
|
|
|
@@ -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
|
+
}
|
|
@@ -597,7 +597,7 @@ export async function resolveFeatureCheckContext({
|
|
|
597
597
|
let scope = boundFeatureScope
|
|
598
598
|
? boundFeatureScope.scope
|
|
599
599
|
: await resolveOrganizationScopeForRequest({ container, auth, request, selectedId, tenantId })
|
|
600
|
-
|
|
600
|
+
let organizationId = boundFeatureScope
|
|
601
601
|
? boundFeatureScope.organizationId
|
|
602
602
|
: resolveFeatureCheckOrganizationId(scope, auth)
|
|
603
603
|
if (
|
|
@@ -635,7 +635,7 @@ export async function resolveFeatureCheckContext({
|
|
|
635
635
|
)
|
|
636
636
|
const approvedOrganizationIds = Array.from(new Set(
|
|
637
637
|
featureOrganizationIds.filter((featureOrganizationId) => candidateOrganizationIds.has(featureOrganizationId)),
|
|
638
|
-
))
|
|
638
|
+
)).sort((left, right) => left.localeCompare(right))
|
|
639
639
|
scope = {
|
|
640
640
|
...scope,
|
|
641
641
|
selectedId: null,
|
|
@@ -643,6 +643,7 @@ export async function resolveFeatureCheckContext({
|
|
|
643
643
|
allowedIds: approvedOrganizationIds,
|
|
644
644
|
tenantId: scope.tenantId,
|
|
645
645
|
}
|
|
646
|
+
if (!organizationId) organizationId = resolveFeatureCheckOrganizationId(scope, auth)
|
|
646
647
|
}
|
|
647
648
|
bindFeatureScopeToRequest(request, { userId: auth.sub, scope, organizationId })
|
|
648
649
|
}
|
|
@@ -5,7 +5,7 @@ import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
|
5
5
|
import type { QueryEngine, QueryOptions, Where, Sort } from '@open-mercato/shared/lib/query/types'
|
|
6
6
|
import { normalizeExportFormat, serializeExport, defaultExportFilename, ensureColumns } from '@open-mercato/shared/lib/crud/exporters'
|
|
7
7
|
import type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'
|
|
8
|
-
import { resolveOrganizationScope, getSelectedOrganizationFromRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
8
|
+
import { resolveOrganizationScope, resolveOrganizationScopeForRequest, getSelectedOrganizationFromRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
9
9
|
import { resolveSingleOrganizationIdOrDeny } from '@open-mercato/core/modules/directory/utils/organizationScopeFilter'
|
|
10
10
|
import { SYSTEM_ENTITY_RECORDS_BLOCKED_CODE } from '@open-mercato/shared/lib/data/engine'
|
|
11
11
|
import { parseBooleanToken, parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'
|
|
@@ -138,11 +138,12 @@ export async function GET(req: Request) {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
try {
|
|
141
|
-
const
|
|
141
|
+
const container = await createRequestContainer()
|
|
142
|
+
const { resolve } = container
|
|
142
143
|
const qe = resolve('queryEngine') as QueryEngine
|
|
143
144
|
const em = resolve('em') as any
|
|
144
145
|
const rbac = resolve('rbacService') as RbacService
|
|
145
|
-
const scope = await
|
|
146
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })
|
|
146
147
|
let organizationIds: string[] | null = scope.filterIds
|
|
147
148
|
// Module-declared custom entities (ce.ts) carry frozen system-style ids and are never
|
|
148
149
|
// registered in `custom_entities`, so classification checks the declared registry plus
|
|
@@ -280,13 +280,13 @@ function RecordsPageInner({ params }: { params: { entityId?: string } }) {
|
|
|
280
280
|
<>
|
|
281
281
|
<Button asChild variant="outline" size="sm">
|
|
282
282
|
<Link href={`/backend/entities/user/${encodeURIComponent(entityId)}`}>
|
|
283
|
-
Edit Entity Definition
|
|
283
|
+
{t('entities.userEntities.records.actions.editDefinition', 'Edit Entity Definition')}
|
|
284
284
|
</Link>
|
|
285
285
|
</Button>
|
|
286
286
|
{hasAnyFormFields && (
|
|
287
287
|
<Button asChild>
|
|
288
288
|
<Link href={`/backend/entities/user/${encodeURIComponent(entityId)}/records/create`}>
|
|
289
|
-
Create
|
|
289
|
+
{t('entities.userEntities.records.form.submitCreate', 'Create')}
|
|
290
290
|
</Link>
|
|
291
291
|
</Button>
|
|
292
292
|
)}
|
|
@@ -300,54 +300,48 @@ function RecordsPageInner({ params }: { params: { entityId?: string } }) {
|
|
|
300
300
|
|
|
301
301
|
return (
|
|
302
302
|
<Page>
|
|
303
|
-
<PageBody>
|
|
304
|
-
<ContextHelp bulb title=
|
|
303
|
+
<PageBody className="[&_h1]:wrap-anywhere">
|
|
304
|
+
<ContextHelp bulb title={t('entities.userEntities.records.apiHelp.title')} className="mb-4">
|
|
305
305
|
<p className="mb-2">
|
|
306
|
-
|
|
306
|
+
{t('entities.userEntities.records.apiHelp.intro')}{' '}
|
|
307
307
|
<a className="underline" target="_blank" rel="noreferrer" href="https://docs.openmercato.com/user-guide/api-keys">
|
|
308
|
-
|
|
309
|
-
</a>
|
|
310
|
-
|
|
308
|
+
{t('entities.userEntities.records.apiHelp.guide')}
|
|
309
|
+
</a>
|
|
310
|
+
{' · '}
|
|
311
311
|
<a className="underline" target="_blank" rel="noreferrer" href="https://docs.openmercato.com/cli/api-keys">
|
|
312
|
-
|
|
313
|
-
</a>
|
|
314
|
-
before running these calls.
|
|
312
|
+
{t('entities.userEntities.records.apiHelp.cli')}
|
|
313
|
+
</a>
|
|
315
314
|
</p>
|
|
316
315
|
<div className="space-y-2">
|
|
317
316
|
<div>
|
|
318
|
-
<div className="font-medium mb-1">
|
|
317
|
+
<div className="font-medium mb-1">{t('entities.userEntities.records.apiHelp.environment')}</div>
|
|
319
318
|
<pre className="bg-muted p-3 rounded text-xs overflow-auto"><code>{`export BASE_URL="http://localhost:3000/api"
|
|
320
319
|
export API_KEY="<paste API key secret here>" # scoped with entities.features
|
|
321
320
|
export ENTITY_ID="${entityId}"
|
|
322
321
|
export RECORD_ID="<record uuid>"`}</code></pre>
|
|
323
322
|
<p className="text-muted-foreground mt-1">
|
|
324
|
-
|
|
325
|
-
<a className="underline" target="_blank" rel="noreferrer" href="https://docs.openmercato.com/user-guide/api-keys">
|
|
326
|
-
Managing API keys
|
|
327
|
-
</a>{' '}
|
|
328
|
-
walkthrough or mint one via{' '}
|
|
323
|
+
{t('entities.userEntities.records.apiHelp.keyHelp')}{' '}
|
|
329
324
|
<a className="underline" target="_blank" rel="noreferrer" href="https://docs.openmercato.com/cli/api-keys">
|
|
330
325
|
mercato api_keys add
|
|
331
|
-
</a
|
|
332
|
-
.
|
|
326
|
+
</a>.
|
|
333
327
|
</p>
|
|
334
328
|
</div>
|
|
335
329
|
|
|
336
330
|
<div>
|
|
337
|
-
<div className="font-medium mb-1">
|
|
331
|
+
<div className="font-medium mb-1">{t('entities.userEntities.records.apiHelp.list')}</div>
|
|
338
332
|
<pre className="bg-muted p-3 rounded text-xs overflow-auto"><code>{`curl -s -H "X-Api-Key: $API_KEY" \
|
|
339
333
|
"$BASE_URL/entities/records?entityId=$ENTITY_ID" | jq`}</code></pre>
|
|
340
334
|
</div>
|
|
341
335
|
|
|
342
336
|
<div>
|
|
343
|
-
<div className="font-medium mb-1">
|
|
337
|
+
<div className="font-medium mb-1">{t('entities.userEntities.records.apiHelp.read')}</div>
|
|
344
338
|
<pre className="bg-muted p-3 rounded text-xs overflow-auto"><code>{`curl -s -H "X-Api-Key: $API_KEY" \
|
|
345
339
|
"$BASE_URL/entities/records?entityId=$ENTITY_ID&id=$RECORD_ID" | jq`}</code></pre>
|
|
346
|
-
<p className="text-muted-foreground mt-1">
|
|
340
|
+
<p className="text-muted-foreground mt-1">{t('entities.userEntities.records.apiHelp.readNote')}</p>
|
|
347
341
|
</div>
|
|
348
342
|
|
|
349
343
|
<div>
|
|
350
|
-
<div className="font-medium mb-1">
|
|
344
|
+
<div className="font-medium mb-1">{t('entities.userEntities.records.apiHelp.create')}</div>
|
|
351
345
|
<pre className="bg-muted p-3 rounded text-xs overflow-auto"><code>{`curl -s -X POST \
|
|
352
346
|
-H "X-Api-Key: $API_KEY" \
|
|
353
347
|
-H "Content-Type: application/json" \
|
|
@@ -359,11 +353,11 @@ export RECORD_ID="<record uuid>"`}</code></pre>
|
|
|
359
353
|
}
|
|
360
354
|
}" \
|
|
361
355
|
"$BASE_URL/entities/records" | jq`}</code></pre>
|
|
362
|
-
<p className="text-muted-foreground mt-1">
|
|
356
|
+
<p className="text-muted-foreground mt-1">{t('entities.userEntities.records.apiHelp.createNote')}</p>
|
|
363
357
|
</div>
|
|
364
358
|
|
|
365
359
|
<div>
|
|
366
|
-
<div className="font-medium mb-1">
|
|
360
|
+
<div className="font-medium mb-1">{t('entities.userEntities.records.apiHelp.update')}</div>
|
|
367
361
|
<pre className="bg-muted p-3 rounded text-xs overflow-auto"><code>{`curl -s -X PUT \
|
|
368
362
|
-H "X-Api-Key: $API_KEY" \
|
|
369
363
|
-H "Content-Type: application/json" \
|
|
@@ -378,18 +372,18 @@ export RECORD_ID="<record uuid>"`}</code></pre>
|
|
|
378
372
|
</div>
|
|
379
373
|
|
|
380
374
|
<div>
|
|
381
|
-
<div className="font-medium mb-1">
|
|
375
|
+
<div className="font-medium mb-1">{t('entities.userEntities.records.apiHelp.delete')}</div>
|
|
382
376
|
<pre className="bg-muted p-3 rounded text-xs overflow-auto"><code>{`curl -s -X DELETE \
|
|
383
377
|
-H "X-Api-Key: $API_KEY" \
|
|
384
378
|
"$BASE_URL/entities/records?entityId=$ENTITY_ID&recordId=$RECORD_ID" | jq`}</code></pre>
|
|
385
379
|
</div>
|
|
386
380
|
|
|
387
381
|
<div className="text-muted-foreground">
|
|
388
|
-
|
|
382
|
+
{t('entities.userEntities.records.apiHelp.security')}
|
|
389
383
|
<ul className="list-disc pl-5 mt-1 space-y-1">
|
|
390
|
-
<li>
|
|
391
|
-
<li>
|
|
392
|
-
<li>
|
|
384
|
+
<li>{t('entities.userEntities.records.apiHelp.scope')}</li>
|
|
385
|
+
<li>{t('entities.userEntities.records.apiHelp.rotate')}</li>
|
|
386
|
+
<li>{t('entities.userEntities.records.apiHelp.protect')}</li>
|
|
393
387
|
</ul>
|
|
394
388
|
</div>
|
|
395
389
|
</div>
|
|
@@ -397,7 +391,7 @@ export RECORD_ID="<record uuid>"`}</code></pre>
|
|
|
397
391
|
<RelationDisplaysProvider displaysByField={relationDisplaysByField}>
|
|
398
392
|
<DataTable
|
|
399
393
|
stickyActionsColumn
|
|
400
|
-
title={
|
|
394
|
+
title={t('entities.userEntities.records.title', 'Records: {{entityId}}', { entityId })}
|
|
401
395
|
titleHeadingLevel={1}
|
|
402
396
|
entityId={entityId}
|
|
403
397
|
actions={actions}
|
|
@@ -255,6 +255,24 @@
|
|
|
255
255
|
"entities.userEntities.help.description": "Erstellen und verwalten Sie Benutzerentitäten — eigene Datentypen, ähnlich wie benutzerdefinierte Datenbanktabellen. Speichern Sie Datensätze und nutzen Sie diese in der Verwaltungsoberfläche und über APIs.",
|
|
256
256
|
"entities.userEntities.help.fields": "Definieren Sie Felder und Formulare einmal; sie werden automatisch für Filter und Eingaben verwendet.",
|
|
257
257
|
"entities.userEntities.help.title": "Eigene Benutzerentitäten gestalten",
|
|
258
|
+
"entities.userEntities.records.actions.editDefinition": "Entitätsdefinition bearbeiten",
|
|
259
|
+
"entities.userEntities.records.apiHelp.cli": "CLI-Dokumentation für API-Schlüssel",
|
|
260
|
+
"entities.userEntities.records.apiHelp.create": "4) Datensatz erstellen",
|
|
261
|
+
"entities.userEntities.records.apiHelp.createNote": "Übergeben Sie benutzerdefinierte Feldschlüssel ohne das Präfix cf_. Die API normalisiert die Schlüssel auf dem Server.",
|
|
262
|
+
"entities.userEntities.records.apiHelp.delete": "6) Datensatz löschen",
|
|
263
|
+
"entities.userEntities.records.apiHelp.environment": "1) Umgebungsvariablen konfigurieren",
|
|
264
|
+
"entities.userEntities.records.apiHelp.guide": "Anleitung zur Verwaltung von API-Schlüsseln",
|
|
265
|
+
"entities.userEntities.records.apiHelp.intro": "Verwalten Sie diese benutzerdefinierte Entität mit cURL über die Backend-API. Erstellen Sie einen Schlüssel, bevor Sie die API aus einem anderen System aufrufen.",
|
|
266
|
+
"entities.userEntities.records.apiHelp.keyHelp": "Erstellen Sie einen Schlüssel im Adminbereich oder verwenden Sie den CLI-Befehl",
|
|
267
|
+
"entities.userEntities.records.apiHelp.list": "2) Datensätze auflisten",
|
|
268
|
+
"entities.userEntities.records.apiHelp.protect": "Bewahren Sie das Geheimnis in einem sicheren Tresor auf. Wer es kennt, kann im Rahmen der Berechtigungen des Schlüssels handeln.",
|
|
269
|
+
"entities.userEntities.records.apiHelp.read": "3) Einzelnen Datensatz anhand der ID abrufen",
|
|
270
|
+
"entities.userEntities.records.apiHelp.readNote": "Die Antwort ist eine Liste. Filtern Sie nach id, um einen einzelnen Datensatz abzurufen.",
|
|
271
|
+
"entities.userEntities.records.apiHelp.rotate": "Wechseln Sie die Schlüssel regelmäßig und löschen Sie ungenutzte Schlüssel im Adminbereich.",
|
|
272
|
+
"entities.userEntities.records.apiHelp.scope": "Alle Endpunkte benötigen einen gültigen API-Schlüssel. Schlüssel übernehmen den Geltungsbereich für Mandant, Organisation und Funktionen.",
|
|
273
|
+
"entities.userEntities.records.apiHelp.security": "Sicherheitshinweise",
|
|
274
|
+
"entities.userEntities.records.apiHelp.title": "API: Datensätze per cURL",
|
|
275
|
+
"entities.userEntities.records.apiHelp.update": "5) Datensatz aktualisieren",
|
|
258
276
|
"entities.userEntities.records.errors.deleteFailed": "Datensatz konnte nicht gelöscht werden",
|
|
259
277
|
"entities.userEntities.records.errors.entityIdRequired": "Entitätskennung ist erforderlich",
|
|
260
278
|
"entities.userEntities.records.errors.notFound": "Datensatz nicht gefunden",
|
|
@@ -264,5 +282,6 @@
|
|
|
264
282
|
"entities.userEntities.records.form.editTitle": "Datensatz bearbeiten",
|
|
265
283
|
"entities.userEntities.records.form.submitCreate": "Erstellen",
|
|
266
284
|
"entities.userEntities.records.form.submitSave": "Speichern",
|
|
267
|
-
"entities.userEntities.records.loading": "Datensatz wird geladen..."
|
|
285
|
+
"entities.userEntities.records.loading": "Datensatz wird geladen...",
|
|
286
|
+
"entities.userEntities.records.title": "Datensätze: {{entityId}}"
|
|
268
287
|
}
|
|
@@ -255,6 +255,24 @@
|
|
|
255
255
|
"entities.userEntities.help.description": "Create and manage user entities — your own data types, similar to custom database tables. Store records and work with them across the admin UI and APIs.",
|
|
256
256
|
"entities.userEntities.help.fields": "Define fields and forms once; they are automatically used for filters and inputs.",
|
|
257
257
|
"entities.userEntities.help.title": "Design your own user entities",
|
|
258
|
+
"entities.userEntities.records.actions.editDefinition": "Edit Entity Definition",
|
|
259
|
+
"entities.userEntities.records.apiHelp.cli": "API keys CLI documentation",
|
|
260
|
+
"entities.userEntities.records.apiHelp.create": "4) Create a record",
|
|
261
|
+
"entities.userEntities.records.apiHelp.createNote": "Send custom field keys without the cf_ prefix. The API normalizes the keys on the server.",
|
|
262
|
+
"entities.userEntities.records.apiHelp.delete": "6) Delete a record",
|
|
263
|
+
"entities.userEntities.records.apiHelp.environment": "1) Configure environment variables",
|
|
264
|
+
"entities.userEntities.records.apiHelp.guide": "Managing API keys guide",
|
|
265
|
+
"entities.userEntities.records.apiHelp.intro": "Use cURL to manage this custom entity through the backend API. Create a key before calling the API from another system.",
|
|
266
|
+
"entities.userEntities.records.apiHelp.keyHelp": "Create a key in the admin UI or run",
|
|
267
|
+
"entities.userEntities.records.apiHelp.list": "2) List records",
|
|
268
|
+
"entities.userEntities.records.apiHelp.protect": "Store the secret in a secure vault. Anyone with the secret can act within the key’s permissions.",
|
|
269
|
+
"entities.userEntities.records.apiHelp.read": "3) Read a single record by ID",
|
|
270
|
+
"entities.userEntities.records.apiHelp.readNote": "The response is a list. Filter by id to retrieve one record.",
|
|
271
|
+
"entities.userEntities.records.apiHelp.rotate": "Rotate keys regularly and delete unused keys in the admin UI.",
|
|
272
|
+
"entities.userEntities.records.apiHelp.scope": "All endpoints require a valid API key. Keys inherit tenant, organization, and feature scope.",
|
|
273
|
+
"entities.userEntities.records.apiHelp.security": "Security notes",
|
|
274
|
+
"entities.userEntities.records.apiHelp.title": "API: Records via cURL",
|
|
275
|
+
"entities.userEntities.records.apiHelp.update": "5) Update a record",
|
|
258
276
|
"entities.userEntities.records.errors.deleteFailed": "Failed to delete record",
|
|
259
277
|
"entities.userEntities.records.errors.entityIdRequired": "Entity identifier is required",
|
|
260
278
|
"entities.userEntities.records.errors.notFound": "Record not found",
|
|
@@ -264,5 +282,6 @@
|
|
|
264
282
|
"entities.userEntities.records.form.editTitle": "Edit record",
|
|
265
283
|
"entities.userEntities.records.form.submitCreate": "Create",
|
|
266
284
|
"entities.userEntities.records.form.submitSave": "Save",
|
|
267
|
-
"entities.userEntities.records.loading": "Loading record..."
|
|
285
|
+
"entities.userEntities.records.loading": "Loading record...",
|
|
286
|
+
"entities.userEntities.records.title": "Records: {{entityId}}"
|
|
268
287
|
}
|
|
@@ -255,6 +255,24 @@
|
|
|
255
255
|
"entities.userEntities.help.description": "Crea y administra entidades de usuario: tus propios tipos de datos, similares a tablas de base de datos personalizadas. Almacena registros y trabaja con ellos desde la interfaz de administración y las API.",
|
|
256
256
|
"entities.userEntities.help.fields": "Define los campos y formularios una vez; se usarán automáticamente en filtros y entradas.",
|
|
257
257
|
"entities.userEntities.help.title": "Diseña tus propias entidades de usuario",
|
|
258
|
+
"entities.userEntities.records.actions.editDefinition": "Editar definición de entidad",
|
|
259
|
+
"entities.userEntities.records.apiHelp.cli": "Documentación de la CLI para claves de API",
|
|
260
|
+
"entities.userEntities.records.apiHelp.create": "4) Crea un registro",
|
|
261
|
+
"entities.userEntities.records.apiHelp.createNote": "Envía las claves de los campos personalizados sin el prefijo cf_. La API normaliza las claves en el servidor.",
|
|
262
|
+
"entities.userEntities.records.apiHelp.delete": "6) Elimina un registro",
|
|
263
|
+
"entities.userEntities.records.apiHelp.environment": "1) Configura las variables de entorno",
|
|
264
|
+
"entities.userEntities.records.apiHelp.guide": "Guía para gestionar claves de API",
|
|
265
|
+
"entities.userEntities.records.apiHelp.intro": "Usa cURL para gestionar esta entidad personalizada mediante la API del servidor. Crea una clave antes de llamar a la API desde otro sistema.",
|
|
266
|
+
"entities.userEntities.records.apiHelp.keyHelp": "Crea una clave en el panel de administración o ejecuta",
|
|
267
|
+
"entities.userEntities.records.apiHelp.list": "2) Enumera los registros",
|
|
268
|
+
"entities.userEntities.records.apiHelp.protect": "Guarda el secreto en un almacén seguro. Quien lo conozca puede actuar con los permisos de la clave.",
|
|
269
|
+
"entities.userEntities.records.apiHelp.read": "3) Consulta un registro por su ID",
|
|
270
|
+
"entities.userEntities.records.apiHelp.readNote": "La respuesta es una lista. Filtra por id para recuperar un solo registro.",
|
|
271
|
+
"entities.userEntities.records.apiHelp.rotate": "Rota las claves con regularidad y elimina las que no uses en el panel de administración.",
|
|
272
|
+
"entities.userEntities.records.apiHelp.scope": "Todos los endpoints requieren una clave de API válida. Las claves heredan el alcance del inquilino, la organización y las funciones.",
|
|
273
|
+
"entities.userEntities.records.apiHelp.security": "Indicaciones de seguridad",
|
|
274
|
+
"entities.userEntities.records.apiHelp.title": "API: registros con cURL",
|
|
275
|
+
"entities.userEntities.records.apiHelp.update": "5) Actualiza un registro",
|
|
258
276
|
"entities.userEntities.records.errors.deleteFailed": "No se pudo eliminar el registro",
|
|
259
277
|
"entities.userEntities.records.errors.entityIdRequired": "Se requiere el identificador de la entidad",
|
|
260
278
|
"entities.userEntities.records.errors.notFound": "Registro no encontrado",
|
|
@@ -264,5 +282,6 @@
|
|
|
264
282
|
"entities.userEntities.records.form.editTitle": "Editar registro",
|
|
265
283
|
"entities.userEntities.records.form.submitCreate": "Crear",
|
|
266
284
|
"entities.userEntities.records.form.submitSave": "Guardar",
|
|
267
|
-
"entities.userEntities.records.loading": "Cargando registro..."
|
|
285
|
+
"entities.userEntities.records.loading": "Cargando registro...",
|
|
286
|
+
"entities.userEntities.records.title": "Registros: {{entityId}}"
|
|
268
287
|
}
|
|
@@ -255,6 +255,24 @@
|
|
|
255
255
|
"entities.userEntities.help.description": "사용자 지정 데이터베이스 테이블과 유사한 고유한 데이터 유형인 사용자 엔티티를 만들고 관리하세요. 레코드를 저장하고 관리 UI 및 API에서 활용할 수 있습니다.",
|
|
256
256
|
"entities.userEntities.help.fields": "필드와 양식을 한 번 정의하면 필터와 입력에 자동으로 사용됩니다.",
|
|
257
257
|
"entities.userEntities.help.title": "사용자 엔티티 직접 설계",
|
|
258
|
+
"entities.userEntities.records.actions.editDefinition": "엔터티 정의 편집",
|
|
259
|
+
"entities.userEntities.records.apiHelp.cli": "API 키 CLI 문서",
|
|
260
|
+
"entities.userEntities.records.apiHelp.create": "4) 레코드 만들기",
|
|
261
|
+
"entities.userEntities.records.apiHelp.createNote": "사용자 지정 필드 키는 cf_ 접두사 없이 보내세요. API가 서버에서 키를 정규화합니다.",
|
|
262
|
+
"entities.userEntities.records.apiHelp.delete": "6) 레코드 삭제",
|
|
263
|
+
"entities.userEntities.records.apiHelp.environment": "1) 환경 변수 설정",
|
|
264
|
+
"entities.userEntities.records.apiHelp.guide": "API 키 관리 가이드",
|
|
265
|
+
"entities.userEntities.records.apiHelp.intro": "cURL을 사용해 백엔드 API에서 이 사용자 지정 엔터티를 관리하세요. 다른 시스템에서 API를 호출하기 전에 키를 만드세요.",
|
|
266
|
+
"entities.userEntities.records.apiHelp.keyHelp": "관리자 화면에서 키를 만들거나 다음 명령을 실행하세요.",
|
|
267
|
+
"entities.userEntities.records.apiHelp.list": "2) 레코드 목록 조회",
|
|
268
|
+
"entities.userEntities.records.apiHelp.protect": "비밀 값은 안전한 저장소에 보관하세요. 값을 아는 사람은 키에 부여된 권한으로 작업할 수 있습니다.",
|
|
269
|
+
"entities.userEntities.records.apiHelp.read": "3) ID로 단일 레코드 조회",
|
|
270
|
+
"entities.userEntities.records.apiHelp.readNote": "응답은 목록입니다. 단일 레코드를 조회하려면 id로 필터링하세요.",
|
|
271
|
+
"entities.userEntities.records.apiHelp.rotate": "키를 정기적으로 교체하고 사용하지 않는 키는 관리자 화면에서 삭제하세요.",
|
|
272
|
+
"entities.userEntities.records.apiHelp.scope": "모든 엔드포인트에는 유효한 API 키가 필요합니다. 키는 테넌트, 조직 및 기능 범위를 상속합니다.",
|
|
273
|
+
"entities.userEntities.records.apiHelp.security": "보안 참고 사항",
|
|
274
|
+
"entities.userEntities.records.apiHelp.title": "API: cURL로 레코드 관리",
|
|
275
|
+
"entities.userEntities.records.apiHelp.update": "5) 레코드 업데이트",
|
|
258
276
|
"entities.userEntities.records.errors.deleteFailed": "레코드 삭제에 실패했습니다",
|
|
259
277
|
"entities.userEntities.records.errors.entityIdRequired": "엔터티 식별자는 필수입니다",
|
|
260
278
|
"entities.userEntities.records.errors.notFound": "레코드를 찾을 수 없습니다",
|
|
@@ -264,5 +282,6 @@
|
|
|
264
282
|
"entities.userEntities.records.form.editTitle": "레코드 편집",
|
|
265
283
|
"entities.userEntities.records.form.submitCreate": "생성",
|
|
266
284
|
"entities.userEntities.records.form.submitSave": "저장",
|
|
267
|
-
"entities.userEntities.records.loading": "레코드를 불러오는 중..."
|
|
285
|
+
"entities.userEntities.records.loading": "레코드를 불러오는 중...",
|
|
286
|
+
"entities.userEntities.records.title": "레코드: {{entityId}}"
|
|
268
287
|
}
|
|
@@ -255,6 +255,24 @@
|
|
|
255
255
|
"entities.userEntities.help.description": "Twórz encje użytkownika i zarządzaj nimi — to własne typy danych, podobne do niestandardowych tabel bazy danych. Przechowuj rekordy i korzystaj z nich w panelu administracyjnym oraz przez API.",
|
|
256
256
|
"entities.userEntities.help.fields": "Zdefiniuj pola i formularze raz; będą automatycznie używane w filtrach i polach wprowadzania danych.",
|
|
257
257
|
"entities.userEntities.help.title": "Projektuj własne encje użytkownika",
|
|
258
|
+
"entities.userEntities.records.actions.editDefinition": "Edytuj definicję encji",
|
|
259
|
+
"entities.userEntities.records.apiHelp.cli": "Dokumentacja CLI dotycząca kluczy API",
|
|
260
|
+
"entities.userEntities.records.apiHelp.create": "4) Utwórz rekord",
|
|
261
|
+
"entities.userEntities.records.apiHelp.createNote": "Przekaż klucze pól niestandardowych bez prefiksu cf_. API normalizuje klucze po stronie serwera.",
|
|
262
|
+
"entities.userEntities.records.apiHelp.delete": "6) Usuń rekord",
|
|
263
|
+
"entities.userEntities.records.apiHelp.environment": "1) Skonfiguruj zmienne środowiskowe",
|
|
264
|
+
"entities.userEntities.records.apiHelp.guide": "Instrukcja zarządzania kluczami API",
|
|
265
|
+
"entities.userEntities.records.apiHelp.intro": "Użyj cURL, aby zarządzać tą encją niestandardową przez API zaplecza. Utwórz klucz przed wywołaniem API z innego systemu.",
|
|
266
|
+
"entities.userEntities.records.apiHelp.keyHelp": "Utwórz klucz w panelu administracyjnym lub uruchom polecenie",
|
|
267
|
+
"entities.userEntities.records.apiHelp.list": "2) Wyświetl listę rekordów",
|
|
268
|
+
"entities.userEntities.records.apiHelp.protect": "Przechowuj sekret w bezpiecznym sejfie. Każdy, kto zna sekret, może działać w ramach uprawnień klucza.",
|
|
269
|
+
"entities.userEntities.records.apiHelp.read": "3) Odczytaj pojedynczy rekord według identyfikatora",
|
|
270
|
+
"entities.userEntities.records.apiHelp.readNote": "Odpowiedź jest listą. Filtruj według id, aby pobrać jeden rekord.",
|
|
271
|
+
"entities.userEntities.records.apiHelp.rotate": "Regularnie wymieniaj klucze i usuwaj nieużywane klucze w panelu administracyjnym.",
|
|
272
|
+
"entities.userEntities.records.apiHelp.scope": "Wszystkie punkty końcowe wymagają prawidłowego klucza API. Klucze dziedziczą zakres tenanta, organizacji i funkcji.",
|
|
273
|
+
"entities.userEntities.records.apiHelp.security": "Wskazówki dotyczące bezpieczeństwa",
|
|
274
|
+
"entities.userEntities.records.apiHelp.title": "API: rekordy przez cURL",
|
|
275
|
+
"entities.userEntities.records.apiHelp.update": "5) Zaktualizuj rekord",
|
|
258
276
|
"entities.userEntities.records.errors.deleteFailed": "Nie udało się usunąć rekordu",
|
|
259
277
|
"entities.userEntities.records.errors.entityIdRequired": "Wymagany jest identyfikator encji",
|
|
260
278
|
"entities.userEntities.records.errors.notFound": "Nie znaleziono rekordu",
|
|
@@ -264,5 +282,6 @@
|
|
|
264
282
|
"entities.userEntities.records.form.editTitle": "Edytuj rekord",
|
|
265
283
|
"entities.userEntities.records.form.submitCreate": "Utwórz",
|
|
266
284
|
"entities.userEntities.records.form.submitSave": "Zapisz",
|
|
267
|
-
"entities.userEntities.records.loading": "Wczytywanie rekordu..."
|
|
285
|
+
"entities.userEntities.records.loading": "Wczytywanie rekordu...",
|
|
286
|
+
"entities.userEntities.records.title": "Rekordy: {{entityId}}"
|
|
268
287
|
}
|
|
@@ -2,8 +2,10 @@ import { NextResponse } from 'next/server'
|
|
|
2
2
|
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
3
3
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
4
4
|
import type { ProgressJob } from '../../data/entities'
|
|
5
|
+
import { createProgressJobMutationPolicy, resolveProgressCancellationScope } from '../jobPermissions'
|
|
5
6
|
import {
|
|
6
7
|
hasReadableProgressScope,
|
|
8
|
+
hasWritableProgressScope,
|
|
7
9
|
resolveProgressRequestScope,
|
|
8
10
|
} from '../requestScope'
|
|
9
11
|
|
|
@@ -39,10 +41,23 @@ export async function GET(req: Request) {
|
|
|
39
41
|
progressService.getRecentlyCompletedJobs(ctx),
|
|
40
42
|
])
|
|
41
43
|
|
|
44
|
+
const cancelScope = jobs.some((job) => job.cancellable) && hasWritableProgressScope(scope)
|
|
45
|
+
? await resolveProgressCancellationScope(container, auth, req)
|
|
46
|
+
: null
|
|
47
|
+
const canMutateJob = createProgressJobMutationPolicy(container, auth)
|
|
48
|
+
const active = await Promise.all(jobs.map(async (job) => ({
|
|
49
|
+
...formatJob(job),
|
|
50
|
+
canCancel: job.cancellable
|
|
51
|
+
&& cancelScope !== null
|
|
52
|
+
&& (cancelScope.filterIds === null
|
|
53
|
+
|| (job.organizationId != null && cancelScope.filterIds.includes(job.organizationId)))
|
|
54
|
+
&& await canMutateJob(job),
|
|
55
|
+
})))
|
|
56
|
+
|
|
42
57
|
return NextResponse.json({
|
|
43
|
-
active
|
|
58
|
+
active,
|
|
44
59
|
recentlyCompleted: recentlyCompleted.map(formatJob),
|
|
45
|
-
})
|
|
60
|
+
}, { headers: { 'Cache-Control': 'private, no-store' } })
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
function formatJob(job: ProgressJob) {
|
|
@@ -67,7 +82,7 @@ function formatJob(job: ProgressJob) {
|
|
|
67
82
|
export const openApi = {
|
|
68
83
|
GET: {
|
|
69
84
|
summary: 'Get active progress jobs',
|
|
70
|
-
description: 'Returns
|
|
85
|
+
description: 'Returns active and recently completed jobs for the progress top bar. Each active job includes canCancel for the authenticated caller.',
|
|
71
86
|
tags: ['Progress'],
|
|
72
87
|
responses: {
|
|
73
88
|
200: { description: 'Active and recently completed jobs' },
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AwilixContainer } from 'awilix'
|
|
2
|
+
import type { AuthContext } from '@open-mercato/shared/lib/auth/server'
|
|
3
|
+
import type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'
|
|
4
|
+
import { resolveFeatureCheckContext } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
5
|
+
import type { ProgressJob } from '../data/entities'
|
|
6
|
+
import { hasWritableProgressScope, resolveProgressRequestScope } from './requestScope'
|
|
7
|
+
|
|
8
|
+
export const progressCancelFeatures = ['progress.cancel']
|
|
9
|
+
|
|
10
|
+
export function createProgressJobMutationPolicy(container: AwilixContainer, auth: NonNullable<AuthContext>) {
|
|
11
|
+
const manageAccessByOrganization = new Map<string | null, Promise<boolean>>()
|
|
12
|
+
|
|
13
|
+
return async (job: Pick<ProgressJob, 'startedByUserId' | 'organizationId'>): Promise<boolean> => {
|
|
14
|
+
if (job.startedByUserId === auth.sub) return true
|
|
15
|
+
const organizationId = job.organizationId ?? null
|
|
16
|
+
const knownAccess = manageAccessByOrganization.get(organizationId)
|
|
17
|
+
if (knownAccess) return knownAccess
|
|
18
|
+
|
|
19
|
+
const rbac = container.resolve<RbacService>('rbacService')
|
|
20
|
+
const access = rbac.userHasAllFeatures(auth.sub, ['progress.manage'], {
|
|
21
|
+
tenantId: auth.tenantId ?? null,
|
|
22
|
+
organizationId,
|
|
23
|
+
})
|
|
24
|
+
manageAccessByOrganization.set(organizationId, access)
|
|
25
|
+
return access
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function resolveProgressCancellationScope(
|
|
30
|
+
container: AwilixContainer,
|
|
31
|
+
auth: NonNullable<AuthContext>,
|
|
32
|
+
request: Request,
|
|
33
|
+
) {
|
|
34
|
+
const cancelRequest = request.clone()
|
|
35
|
+
const { organizationId, scope: featureScope } = await resolveFeatureCheckContext({
|
|
36
|
+
container,
|
|
37
|
+
auth,
|
|
38
|
+
request: cancelRequest,
|
|
39
|
+
requiredFeatures: progressCancelFeatures,
|
|
40
|
+
})
|
|
41
|
+
const rbac = container.resolve<RbacService>('rbacService')
|
|
42
|
+
const hasCancelFeature = await rbac.userHasAllFeatures(auth.sub, progressCancelFeatures, {
|
|
43
|
+
tenantId: featureScope.tenantId ?? auth.tenantId ?? null,
|
|
44
|
+
organizationId,
|
|
45
|
+
})
|
|
46
|
+
if (!hasCancelFeature) return null
|
|
47
|
+
|
|
48
|
+
const scope = await resolveProgressRequestScope(container, auth, cancelRequest)
|
|
49
|
+
return hasWritableProgressScope(scope) ? scope : null
|
|
50
|
+
}
|