@open-mercato/core 0.4.7-develop-78d7541539 → 0.4.7-develop-74069040de
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/AGENTS.md +1 -0
- package/dist/modules/catalog/api/bulk-delete/route.js +86 -0
- package/dist/modules/catalog/api/bulk-delete/route.js.map +7 -0
- package/dist/modules/catalog/api/prices/route.js +39 -6
- package/dist/modules/catalog/api/prices/route.js.map +2 -2
- package/dist/modules/catalog/api/products/route.js +6 -11
- package/dist/modules/catalog/api/products/route.js.map +2 -2
- package/dist/modules/catalog/commands/products.js +2 -0
- package/dist/modules/catalog/commands/products.js.map +2 -2
- package/dist/modules/catalog/components/products/ProductsDataTable.js +9 -1
- package/dist/modules/catalog/components/products/ProductsDataTable.js.map +2 -2
- package/dist/modules/catalog/lib/bulkDelete.js +70 -0
- package/dist/modules/catalog/lib/bulkDelete.js.map +7 -0
- package/dist/modules/catalog/widgets/injection/product-bulk-delete/widget.js +185 -0
- package/dist/modules/catalog/widgets/injection/product-bulk-delete/widget.js.map +7 -0
- package/dist/modules/catalog/widgets/injection-table.js +9 -1
- package/dist/modules/catalog/widgets/injection-table.js.map +2 -2
- package/dist/modules/catalog/workers/catalog-product-bulk-delete.js +40 -0
- package/dist/modules/catalog/workers/catalog-product-bulk-delete.js.map +7 -0
- package/dist/modules/data_sync/api/options.js +52 -0
- package/dist/modules/data_sync/api/options.js.map +7 -0
- package/dist/modules/data_sync/api/run.js +30 -35
- package/dist/modules/data_sync/api/run.js.map +2 -2
- package/dist/modules/data_sync/api/runs/[id]/cancel.js +2 -2
- package/dist/modules/data_sync/api/runs/[id]/cancel.js.map +2 -2
- package/dist/modules/data_sync/api/runs/[id]/retry.js +15 -30
- package/dist/modules/data_sync/api/runs/[id]/retry.js.map +2 -2
- package/dist/modules/data_sync/api/schedules/[id]/route.js +109 -0
- package/dist/modules/data_sync/api/schedules/[id]/route.js.map +7 -0
- package/dist/modules/data_sync/api/schedules/route.js +72 -0
- package/dist/modules/data_sync/api/schedules/route.js.map +7 -0
- package/dist/modules/data_sync/api/schedules/serialize.js +21 -0
- package/dist/modules/data_sync/api/schedules/serialize.js.map +7 -0
- package/dist/modules/data_sync/backend/data-sync/page.js +656 -47
- package/dist/modules/data_sync/backend/data-sync/page.js.map +2 -2
- package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js +116 -34
- package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js.map +2 -2
- package/dist/modules/data_sync/components/IntegrationScheduleTab.js +394 -0
- package/dist/modules/data_sync/components/IntegrationScheduleTab.js.map +7 -0
- package/dist/modules/data_sync/data/validators.js +32 -0
- package/dist/modules/data_sync/data/validators.js.map +2 -2
- package/dist/modules/data_sync/di.js +2 -0
- package/dist/modules/data_sync/di.js.map +2 -2
- package/dist/modules/data_sync/lib/id-mapping.js +24 -2
- package/dist/modules/data_sync/lib/id-mapping.js.map +2 -2
- package/dist/modules/data_sync/lib/start-run.js +57 -0
- package/dist/modules/data_sync/lib/start-run.js.map +7 -0
- package/dist/modules/data_sync/lib/sync-engine.js +93 -4
- package/dist/modules/data_sync/lib/sync-engine.js.map +2 -2
- package/dist/modules/data_sync/lib/sync-run-service.js +5 -1
- package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
- package/dist/modules/data_sync/lib/sync-schedule-service.js +138 -0
- package/dist/modules/data_sync/lib/sync-schedule-service.js.map +7 -0
- package/dist/modules/data_sync/workers/sync-export.js +28 -2
- package/dist/modules/data_sync/workers/sync-export.js.map +2 -2
- package/dist/modules/data_sync/workers/sync-import.js +28 -2
- package/dist/modules/data_sync/workers/sync-import.js.map +2 -2
- package/dist/modules/data_sync/workers/sync-scheduled.js +5 -0
- package/dist/modules/data_sync/workers/sync-scheduled.js.map +2 -2
- package/dist/modules/entities/api/definitions.js +5 -2
- package/dist/modules/entities/api/definitions.js.map +2 -2
- package/dist/modules/entities/lib/field-definitions.js +3 -1
- package/dist/modules/entities/lib/field-definitions.js.map +2 -2
- package/dist/modules/integrations/api/[id]/route.js +14 -15
- package/dist/modules/integrations/api/[id]/route.js.map +2 -2
- package/dist/modules/integrations/api/route.js +3 -3
- package/dist/modules/integrations/api/route.js.map +2 -2
- package/dist/modules/integrations/backend/integrations/[id]/page.js +148 -33
- package/dist/modules/integrations/backend/integrations/[id]/page.js.map +2 -2
- package/dist/modules/integrations/lib/state-service.js +15 -1
- package/dist/modules/integrations/lib/state-service.js.map +2 -2
- package/dist/modules/messages/api/[id]/route.js +24 -22
- package/dist/modules/messages/api/[id]/route.js.map +2 -2
- package/dist/modules/payment_gateways/api/webhook/[provider]/route.js.map +2 -2
- package/dist/modules/progress/api/active/route.js +3 -1
- package/dist/modules/progress/api/active/route.js.map +2 -2
- package/dist/modules/progress/api/jobs/[id]/route.js +1 -1
- package/dist/modules/progress/api/jobs/[id]/route.js.map +2 -2
- package/dist/modules/progress/api/jobs/route.js +1 -1
- package/dist/modules/progress/api/jobs/route.js.map +2 -2
- package/dist/modules/progress/lib/events.js.map +1 -1
- package/dist/modules/progress/lib/progressService.js.map +2 -2
- package/dist/modules/progress/lib/progressServiceImpl.js +42 -1
- package/dist/modules/progress/lib/progressServiceImpl.js.map +2 -2
- package/dist/modules/query_index/lib/document.js +35 -1
- package/dist/modules/query_index/lib/document.js.map +2 -2
- package/dist/modules/query_index/lib/engine.js +91 -4
- package/dist/modules/query_index/lib/engine.js.map +2 -2
- package/dist/modules/query_index/lib/indexer.js +2 -0
- package/dist/modules/query_index/lib/indexer.js.map +2 -2
- package/dist/modules/sales/api/adjustment-kinds/route.js +3 -9
- package/dist/modules/sales/api/adjustment-kinds/route.js.map +2 -2
- package/dist/modules/sales/api/channels/route.js +3 -10
- package/dist/modules/sales/api/channels/route.js.map +2 -2
- package/dist/modules/sales/api/delivery-windows/route.js +3 -10
- package/dist/modules/sales/api/delivery-windows/route.js.map +2 -2
- package/dist/modules/sales/api/payment-methods/route.js +3 -11
- package/dist/modules/sales/api/payment-methods/route.js.map +2 -2
- package/dist/modules/sales/api/price-kinds/route.js +3 -5
- package/dist/modules/sales/api/price-kinds/route.js.map +2 -2
- package/dist/modules/sales/api/shipping-methods/route.js +3 -11
- package/dist/modules/sales/api/shipping-methods/route.js.map +2 -2
- package/dist/modules/sales/api/tags/route.js +3 -9
- package/dist/modules/sales/api/tags/route.js.map +2 -2
- package/dist/modules/sales/api/tax-rates/route.js +3 -13
- package/dist/modules/sales/api/tax-rates/route.js.map +2 -2
- package/dist/modules/sales/api/utils.js +9 -0
- package/dist/modules/sales/api/utils.js.map +2 -2
- package/dist/modules/sales/lib/makeStatusDictionaryRoute.js +3 -9
- package/dist/modules/sales/lib/makeStatusDictionaryRoute.js.map +2 -2
- package/dist/modules/workflows/api/definitions/[id]/route.js +3 -2
- package/dist/modules/workflows/api/definitions/[id]/route.js.map +2 -2
- package/dist/modules/workflows/api/definitions/route.js +4 -3
- package/dist/modules/workflows/api/definitions/route.js.map +2 -2
- package/dist/modules/workflows/api/definitions/serialize.js +25 -0
- package/dist/modules/workflows/api/definitions/serialize.js.map +7 -0
- package/package.json +3 -3
- package/src/modules/catalog/api/bulk-delete/route.ts +93 -0
- package/src/modules/catalog/api/prices/route.ts +53 -6
- package/src/modules/catalog/api/products/route.ts +6 -11
- package/src/modules/catalog/commands/products.ts +2 -0
- package/src/modules/catalog/components/products/ProductsDataTable.tsx +8 -0
- package/src/modules/catalog/i18n/de.json +10 -0
- package/src/modules/catalog/i18n/en.json +10 -0
- package/src/modules/catalog/i18n/es.json +10 -0
- package/src/modules/catalog/i18n/pl.json +10 -0
- package/src/modules/catalog/lib/bulkDelete.ts +106 -0
- package/src/modules/catalog/widgets/injection/product-bulk-delete/widget.ts +242 -0
- package/src/modules/catalog/widgets/injection-table.ts +8 -0
- package/src/modules/catalog/workers/catalog-product-bulk-delete.ts +48 -0
- package/src/modules/data_sync/AGENTS.md +11 -3
- package/src/modules/data_sync/api/options.ts +58 -0
- package/src/modules/data_sync/api/run.ts +34 -36
- package/src/modules/data_sync/api/runs/[id]/cancel.ts +2 -2
- package/src/modules/data_sync/api/runs/[id]/retry.ts +14 -31
- package/src/modules/data_sync/api/schedules/[id]/route.ts +130 -0
- package/src/modules/data_sync/api/schedules/route.ts +77 -0
- package/src/modules/data_sync/api/schedules/serialize.ts +31 -0
- package/src/modules/data_sync/backend/data-sync/page.tsx +756 -2
- package/src/modules/data_sync/backend/data-sync/runs/[id]/page.tsx +179 -53
- package/src/modules/data_sync/components/IntegrationScheduleTab.tsx +512 -0
- package/src/modules/data_sync/data/validators.ts +35 -0
- package/src/modules/data_sync/di.ts +6 -0
- package/src/modules/data_sync/i18n/de.json +72 -0
- package/src/modules/data_sync/i18n/en.json +72 -0
- package/src/modules/data_sync/i18n/es.json +72 -0
- package/src/modules/data_sync/i18n/pl.json +72 -0
- package/src/modules/data_sync/lib/adapter.ts +4 -1
- package/src/modules/data_sync/lib/id-mapping.ts +32 -2
- package/src/modules/data_sync/lib/start-run.ts +90 -0
- package/src/modules/data_sync/lib/sync-engine.ts +111 -4
- package/src/modules/data_sync/lib/sync-run-service.ts +5 -1
- package/src/modules/data_sync/lib/sync-schedule-service.ts +207 -0
- package/src/modules/data_sync/workers/sync-export.ts +33 -2
- package/src/modules/data_sync/workers/sync-import.ts +33 -2
- package/src/modules/data_sync/workers/sync-scheduled.ts +7 -0
- package/src/modules/entities/api/definitions.ts +12 -2
- package/src/modules/entities/lib/field-definitions.ts +2 -0
- package/src/modules/integrations/AGENTS.md +16 -3
- package/src/modules/integrations/api/[id]/route.ts +14 -15
- package/src/modules/integrations/api/route.ts +3 -3
- package/src/modules/integrations/backend/integrations/[id]/page.tsx +176 -54
- package/src/modules/integrations/lib/state-service.ts +25 -1
- package/src/modules/messages/api/[id]/route.ts +25 -22
- package/src/modules/payment_gateways/api/webhook/[provider]/route.ts +3 -3
- package/src/modules/progress/api/active/route.ts +4 -1
- package/src/modules/progress/api/jobs/[id]/route.ts +1 -1
- package/src/modules/progress/api/jobs/route.ts +1 -1
- package/src/modules/progress/lib/events.ts +6 -0
- package/src/modules/progress/lib/progressService.ts +1 -0
- package/src/modules/progress/lib/progressServiceImpl.ts +47 -1
- package/src/modules/query_index/lib/document.ts +52 -1
- package/src/modules/query_index/lib/engine.ts +104 -4
- package/src/modules/query_index/lib/indexer.ts +2 -0
- package/src/modules/sales/api/adjustment-kinds/route.ts +3 -9
- package/src/modules/sales/api/channels/route.ts +3 -10
- package/src/modules/sales/api/delivery-windows/route.ts +3 -10
- package/src/modules/sales/api/payment-methods/route.ts +3 -11
- package/src/modules/sales/api/price-kinds/route.ts +3 -5
- package/src/modules/sales/api/shipping-methods/route.ts +3 -11
- package/src/modules/sales/api/tags/route.ts +3 -9
- package/src/modules/sales/api/tax-rates/route.ts +3 -13
- package/src/modules/sales/api/utils.ts +9 -0
- package/src/modules/sales/lib/makeStatusDictionaryRoute.ts +3 -9
- package/src/modules/workflows/api/definitions/[id]/route.ts +3 -2
- package/src/modules/workflows/api/definitions/route.ts +4 -3
- package/src/modules/workflows/api/definitions/serialize.ts +23 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
|
|
3
|
+
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
4
|
+
import { getAllIntegrations } from "@open-mercato/shared/modules/integrations/types";
|
|
5
|
+
import { getDataSyncAdapter } from "../lib/adapter-registry.js";
|
|
6
|
+
const metadata = {
|
|
7
|
+
GET: { requireAuth: true, requireFeatures: ["data_sync.view"] }
|
|
8
|
+
};
|
|
9
|
+
const openApi = {
|
|
10
|
+
tags: ["DataSync"],
|
|
11
|
+
summary: "List data sync integration options"
|
|
12
|
+
};
|
|
13
|
+
async function GET(req) {
|
|
14
|
+
const auth = await getAuthFromRequest(req);
|
|
15
|
+
if (!auth?.tenantId || !auth.orgId) {
|
|
16
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
17
|
+
}
|
|
18
|
+
const container = await createRequestContainer();
|
|
19
|
+
const credentialsService = container.resolve("integrationCredentialsService");
|
|
20
|
+
const stateService = container.resolve("integrationStateService");
|
|
21
|
+
const scope = { organizationId: auth.orgId, tenantId: auth.tenantId };
|
|
22
|
+
const items = await Promise.all(
|
|
23
|
+
getAllIntegrations().filter((integration) => integration.hub === "data_sync" && integration.providerKey).map(async (integration) => {
|
|
24
|
+
const adapter = getDataSyncAdapter(integration.providerKey);
|
|
25
|
+
if (!adapter) return null;
|
|
26
|
+
const [credentials, state] = await Promise.all([
|
|
27
|
+
credentialsService.resolve(integration.id, scope),
|
|
28
|
+
stateService.resolveState(integration.id, scope)
|
|
29
|
+
]);
|
|
30
|
+
return {
|
|
31
|
+
integrationId: integration.id,
|
|
32
|
+
title: integration.title,
|
|
33
|
+
description: integration.description ?? null,
|
|
34
|
+
providerKey: integration.providerKey ?? null,
|
|
35
|
+
direction: adapter.direction,
|
|
36
|
+
supportedEntities: adapter.supportedEntities,
|
|
37
|
+
hasCredentials: Boolean(credentials),
|
|
38
|
+
isEnabled: state.isEnabled,
|
|
39
|
+
settingsPath: `/backend/integrations/${encodeURIComponent(integration.id)}`
|
|
40
|
+
};
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
return NextResponse.json({
|
|
44
|
+
items: items.filter((item) => Boolean(item))
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
GET,
|
|
49
|
+
metadata,
|
|
50
|
+
openApi
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/data_sync/api/options.ts"],
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { getAllIntegrations } from '@open-mercato/shared/modules/integrations/types'\nimport type { CredentialsService } from '../../integrations/lib/credentials-service'\nimport type { IntegrationStateService } from '../../integrations/lib/state-service'\nimport { getDataSyncAdapter } from '../lib/adapter-registry'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['data_sync.view'] },\n}\n\nexport const openApi = {\n tags: ['DataSync'],\n summary: 'List data sync integration options',\n}\n\nexport async function GET(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const container = await createRequestContainer()\n const credentialsService = container.resolve('integrationCredentialsService') as CredentialsService\n const stateService = container.resolve('integrationStateService') as IntegrationStateService\n const scope = { organizationId: auth.orgId as string, tenantId: auth.tenantId }\n\n const items = await Promise.all(\n getAllIntegrations()\n .filter((integration) => integration.hub === 'data_sync' && integration.providerKey)\n .map(async (integration) => {\n const adapter = getDataSyncAdapter(integration.providerKey as string)\n if (!adapter) return null\n\n const [credentials, state] = await Promise.all([\n credentialsService.resolve(integration.id, scope),\n stateService.resolveState(integration.id, scope),\n ])\n\n return {\n integrationId: integration.id,\n title: integration.title,\n description: integration.description ?? null,\n providerKey: integration.providerKey ?? null,\n direction: adapter.direction,\n supportedEntities: adapter.supportedEntities,\n hasCredentials: Boolean(credentials),\n isEnabled: state.isEnabled,\n settingsPath: `/backend/integrations/${encodeURIComponent(integration.id)}`,\n }\n }),\n )\n\n return NextResponse.json({\n items: items.filter((item): item is NonNullable<typeof item> => Boolean(item)),\n })\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AAGnC,SAAS,0BAA0B;AAE5B,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,gBAAgB,EAAE;AAChE;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,UAAU;AAAA,EACjB,SAAS;AAC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 -1,8 +1,11 @@
|
|
|
1
1
|
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
|
+
import { readJsonSafe } from "@open-mercato/shared/lib/http/readJsonSafe";
|
|
5
|
+
import { getIntegration } from "@open-mercato/shared/modules/integrations/types";
|
|
4
6
|
import { runSyncSchema } from "../data/validators.js";
|
|
5
|
-
import {
|
|
7
|
+
import { startDataSyncRun } from "../lib/start-run.js";
|
|
8
|
+
import { getDataSyncAdapter } from "../lib/adapter-registry.js";
|
|
6
9
|
const metadata = {
|
|
7
10
|
POST: { requireAuth: true, requireFeatures: ["data_sync.run"] }
|
|
8
11
|
};
|
|
@@ -15,7 +18,7 @@ async function POST(req) {
|
|
|
15
18
|
if (!auth?.tenantId || !auth.orgId) {
|
|
16
19
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
17
20
|
}
|
|
18
|
-
const payload = await req
|
|
21
|
+
const payload = await readJsonSafe(req);
|
|
19
22
|
const parsed = runSyncSchema.safeParse(payload);
|
|
20
23
|
if (!parsed.success) {
|
|
21
24
|
return NextResponse.json({ error: "Invalid payload", details: parsed.error.flatten() }, { status: 422 });
|
|
@@ -23,10 +26,26 @@ async function POST(req) {
|
|
|
23
26
|
const container = await createRequestContainer();
|
|
24
27
|
const syncRunService = container.resolve("dataSyncRunService");
|
|
25
28
|
const progressService = container.resolve("progressService");
|
|
29
|
+
const integrationStateService = container.resolve("integrationStateService");
|
|
26
30
|
const scope = {
|
|
27
31
|
organizationId: auth.orgId,
|
|
28
32
|
tenantId: auth.tenantId
|
|
29
33
|
};
|
|
34
|
+
const integration = getIntegration(parsed.data.integrationId);
|
|
35
|
+
if (!integration?.providerKey) {
|
|
36
|
+
return NextResponse.json({ error: "Integration not found" }, { status: 404 });
|
|
37
|
+
}
|
|
38
|
+
const adapter = getDataSyncAdapter(integration.providerKey);
|
|
39
|
+
if (!adapter) {
|
|
40
|
+
return NextResponse.json({ error: "No registered sync adapter for provider" }, { status: 404 });
|
|
41
|
+
}
|
|
42
|
+
if (!adapter.supportedEntities.includes(parsed.data.entityType)) {
|
|
43
|
+
return NextResponse.json({ error: "Unsupported entity type for this integration" }, { status: 422 });
|
|
44
|
+
}
|
|
45
|
+
const integrationEnabled = await integrationStateService.isEnabled(parsed.data.integrationId, scope);
|
|
46
|
+
if (!integrationEnabled) {
|
|
47
|
+
return NextResponse.json({ error: "Integration is disabled" }, { status: 409 });
|
|
48
|
+
}
|
|
30
49
|
const overlap = await syncRunService.findRunningOverlap(
|
|
31
50
|
parsed.data.integrationId,
|
|
32
51
|
parsed.data.entityType,
|
|
@@ -37,47 +56,23 @@ async function POST(req) {
|
|
|
37
56
|
return NextResponse.json({ error: "A sync run is already in progress for this integration and entity direction" }, { status: 409 });
|
|
38
57
|
}
|
|
39
58
|
const cursor = parsed.data.fullSync ? null : await syncRunService.resolveCursor(parsed.data.integrationId, parsed.data.entityType, parsed.data.direction, scope);
|
|
40
|
-
const progressJob = await
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
cancellable: true,
|
|
46
|
-
meta: {
|
|
47
|
-
integrationId: parsed.data.integrationId,
|
|
48
|
-
entityType: parsed.data.entityType,
|
|
49
|
-
direction: parsed.data.direction
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
tenantId: auth.tenantId,
|
|
54
|
-
organizationId: auth.orgId,
|
|
59
|
+
const { run, progressJob } = await startDataSyncRun({
|
|
60
|
+
syncRunService,
|
|
61
|
+
progressService,
|
|
62
|
+
scope: {
|
|
63
|
+
...scope,
|
|
55
64
|
userId: auth.sub
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const run = await syncRunService.createRun(
|
|
59
|
-
{
|
|
65
|
+
},
|
|
66
|
+
input: {
|
|
60
67
|
integrationId: parsed.data.integrationId,
|
|
61
68
|
entityType: parsed.data.entityType,
|
|
62
69
|
direction: parsed.data.direction,
|
|
63
70
|
cursor,
|
|
64
71
|
triggeredBy: parsed.data.triggeredBy ?? auth.sub,
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
scope
|
|
68
|
-
);
|
|
69
|
-
const queueName = parsed.data.direction === "import" ? "data-sync-import" : "data-sync-export";
|
|
70
|
-
const queue = getSyncQueue(queueName);
|
|
71
|
-
await queue.enqueue({
|
|
72
|
-
runId: run.id,
|
|
73
|
-
batchSize: parsed.data.batchSize,
|
|
74
|
-
scope: {
|
|
75
|
-
organizationId: scope.organizationId,
|
|
76
|
-
tenantId: scope.tenantId,
|
|
77
|
-
userId: auth.sub
|
|
72
|
+
batchSize: parsed.data.batchSize
|
|
78
73
|
}
|
|
79
74
|
});
|
|
80
|
-
return NextResponse.json({ id: run.id, progressJobId: progressJob
|
|
75
|
+
return NextResponse.json({ id: run.id, progressJobId: progressJob?.id ?? null }, { status: 201 });
|
|
81
76
|
}
|
|
82
77
|
export {
|
|
83
78
|
POST,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/data_sync/api/run.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { ProgressService } from '../../progress/lib/progressService'\nimport type { SyncRunService } from '../lib/sync-run-service'\nimport { runSyncSchema } from '../data/validators'\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'\nimport { getIntegration } from '@open-mercato/shared/modules/integrations/types'\nimport type { ProgressService } from '../../progress/lib/progressService'\nimport type { IntegrationStateService } from '../../integrations/lib/state-service'\nimport type { SyncRunService } from '../lib/sync-run-service'\nimport { runSyncSchema } from '../data/validators'\nimport { startDataSyncRun } from '../lib/start-run'\nimport { getDataSyncAdapter } from '../lib/adapter-registry'\n\nexport const metadata = {\n POST: { requireAuth: true, requireFeatures: ['data_sync.run'] },\n}\n\nexport const openApi = {\n tags: ['DataSync'],\n summary: 'Start a data sync run',\n}\n\nexport async function POST(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const payload = await readJsonSafe(req)\n const parsed = runSyncSchema.safeParse(payload)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid payload', details: parsed.error.flatten() }, { status: 422 })\n }\n\n const container = await createRequestContainer()\n const syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const progressService = container.resolve('progressService') as ProgressService\n const integrationStateService = container.resolve('integrationStateService') as IntegrationStateService\n\n const scope = {\n organizationId: auth.orgId as string,\n tenantId: auth.tenantId,\n }\n\n const integration = getIntegration(parsed.data.integrationId)\n if (!integration?.providerKey) {\n return NextResponse.json({ error: 'Integration not found' }, { status: 404 })\n }\n\n const adapter = getDataSyncAdapter(integration.providerKey)\n if (!adapter) {\n return NextResponse.json({ error: 'No registered sync adapter for provider' }, { status: 404 })\n }\n\n if (!adapter.supportedEntities.includes(parsed.data.entityType)) {\n return NextResponse.json({ error: 'Unsupported entity type for this integration' }, { status: 422 })\n }\n\n const integrationEnabled = await integrationStateService.isEnabled(parsed.data.integrationId, scope)\n if (!integrationEnabled) {\n return NextResponse.json({ error: 'Integration is disabled' }, { status: 409 })\n }\n\n const overlap = await syncRunService.findRunningOverlap(\n parsed.data.integrationId,\n parsed.data.entityType,\n parsed.data.direction,\n scope,\n )\n if (overlap) {\n return NextResponse.json({ error: 'A sync run is already in progress for this integration and entity direction' }, { status: 409 })\n }\n\n const cursor = parsed.data.fullSync\n ? null\n : await syncRunService.resolveCursor(parsed.data.integrationId, parsed.data.entityType, parsed.data.direction, scope)\n\n const { run, progressJob } = await startDataSyncRun({\n syncRunService,\n progressService,\n scope: {\n ...scope,\n userId: auth.sub,\n },\n input: {\n integrationId: parsed.data.integrationId,\n entityType: parsed.data.entityType,\n direction: parsed.data.direction,\n cursor,\n triggeredBy: parsed.data.triggeredBy ?? auth.sub,\n batchSize: parsed.data.batchSize,\n },\n })\n\n return NextResponse.json({ id: run.id, progressJobId: progressJob?.id ?? null }, { status: 201 })\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAI/B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAE5B,MAAM,WAAW;AAAA,EACtB,MAAM,EAAE,aAAa,MAAM,iBAAiB,CAAC,eAAe,EAAE;AAChE;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,UAAU;AAAA,EACjB,SAAS;AACX;AAEA,eAAsB,KAAK,KAAc;AACvC,QAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,MAAI,CAAC,MAAM,YAAY,CAAC,KAAK,OAAO;AAClC,WAAO,aAAa,KAAK,EAAE,OAAO,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACrE;AAEA,QAAM,UAAU,MAAM,aAAa,GAAG;AACtC,QAAM,SAAS,cAAc,UAAU,OAAO;AAC9C,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,aAAa,KAAK,EAAE,OAAO,mBAAmB,SAAS,OAAO,MAAM,QAAQ,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACzG;AAEA,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,iBAAiB,UAAU,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AAAA,IAClD;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACL,GAAG;AAAA,MACH,QAAQ,KAAK;AAAA,IACf;AAAA,IACA,OAAO;AAAA,MACL,eAAe,OAAO,KAAK;AAAA,MAC3B,YAAY,OAAO,KAAK;AAAA,MACxB,WAAW,OAAO,KAAK;AAAA,MACvB;AAAA,MACA,aAAa,OAAO,KAAK,eAAe,KAAK;AAAA,MAC7C,WAAW,OAAO,KAAK;AAAA,IACzB;AAAA,EACF,CAAC;AAED,SAAO,aAAa,KAAK,EAAE,IAAI,IAAI,IAAI,eAAe,aAAa,MAAM,KAAK,GAAG,EAAE,QAAQ,IAAI,CAAC;AAClG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -38,10 +38,10 @@ async function POST(req, ctx) {
|
|
|
38
38
|
};
|
|
39
39
|
if (run.progressJobId) {
|
|
40
40
|
try {
|
|
41
|
-
await progressService.
|
|
41
|
+
await progressService.markCancelled(run.progressJobId, progressCtx);
|
|
42
42
|
} catch (error) {
|
|
43
43
|
const job = await progressService.getJob(run.progressJobId, progressCtx);
|
|
44
|
-
const cancelRequested = job && job.status === "running" ? await progressService.isCancellationRequested(run.progressJobId) : false;
|
|
44
|
+
const cancelRequested = job && (job.status === "running" || job.status === "cancelled") ? await progressService.isCancellationRequested(run.progressJobId) : false;
|
|
45
45
|
if (job?.status !== "cancelled" && !cancelRequested) {
|
|
46
46
|
throw error;
|
|
47
47
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/data_sync/api/runs/%5Bid%5D/cancel.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { ProgressService } from '../../../../progress/lib/progressService'\nimport type { SyncRunService } from '../../../lib/sync-run-service'\n\nconst paramsSchema = z.object({ id: z.string().uuid() })\n\nexport const metadata = {\n POST: { requireAuth: true, requireFeatures: ['data_sync.run'] },\n}\n\nexport const openApi = {\n tags: ['DataSync'],\n summary: 'Cancel a running sync',\n}\n\nexport async function POST(req: Request, ctx: { params?: Promise<{ id?: string }> | { id?: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const rawParams = (ctx.params && typeof (ctx.params as Promise<unknown>).then === 'function')\n ? await (ctx.params as Promise<{ id?: string }>)\n : (ctx.params as { id?: string } | undefined)\n\n const parsed = paramsSchema.safeParse(rawParams)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid run id' }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const progressService = container.resolve('progressService') as ProgressService\n const scope = { organizationId: auth.orgId as string, tenantId: auth.tenantId }\n\n const run = await syncRunService.getRun(parsed.data.id, scope)\n if (!run) {\n return NextResponse.json({ error: 'Run not found' }, { status: 404 })\n }\n if (run.status !== 'running' && run.status !== 'pending') {\n return NextResponse.json({ error: 'Only pending or running runs can be cancelled' }, { status: 409 })\n }\n\n const progressCtx = {\n tenantId: auth.tenantId,\n organizationId: auth.orgId,\n userId: auth.sub,\n }\n\n if (run.progressJobId) {\n try {\n await progressService.
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAIvC,MAAM,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAEhD,MAAM,WAAW;AAAA,EACtB,MAAM,EAAE,aAAa,MAAM,iBAAiB,CAAC,eAAe,EAAE;AAChE;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,UAAU;AAAA,EACjB,SAAS;AACX;AAEA,eAAsB,KAAK,KAAc,KAA8D;AACrG,QAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,MAAI,CAAC,MAAM,YAAY,CAAC,KAAK,OAAO;AAClC,WAAO,aAAa,KAAK,EAAE,OAAO,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACrE;AAEA,QAAM,YAAa,IAAI,UAAU,OAAQ,IAAI,OAA4B,SAAS,aAC9E,MAAO,IAAI,SACV,IAAI;AAET,QAAM,SAAS,aAAa,UAAU,SAAS;AAC/C,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,aAAa,KAAK,EAAE,OAAO,iBAAiB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACvE;AAEA,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,iBAAiB,UAAU,QAAQ,oBAAoB;AAC7D,QAAM,kBAAkB,UAAU,QAAQ,iBAAiB;AAC3D,QAAM,QAAQ,EAAE,gBAAgB,KAAK,OAAiB,UAAU,KAAK,SAAS;AAE9E,QAAM,MAAM,MAAM,eAAe,OAAO,OAAO,KAAK,IAAI,KAAK;AAC7D,MAAI,CAAC,KAAK;AACR,WAAO,aAAa,KAAK,EAAE,OAAO,gBAAgB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACA,MAAI,IAAI,WAAW,aAAa,IAAI,WAAW,WAAW;AACxD,WAAO,aAAa,KAAK,EAAE,OAAO,gDAAgD,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtG;AAEA,QAAM,cAAc;AAAA,IAClB,UAAU,KAAK;AAAA,IACf,gBAAgB,KAAK;AAAA,IACrB,QAAQ,KAAK;AAAA,EACf;AAEA,MAAI,IAAI,eAAe;AACrB,QAAI;AACF,YAAM,gBAAgB,
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { ProgressService } from '../../../../progress/lib/progressService'\nimport type { SyncRunService } from '../../../lib/sync-run-service'\n\nconst paramsSchema = z.object({ id: z.string().uuid() })\n\nexport const metadata = {\n POST: { requireAuth: true, requireFeatures: ['data_sync.run'] },\n}\n\nexport const openApi = {\n tags: ['DataSync'],\n summary: 'Cancel a running sync',\n}\n\nexport async function POST(req: Request, ctx: { params?: Promise<{ id?: string }> | { id?: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const rawParams = (ctx.params && typeof (ctx.params as Promise<unknown>).then === 'function')\n ? await (ctx.params as Promise<{ id?: string }>)\n : (ctx.params as { id?: string } | undefined)\n\n const parsed = paramsSchema.safeParse(rawParams)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid run id' }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const progressService = container.resolve('progressService') as ProgressService\n const scope = { organizationId: auth.orgId as string, tenantId: auth.tenantId }\n\n const run = await syncRunService.getRun(parsed.data.id, scope)\n if (!run) {\n return NextResponse.json({ error: 'Run not found' }, { status: 404 })\n }\n if (run.status !== 'running' && run.status !== 'pending') {\n return NextResponse.json({ error: 'Only pending or running runs can be cancelled' }, { status: 409 })\n }\n\n const progressCtx = {\n tenantId: auth.tenantId,\n organizationId: auth.orgId,\n userId: auth.sub,\n }\n\n if (run.progressJobId) {\n try {\n await progressService.markCancelled(run.progressJobId, progressCtx)\n } catch (error) {\n const job = await progressService.getJob(run.progressJobId, progressCtx)\n const cancelRequested = job && (job.status === 'running' || job.status === 'cancelled')\n ? await progressService.isCancellationRequested(run.progressJobId)\n : false\n\n if (job?.status !== 'cancelled' && !cancelRequested) {\n throw error\n }\n }\n }\n\n await syncRunService.markStatus(run.id, 'cancelled', scope)\n return NextResponse.json({ ok: true })\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAA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A,EACtG;AAEA,QAAM,cAAc;AAAA,IAClB,UAAU,KAAK;AAAA,IACf,gBAAgB,KAAK;AAAA,IACrB,QAAQ,KAAK;AAAA,EACf;AAEA,MAAI,IAAI,eAAe;AACrB,QAAI;AACF,YAAM,gBAAgB,cAAc,IAAI,eAAe,WAAW;AAAA,IACpE,SAAS,OAAO;AACd,YAAM,MAAM,MAAM,gBAAgB,OAAO,IAAI,eAAe,WAAW;AACvE,YAAM,kBAAkB,QAAQ,IAAI,WAAW,aAAa,IAAI,WAAW,eACvE,MAAM,gBAAgB,wBAAwB,IAAI,aAAa,IAC/D;AAEJ,UAAI,KAAK,WAAW,eAAe,CAAC,iBAAiB;AACnD,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,WAAW,IAAI,IAAI,aAAa,KAAK;AAC1D,SAAO,aAAa,KAAK,EAAE,IAAI,KAAK,CAAC;AACvC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,8 +2,9 @@ import { NextResponse } from "next/server";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
|
|
4
4
|
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
5
|
+
import { readJsonSafe } from "@open-mercato/shared/lib/http/readJsonSafe";
|
|
5
6
|
import { retrySyncSchema } from "../../../data/validators.js";
|
|
6
|
-
import {
|
|
7
|
+
import { startDataSyncRun } from "../../../lib/start-run.js";
|
|
7
8
|
const paramsSchema = z.object({ id: z.string().uuid() });
|
|
8
9
|
const metadata = {
|
|
9
10
|
POST: { requireAuth: true, requireFeatures: ["data_sync.run"] }
|
|
@@ -22,7 +23,7 @@ async function POST(req, ctx) {
|
|
|
22
23
|
if (!parsedParams.success) {
|
|
23
24
|
return NextResponse.json({ error: "Invalid run id" }, { status: 400 });
|
|
24
25
|
}
|
|
25
|
-
const payload = await req
|
|
26
|
+
const payload = await readJsonSafe(req);
|
|
26
27
|
const parsedBody = retrySyncSchema.safeParse(payload ?? {});
|
|
27
28
|
if (!parsedBody.success) {
|
|
28
29
|
return NextResponse.json({ error: "Invalid payload", details: parsedBody.error.flatten() }, { status: 422 });
|
|
@@ -48,42 +49,26 @@ async function POST(req, ctx) {
|
|
|
48
49
|
return NextResponse.json({ error: "A sync run is already in progress for this integration and entity direction" }, { status: 409 });
|
|
49
50
|
}
|
|
50
51
|
const cursor = parsedBody.data.fromBeginning ? null : previous.cursor ?? await syncRunService.resolveCursor(previous.integrationId, previous.entityType, previous.direction, scope);
|
|
51
|
-
const progressJob = await
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
cancellable: true
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
tenantId: auth.tenantId,
|
|
60
|
-
organizationId: auth.orgId,
|
|
52
|
+
const { run, progressJob } = await startDataSyncRun({
|
|
53
|
+
syncRunService,
|
|
54
|
+
progressService,
|
|
55
|
+
scope: {
|
|
56
|
+
...scope,
|
|
61
57
|
userId: auth.sub
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const run = await syncRunService.createRun(
|
|
65
|
-
{
|
|
58
|
+
},
|
|
59
|
+
input: {
|
|
66
60
|
integrationId: previous.integrationId,
|
|
67
61
|
entityType: previous.entityType,
|
|
68
62
|
direction: previous.direction,
|
|
69
63
|
cursor,
|
|
70
64
|
triggeredBy: auth.sub,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const queueName = run.direction === "import" ? "data-sync-import" : "data-sync-export";
|
|
76
|
-
const queue = getSyncQueue(queueName);
|
|
77
|
-
await queue.enqueue({
|
|
78
|
-
runId: run.id,
|
|
79
|
-
batchSize: 100,
|
|
80
|
-
scope: {
|
|
81
|
-
organizationId: scope.organizationId,
|
|
82
|
-
tenantId: scope.tenantId,
|
|
83
|
-
userId: auth.sub
|
|
65
|
+
batchSize: 100,
|
|
66
|
+
progressJob: {
|
|
67
|
+
name: `Retry data sync ${previous.integrationId} \u2014 ${previous.entityType}`
|
|
68
|
+
}
|
|
84
69
|
}
|
|
85
70
|
});
|
|
86
|
-
return NextResponse.json({ id: run.id, progressJobId: progressJob
|
|
71
|
+
return NextResponse.json({ id: run.id, progressJobId: progressJob?.id ?? null }, { status: 201 });
|
|
87
72
|
}
|
|
88
73
|
export {
|
|
89
74
|
POST,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/data_sync/api/runs/%5Bid%5D/retry.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { ProgressService } from '../../../../progress/lib/progressService'\nimport type { SyncRunService } from '../../../lib/sync-run-service'\nimport { retrySyncSchema } from '../../../data/validators'\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'\nimport type { ProgressService } from '../../../../progress/lib/progressService'\nimport type { SyncRunService } from '../../../lib/sync-run-service'\nimport { retrySyncSchema } from '../../../data/validators'\nimport { startDataSyncRun } from '../../../lib/start-run'\n\nconst paramsSchema = z.object({ id: z.string().uuid() })\n\nexport const metadata = {\n POST: { requireAuth: true, requireFeatures: ['data_sync.run'] },\n}\n\nexport const openApi = {\n tags: ['DataSync'],\n summary: 'Retry a failed sync run',\n}\n\nexport async function POST(req: Request, ctx: { params?: Promise<{ id?: string }> | { id?: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const rawParams = (ctx.params && typeof (ctx.params as Promise<unknown>).then === 'function')\n ? await (ctx.params as Promise<{ id?: string }>)\n : (ctx.params as { id?: string } | undefined)\n\n const parsedParams = paramsSchema.safeParse(rawParams)\n if (!parsedParams.success) {\n return NextResponse.json({ error: 'Invalid run id' }, { status: 400 })\n }\n\n const payload = await readJsonSafe(req)\n const parsedBody = retrySyncSchema.safeParse(payload ?? {})\n if (!parsedBody.success) {\n return NextResponse.json({ error: 'Invalid payload', details: parsedBody.error.flatten() }, { status: 422 })\n }\n\n const container = await createRequestContainer()\n const syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const progressService = container.resolve('progressService') as ProgressService\n const scope = { organizationId: auth.orgId as string, tenantId: auth.tenantId }\n\n const previous = await syncRunService.getRun(parsedParams.data.id, scope)\n if (!previous) {\n return NextResponse.json({ error: 'Run not found' }, { status: 404 })\n }\n if (previous.status !== 'failed' && previous.status !== 'cancelled') {\n return NextResponse.json({ error: 'Only failed or cancelled runs can be retried' }, { status: 409 })\n }\n\n const overlap = await syncRunService.findRunningOverlap(\n previous.integrationId,\n previous.entityType,\n previous.direction,\n scope,\n )\n if (overlap) {\n return NextResponse.json({ error: 'A sync run is already in progress for this integration and entity direction' }, { status: 409 })\n }\n\n const cursor = parsedBody.data.fromBeginning\n ? null\n : previous.cursor ?? await syncRunService.resolveCursor(previous.integrationId, previous.entityType, previous.direction, scope)\n\n const { run, progressJob } = await startDataSyncRun({\n syncRunService,\n progressService,\n scope: {\n ...scope,\n userId: auth.sub,\n },\n input: {\n integrationId: previous.integrationId,\n entityType: previous.entityType,\n direction: previous.direction,\n cursor,\n triggeredBy: auth.sub,\n batchSize: 100,\n progressJob: {\n name: `Retry data sync ${previous.integrationId} \u2014 ${previous.entityType}`,\n },\n },\n })\n\n return NextResponse.json({ id: run.id, progressJobId: progressJ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
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
|
|
4
|
+
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
5
|
+
import { readJsonSafe } from "@open-mercato/shared/lib/http/readJsonSafe";
|
|
6
|
+
import { updateSyncScheduleSchema } from "../../../data/validators.js";
|
|
7
|
+
import { serializeSchedule } from "../serialize.js";
|
|
8
|
+
const paramsSchema = z.object({
|
|
9
|
+
id: z.string().uuid()
|
|
10
|
+
});
|
|
11
|
+
const metadata = {
|
|
12
|
+
GET: { requireAuth: true, requireFeatures: ["data_sync.configure"] },
|
|
13
|
+
PUT: { requireAuth: true, requireFeatures: ["data_sync.configure"] },
|
|
14
|
+
DELETE: { requireAuth: true, requireFeatures: ["data_sync.configure"] }
|
|
15
|
+
};
|
|
16
|
+
const openApi = {
|
|
17
|
+
tags: ["DataSync"],
|
|
18
|
+
summary: "Manage a sync schedule"
|
|
19
|
+
};
|
|
20
|
+
async function GET(req, ctx) {
|
|
21
|
+
const auth = await getAuthFromRequest(req);
|
|
22
|
+
if (!auth?.tenantId || !auth.orgId) {
|
|
23
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
24
|
+
}
|
|
25
|
+
const rawParams = ctx.params && typeof ctx.params.then === "function" ? await ctx.params : ctx.params;
|
|
26
|
+
const parsedParams = paramsSchema.safeParse(rawParams);
|
|
27
|
+
if (!parsedParams.success) {
|
|
28
|
+
return NextResponse.json({ error: "Invalid schedule id" }, { status: 400 });
|
|
29
|
+
}
|
|
30
|
+
const container = await createRequestContainer();
|
|
31
|
+
const scheduleService = container.resolve("dataSyncScheduleService");
|
|
32
|
+
const schedule = await scheduleService.getById(parsedParams.data.id, {
|
|
33
|
+
organizationId: auth.orgId,
|
|
34
|
+
tenantId: auth.tenantId
|
|
35
|
+
});
|
|
36
|
+
if (!schedule) {
|
|
37
|
+
return NextResponse.json({ error: "Schedule not found" }, { status: 404 });
|
|
38
|
+
}
|
|
39
|
+
return NextResponse.json(serializeSchedule(schedule));
|
|
40
|
+
}
|
|
41
|
+
async function PUT(req, ctx) {
|
|
42
|
+
const auth = await getAuthFromRequest(req);
|
|
43
|
+
if (!auth?.tenantId || !auth.orgId) {
|
|
44
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
45
|
+
}
|
|
46
|
+
const rawParams = ctx.params && typeof ctx.params.then === "function" ? await ctx.params : ctx.params;
|
|
47
|
+
const parsedParams = paramsSchema.safeParse(rawParams);
|
|
48
|
+
if (!parsedParams.success) {
|
|
49
|
+
return NextResponse.json({ error: "Invalid schedule id" }, { status: 400 });
|
|
50
|
+
}
|
|
51
|
+
const payload = await readJsonSafe(req);
|
|
52
|
+
const parsed = updateSyncScheduleSchema.safeParse(payload);
|
|
53
|
+
if (!parsed.success) {
|
|
54
|
+
return NextResponse.json({ error: "Invalid payload", details: parsed.error.flatten() }, { status: 422 });
|
|
55
|
+
}
|
|
56
|
+
const container = await createRequestContainer();
|
|
57
|
+
const scheduleService = container.resolve("dataSyncScheduleService");
|
|
58
|
+
const scope = { organizationId: auth.orgId, tenantId: auth.tenantId };
|
|
59
|
+
const current = await scheduleService.getById(parsedParams.data.id, scope);
|
|
60
|
+
if (!current) {
|
|
61
|
+
return NextResponse.json({ error: "Schedule not found" }, { status: 404 });
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const schedule = await scheduleService.saveSchedule({
|
|
65
|
+
id: current.id,
|
|
66
|
+
integrationId: parsed.data.integrationId ?? current.integrationId,
|
|
67
|
+
entityType: parsed.data.entityType ?? current.entityType,
|
|
68
|
+
direction: parsed.data.direction ?? current.direction,
|
|
69
|
+
scheduleType: parsed.data.scheduleType ?? current.scheduleType,
|
|
70
|
+
scheduleValue: parsed.data.scheduleValue ?? current.scheduleValue,
|
|
71
|
+
timezone: parsed.data.timezone ?? current.timezone,
|
|
72
|
+
fullSync: parsed.data.fullSync ?? current.fullSync,
|
|
73
|
+
isEnabled: parsed.data.isEnabled ?? current.isEnabled
|
|
74
|
+
}, scope);
|
|
75
|
+
return NextResponse.json(serializeSchedule(schedule));
|
|
76
|
+
} catch (error) {
|
|
77
|
+
const message = error instanceof Error ? error.message : "Failed to update sync schedule";
|
|
78
|
+
return NextResponse.json({ error: message }, { status: 422 });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function DELETE(req, ctx) {
|
|
82
|
+
const auth = await getAuthFromRequest(req);
|
|
83
|
+
if (!auth?.tenantId || !auth.orgId) {
|
|
84
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
85
|
+
}
|
|
86
|
+
const rawParams = ctx.params && typeof ctx.params.then === "function" ? await ctx.params : ctx.params;
|
|
87
|
+
const parsedParams = paramsSchema.safeParse(rawParams);
|
|
88
|
+
if (!parsedParams.success) {
|
|
89
|
+
return NextResponse.json({ error: "Invalid schedule id" }, { status: 400 });
|
|
90
|
+
}
|
|
91
|
+
const container = await createRequestContainer();
|
|
92
|
+
const scheduleService = container.resolve("dataSyncScheduleService");
|
|
93
|
+
const deleted = await scheduleService.deleteSchedule(parsedParams.data.id, {
|
|
94
|
+
organizationId: auth.orgId,
|
|
95
|
+
tenantId: auth.tenantId
|
|
96
|
+
});
|
|
97
|
+
if (!deleted) {
|
|
98
|
+
return NextResponse.json({ error: "Schedule not found" }, { status: 404 });
|
|
99
|
+
}
|
|
100
|
+
return NextResponse.json({ deleted: true });
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
DELETE,
|
|
104
|
+
GET,
|
|
105
|
+
PUT,
|
|
106
|
+
metadata,
|
|
107
|
+
openApi
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/data_sync/api/schedules/%5Bid%5D/route.ts"],
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'\nimport { updateSyncScheduleSchema } from '../../../data/validators'\nimport type { SyncScheduleService } from '../../../lib/sync-schedule-service'\nimport { serializeSchedule } from '../serialize'\n\nconst paramsSchema = z.object({\n id: z.string().uuid(),\n})\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n PUT: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n DELETE: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n}\n\nexport const openApi = {\n tags: ['DataSync'],\n summary: 'Manage a sync schedule',\n}\n\nexport async function GET(req: Request, ctx: { params?: Promise<{ id?: string }> | { id?: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const rawParams = (ctx.params && typeof (ctx.params as Promise<unknown>).then === 'function')\n ? await (ctx.params as Promise<{ id?: string }>)\n : (ctx.params as { id?: string } | undefined)\n\n const parsedParams = paramsSchema.safeParse(rawParams)\n if (!parsedParams.success) {\n return NextResponse.json({ error: 'Invalid schedule id' }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const scheduleService = container.resolve('dataSyncScheduleService') as SyncScheduleService\n const schedule = await scheduleService.getById(parsedParams.data.id, {\n organizationId: auth.orgId as string,\n tenantId: auth.tenantId,\n })\n\n if (!schedule) {\n return NextResponse.json({ error: 'Schedule not found' }, { status: 404 })\n }\n\n return NextResponse.json(serializeSchedule(schedule))\n}\n\nexport async function PUT(req: Request, ctx: { params?: Promise<{ id?: string }> | { id?: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const rawParams = (ctx.params && typeof (ctx.params as Promise<unknown>).then === 'function')\n ? await (ctx.params as Promise<{ id?: string }>)\n : (ctx.params as { id?: string } | undefined)\n\n const parsedParams = paramsSchema.safeParse(rawParams)\n if (!parsedParams.success) {\n return NextResponse.json({ error: 'Invalid schedule id' }, { status: 400 })\n }\n\n const payload = await readJsonSafe(req)\n const parsed = updateSyncScheduleSchema.safeParse(payload)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid payload', details: parsed.error.flatten() }, { status: 422 })\n }\n\n const container = await createRequestContainer()\n const scheduleService = container.resolve('dataSyncScheduleService') as SyncScheduleService\n const scope = { organizationId: auth.orgId as string, tenantId: auth.tenantId }\n const current = await scheduleService.getById(parsedParams.data.id, scope)\n\n if (!current) {\n return NextResponse.json({ error: 'Schedule not found' }, { status: 404 })\n }\n\n try {\n const schedule = await scheduleService.saveSchedule({\n id: current.id,\n integrationId: parsed.data.integrationId ?? current.integrationId,\n entityType: parsed.data.entityType ?? current.entityType,\n direction: parsed.data.direction ?? current.direction,\n scheduleType: parsed.data.scheduleType ?? current.scheduleType,\n scheduleValue: parsed.data.scheduleValue ?? current.scheduleValue,\n timezone: parsed.data.timezone ?? current.timezone,\n fullSync: parsed.data.fullSync ?? current.fullSync,\n isEnabled: parsed.data.isEnabled ?? current.isEnabled,\n }, scope)\n return NextResponse.json(serializeSchedule(schedule))\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Failed to update sync schedule'\n return NextResponse.json({ error: message }, { status: 422 })\n }\n}\n\nexport async function DELETE(req: Request, ctx: { params?: Promise<{ id?: string }> | { id?: string } }) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const rawParams = (ctx.params && typeof (ctx.params as Promise<unknown>).then === 'function')\n ? await (ctx.params as Promise<{ id?: string }>)\n : (ctx.params as { id?: string } | undefined)\n\n const parsedParams = paramsSchema.safeParse(rawParams)\n if (!parsedParams.success) {\n return NextResponse.json({ error: 'Invalid schedule id' }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const scheduleService = container.resolve('dataSyncScheduleService') as SyncScheduleService\n const deleted = await scheduleService.deleteSchedule(parsedParams.data.id, {\n organizationId: auth.orgId as string,\n tenantId: auth.tenantId,\n })\n\n if (!deleted) {\n return NextResponse.json({ error: 'Schedule not found' }, { status: 404 })\n }\n\n return NextResponse.json({ deleted: true })\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,oBAAoB;AAC7B,SAAS,gCAAgC;AAEzC,SAAS,yBAAyB;AAElC,MAAM,eAAe,EAAE,OAAO;AAAA,EAC5B,IAAI,EAAE,OAAO,EAAE,KAAK;AACtB,CAAC;AAEM,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,qBAAqB,EAAE;AAAA,EACnE,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,qBAAqB,EAAE;AAAA,EACnE,QAAQ,EAAE,aAAa,MAAM,iBAAiB,CAAC,qBAAqB,EAAE;AACxE;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,UAAU;AAAA,EACjB,SAAS;AACX;AAEA,eAAsB,IAAI,KAAc,KAA8D;AACpG,QAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,MAAI,CAAC,MAAM,YAAY,CAAC,KAAK,OAAO;AAClC,WAAO,aAAa,KAAK,EAAE,OAAO,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACrE;AAEA,QAAM,YAAa,IAAI,UAAU,OAAQ,IAAI,OAA4B,SAAS,aAC9E,MAAO,IAAI,SACV,IAAI;AAET,QAAM,eAAe,aAAa,UAAU,SAAS;AACrD,MAAI,CAAC,aAAa,SAAS;AACzB,WAAO,aAAa,K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AK,EAAE,OAAO,sBAAsB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC5E;AAEA,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,kBAAkB,UAAU,QAAQ,yBAAyB;AACnE,QAAM,UAAU,MAAM,gBAAgB,eAAe,aAAa,KAAK,IAAI;AAAA,IACzE,gBAAgB,KAAK;AAAA,IACrB,UAAU,KAAK;AAAA,EACjB,CAAC;AAED,MAAI,CAAC,SAAS;AACZ,WAAO,aAAa,KAAK,EAAE,OAAO,qBAAqB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC3E;AAEA,SAAO,aAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAC5C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
|
|
3
|
+
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
4
|
+
import { readJsonSafe } from "@open-mercato/shared/lib/http/readJsonSafe";
|
|
5
|
+
import { createSyncScheduleSchema, listSyncSchedulesQuerySchema } from "../../data/validators.js";
|
|
6
|
+
import { serializeSchedule } from "./serialize.js";
|
|
7
|
+
const metadata = {
|
|
8
|
+
GET: { requireAuth: true, requireFeatures: ["data_sync.configure"] },
|
|
9
|
+
POST: { requireAuth: true, requireFeatures: ["data_sync.configure"] }
|
|
10
|
+
};
|
|
11
|
+
const openApi = {
|
|
12
|
+
tags: ["DataSync"],
|
|
13
|
+
summary: "List or create sync schedules"
|
|
14
|
+
};
|
|
15
|
+
async function GET(req) {
|
|
16
|
+
const auth = await getAuthFromRequest(req);
|
|
17
|
+
if (!auth?.tenantId || !auth.orgId) {
|
|
18
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
19
|
+
}
|
|
20
|
+
const url = new URL(req.url);
|
|
21
|
+
const parsed = listSyncSchedulesQuerySchema.safeParse({
|
|
22
|
+
integrationId: url.searchParams.get("integrationId") ?? void 0,
|
|
23
|
+
entityType: url.searchParams.get("entityType") ?? void 0,
|
|
24
|
+
direction: url.searchParams.get("direction") ?? void 0,
|
|
25
|
+
page: url.searchParams.get("page") ?? void 0,
|
|
26
|
+
pageSize: url.searchParams.get("pageSize") ?? void 0
|
|
27
|
+
});
|
|
28
|
+
if (!parsed.success) {
|
|
29
|
+
return NextResponse.json({ error: "Invalid query", details: parsed.error.flatten() }, { status: 400 });
|
|
30
|
+
}
|
|
31
|
+
const container = await createRequestContainer();
|
|
32
|
+
const scheduleService = container.resolve("dataSyncScheduleService");
|
|
33
|
+
const scope = { organizationId: auth.orgId, tenantId: auth.tenantId };
|
|
34
|
+
const { items, total } = await scheduleService.listSchedules(parsed.data, scope);
|
|
35
|
+
return NextResponse.json({
|
|
36
|
+
items: items.map(serializeSchedule),
|
|
37
|
+
total,
|
|
38
|
+
page: parsed.data.page,
|
|
39
|
+
pageSize: parsed.data.pageSize,
|
|
40
|
+
totalPages: Math.max(1, Math.ceil(total / parsed.data.pageSize))
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async function POST(req) {
|
|
44
|
+
const auth = await getAuthFromRequest(req);
|
|
45
|
+
if (!auth?.tenantId || !auth.orgId) {
|
|
46
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
47
|
+
}
|
|
48
|
+
const payload = await readJsonSafe(req);
|
|
49
|
+
const parsed = createSyncScheduleSchema.safeParse(payload);
|
|
50
|
+
if (!parsed.success) {
|
|
51
|
+
return NextResponse.json({ error: "Invalid payload", details: parsed.error.flatten() }, { status: 422 });
|
|
52
|
+
}
|
|
53
|
+
const container = await createRequestContainer();
|
|
54
|
+
const scheduleService = container.resolve("dataSyncScheduleService");
|
|
55
|
+
try {
|
|
56
|
+
const schedule = await scheduleService.saveSchedule(parsed.data, {
|
|
57
|
+
organizationId: auth.orgId,
|
|
58
|
+
tenantId: auth.tenantId
|
|
59
|
+
});
|
|
60
|
+
return NextResponse.json(serializeSchedule(schedule), { status: 201 });
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const message = error instanceof Error ? error.message : "Failed to save sync schedule";
|
|
63
|
+
return NextResponse.json({ error: message }, { status: 422 });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
GET,
|
|
68
|
+
POST,
|
|
69
|
+
metadata,
|
|
70
|
+
openApi
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/data_sync/api/schedules/route.ts"],
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'\nimport { createSyncScheduleSchema, listSyncSchedulesQuerySchema } from '../../data/validators'\nimport type { SyncScheduleService } from '../../lib/sync-schedule-service'\nimport { serializeSchedule } from './serialize'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n POST: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n}\n\nexport const openApi = {\n tags: ['DataSync'],\n summary: 'List or create sync schedules',\n}\n\nexport async function GET(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const url = new URL(req.url)\n const parsed = listSyncSchedulesQuerySchema.safeParse({\n integrationId: url.searchParams.get('integrationId') ?? undefined,\n entityType: url.searchParams.get('entityType') ?? undefined,\n direction: url.searchParams.get('direction') ?? undefined,\n page: url.searchParams.get('page') ?? undefined,\n pageSize: url.searchParams.get('pageSize') ?? undefined,\n })\n\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid query', details: parsed.error.flatten() }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const scheduleService = container.resolve('dataSyncScheduleService') as SyncScheduleService\n const scope = { organizationId: auth.orgId as string, tenantId: auth.tenantId }\n const { items, total } = await scheduleService.listSchedules(parsed.data, scope)\n\n return NextResponse.json({\n items: items.map(serializeSchedule),\n total,\n page: parsed.data.page,\n pageSize: parsed.data.pageSize,\n totalPages: Math.max(1, Math.ceil(total / parsed.data.pageSize)),\n })\n}\n\nexport async function POST(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })\n }\n\n const payload = await readJsonSafe(req)\n const parsed = createSyncScheduleSchema.safeParse(payload)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid payload', details: parsed.error.flatten() }, { status: 422 })\n }\n\n const container = await createRequestContainer()\n const scheduleService = container.resolve('dataSyncScheduleService') as SyncScheduleService\n\n try {\n const schedule = await scheduleService.saveSchedule(parsed.data, {\n organizationId: auth.orgId as string,\n tenantId: auth.tenantId,\n })\n return NextResponse.json(serializeSchedule(schedule), { status: 201 })\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Failed to save sync schedule'\n return NextResponse.json({ error: message }, { status: 422 })\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B,oCAAoC;AAEvE,SAAS,yBAAyB;AAE3B,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,qBAAqB,EAAE;AAAA,EACnE,MAAM,EAAE,aAAa,MAAM,iBAAiB,CAAC,qBAAqB,EAAE;AACtE;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,UAAU;AAAA,EACjB,SAAS;AACX;AAEA,eAAsB,IAAI,KAAc;AACtC,QAAM,OAAO,MAAM,mB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AAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACrE;AAEA,QAAM,UAAU,MAAM,aAAa,GAAG;AACtC,QAAM,SAAS,yBAAyB,UAAU,OAAO;AACzD,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,aAAa,KAAK,EAAE,OAAO,mBAAmB,SAAS,OAAO,MAAM,QAAQ,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACzG;AAEA,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,kBAAkB,UAAU,QAAQ,yBAAyB;AAEnE,MAAI;AACF,UAAM,WAAW,MAAM,gBAAgB,aAAa,OAAO,MAAM;AAAA,MAC/D,gBAAgB,KAAK;AAAA,MACrB,UAAU,KAAK;AAAA,IACjB,CAAC;AACD,WAAO,aAAa,KAAK,kBAAkB,QAAQ,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACvE,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;AACzD,WAAO,aAAa,KAAK,EAAE,OAAO,QAAQ,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC9D;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function serializeSchedule(item) {
|
|
2
|
+
return {
|
|
3
|
+
id: item.id,
|
|
4
|
+
integrationId: item.integrationId,
|
|
5
|
+
entityType: item.entityType,
|
|
6
|
+
direction: item.direction,
|
|
7
|
+
scheduleType: item.scheduleType,
|
|
8
|
+
scheduleValue: item.scheduleValue,
|
|
9
|
+
timezone: item.timezone,
|
|
10
|
+
fullSync: item.fullSync,
|
|
11
|
+
isEnabled: item.isEnabled,
|
|
12
|
+
scheduledJobId: item.scheduledJobId ?? null,
|
|
13
|
+
lastRunAt: item.lastRunAt?.toISOString() ?? null,
|
|
14
|
+
createdAt: item.createdAt.toISOString(),
|
|
15
|
+
updatedAt: item.updatedAt.toISOString()
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
serializeSchedule
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/data_sync/api/schedules/serialize.ts"],
|
|
4
|
+
"sourcesContent": ["export function serializeSchedule(item: {\n id: string\n integrationId: string\n entityType: string\n direction: 'import' | 'export'\n scheduleType: 'cron' | 'interval'\n scheduleValue: string\n timezone: string\n fullSync: boolean\n isEnabled: boolean\n scheduledJobId?: string | null\n lastRunAt?: Date | null\n createdAt: Date\n updatedAt: Date\n}) {\n return {\n id: item.id,\n integrationId: item.integrationId,\n entityType: item.entityType,\n direction: item.direction,\n scheduleType: item.scheduleType,\n scheduleValue: item.scheduleValue,\n timezone: item.timezone,\n fullSync: item.fullSync,\n isEnabled: item.isEnabled,\n scheduledJobId: item.scheduledJobId ?? null,\n lastRunAt: item.lastRunAt?.toISOString() ?? null,\n createdAt: item.createdAt.toISOString(),\n updatedAt: item.updatedAt.toISOString(),\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAO,SAAS,kBAAkB,MAc/B;AACD,SAAO;AAAA,IACL,IAAI,KAAK;AAAA,IACT,eAAe,KAAK;AAAA,IACpB,YAAY,KAAK;AAAA,IACjB,WAAW,KAAK;AAAA,IAChB,cAAc,KAAK;AAAA,IACnB,eAAe,KAAK;AAAA,IACpB,UAAU,KAAK;AAAA,IACf,UAAU,KAAK;AAAA,IACf,WAAW,KAAK;AAAA,IAChB,gBAAgB,KAAK,kBAAkB;AAAA,IACvC,WAAW,KAAK,WAAW,YAAY,KAAK;AAAA,IAC5C,WAAW,KAAK,UAAU,YAAY;AAAA,IACtC,WAAW,KAAK,UAAU,YAAY;AAAA,EACxC;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|