@open-mercato/core 0.4.7-develop-0a657b411f → 0.4.7-develop-e249d3e7d0
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/carrier_shipment/index.js +37 -0
- package/dist/generated/entities/carrier_shipment/index.js.map +7 -0
- package/dist/generated/entities/gateway_transaction/index.js +47 -0
- package/dist/generated/entities/gateway_transaction/index.js.map +7 -0
- package/dist/generated/entities/webhook_processed_event/index.js +17 -0
- package/dist/generated/entities/webhook_processed_event/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +10 -1
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +6 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/data_sync/api/runs/[id]/cancel.js +14 -5
- package/dist/modules/data_sync/api/runs/[id]/cancel.js.map +2 -2
- package/dist/modules/data_sync/backend/data-sync/page.meta.js +2 -2
- package/dist/modules/data_sync/backend/data-sync/page.meta.js.map +1 -1
- package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js +37 -12
- package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js.map +2 -2
- package/dist/modules/directory/api/get/tenants/lookup.js +1 -0
- package/dist/modules/directory/api/get/tenants/lookup.js.map +2 -2
- package/dist/modules/integrations/api/[id]/route.js +38 -11
- package/dist/modules/integrations/api/[id]/route.js.map +2 -2
- package/dist/modules/integrations/api/logs/route.js +52 -26
- package/dist/modules/integrations/api/logs/route.js.map +2 -2
- package/dist/modules/integrations/api/route.js +37 -7
- package/dist/modules/integrations/api/route.js.map +2 -2
- package/dist/modules/integrations/api/umes-read.js +121 -0
- package/dist/modules/integrations/api/umes-read.js.map +7 -0
- package/dist/modules/integrations/backend/integrations/[id]/page.js +715 -183
- package/dist/modules/integrations/backend/integrations/[id]/page.js.map +2 -2
- package/dist/modules/integrations/backend/integrations/bundle/[id]/page.js +30 -9
- package/dist/modules/integrations/backend/integrations/bundle/[id]/page.js.map +2 -2
- package/dist/modules/integrations/backend/integrations/detail-page-widgets.js +46 -0
- package/dist/modules/integrations/backend/integrations/detail-page-widgets.js.map +7 -0
- package/dist/modules/integrations/backend/integrations/page.js +78 -62
- package/dist/modules/integrations/backend/integrations/page.js.map +2 -2
- package/dist/modules/integrations/backend/integrations/page.meta.js +2 -2
- package/dist/modules/integrations/backend/integrations/page.meta.js.map +1 -1
- package/dist/modules/integrations/setup.js +2 -2
- package/dist/modules/integrations/setup.js.map +2 -2
- package/dist/modules/payment_gateways/acl.js +12 -0
- package/dist/modules/payment_gateways/acl.js.map +7 -0
- package/dist/modules/payment_gateways/api/cancel/route.js +55 -0
- package/dist/modules/payment_gateways/api/cancel/route.js.map +7 -0
- package/dist/modules/payment_gateways/api/capture/route.js +55 -0
- package/dist/modules/payment_gateways/api/capture/route.js.map +7 -0
- package/dist/modules/payment_gateways/api/interceptors.js +24 -0
- package/dist/modules/payment_gateways/api/interceptors.js.map +7 -0
- package/dist/modules/payment_gateways/api/openapi.js +5 -0
- package/dist/modules/payment_gateways/api/openapi.js.map +7 -0
- package/dist/modules/payment_gateways/api/refund/route.js +56 -0
- package/dist/modules/payment_gateways/api/refund/route.js.map +7 -0
- package/dist/modules/payment_gateways/api/sessions/route.js +74 -0
- package/dist/modules/payment_gateways/api/sessions/route.js.map +7 -0
- package/dist/modules/payment_gateways/api/status/route.js +66 -0
- package/dist/modules/payment_gateways/api/status/route.js.map +7 -0
- package/dist/modules/payment_gateways/api/transactions/[id]/route.js +118 -0
- package/dist/modules/payment_gateways/api/transactions/[id]/route.js.map +7 -0
- package/dist/modules/payment_gateways/api/transactions/route.js +113 -0
- package/dist/modules/payment_gateways/api/transactions/route.js.map +7 -0
- package/dist/modules/payment_gateways/api/webhook/[provider]/route.js +136 -0
- package/dist/modules/payment_gateways/api/webhook/[provider]/route.js.map +7 -0
- package/dist/modules/payment_gateways/backend/payment-gateways/page.js +496 -0
- package/dist/modules/payment_gateways/backend/payment-gateways/page.js.map +7 -0
- package/dist/modules/payment_gateways/backend/payment-gateways/page.meta.js +23 -0
- package/dist/modules/payment_gateways/backend/payment-gateways/page.meta.js.map +7 -0
- package/dist/modules/payment_gateways/data/enrichers.js +5 -0
- package/dist/modules/payment_gateways/data/enrichers.js.map +7 -0
- package/dist/modules/payment_gateways/data/entities.js +131 -0
- package/dist/modules/payment_gateways/data/entities.js.map +7 -0
- package/dist/modules/payment_gateways/data/validators.js +57 -0
- package/dist/modules/payment_gateways/data/validators.js.map +7 -0
- package/dist/modules/payment_gateways/di.js +16 -0
- package/dist/modules/payment_gateways/di.js.map +7 -0
- package/dist/modules/payment_gateways/events.js +21 -0
- package/dist/modules/payment_gateways/events.js.map +7 -0
- package/dist/modules/payment_gateways/i18n/en.js +6 -0
- package/dist/modules/payment_gateways/i18n/en.js.map +7 -0
- package/dist/modules/payment_gateways/i18n/pl.js +6 -0
- package/dist/modules/payment_gateways/i18n/pl.js.map +7 -0
- package/dist/modules/payment_gateways/index.js +9 -0
- package/dist/modules/payment_gateways/index.js.map +7 -0
- package/dist/modules/payment_gateways/lib/gateway-service.js +378 -0
- package/dist/modules/payment_gateways/lib/gateway-service.js.map +7 -0
- package/dist/modules/payment_gateways/lib/queue.js +17 -0
- package/dist/modules/payment_gateways/lib/queue.js.map +7 -0
- package/dist/modules/payment_gateways/lib/status-machine.js +29 -0
- package/dist/modules/payment_gateways/lib/status-machine.js.map +7 -0
- package/dist/modules/payment_gateways/lib/webhook-processor.js +88 -0
- package/dist/modules/payment_gateways/lib/webhook-processor.js.map +7 -0
- package/dist/modules/payment_gateways/lib/webhook-utils.js +42 -0
- package/dist/modules/payment_gateways/lib/webhook-utils.js.map +7 -0
- package/dist/modules/payment_gateways/migrations/Migration20260305122155.js +19 -0
- package/dist/modules/payment_gateways/migrations/Migration20260305122155.js.map +7 -0
- package/dist/modules/payment_gateways/setup.js +13 -0
- package/dist/modules/payment_gateways/setup.js.map +7 -0
- package/dist/modules/payment_gateways/widgets/injection-table.js +7 -0
- package/dist/modules/payment_gateways/widgets/injection-table.js.map +7 -0
- package/dist/modules/payment_gateways/workers/status-poller.js +44 -0
- package/dist/modules/payment_gateways/workers/status-poller.js.map +7 -0
- package/dist/modules/payment_gateways/workers/webhook-processor.js +20 -0
- package/dist/modules/payment_gateways/workers/webhook-processor.js.map +7 -0
- package/dist/modules/sales/data/enrichers.js +72 -0
- package/dist/modules/sales/data/enrichers.js.map +7 -0
- package/dist/modules/sales/lib/makeSalesLineRoute.js +3 -0
- package/dist/modules/sales/lib/makeSalesLineRoute.js.map +2 -2
- package/dist/modules/sales/widgets/injection/payment-gateway-config-field/widget.js +29 -0
- package/dist/modules/sales/widgets/injection/payment-gateway-config-field/widget.js.map +7 -0
- package/dist/modules/sales/widgets/injection/payment-gateway-status-column/widget.js +23 -0
- package/dist/modules/sales/widgets/injection/payment-gateway-status-column/widget.js.map +7 -0
- package/dist/modules/sales/widgets/injection-table.js +13 -1
- package/dist/modules/sales/widgets/injection-table.js.map +2 -2
- package/dist/modules/shipping_carriers/acl.js +10 -0
- package/dist/modules/shipping_carriers/acl.js.map +7 -0
- package/dist/modules/shipping_carriers/api/cancel/route.js +55 -0
- package/dist/modules/shipping_carriers/api/cancel/route.js.map +7 -0
- package/dist/modules/shipping_carriers/api/interceptors.js +21 -0
- package/dist/modules/shipping_carriers/api/interceptors.js.map +7 -0
- package/dist/modules/shipping_carriers/api/openapi.js +5 -0
- package/dist/modules/shipping_carriers/api/openapi.js.map +7 -0
- package/dist/modules/shipping_carriers/api/rates/route.js +55 -0
- package/dist/modules/shipping_carriers/api/rates/route.js.map +7 -0
- package/dist/modules/shipping_carriers/api/shipments/route.js +61 -0
- package/dist/modules/shipping_carriers/api/shipments/route.js.map +7 -0
- package/dist/modules/shipping_carriers/api/tracking/route.js +58 -0
- package/dist/modules/shipping_carriers/api/tracking/route.js.map +7 -0
- package/dist/modules/shipping_carriers/api/webhook/[provider]/route.js +119 -0
- package/dist/modules/shipping_carriers/api/webhook/[provider]/route.js.map +7 -0
- package/dist/modules/shipping_carriers/data/enrichers.js +82 -0
- package/dist/modules/shipping_carriers/data/enrichers.js.map +7 -0
- package/dist/modules/shipping_carriers/data/entities.js +80 -0
- package/dist/modules/shipping_carriers/data/entities.js.map +7 -0
- package/dist/modules/shipping_carriers/data/validators.js +49 -0
- package/dist/modules/shipping_carriers/data/validators.js.map +7 -0
- package/dist/modules/shipping_carriers/di.js +15 -0
- package/dist/modules/shipping_carriers/di.js.map +7 -0
- package/dist/modules/shipping_carriers/events.js +19 -0
- package/dist/modules/shipping_carriers/events.js.map +7 -0
- package/dist/modules/shipping_carriers/i18n/en.js +11 -0
- package/dist/modules/shipping_carriers/i18n/en.js.map +7 -0
- package/dist/modules/shipping_carriers/i18n/pl.js +11 -0
- package/dist/modules/shipping_carriers/i18n/pl.js.map +7 -0
- package/dist/modules/shipping_carriers/index.js +9 -0
- package/dist/modules/shipping_carriers/index.js.map +7 -0
- package/dist/modules/shipping_carriers/lib/adapter-registry.js +29 -0
- package/dist/modules/shipping_carriers/lib/adapter-registry.js.map +7 -0
- package/dist/modules/shipping_carriers/lib/adapter.js +1 -0
- package/dist/modules/shipping_carriers/lib/adapter.js.map +7 -0
- package/dist/modules/shipping_carriers/lib/queue.js +17 -0
- package/dist/modules/shipping_carriers/lib/queue.js.map +7 -0
- package/dist/modules/shipping_carriers/lib/shipping-service.js +155 -0
- package/dist/modules/shipping_carriers/lib/shipping-service.js.map +7 -0
- package/dist/modules/shipping_carriers/lib/status-sync.js +37 -0
- package/dist/modules/shipping_carriers/lib/status-sync.js.map +7 -0
- package/dist/modules/shipping_carriers/migrations/Migration20260305170000.js +16 -0
- package/dist/modules/shipping_carriers/migrations/Migration20260305170000.js.map +7 -0
- package/dist/modules/shipping_carriers/setup.js +13 -0
- package/dist/modules/shipping_carriers/setup.js.map +7 -0
- package/dist/modules/shipping_carriers/widgets/injection/create-shipment-button/widget.js +25 -0
- package/dist/modules/shipping_carriers/widgets/injection/create-shipment-button/widget.js.map +7 -0
- package/dist/modules/shipping_carriers/widgets/injection/tracking-column/widget.js +23 -0
- package/dist/modules/shipping_carriers/widgets/injection/tracking-column/widget.js.map +7 -0
- package/dist/modules/shipping_carriers/widgets/injection/tracking-status-badge/widget.js +40 -0
- package/dist/modules/shipping_carriers/widgets/injection/tracking-status-badge/widget.js.map +7 -0
- package/dist/modules/shipping_carriers/widgets/injection-table.js +24 -0
- package/dist/modules/shipping_carriers/widgets/injection-table.js.map +7 -0
- package/dist/modules/shipping_carriers/workers/status-poller.js +21 -0
- package/dist/modules/shipping_carriers/workers/status-poller.js.map +7 -0
- package/dist/modules/shipping_carriers/workers/webhook-processor.js +54 -0
- package/dist/modules/shipping_carriers/workers/webhook-processor.js.map +7 -0
- package/dist/modules/translations/api/get/locales.js +1 -0
- package/dist/modules/translations/api/get/locales.js.map +2 -2
- package/dist/modules/translations/api/put/locales.js +1 -0
- package/dist/modules/translations/api/put/locales.js.map +2 -2
- package/generated/entities/carrier_shipment/index.ts +17 -0
- package/generated/entities/gateway_transaction/index.ts +22 -0
- package/generated/entities/webhook_processed_event/index.ts +7 -0
- package/generated/entities.ids.generated.ts +10 -1
- package/generated/entity-fields-registry.ts +6 -0
- package/jest.config.cjs +1 -0
- package/package.json +5 -2
- package/src/modules/auth/i18n/de.json +1 -0
- package/src/modules/auth/i18n/en.json +1 -0
- package/src/modules/auth/i18n/es.json +1 -0
- package/src/modules/auth/i18n/pl.json +1 -0
- package/src/modules/data_sync/api/runs/[id]/cancel.ts +18 -5
- package/src/modules/data_sync/backend/data-sync/page.meta.ts +2 -2
- package/src/modules/data_sync/backend/data-sync/runs/[id]/page.tsx +50 -12
- package/src/modules/directory/api/get/tenants/lookup.ts +1 -0
- package/src/modules/integrations/AGENTS.md +31 -0
- package/src/modules/integrations/api/[id]/route.ts +38 -11
- package/src/modules/integrations/api/logs/route.ts +53 -27
- package/src/modules/integrations/api/route.ts +31 -1
- package/src/modules/integrations/api/umes-read.ts +177 -0
- package/src/modules/integrations/backend/integrations/[id]/page.tsx +902 -202
- package/src/modules/integrations/backend/integrations/bundle/[id]/page.tsx +43 -9
- package/src/modules/integrations/backend/integrations/detail-page-widgets.ts +74 -0
- package/src/modules/integrations/backend/integrations/page.meta.ts +2 -2
- package/src/modules/integrations/backend/integrations/page.tsx +65 -54
- package/src/modules/integrations/i18n/de.json +15 -0
- package/src/modules/integrations/i18n/en.json +15 -0
- package/src/modules/integrations/i18n/es.json +15 -0
- package/src/modules/integrations/i18n/pl.json +15 -0
- package/src/modules/integrations/setup.ts +2 -2
- package/src/modules/payment_gateways/acl.ts +8 -0
- package/src/modules/payment_gateways/api/cancel/route.ts +56 -0
- package/src/modules/payment_gateways/api/capture/route.ts +56 -0
- package/src/modules/payment_gateways/api/interceptors.ts +22 -0
- package/src/modules/payment_gateways/api/openapi.ts +1 -0
- package/src/modules/payment_gateways/api/refund/route.ts +57 -0
- package/src/modules/payment_gateways/api/sessions/route.ts +76 -0
- package/src/modules/payment_gateways/api/status/route.ts +69 -0
- package/src/modules/payment_gateways/api/transactions/[id]/route.ts +123 -0
- package/src/modules/payment_gateways/api/transactions/route.ts +120 -0
- package/src/modules/payment_gateways/api/webhook/[provider]/route.ts +161 -0
- package/src/modules/payment_gateways/backend/payment-gateways/page.meta.ts +19 -0
- package/src/modules/payment_gateways/backend/payment-gateways/page.tsx +660 -0
- package/src/modules/payment_gateways/data/enrichers.ts +8 -0
- package/src/modules/payment_gateways/data/entities.ts +106 -0
- package/src/modules/payment_gateways/data/validators.ts +67 -0
- package/src/modules/payment_gateways/di.ts +26 -0
- package/src/modules/payment_gateways/events.ts +17 -0
- package/src/modules/payment_gateways/i18n/de.json +77 -0
- package/src/modules/payment_gateways/i18n/en.json +77 -0
- package/src/modules/payment_gateways/i18n/en.ts +4 -0
- package/src/modules/payment_gateways/i18n/es.json +77 -0
- package/src/modules/payment_gateways/i18n/pl.json +77 -0
- package/src/modules/payment_gateways/i18n/pl.ts +4 -0
- package/src/modules/payment_gateways/index.ts +5 -0
- package/src/modules/payment_gateways/lib/gateway-service.ts +486 -0
- package/src/modules/payment_gateways/lib/queue.ts +19 -0
- package/src/modules/payment_gateways/lib/status-machine.ts +28 -0
- package/src/modules/payment_gateways/lib/webhook-processor.ts +133 -0
- package/src/modules/payment_gateways/lib/webhook-utils.ts +52 -0
- package/src/modules/payment_gateways/migrations/.snapshot-open-mercato.json +373 -0
- package/src/modules/payment_gateways/migrations/Migration20260305122155.ts +20 -0
- package/src/modules/payment_gateways/setup.ts +11 -0
- package/src/modules/payment_gateways/widgets/injection-table.ts +9 -0
- package/src/modules/payment_gateways/workers/status-poller.ts +58 -0
- package/src/modules/payment_gateways/workers/webhook-processor.ts +30 -0
- package/src/modules/sales/data/enrichers.ts +120 -0
- package/src/modules/sales/lib/makeSalesLineRoute.ts +3 -0
- package/src/modules/sales/widgets/injection/payment-gateway-config-field/widget.ts +28 -0
- package/src/modules/sales/widgets/injection/payment-gateway-status-column/widget.ts +22 -0
- package/src/modules/sales/widgets/injection-table.ts +12 -0
- package/src/modules/shipping_carriers/acl.ts +6 -0
- package/src/modules/shipping_carriers/api/cancel/route.ts +53 -0
- package/src/modules/shipping_carriers/api/interceptors.ts +19 -0
- package/src/modules/shipping_carriers/api/openapi.ts +1 -0
- package/src/modules/shipping_carriers/api/rates/route.ts +53 -0
- package/src/modules/shipping_carriers/api/shipments/route.ts +59 -0
- package/src/modules/shipping_carriers/api/tracking/route.ts +56 -0
- package/src/modules/shipping_carriers/api/webhook/[provider]/route.ts +134 -0
- package/src/modules/shipping_carriers/data/enrichers.ts +89 -0
- package/src/modules/shipping_carriers/data/entities.ts +60 -0
- package/src/modules/shipping_carriers/data/validators.ts +48 -0
- package/src/modules/shipping_carriers/di.ts +20 -0
- package/src/modules/shipping_carriers/events.ts +16 -0
- package/src/modules/shipping_carriers/i18n/de.json +7 -0
- package/src/modules/shipping_carriers/i18n/en.json +7 -0
- package/src/modules/shipping_carriers/i18n/en.ts +7 -0
- package/src/modules/shipping_carriers/i18n/es.json +7 -0
- package/src/modules/shipping_carriers/i18n/pl.json +7 -0
- package/src/modules/shipping_carriers/i18n/pl.ts +7 -0
- package/src/modules/shipping_carriers/index.ts +5 -0
- package/src/modules/shipping_carriers/lib/adapter-registry.ts +33 -0
- package/src/modules/shipping_carriers/lib/adapter.ts +93 -0
- package/src/modules/shipping_carriers/lib/queue.ts +19 -0
- package/src/modules/shipping_carriers/lib/shipping-service.ts +204 -0
- package/src/modules/shipping_carriers/lib/status-sync.ts +38 -0
- package/src/modules/shipping_carriers/migrations/Migration20260305170000.ts +14 -0
- package/src/modules/shipping_carriers/setup.ts +11 -0
- package/src/modules/shipping_carriers/widgets/injection/create-shipment-button/widget.ts +24 -0
- package/src/modules/shipping_carriers/widgets/injection/tracking-column/widget.ts +22 -0
- package/src/modules/shipping_carriers/widgets/injection/tracking-status-badge/widget.tsx +44 -0
- package/src/modules/shipping_carriers/widgets/injection-table.ts +22 -0
- package/src/modules/shipping_carriers/workers/status-poller.ts +33 -0
- package/src/modules/shipping_carriers/workers/webhook-processor.ts +79 -0
- package/src/modules/translations/api/get/locales.ts +1 -0
- package/src/modules/translations/api/put/locales.ts +1 -0
|
@@ -5,6 +5,11 @@ import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
|
5
5
|
import { getBundle, getBundleIntegrations, getIntegration } from '@open-mercato/shared/modules/integrations/types'
|
|
6
6
|
import type { CredentialsService } from '../../lib/credentials-service'
|
|
7
7
|
import type { IntegrationStateService } from '../../lib/state-service'
|
|
8
|
+
import {
|
|
9
|
+
finalizeIntegrationsReadResponse,
|
|
10
|
+
integrationApiRoutePaths,
|
|
11
|
+
runIntegrationsReadBeforeInterceptors,
|
|
12
|
+
} from '../umes-read'
|
|
8
13
|
|
|
9
14
|
const idParamsSchema = z.object({ id: z.string().min(1) })
|
|
10
15
|
|
|
@@ -38,6 +43,15 @@ export async function GET(req: Request, ctx: { params?: Promise<{ id?: string }>
|
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
const container = await createRequestContainer()
|
|
46
|
+
const beforeInterceptors = await runIntegrationsReadBeforeInterceptors({
|
|
47
|
+
routePath: integrationApiRoutePaths.detail,
|
|
48
|
+
request: req,
|
|
49
|
+
auth,
|
|
50
|
+
container,
|
|
51
|
+
})
|
|
52
|
+
if (!beforeInterceptors.ok) {
|
|
53
|
+
return NextResponse.json(beforeInterceptors.body, { status: beforeInterceptors.statusCode })
|
|
54
|
+
}
|
|
41
55
|
const credentialsService = container.resolve('integrationCredentialsService') as CredentialsService
|
|
42
56
|
const stateService = container.resolve('integrationStateService') as IntegrationStateService
|
|
43
57
|
const scope = { organizationId: auth.orgId as string, tenantId: auth.tenantId }
|
|
@@ -68,17 +82,30 @@ export async function GET(req: Request, ctx: { params?: Promise<{ id?: string }>
|
|
|
68
82
|
)
|
|
69
83
|
: []
|
|
70
84
|
|
|
71
|
-
return
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
return finalizeIntegrationsReadResponse({
|
|
86
|
+
routePath: integrationApiRoutePaths.detail,
|
|
87
|
+
request: req,
|
|
88
|
+
auth,
|
|
89
|
+
container,
|
|
90
|
+
interceptorRequest: beforeInterceptors.request,
|
|
91
|
+
beforeMetadata: beforeInterceptors.metadataByInterceptor,
|
|
92
|
+
enrich: {
|
|
93
|
+
targetEntity: 'integrations.integration',
|
|
94
|
+
recordKeys: ['integration'],
|
|
95
|
+
listKeys: ['bundleIntegrations'],
|
|
96
|
+
},
|
|
97
|
+
body: {
|
|
98
|
+
integration,
|
|
99
|
+
bundle,
|
|
100
|
+
bundleIntegrations,
|
|
101
|
+
state: {
|
|
102
|
+
isEnabled: state?.isEnabled ?? true,
|
|
103
|
+
apiVersion: state?.apiVersion ?? null,
|
|
104
|
+
reauthRequired: state?.reauthRequired ?? false,
|
|
105
|
+
lastHealthStatus: state?.lastHealthStatus ?? null,
|
|
106
|
+
lastHealthCheckedAt: state?.lastHealthCheckedAt?.toISOString() ?? null,
|
|
107
|
+
},
|
|
108
|
+
hasCredentials: Boolean(credentials),
|
|
81
109
|
},
|
|
82
|
-
hasCredentials: Boolean(credentials),
|
|
83
110
|
})
|
|
84
111
|
}
|
|
@@ -3,6 +3,11 @@ import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
|
3
3
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
4
4
|
import { listIntegrationLogsQuerySchema } from '@open-mercato/core/modules/integrations/data/validators'
|
|
5
5
|
import type { IntegrationLogService } from '@open-mercato/core/modules/integrations/lib/log-service'
|
|
6
|
+
import {
|
|
7
|
+
finalizeIntegrationsReadResponse,
|
|
8
|
+
integrationApiRoutePaths,
|
|
9
|
+
runIntegrationsReadBeforeInterceptors,
|
|
10
|
+
} from '../umes-read'
|
|
6
11
|
|
|
7
12
|
export const metadata = {
|
|
8
13
|
GET: { requireAuth: true, requireFeatures: ['integrations.manage'] },
|
|
@@ -19,22 +24,31 @@ export async function GET(req: Request) {
|
|
|
19
24
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
const
|
|
27
|
+
const container = await createRequestContainer()
|
|
28
|
+
const beforeInterceptors = await runIntegrationsReadBeforeInterceptors({
|
|
29
|
+
routePath: integrationApiRoutePaths.logs,
|
|
30
|
+
request: req,
|
|
31
|
+
auth,
|
|
32
|
+
container,
|
|
33
|
+
})
|
|
34
|
+
if (!beforeInterceptors.ok) {
|
|
35
|
+
return NextResponse.json(beforeInterceptors.body, { status: beforeInterceptors.statusCode })
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const query = beforeInterceptors.request.query ?? {}
|
|
23
39
|
const parsed = listIntegrationLogsQuerySchema.safeParse({
|
|
24
|
-
integrationId:
|
|
25
|
-
level:
|
|
26
|
-
runId:
|
|
27
|
-
entityType:
|
|
28
|
-
entityId:
|
|
29
|
-
page:
|
|
30
|
-
pageSize:
|
|
40
|
+
integrationId: typeof query.integrationId === 'string' ? query.integrationId : undefined,
|
|
41
|
+
level: typeof query.level === 'string' ? query.level : undefined,
|
|
42
|
+
runId: typeof query.runId === 'string' ? query.runId : undefined,
|
|
43
|
+
entityType: typeof query.entityType === 'string' ? query.entityType : undefined,
|
|
44
|
+
entityId: typeof query.entityId === 'string' ? query.entityId : undefined,
|
|
45
|
+
page: typeof query.page === 'string' ? query.page : undefined,
|
|
46
|
+
pageSize: typeof query.pageSize === 'string' ? query.pageSize : undefined,
|
|
31
47
|
})
|
|
32
48
|
|
|
33
49
|
if (!parsed.success) {
|
|
34
50
|
return NextResponse.json({ error: 'Invalid query', details: parsed.error.flatten() }, { status: 400 })
|
|
35
51
|
}
|
|
36
|
-
|
|
37
|
-
const container = await createRequestContainer()
|
|
38
52
|
const logService = container.resolve('integrationLogService') as IntegrationLogService
|
|
39
53
|
|
|
40
54
|
const { items, total } = await logService.query(parsed.data, {
|
|
@@ -42,22 +56,34 @@ export async function GET(req: Request) {
|
|
|
42
56
|
tenantId: auth.tenantId,
|
|
43
57
|
})
|
|
44
58
|
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
return finalizeIntegrationsReadResponse({
|
|
60
|
+
routePath: integrationApiRoutePaths.logs,
|
|
61
|
+
request: req,
|
|
62
|
+
auth,
|
|
63
|
+
container,
|
|
64
|
+
interceptorRequest: beforeInterceptors.request,
|
|
65
|
+
beforeMetadata: beforeInterceptors.metadataByInterceptor,
|
|
66
|
+
enrich: {
|
|
67
|
+
targetEntity: 'integrations.log',
|
|
68
|
+
listKeys: ['items'],
|
|
69
|
+
},
|
|
70
|
+
body: {
|
|
71
|
+
items: items.map((item) => ({
|
|
72
|
+
id: item.id,
|
|
73
|
+
integrationId: item.integrationId,
|
|
74
|
+
runId: item.runId ?? null,
|
|
75
|
+
scopeEntityType: item.scopeEntityType ?? null,
|
|
76
|
+
scopeEntityId: item.scopeEntityId ?? null,
|
|
77
|
+
level: item.level,
|
|
78
|
+
message: item.message,
|
|
79
|
+
code: item.code ?? null,
|
|
80
|
+
payload: item.payload ?? null,
|
|
81
|
+
createdAt: item.createdAt.toISOString(),
|
|
82
|
+
})),
|
|
83
|
+
total,
|
|
84
|
+
page: parsed.data.page,
|
|
85
|
+
pageSize: parsed.data.pageSize,
|
|
86
|
+
totalPages: Math.max(1, Math.ceil(total / parsed.data.pageSize)),
|
|
87
|
+
},
|
|
62
88
|
})
|
|
63
89
|
}
|
|
@@ -5,6 +5,11 @@ import type { CredentialsService } from '../lib/credentials-service'
|
|
|
5
5
|
import type { IntegrationStateService } from '../lib/state-service'
|
|
6
6
|
import { getAllBundles, getAllIntegrations } from '@open-mercato/shared/modules/integrations/types'
|
|
7
7
|
import { buildIntegrationsCrudOpenApi, createPagedListResponseSchema, integrationInfoSchema } from './openapi'
|
|
8
|
+
import {
|
|
9
|
+
finalizeIntegrationsReadResponse,
|
|
10
|
+
integrationApiRoutePaths,
|
|
11
|
+
runIntegrationsReadBeforeInterceptors,
|
|
12
|
+
} from './umes-read'
|
|
8
13
|
|
|
9
14
|
export const metadata = {
|
|
10
15
|
GET: { requireAuth: true, requireFeatures: ['integrations.view'] },
|
|
@@ -24,6 +29,15 @@ export async function GET(req: Request) {
|
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
const container = await createRequestContainer()
|
|
32
|
+
const beforeInterceptors = await runIntegrationsReadBeforeInterceptors({
|
|
33
|
+
routePath: integrationApiRoutePaths.list,
|
|
34
|
+
request: req,
|
|
35
|
+
auth,
|
|
36
|
+
container,
|
|
37
|
+
})
|
|
38
|
+
if (!beforeInterceptors.ok) {
|
|
39
|
+
return NextResponse.json(beforeInterceptors.body, { status: beforeInterceptors.statusCode })
|
|
40
|
+
}
|
|
27
41
|
const credentialsService = container.resolve('integrationCredentialsService') as CredentialsService
|
|
28
42
|
const stateService = container.resolve('integrationStateService') as IntegrationStateService
|
|
29
43
|
|
|
@@ -37,10 +51,14 @@ export async function GET(req: Request) {
|
|
|
37
51
|
return {
|
|
38
52
|
id: integration.id,
|
|
39
53
|
title: integration.title,
|
|
54
|
+
description: integration.description ?? null,
|
|
40
55
|
category: integration.category ?? null,
|
|
41
56
|
hub: integration.hub ?? null,
|
|
42
57
|
providerKey: integration.providerKey ?? null,
|
|
43
58
|
bundleId: integration.bundleId ?? null,
|
|
59
|
+
author: integration.author ?? null,
|
|
60
|
+
company: integration.company ?? null,
|
|
61
|
+
version: integration.version ?? null,
|
|
44
62
|
hasCredentials: Boolean(resolvedCredentials),
|
|
45
63
|
isEnabled: state?.isEnabled ?? true,
|
|
46
64
|
apiVersion: state?.apiVersion ?? null,
|
|
@@ -62,12 +80,24 @@ export async function GET(req: Request) {
|
|
|
62
80
|
}
|
|
63
81
|
})
|
|
64
82
|
|
|
65
|
-
return
|
|
83
|
+
return finalizeIntegrationsReadResponse({
|
|
84
|
+
routePath: integrationApiRoutePaths.list,
|
|
85
|
+
request: req,
|
|
86
|
+
auth,
|
|
87
|
+
container,
|
|
88
|
+
interceptorRequest: beforeInterceptors.request,
|
|
89
|
+
beforeMetadata: beforeInterceptors.metadataByInterceptor,
|
|
90
|
+
enrich: {
|
|
91
|
+
targetEntity: 'integrations.integration',
|
|
92
|
+
listKeys: ['items'],
|
|
93
|
+
},
|
|
94
|
+
body: {
|
|
66
95
|
items: rows,
|
|
67
96
|
bundles,
|
|
68
97
|
total: rows.length,
|
|
69
98
|
page: 1,
|
|
70
99
|
pageSize: 100,
|
|
71
100
|
totalPages: 1,
|
|
101
|
+
},
|
|
72
102
|
})
|
|
73
103
|
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
+
import { NextResponse } from 'next/server'
|
|
3
|
+
import type { AwilixContainer } from 'awilix'
|
|
4
|
+
import { runApiInterceptorsAfter, runApiInterceptorsBefore, type RunInterceptorsBeforeResult } from '@open-mercato/shared/lib/crud/interceptor-runner'
|
|
5
|
+
import { applyResponseEnrichers, applyResponseEnricherToRecord } from '@open-mercato/shared/lib/crud/enricher-runner'
|
|
6
|
+
import type { ApiInterceptorMethod, InterceptorRequest } from '@open-mercato/shared/lib/crud/api-interceptor'
|
|
7
|
+
|
|
8
|
+
export const integrationApiRoutePaths = {
|
|
9
|
+
list: 'integrations',
|
|
10
|
+
detail: 'integrations/detail',
|
|
11
|
+
logs: 'integrations/logs',
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
type ReadRouteFieldConfig = {
|
|
15
|
+
targetEntity: string
|
|
16
|
+
recordKeys?: string[]
|
|
17
|
+
listKeys?: string[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ReadRouteContext = {
|
|
21
|
+
routePath: string
|
|
22
|
+
request: Request
|
|
23
|
+
auth: {
|
|
24
|
+
tenantId: string | null
|
|
25
|
+
orgId: string | null
|
|
26
|
+
sub?: string | null
|
|
27
|
+
features?: unknown
|
|
28
|
+
}
|
|
29
|
+
container: AwilixContainer
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function headersToObject(headers: Headers): Record<string, string> {
|
|
33
|
+
return Object.fromEntries(headers.entries())
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function searchParamsToObject(url: URL): Record<string, string> {
|
|
37
|
+
const entries: Record<string, string> = {}
|
|
38
|
+
url.searchParams.forEach((value, key) => {
|
|
39
|
+
entries[key] = value
|
|
40
|
+
})
|
|
41
|
+
return entries
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function toUserFeatures(features: unknown): string[] {
|
|
45
|
+
if (!Array.isArray(features)) return []
|
|
46
|
+
return features.filter((value): value is string => typeof value === 'string')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function mergeAdditiveRecord<T extends Record<string, unknown>>(base: T, candidate: T): T {
|
|
50
|
+
const additions = Object.fromEntries(
|
|
51
|
+
Object.entries(candidate).filter(([key]) => !(key in base)),
|
|
52
|
+
) as Partial<T>
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
...base,
|
|
56
|
+
...additions,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function mergeAdditiveBody(
|
|
61
|
+
baseBody: Record<string, unknown>,
|
|
62
|
+
candidateBody: Record<string, unknown>,
|
|
63
|
+
): Record<string, unknown> {
|
|
64
|
+
return mergeAdditiveRecord(baseBody, candidateBody)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getEnricherContext(input: ReadRouteContext) {
|
|
68
|
+
return {
|
|
69
|
+
organizationId: input.auth.orgId as string,
|
|
70
|
+
tenantId: input.auth.tenantId as string,
|
|
71
|
+
userId: input.auth.sub ?? '',
|
|
72
|
+
em: input.container.resolve('em') as EntityManager,
|
|
73
|
+
container: input.container,
|
|
74
|
+
userFeatures: toUserFeatures(input.auth.features),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function runIntegrationsReadBeforeInterceptors(
|
|
79
|
+
input: ReadRouteContext,
|
|
80
|
+
): Promise<RunInterceptorsBeforeResult> {
|
|
81
|
+
const url = new URL(input.request.url)
|
|
82
|
+
|
|
83
|
+
return runApiInterceptorsBefore({
|
|
84
|
+
routePath: input.routePath,
|
|
85
|
+
method: 'GET',
|
|
86
|
+
request: {
|
|
87
|
+
method: 'GET',
|
|
88
|
+
url: input.request.url,
|
|
89
|
+
headers: headersToObject(input.request.headers),
|
|
90
|
+
query: searchParamsToObject(url),
|
|
91
|
+
},
|
|
92
|
+
context: getEnricherContext(input),
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function applySafeRecordEnrichment(
|
|
97
|
+
record: Record<string, unknown>,
|
|
98
|
+
targetEntity: string,
|
|
99
|
+
context: ReturnType<typeof getEnricherContext>,
|
|
100
|
+
): Promise<Record<string, unknown>> {
|
|
101
|
+
const enriched = await applyResponseEnricherToRecord(record, targetEntity, context)
|
|
102
|
+
return mergeAdditiveRecord(record, enriched.record)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function applySafeListEnrichment(
|
|
106
|
+
items: Record<string, unknown>[],
|
|
107
|
+
targetEntity: string,
|
|
108
|
+
context: ReturnType<typeof getEnricherContext>,
|
|
109
|
+
): Promise<Record<string, unknown>[]> {
|
|
110
|
+
const enriched = await applyResponseEnrichers(items, targetEntity, context)
|
|
111
|
+
return items.map((item, index) => {
|
|
112
|
+
const enrichedItem = enriched.items[index]
|
|
113
|
+
if (!enrichedItem) return item
|
|
114
|
+
return mergeAdditiveRecord(item, enrichedItem)
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function finalizeIntegrationsReadResponse(
|
|
119
|
+
input: ReadRouteContext & {
|
|
120
|
+
interceptorRequest: InterceptorRequest
|
|
121
|
+
body: Record<string, unknown>
|
|
122
|
+
enrich?: ReadRouteFieldConfig
|
|
123
|
+
method?: ApiInterceptorMethod
|
|
124
|
+
beforeMetadata?: Record<string, Record<string, unknown> | undefined>
|
|
125
|
+
},
|
|
126
|
+
): Promise<NextResponse> {
|
|
127
|
+
const method = input.method ?? 'GET'
|
|
128
|
+
const baseBody = input.body
|
|
129
|
+
const context = getEnricherContext(input)
|
|
130
|
+
|
|
131
|
+
const intercepted = await runApiInterceptorsAfter({
|
|
132
|
+
routePath: input.routePath,
|
|
133
|
+
method,
|
|
134
|
+
request: input.interceptorRequest,
|
|
135
|
+
response: {
|
|
136
|
+
statusCode: 200,
|
|
137
|
+
body: baseBody,
|
|
138
|
+
headers: {},
|
|
139
|
+
},
|
|
140
|
+
context,
|
|
141
|
+
metadataByInterceptor: input.beforeMetadata,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
if (!intercepted.ok) {
|
|
145
|
+
return NextResponse.json(intercepted.body, { status: intercepted.statusCode, headers: intercepted.headers })
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let responseBody = mergeAdditiveBody(baseBody, intercepted.body)
|
|
149
|
+
|
|
150
|
+
if (input.enrich) {
|
|
151
|
+
const { targetEntity, recordKeys = [], listKeys = [] } = input.enrich
|
|
152
|
+
|
|
153
|
+
for (const key of recordKeys) {
|
|
154
|
+
const current = responseBody[key]
|
|
155
|
+
if (!current || typeof current !== 'object' || Array.isArray(current)) continue
|
|
156
|
+
responseBody = {
|
|
157
|
+
...responseBody,
|
|
158
|
+
[key]: await applySafeRecordEnrichment(current as Record<string, unknown>, targetEntity, context),
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
for (const key of listKeys) {
|
|
163
|
+
const current = responseBody[key]
|
|
164
|
+
if (!Array.isArray(current)) continue
|
|
165
|
+
const records = current.filter(
|
|
166
|
+
(item): item is Record<string, unknown> => typeof item === 'object' && item !== null && !Array.isArray(item),
|
|
167
|
+
)
|
|
168
|
+
if (records.length !== current.length) continue
|
|
169
|
+
responseBody = {
|
|
170
|
+
...responseBody,
|
|
171
|
+
[key]: await applySafeListEnrichment(records, targetEntity, context),
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return NextResponse.json(responseBody, { headers: intercepted.headers })
|
|
177
|
+
}
|