@open-mercato/sync-akeneo 0.11.1-develop.8754.1.21677f1ed5 → 0.11.1-develop.8759.1.ac7b7cb1db
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/modules/sync_akeneo/api/first-import/route.js +11 -2
- package/dist/modules/sync_akeneo/api/first-import/route.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/adapter.js +7 -0
- package/dist/modules/sync_akeneo/lib/adapter.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/first-import.js +11 -0
- package/dist/modules/sync_akeneo/lib/first-import.js.map +2 -2
- package/dist/modules/sync_akeneo/widgets/injection/akeneo-config/widget.client.js +1 -1
- package/dist/modules/sync_akeneo/widgets/injection/akeneo-config/widget.client.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/sync_akeneo/__tests__/adapter.test.ts +35 -3
- package/src/modules/sync_akeneo/__tests__/first-import-route.test.ts +81 -0
- package/src/modules/sync_akeneo/__tests__/first-import.test.ts +79 -6
- package/src/modules/sync_akeneo/api/first-import/route.ts +12 -2
- package/src/modules/sync_akeneo/lib/adapter.ts +9 -0
- package/src/modules/sync_akeneo/lib/first-import.ts +13 -0
- package/src/modules/sync_akeneo/widgets/injection/akeneo-config/widget.client.tsx +3 -3
|
@@ -2,6 +2,7 @@ import { NextResponse } from "next/server";
|
|
|
2
2
|
import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
|
|
3
3
|
import { findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
4
4
|
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
5
|
+
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
5
6
|
import { ProgressJob } from "@open-mercato/core/modules/progress/data/entities";
|
|
6
7
|
import { getSyncQueue } from "@open-mercato/core/modules/data_sync/lib/queue";
|
|
7
8
|
import {
|
|
@@ -62,13 +63,21 @@ async function POST(req) {
|
|
|
62
63
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
63
64
|
}
|
|
64
65
|
const container = await createRequestContainer();
|
|
65
|
-
const em = container.resolve("em");
|
|
66
|
-
const progressService = container.resolve("progressService");
|
|
67
66
|
const scope = {
|
|
68
67
|
organizationId: auth.orgId,
|
|
69
68
|
tenantId: auth.tenantId,
|
|
70
69
|
userId: auth.sub
|
|
71
70
|
};
|
|
71
|
+
const integrationStateService = container.resolve("integrationStateService");
|
|
72
|
+
if (!await integrationStateService.isEnabled("sync_akeneo", scope)) {
|
|
73
|
+
const { t } = await resolveTranslations();
|
|
74
|
+
return NextResponse.json(
|
|
75
|
+
{ ok: false, error: t("sync_akeneo.firstImport.integrationDisabled"), code: "integrationDisabled" },
|
|
76
|
+
{ status: 409 }
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const em = container.resolve("em");
|
|
80
|
+
const progressService = container.resolve("progressService");
|
|
72
81
|
const [activeJob] = await findWithDecryption(
|
|
73
82
|
em,
|
|
74
83
|
ProgressJob,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/sync_akeneo/api/first-import/route.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { ProgressJob } from '@open-mercato/core/modules/progress/data/entities'\nimport type { ProgressService } from '@open-mercato/core/modules/progress/lib/progressService'\nimport { getSyncQueue } from '@open-mercato/core/modules/data_sync/lib/queue'\nimport type { SyncRunService } from '@open-mercato/core/modules/data_sync/lib/sync-run-service'\nimport {\n AKENEO_FIRST_IMPORT_QUEUE,\n getAkeneoFirstImportStatus,\n} from '../../lib/first-import'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n POST: { requireAuth: true, requireFeatures: ['data_sync.run'] },\n}\n\nexport const openApi = {\n GET: {\n tags: ['Akeneo'],\n summary: 'Get the current Akeneo first-import sequence status',\n },\n POST: {\n tags: ['Akeneo'],\n summary: 'Start the first full Akeneo import sequence',\n },\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 syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const status = await getAkeneoFirstImportStatus({\n container,\n scope: {\n organizationId: auth.orgId,\n tenantId: auth.tenantId,\n },\n })\n const completedProductRuns = await syncRunService.listRuns(\n {\n integrationId: 'sync_akeneo',\n entityType: 'products',\n direction: 'import',\n status: 'completed',\n page: 1,\n pageSize: 1,\n },\n {\n organizationId: auth.orgId,\n tenantId: auth.tenantId,\n },\n )\n\n return NextResponse.json({\n ok: true,\n sequence: status,\n hasCompletedProductImport: completedProductRuns.total > 0,\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 container = await createRequestContainer()\n const
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { ProgressJob } from '@open-mercato/core/modules/progress/data/entities'\nimport type { ProgressService } from '@open-mercato/core/modules/progress/lib/progressService'\nimport type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport { getSyncQueue } from '@open-mercato/core/modules/data_sync/lib/queue'\nimport type { SyncRunService } from '@open-mercato/core/modules/data_sync/lib/sync-run-service'\nimport {\n AKENEO_FIRST_IMPORT_QUEUE,\n getAkeneoFirstImportStatus,\n} from '../../lib/first-import'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n POST: { requireAuth: true, requireFeatures: ['data_sync.run'] },\n}\n\nexport const openApi = {\n GET: {\n tags: ['Akeneo'],\n summary: 'Get the current Akeneo first-import sequence status',\n },\n POST: {\n tags: ['Akeneo'],\n summary: 'Start the first full Akeneo import sequence',\n },\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 syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const status = await getAkeneoFirstImportStatus({\n container,\n scope: {\n organizationId: auth.orgId,\n tenantId: auth.tenantId,\n },\n })\n const completedProductRuns = await syncRunService.listRuns(\n {\n integrationId: 'sync_akeneo',\n entityType: 'products',\n direction: 'import',\n status: 'completed',\n page: 1,\n pageSize: 1,\n },\n {\n organizationId: auth.orgId,\n tenantId: auth.tenantId,\n },\n )\n\n return NextResponse.json({\n ok: true,\n sequence: status,\n hasCompletedProductImport: completedProductRuns.total > 0,\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 container = await createRequestContainer()\n const scope = {\n organizationId: auth.orgId,\n tenantId: auth.tenantId,\n userId: auth.sub,\n }\n const integrationStateService = container.resolve<IntegrationStateService>('integrationStateService')\n if (!(await integrationStateService.isEnabled('sync_akeneo', scope))) {\n const { t } = await resolveTranslations()\n return NextResponse.json(\n { ok: false, error: t('sync_akeneo.firstImport.integrationDisabled'), code: 'integrationDisabled' },\n { status: 409 },\n )\n }\n\n const em = container.resolve('em') as EntityManager\n const progressService = container.resolve('progressService') as ProgressService\n const [activeJob] = await findWithDecryption(\n em,\n ProgressJob,\n {\n jobType: 'sync_akeneo.first_import',\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n status: { $in: ['pending', 'running'] },\n },\n {\n limit: 1,\n orderBy: { createdAt: 'DESC' },\n },\n scope,\n )\n\n if (activeJob) {\n return NextResponse.json(\n {\n ok: false,\n error: 'The first full Akeneo import is already running.',\n },\n { status: 409 },\n )\n }\n\n const progressJob = await progressService.createJob(\n {\n jobType: 'sync_akeneo.first_import',\n name: 'Akeneo first full import',\n description: 'Categories, attributes, then products',\n totalCount: 3,\n cancellable: false,\n meta: {\n integrationId: 'sync_akeneo',\n workflow: 'first_import',\n hiddenFromTopBar: true,\n currentStep: null,\n currentRunId: null,\n },\n },\n scope,\n )\n\n const queue = getSyncQueue(AKENEO_FIRST_IMPORT_QUEUE)\n await queue.enqueue({\n progressJobId: progressJob.id,\n scope,\n })\n\n return NextResponse.json({\n ok: true,\n progressJobId: progressJob.id,\n }, { status: 202 })\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,mBAAmB;AAG5B,SAAS,oBAAoB;AAE7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEA,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,qBAAqB,EAAE;AAAA,EACnE,MAAM,EAAE,aAAa,MAAM,iBAAiB,CAAC,eAAe,EAAE;AAChE;AAEO,MAAM,UAAU;AAAA,EACrB,KAAK;AAAA,IACH,MAAM,CAAC,QAAQ;AAAA,IACf,SAAS;AAAA,EACX;AAAA,EACA,MAAM;A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EAAE,QAAQ,IAAI,CAAC;AACpB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
2
|
+
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
2
3
|
import { buildListResumeCursor, buildProductResumeCursor, parseCursor } from "./cursor.js";
|
|
3
4
|
import { createAkeneoClient } from "./client.js";
|
|
4
5
|
import { createAkeneoImporter } from "./catalog-importer.js";
|
|
@@ -55,6 +56,12 @@ const akeneoDataSyncAdapter = {
|
|
|
55
56
|
},
|
|
56
57
|
async *streamImport(input) {
|
|
57
58
|
const entityType = assertEntityType(input.entityType);
|
|
59
|
+
const container = await createRequestContainer();
|
|
60
|
+
const integrationStateService = container.resolve("integrationStateService");
|
|
61
|
+
if (!await integrationStateService.isEnabled("sync_akeneo", input.scope)) {
|
|
62
|
+
const { t } = await resolveTranslations();
|
|
63
|
+
throw new Error(t("data_sync.errors.integrationDisabled"));
|
|
64
|
+
}
|
|
58
65
|
const mapping = normalizeAkeneoMapping(entityType, input.mapping);
|
|
59
66
|
const client = createAkeneoClient(input.credentials);
|
|
60
67
|
const importer = await createAkeneoImporter(client, input.scope);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sync_akeneo/lib/adapter.ts"],
|
|
4
|
-
"sourcesContent": ["import { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { DataSyncAdapter, DataMapping, ImportBatch, ImportItem, ValidationResult } from '@open-mercato/core/modules/data_sync/lib/adapter'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { buildListResumeCursor, buildProductResumeCursor, parseCursor } from './cursor'\nimport { createAkeneoClient } from './client'\nimport { createAkeneoImporter } from './catalog-importer'\nimport { loadAkeneoMapping } from './mapping'\nimport { buildDefaultReconciliationSettings, normalizeAkeneoMapping, type AkeneoEntityType, type AkeneoDataMapping } from './shared'\n\nfunction assertEntityType(entityType: string): AkeneoEntityType {\n if (entityType === 'categories' || entityType === 'attributes' || entityType === 'products') {\n return entityType\n }\n throw new Error(`Unsupported Akeneo entity type: ${entityType}`)\n}\n\nasync function resolveMapping(entityType: AkeneoEntityType, scope: { organizationId: string; tenantId: string }): Promise<AkeneoDataMapping> {\n const container = await createRequestContainer()\n const em = container.resolve('em') as EntityManager\n return loadAkeneoMapping(em, entityType, scope)\n}\n\nexport const akeneoDataSyncAdapter: DataSyncAdapter = {\n providerKey: 'akeneo',\n direction: 'import',\n supportedEntities: ['categories', 'attributes', 'products'],\n\n async getMapping(input): Promise<DataMapping> {\n const entityType = assertEntityType(input.entityType)\n return resolveMapping(entityType, input.scope)\n },\n\n async validateConnection(input): Promise<ValidationResult> {\n try {\n const entityType = assertEntityType(input.entityType)\n const client = createAkeneoClient(input.credentials)\n if (entityType === 'products') {\n await client.listProducts({ batchSize: 1 })\n } else if (entityType === 'categories') {\n await client.listCategories(null, 1)\n } else {\n await client.listFamilies(null, 1)\n }\n\n const discovery = await client.collectDiscoveryData().catch(() => null)\n return {\n ok: true,\n message: 'Akeneo connection validated successfully',\n details: discovery\n ? {\n locales: discovery.locales.length,\n channels: discovery.channels.length,\n attributes: discovery.attributes.length,\n families: discovery.families.length,\n version: discovery.version,\n }\n : undefined,\n }\n } catch (error) {\n return {\n ok: false,\n message: error instanceof Error ? error.message : 'Akeneo validation failed',\n }\n }\n },\n\n async *streamImport(input): AsyncIterable<ImportBatch> {\n const entityType = assertEntityType(input.entityType)\n const mapping = normalizeAkeneoMapping(entityType, input.mapping as unknown as Record<string, unknown>)\n const client = createAkeneoClient(input.credentials)\n const importer = await createAkeneoImporter(client, input.scope)\n\n if (entityType === 'categories') {\n let batchIndex = 0\n let nextUrl = parseCursor(input.cursor)?.nextUrl ?? null\n const safeFullSync = !input.cursor\n const seenCategoryIds = new Set<string>()\n const reconciliation = buildDefaultReconciliationSettings()\n do {\n const page = await client.listCategories(nextUrl, input.batchSize)\n const items: ImportItem[] = []\n const locale = mapping.settings?.categories?.locale ?? 'en_US'\n for (const category of page.items) {\n // Above the yield, so an abandoned page is never yielded and its cursor never committed.\n // Returning here also skips the `safeFullSync` reconcile below, which is required: a\n // partial walk has not seen every category, so reconciling would delete live records.\n if (input.signal?.aborted) return\n seenCategoryIds.add(category.code)\n const result = await importer.upsertCategory(category, locale)\n items.push({\n externalId: category.code,\n data: {\n localId: result.localId,\n code: category.code,\n parent: category.parent ?? null,\n },\n action: result.action,\n })\n }\n nextUrl = page.nextUrl\n yield {\n items,\n cursor: buildListResumeCursor(nextUrl),\n hasMore: Boolean(nextUrl),\n totalEstimate: page.totalEstimate ?? undefined,\n processedCount: page.items.length,\n batchIndex,\n }\n batchIndex += 1\n } while (nextUrl)\n if (safeFullSync) {\n const locale = mapping.settings?.categories?.locale ?? 'en_US'\n await importer.reconcileCategories(seenCategoryIds, locale, reconciliation)\n }\n return\n }\n\n if (entityType === 'attributes') {\n const productMapping = await resolveMapping('products', input.scope)\n let batchIndex = 0\n let nextUrl = parseCursor(input.cursor)?.nextUrl ?? null\n const safeFullSync = !input.cursor\n const seenFamilyIds = new Set<string>()\n const reconciliation = buildDefaultReconciliationSettings()\n const locale = productMapping.settings?.products?.locale\n ?? mapping.settings?.categories?.locale\n ?? 'en_US'\n const customFieldItems = await importer.syncMappedCustomFields(productMapping, locale)\n const currentCustomFieldKeys = new Set(\n customFieldItems\n .map((item) => {\n const key = typeof item.data.key === 'string' ? item.data.key : null\n const target = item.data.target === 'variant' ? 'catalog:catalog_product_variant' : item.data.target === 'product' ? 'catalog:catalog_product' : null\n return key && target ? `${target}:${key}` : null\n })\n .filter((value): value is string => Boolean(value)),\n )\n do {\n const page = await client.listFamilies(nextUrl, input.batchSize)\n const items: ImportItem[] = []\n const includeTextAttributes = mapping.settings?.attributes?.includeTextAttributes ?? true\n const includeNumericAttributes = mapping.settings?.attributes?.includeNumericAttributes ?? true\n const familyFilter = mapping.settings?.attributes?.familyCodeFilter ?? []\n if (batchIndex === 0) {\n customFieldItems.forEach((item) => {\n items.push(item)\n })\n }\n for (const family of page.items) {\n // Above the yield \u2014 see the categories walk. Returning also skips the reconcile, which a\n // partial walk must not run.\n if (input.signal?.aborted) return\n if (familyFilter.length > 0 && !familyFilter.includes(family.code)) continue\n seenFamilyIds.add(family.code)\n const result = await importer.upsertAttributeFamily(\n family,\n locale,\n includeTextAttributes,\n includeNumericAttributes,\n )\n if (!result) continue\n items.push({\n externalId: family.code,\n data: {\n localId: result.localId,\n familyCode: family.code,\n },\n action: result.action,\n })\n }\n nextUrl = page.nextUrl\n yield {\n items,\n cursor: buildListResumeCursor(nextUrl),\n hasMore: Boolean(nextUrl),\n totalEstimate: page.totalEstimate ?? undefined,\n processedCount: page.items.length,\n batchIndex,\n }\n batchIndex += 1\n } while (nextUrl)\n if (safeFullSync) {\n await importer.reconcileMappedCustomFieldFieldsets(productMapping)\n await importer.reconcileAttributes({\n seenFamilyExternalIds: seenFamilyIds,\n currentCustomFieldKeys,\n reconciliation,\n })\n }\n return\n }\n\n let batchIndex = 0\n const currentCursor = parseCursor(input.cursor)\n let nextUrl = currentCursor?.nextUrl ?? null\n let updatedAfter = currentCursor?.updatedAfter ?? null\n let maxUpdatedAt = currentCursor?.maxUpdatedAt ?? updatedAfter\n const safeFullSync = !input.cursor\n const seenProductExternalIds = new Set<string>()\n const seenVariantExternalIds = new Set<string>()\n const reconciliation = mapping.settings?.products?.reconciliation ?? buildDefaultReconciliationSettings()\n\n do {\n const productPageSize = Math.min(Math.max(input.batchSize, 1), 10)\n const page = await client.listProducts({\n nextUrl,\n batchSize: productPageSize,\n updatedAfter,\n })\n\n const items: ImportItem[] = []\n for (const product of page.items) {\n // Above the yield \u2014 see the categories walk. Returning also skips the reconcile, which a\n // partial walk must not run.\n if (input.signal?.aborted) return\n try {\n const imported = await importer.upsertProduct(product, mapping)\n for (const item of imported) {\n if (item.data.localProductId) seenProductExternalIds.add(item.externalId)\n if (item.data.localVariantId) seenVariantExternalIds.add(item.externalId)\n items.push(item)\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Akeneo product import failed'\n items.push({\n externalId: product.parent ? `${product.parent}:${product.uuid}` : product.uuid,\n action: 'failed',\n data: {\n errorMessage: message,\n sourceProductUuid: product.uuid,\n sourceIdentifier: product.identifier ?? null,\n sourceParentCode: product.parent ?? null,\n family: product.family ?? null,\n },\n })\n }\n if (typeof product.updated === 'string' && (!maxUpdatedAt || product.updated > maxUpdatedAt)) {\n maxUpdatedAt = product.updated\n }\n }\n\n nextUrl = page.nextUrl\n const nextCursor = nextUrl\n ? buildProductResumeCursor({\n updatedAfter,\n nextUrl,\n maxUpdatedAt,\n })\n : buildProductResumeCursor({\n updatedAfter: maxUpdatedAt ?? updatedAfter,\n nextUrl: null,\n maxUpdatedAt: null,\n })\n\n yield {\n items,\n cursor: nextCursor,\n hasMore: Boolean(nextUrl),\n totalEstimate: page.totalEstimate ?? undefined,\n processedCount: page.items.length,\n refreshCoverageEntityTypes: [\n 'catalog:catalog_product',\n 'catalog:catalog_product_variant',\n ],\n batchIndex,\n }\n batchIndex += 1\n\n if (!nextUrl && maxUpdatedAt) {\n updatedAfter = maxUpdatedAt\n }\n } while (nextUrl)\n\n if (safeFullSync) {\n yield {\n items: [],\n cursor: buildProductResumeCursor({\n updatedAfter: maxUpdatedAt ?? updatedAfter,\n nextUrl: null,\n maxUpdatedAt: null,\n }),\n hasMore: false,\n totalEstimate: undefined,\n processedCount: 0,\n message: 'Reconciling imported Akeneo products after the final batch',\n batchIndex,\n }\n await importer.reconcileMappedCustomFieldFieldsets(mapping)\n await importer.reconcileProducts(seenProductExternalIds, seenVariantExternalIds, reconciliation)\n }\n },\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,8BAA8B;
|
|
4
|
+
"sourcesContent": ["import { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport type { DataSyncAdapter, DataMapping, ImportBatch, ImportItem, ValidationResult } from '@open-mercato/core/modules/data_sync/lib/adapter'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { buildListResumeCursor, buildProductResumeCursor, parseCursor } from './cursor'\nimport { createAkeneoClient } from './client'\nimport { createAkeneoImporter } from './catalog-importer'\nimport { loadAkeneoMapping } from './mapping'\nimport { buildDefaultReconciliationSettings, normalizeAkeneoMapping, type AkeneoEntityType, type AkeneoDataMapping } from './shared'\n\nfunction assertEntityType(entityType: string): AkeneoEntityType {\n if (entityType === 'categories' || entityType === 'attributes' || entityType === 'products') {\n return entityType\n }\n throw new Error(`Unsupported Akeneo entity type: ${entityType}`)\n}\n\nasync function resolveMapping(entityType: AkeneoEntityType, scope: { organizationId: string; tenantId: string }): Promise<AkeneoDataMapping> {\n const container = await createRequestContainer()\n const em = container.resolve('em') as EntityManager\n return loadAkeneoMapping(em, entityType, scope)\n}\n\nexport const akeneoDataSyncAdapter: DataSyncAdapter = {\n providerKey: 'akeneo',\n direction: 'import',\n supportedEntities: ['categories', 'attributes', 'products'],\n\n async getMapping(input): Promise<DataMapping> {\n const entityType = assertEntityType(input.entityType)\n return resolveMapping(entityType, input.scope)\n },\n\n async validateConnection(input): Promise<ValidationResult> {\n try {\n const entityType = assertEntityType(input.entityType)\n const client = createAkeneoClient(input.credentials)\n if (entityType === 'products') {\n await client.listProducts({ batchSize: 1 })\n } else if (entityType === 'categories') {\n await client.listCategories(null, 1)\n } else {\n await client.listFamilies(null, 1)\n }\n\n const discovery = await client.collectDiscoveryData().catch(() => null)\n return {\n ok: true,\n message: 'Akeneo connection validated successfully',\n details: discovery\n ? {\n locales: discovery.locales.length,\n channels: discovery.channels.length,\n attributes: discovery.attributes.length,\n families: discovery.families.length,\n version: discovery.version,\n }\n : undefined,\n }\n } catch (error) {\n return {\n ok: false,\n message: error instanceof Error ? error.message : 'Akeneo validation failed',\n }\n }\n },\n\n async *streamImport(input): AsyncIterable<ImportBatch> {\n const entityType = assertEntityType(input.entityType)\n const container = await createRequestContainer()\n const integrationStateService = container.resolve<IntegrationStateService>('integrationStateService')\n if (!(await integrationStateService.isEnabled('sync_akeneo', input.scope))) {\n const { t } = await resolveTranslations()\n throw new Error(t('data_sync.errors.integrationDisabled'))\n }\n\n const mapping = normalizeAkeneoMapping(entityType, input.mapping as unknown as Record<string, unknown>)\n const client = createAkeneoClient(input.credentials)\n const importer = await createAkeneoImporter(client, input.scope)\n\n if (entityType === 'categories') {\n let batchIndex = 0\n let nextUrl = parseCursor(input.cursor)?.nextUrl ?? null\n const safeFullSync = !input.cursor\n const seenCategoryIds = new Set<string>()\n const reconciliation = buildDefaultReconciliationSettings()\n do {\n const page = await client.listCategories(nextUrl, input.batchSize)\n const items: ImportItem[] = []\n const locale = mapping.settings?.categories?.locale ?? 'en_US'\n for (const category of page.items) {\n // Above the yield, so an abandoned page is never yielded and its cursor never committed.\n // Returning here also skips the `safeFullSync` reconcile below, which is required: a\n // partial walk has not seen every category, so reconciling would delete live records.\n if (input.signal?.aborted) return\n seenCategoryIds.add(category.code)\n const result = await importer.upsertCategory(category, locale)\n items.push({\n externalId: category.code,\n data: {\n localId: result.localId,\n code: category.code,\n parent: category.parent ?? null,\n },\n action: result.action,\n })\n }\n nextUrl = page.nextUrl\n yield {\n items,\n cursor: buildListResumeCursor(nextUrl),\n hasMore: Boolean(nextUrl),\n totalEstimate: page.totalEstimate ?? undefined,\n processedCount: page.items.length,\n batchIndex,\n }\n batchIndex += 1\n } while (nextUrl)\n if (safeFullSync) {\n const locale = mapping.settings?.categories?.locale ?? 'en_US'\n await importer.reconcileCategories(seenCategoryIds, locale, reconciliation)\n }\n return\n }\n\n if (entityType === 'attributes') {\n const productMapping = await resolveMapping('products', input.scope)\n let batchIndex = 0\n let nextUrl = parseCursor(input.cursor)?.nextUrl ?? null\n const safeFullSync = !input.cursor\n const seenFamilyIds = new Set<string>()\n const reconciliation = buildDefaultReconciliationSettings()\n const locale = productMapping.settings?.products?.locale\n ?? mapping.settings?.categories?.locale\n ?? 'en_US'\n const customFieldItems = await importer.syncMappedCustomFields(productMapping, locale)\n const currentCustomFieldKeys = new Set(\n customFieldItems\n .map((item) => {\n const key = typeof item.data.key === 'string' ? item.data.key : null\n const target = item.data.target === 'variant' ? 'catalog:catalog_product_variant' : item.data.target === 'product' ? 'catalog:catalog_product' : null\n return key && target ? `${target}:${key}` : null\n })\n .filter((value): value is string => Boolean(value)),\n )\n do {\n const page = await client.listFamilies(nextUrl, input.batchSize)\n const items: ImportItem[] = []\n const includeTextAttributes = mapping.settings?.attributes?.includeTextAttributes ?? true\n const includeNumericAttributes = mapping.settings?.attributes?.includeNumericAttributes ?? true\n const familyFilter = mapping.settings?.attributes?.familyCodeFilter ?? []\n if (batchIndex === 0) {\n customFieldItems.forEach((item) => {\n items.push(item)\n })\n }\n for (const family of page.items) {\n // Above the yield \u2014 see the categories walk. Returning also skips the reconcile, which a\n // partial walk must not run.\n if (input.signal?.aborted) return\n if (familyFilter.length > 0 && !familyFilter.includes(family.code)) continue\n seenFamilyIds.add(family.code)\n const result = await importer.upsertAttributeFamily(\n family,\n locale,\n includeTextAttributes,\n includeNumericAttributes,\n )\n if (!result) continue\n items.push({\n externalId: family.code,\n data: {\n localId: result.localId,\n familyCode: family.code,\n },\n action: result.action,\n })\n }\n nextUrl = page.nextUrl\n yield {\n items,\n cursor: buildListResumeCursor(nextUrl),\n hasMore: Boolean(nextUrl),\n totalEstimate: page.totalEstimate ?? undefined,\n processedCount: page.items.length,\n batchIndex,\n }\n batchIndex += 1\n } while (nextUrl)\n if (safeFullSync) {\n await importer.reconcileMappedCustomFieldFieldsets(productMapping)\n await importer.reconcileAttributes({\n seenFamilyExternalIds: seenFamilyIds,\n currentCustomFieldKeys,\n reconciliation,\n })\n }\n return\n }\n\n let batchIndex = 0\n const currentCursor = parseCursor(input.cursor)\n let nextUrl = currentCursor?.nextUrl ?? null\n let updatedAfter = currentCursor?.updatedAfter ?? null\n let maxUpdatedAt = currentCursor?.maxUpdatedAt ?? updatedAfter\n const safeFullSync = !input.cursor\n const seenProductExternalIds = new Set<string>()\n const seenVariantExternalIds = new Set<string>()\n const reconciliation = mapping.settings?.products?.reconciliation ?? buildDefaultReconciliationSettings()\n\n do {\n const productPageSize = Math.min(Math.max(input.batchSize, 1), 10)\n const page = await client.listProducts({\n nextUrl,\n batchSize: productPageSize,\n updatedAfter,\n })\n\n const items: ImportItem[] = []\n for (const product of page.items) {\n // Above the yield \u2014 see the categories walk. Returning also skips the reconcile, which a\n // partial walk must not run.\n if (input.signal?.aborted) return\n try {\n const imported = await importer.upsertProduct(product, mapping)\n for (const item of imported) {\n if (item.data.localProductId) seenProductExternalIds.add(item.externalId)\n if (item.data.localVariantId) seenVariantExternalIds.add(item.externalId)\n items.push(item)\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Akeneo product import failed'\n items.push({\n externalId: product.parent ? `${product.parent}:${product.uuid}` : product.uuid,\n action: 'failed',\n data: {\n errorMessage: message,\n sourceProductUuid: product.uuid,\n sourceIdentifier: product.identifier ?? null,\n sourceParentCode: product.parent ?? null,\n family: product.family ?? null,\n },\n })\n }\n if (typeof product.updated === 'string' && (!maxUpdatedAt || product.updated > maxUpdatedAt)) {\n maxUpdatedAt = product.updated\n }\n }\n\n nextUrl = page.nextUrl\n const nextCursor = nextUrl\n ? buildProductResumeCursor({\n updatedAfter,\n nextUrl,\n maxUpdatedAt,\n })\n : buildProductResumeCursor({\n updatedAfter: maxUpdatedAt ?? updatedAfter,\n nextUrl: null,\n maxUpdatedAt: null,\n })\n\n yield {\n items,\n cursor: nextCursor,\n hasMore: Boolean(nextUrl),\n totalEstimate: page.totalEstimate ?? undefined,\n processedCount: page.items.length,\n refreshCoverageEntityTypes: [\n 'catalog:catalog_product',\n 'catalog:catalog_product_variant',\n ],\n batchIndex,\n }\n batchIndex += 1\n\n if (!nextUrl && maxUpdatedAt) {\n updatedAfter = maxUpdatedAt\n }\n } while (nextUrl)\n\n if (safeFullSync) {\n yield {\n items: [],\n cursor: buildProductResumeCursor({\n updatedAfter: maxUpdatedAt ?? updatedAfter,\n nextUrl: null,\n maxUpdatedAt: null,\n }),\n hasMore: false,\n totalEstimate: undefined,\n processedCount: 0,\n message: 'Reconciling imported Akeneo products after the final batch',\n batchIndex,\n }\n await importer.reconcileMappedCustomFieldFieldsets(mapping)\n await importer.reconcileProducts(seenProductExternalIds, seenVariantExternalIds, reconciliation)\n }\n },\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AAIpC,SAAS,uBAAuB,0BAA0B,mBAAmB;AAC7E,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,oCAAoC,8BAA6E;AAE1H,SAAS,iBAAiB,YAAsC;AAC9D,MAAI,eAAe,gBAAgB,eAAe,gBAAgB,eAAe,YAAY;AAC3F,WAAO;AAAA,EACT;AACA,QAAM,IAAI,MAAM,mCAAmC,UAAU,EAAE;AACjE;AAEA,eAAe,eAAe,YAA8B,OAAiF;AAC3I,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,KAAK,UAAU,QAAQ,IAAI;AACjC,SAAO,kBAAkB,IAAI,YAAY,KAAK;AAChD;AAEO,MAAM,wBAAyC;AAAA,EACpD,aAAa;AAAA,EACb,WAAW;AAAA,EACX,mBAAmB,CAAC,cAAc,cAAc,UAAU;AAAA,EAE1D,MAAM,WAAW,OAA6B;AAC5C,UAAM,aAAa,iBAAiB,MAAM,UAAU;AACpD,WAAO,eAAe,YAAY,MAAM,KAAK;AAAA,EAC/C;AAAA,EAEA,MAAM,mBAAmB,OAAkC;AACzD,QAAI;AACF,YAAM,aAAa,iBAAiB,MAAM,UAAU;AACpD,YAAM,SAAS,mBAAmB,MAAM,WAAW;AACnD,UAAI,eAAe,YAAY;AAC7B,cAAM,OAAO,aAAa,EAAE,WAAW,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,wBAAwB,wBAAwB,cAAc;AAAA,IACjG;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["batchIndex", "nextUrl", "safeFullSync", "reconciliation"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
2
|
import { findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
3
|
+
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
3
4
|
import { ProgressJob } from "@open-mercato/core/modules/progress/data/entities";
|
|
4
5
|
import { startDataSyncRun } from "@open-mercato/core/modules/data_sync/lib/start-run";
|
|
5
6
|
const AKENEO_FIRST_IMPORT_QUEUE = "sync-akeneo-first-import";
|
|
@@ -76,6 +77,7 @@ async function runAkeneoFirstImportSequence(params) {
|
|
|
76
77
|
const em = container.resolve("em");
|
|
77
78
|
const progressService = container.resolve("progressService");
|
|
78
79
|
const syncRunService = container.resolve("dataSyncRunService");
|
|
80
|
+
const integrationStateService = container.resolve("integrationStateService");
|
|
79
81
|
const progressContext = buildProgressContext(scope);
|
|
80
82
|
await progressService.startJob(progressJobId, progressContext);
|
|
81
83
|
await progressService.updateProgress(
|
|
@@ -88,6 +90,15 @@ async function runAkeneoFirstImportSequence(params) {
|
|
|
88
90
|
progressContext
|
|
89
91
|
);
|
|
90
92
|
for (const [stepIndex, entityType] of FIRST_IMPORT_STEPS.entries()) {
|
|
93
|
+
if (!await integrationStateService.isEnabled("sync_akeneo", scope)) {
|
|
94
|
+
const { t } = await resolveTranslations();
|
|
95
|
+
await progressService.failJob(
|
|
96
|
+
progressJobId,
|
|
97
|
+
{ errorMessage: t("sync_akeneo.firstImport.integrationDisabled") },
|
|
98
|
+
progressContext
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
91
102
|
const overlap = await syncRunService.findRunningOverlap("sync_akeneo", entityType, "import", scope);
|
|
92
103
|
const run = overlap ?? (await startDataSyncRun({
|
|
93
104
|
syncRunService,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sync_akeneo/lib/first-import.ts"],
|
|
4
|
-
"sourcesContent": ["import { setTimeout as sleep } from 'node:timers/promises'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { AwilixContainer } from 'awilix'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { ProgressJob } from '@open-mercato/core/modules/progress/data/entities'\nimport type { ProgressService, ProgressServiceContext } from '@open-mercato/core/modules/progress/lib/progressService'\nimport type { SyncRunService } from '@open-mercato/core/modules/data_sync/lib/sync-run-service'\nimport { startDataSyncRun } from '@open-mercato/core/modules/data_sync/lib/start-run'\n\nexport const AKENEO_FIRST_IMPORT_QUEUE = 'sync-akeneo-first-import'\n\nconst FIRST_IMPORT_STEPS = ['categories', 'attributes', 'products'] as const\n\ntype FirstImportStep = (typeof FIRST_IMPORT_STEPS)[number]\n\nexport type AkeneoFirstImportScope = {\n organizationId: string\n tenantId: string\n userId?: string | null\n}\n\nexport type AkeneoFirstImportJobPayload = {\n progressJobId: string\n scope: AkeneoFirstImportScope\n}\n\nexport type FirstImportSequenceStatus = {\n progressJobId: string\n status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled'\n currentStep: FirstImportStep | null\n currentRunId: string | null\n currentRunProgressJobId: string | null\n currentRunStatus: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | null\n progressPercent: number | null\n processedCount: number | null\n totalCount: number | null\n errorMessage: string | null\n}\n\nfunction buildProgressContext(scope: AkeneoFirstImportScope): ProgressServiceContext {\n return {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n userId: scope.userId,\n }\n}\n\nfunction buildSequenceMeta(input?: Partial<{\n currentStep: FirstImportStep | null\n currentRunId: string | null\n currentRunProgressJobId: string | null\n currentRunStatus: string | null\n currentRunProgressPercent: number | null\n currentRunProcessedCount: number | null\n currentRunTotalCount: number | null\n}>): Record<string, unknown> {\n return {\n integrationId: 'sync_akeneo',\n workflow: 'first_import',\n hiddenFromTopBar: true,\n currentStep: input?.currentStep ?? null,\n currentRunId: input?.currentRunId ?? null,\n currentRunProgressJobId: input?.currentRunProgressJobId ?? null,\n currentRunStatus: input?.currentRunStatus ?? null,\n currentRunProgressPercent: input?.currentRunProgressPercent ?? null,\n currentRunProcessedCount: input?.currentRunProcessedCount ?? null,\n currentRunTotalCount: input?.currentRunTotalCount ?? null,\n }\n}\n\nfunction readString(value: unknown): string | null {\n return typeof value === 'string' && value.trim().length > 0 ? value : null\n}\n\nfunction readNumber(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null\n}\n\nfunction buildSequenceStatus(job: ProgressJob): FirstImportSequenceStatus {\n const meta = (job.meta && typeof job.meta === 'object') ? job.meta : null\n const currentStep = readString(meta?.currentStep)\n const currentRunStatus = readString(meta?.currentRunStatus)\n return {\n progressJobId: job.id,\n status: job.status,\n currentStep: currentStep === 'categories' || currentStep === 'attributes' || currentStep === 'products'\n ? currentStep\n : null,\n currentRunId: readString(meta?.currentRunId),\n currentRunProgressJobId: readString(meta?.currentRunProgressJobId),\n currentRunStatus: currentRunStatus === 'pending'\n || currentRunStatus === 'running'\n || currentRunStatus === 'completed'\n || currentRunStatus === 'failed'\n || currentRunStatus === 'cancelled'\n ? currentRunStatus\n : null,\n progressPercent: readNumber(meta?.currentRunProgressPercent),\n processedCount: readNumber(meta?.currentRunProcessedCount),\n totalCount: readNumber(meta?.currentRunTotalCount),\n errorMessage: job.errorMessage ?? null,\n }\n}\n\nexport async function findLatestAkeneoFirstImportJob(\n em: EntityManager,\n scope: Pick<AkeneoFirstImportScope, 'organizationId' | 'tenantId'>,\n): Promise<ProgressJob | null> {\n const [job] = await findWithDecryption(\n em,\n ProgressJob,\n {\n jobType: 'sync_akeneo.first_import',\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n status: { $in: ['pending', 'running', 'failed'] },\n },\n {\n limit: 1,\n orderBy: { createdAt: 'DESC' },\n },\n scope,\n )\n\n return job ?? null\n}\n\nexport async function getAkeneoFirstImportStatus(params: {\n container: AwilixContainer\n scope: Pick<AkeneoFirstImportScope, 'organizationId' | 'tenantId'>\n}): Promise<FirstImportSequenceStatus | null> {\n const em = params.container.resolve('em') as EntityManager\n const job = await findLatestAkeneoFirstImportJob(em, params.scope)\n return job ? buildSequenceStatus(job) : null\n}\n\nexport async function runAkeneoFirstImportSequence(params: {\n container: AwilixContainer\n progressJobId: string\n scope: AkeneoFirstImportScope\n}): Promise<void> {\n const { container, progressJobId, scope } = params\n const em = container.resolve('em') as EntityManager\n const progressService = container.resolve('progressService') as ProgressService\n const syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const progressContext = buildProgressContext(scope)\n\n await progressService.startJob(progressJobId, progressContext)\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: 0,\n meta: buildSequenceMeta(),\n },\n progressContext,\n )\n\n for (const [stepIndex, entityType] of FIRST_IMPORT_STEPS.entries()) {\n const overlap = await syncRunService.findRunningOverlap('sync_akeneo', entityType, 'import', scope)\n const run = overlap ?? (await startDataSyncRun({\n syncRunService,\n progressService,\n scope,\n input: {\n integrationId: 'sync_akeneo',\n entityType,\n direction: 'import',\n triggeredBy: scope.userId ?? null,\n },\n })).run\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: run.id,\n currentRunProgressJobId: run.progressJobId ?? null,\n currentRunStatus: run.status,\n currentRunProgressPercent: null,\n currentRunProcessedCount: 0,\n currentRunTotalCount: null,\n }),\n },\n progressContext,\n )\n\n while (true) {\n em.clear()\n const currentRun = await syncRunService.getRun(run.id, scope)\n if (!currentRun) {\n throw new Error(`Sync run ${run.id} could not be loaded`)\n }\n\n const currentRunJob = currentRun.progressJobId\n ? await progressService.getJob(currentRun.progressJobId, progressContext)\n : null\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: currentRun.id,\n currentRunProgressJobId: currentRun.progressJobId ?? null,\n currentRunStatus: currentRun.status,\n currentRunProgressPercent: currentRunJob?.totalCount ? currentRunJob.progressPercent : null,\n currentRunProcessedCount: currentRunJob?.processedCount ?? null,\n currentRunTotalCount: currentRunJob?.totalCount ?? null,\n }),\n },\n progressContext,\n )\n\n if (currentRun.status === 'completed') {\n break\n }\n\n if (currentRun.status === 'failed') {\n throw new Error(currentRun.lastError ?? `${entityType} sync failed`)\n }\n\n if (currentRun.status === 'cancelled') {\n throw new Error(`${entityType} sync was cancelled`)\n }\n\n await sleep(1500)\n }\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex + 1,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: run.id,\n currentRunProgressJobId: run.progressJobId ?? null,\n currentRunStatus: 'completed',\n currentRunProgressPercent: 100,\n currentRunProcessedCount: null,\n currentRunTotalCount: null,\n }),\n },\n progressContext,\n )\n }\n\n await progressService.completeJob(\n progressJobId,\n {\n resultSummary: {\n message: 'The first full Akeneo import finished successfully.',\n },\n },\n progressContext,\n )\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,cAAc,aAAa;AAGpC,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import { setTimeout as sleep } from 'node:timers/promises'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { AwilixContainer } from 'awilix'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { ProgressJob } from '@open-mercato/core/modules/progress/data/entities'\nimport type { ProgressService, ProgressServiceContext } from '@open-mercato/core/modules/progress/lib/progressService'\nimport type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport type { SyncRunService } from '@open-mercato/core/modules/data_sync/lib/sync-run-service'\nimport { startDataSyncRun } from '@open-mercato/core/modules/data_sync/lib/start-run'\n\nexport const AKENEO_FIRST_IMPORT_QUEUE = 'sync-akeneo-first-import'\n\nconst FIRST_IMPORT_STEPS = ['categories', 'attributes', 'products'] as const\n\ntype FirstImportStep = (typeof FIRST_IMPORT_STEPS)[number]\n\nexport type AkeneoFirstImportScope = {\n organizationId: string\n tenantId: string\n userId?: string | null\n}\n\nexport type AkeneoFirstImportJobPayload = {\n progressJobId: string\n scope: AkeneoFirstImportScope\n}\n\nexport type FirstImportSequenceStatus = {\n progressJobId: string\n status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled'\n currentStep: FirstImportStep | null\n currentRunId: string | null\n currentRunProgressJobId: string | null\n currentRunStatus: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | null\n progressPercent: number | null\n processedCount: number | null\n totalCount: number | null\n errorMessage: string | null\n}\n\nfunction buildProgressContext(scope: AkeneoFirstImportScope): ProgressServiceContext {\n return {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n userId: scope.userId,\n }\n}\n\nfunction buildSequenceMeta(input?: Partial<{\n currentStep: FirstImportStep | null\n currentRunId: string | null\n currentRunProgressJobId: string | null\n currentRunStatus: string | null\n currentRunProgressPercent: number | null\n currentRunProcessedCount: number | null\n currentRunTotalCount: number | null\n}>): Record<string, unknown> {\n return {\n integrationId: 'sync_akeneo',\n workflow: 'first_import',\n hiddenFromTopBar: true,\n currentStep: input?.currentStep ?? null,\n currentRunId: input?.currentRunId ?? null,\n currentRunProgressJobId: input?.currentRunProgressJobId ?? null,\n currentRunStatus: input?.currentRunStatus ?? null,\n currentRunProgressPercent: input?.currentRunProgressPercent ?? null,\n currentRunProcessedCount: input?.currentRunProcessedCount ?? null,\n currentRunTotalCount: input?.currentRunTotalCount ?? null,\n }\n}\n\nfunction readString(value: unknown): string | null {\n return typeof value === 'string' && value.trim().length > 0 ? value : null\n}\n\nfunction readNumber(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null\n}\n\nfunction buildSequenceStatus(job: ProgressJob): FirstImportSequenceStatus {\n const meta = (job.meta && typeof job.meta === 'object') ? job.meta : null\n const currentStep = readString(meta?.currentStep)\n const currentRunStatus = readString(meta?.currentRunStatus)\n return {\n progressJobId: job.id,\n status: job.status,\n currentStep: currentStep === 'categories' || currentStep === 'attributes' || currentStep === 'products'\n ? currentStep\n : null,\n currentRunId: readString(meta?.currentRunId),\n currentRunProgressJobId: readString(meta?.currentRunProgressJobId),\n currentRunStatus: currentRunStatus === 'pending'\n || currentRunStatus === 'running'\n || currentRunStatus === 'completed'\n || currentRunStatus === 'failed'\n || currentRunStatus === 'cancelled'\n ? currentRunStatus\n : null,\n progressPercent: readNumber(meta?.currentRunProgressPercent),\n processedCount: readNumber(meta?.currentRunProcessedCount),\n totalCount: readNumber(meta?.currentRunTotalCount),\n errorMessage: job.errorMessage ?? null,\n }\n}\n\nexport async function findLatestAkeneoFirstImportJob(\n em: EntityManager,\n scope: Pick<AkeneoFirstImportScope, 'organizationId' | 'tenantId'>,\n): Promise<ProgressJob | null> {\n const [job] = await findWithDecryption(\n em,\n ProgressJob,\n {\n jobType: 'sync_akeneo.first_import',\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n status: { $in: ['pending', 'running', 'failed'] },\n },\n {\n limit: 1,\n orderBy: { createdAt: 'DESC' },\n },\n scope,\n )\n\n return job ?? null\n}\n\nexport async function getAkeneoFirstImportStatus(params: {\n container: AwilixContainer\n scope: Pick<AkeneoFirstImportScope, 'organizationId' | 'tenantId'>\n}): Promise<FirstImportSequenceStatus | null> {\n const em = params.container.resolve('em') as EntityManager\n const job = await findLatestAkeneoFirstImportJob(em, params.scope)\n return job ? buildSequenceStatus(job) : null\n}\n\nexport async function runAkeneoFirstImportSequence(params: {\n container: AwilixContainer\n progressJobId: string\n scope: AkeneoFirstImportScope\n}): Promise<void> {\n const { container, progressJobId, scope } = params\n const em = container.resolve('em') as EntityManager\n const progressService = container.resolve('progressService') as ProgressService\n const syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const integrationStateService = container.resolve<IntegrationStateService>('integrationStateService')\n const progressContext = buildProgressContext(scope)\n\n await progressService.startJob(progressJobId, progressContext)\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: 0,\n meta: buildSequenceMeta(),\n },\n progressContext,\n )\n\n for (const [stepIndex, entityType] of FIRST_IMPORT_STEPS.entries()) {\n if (!(await integrationStateService.isEnabled('sync_akeneo', scope))) {\n const { t } = await resolveTranslations()\n await progressService.failJob(\n progressJobId,\n { errorMessage: t('sync_akeneo.firstImport.integrationDisabled') },\n progressContext,\n )\n return\n }\n\n const overlap = await syncRunService.findRunningOverlap('sync_akeneo', entityType, 'import', scope)\n const run = overlap ?? (await startDataSyncRun({\n syncRunService,\n progressService,\n scope,\n input: {\n integrationId: 'sync_akeneo',\n entityType,\n direction: 'import',\n triggeredBy: scope.userId ?? null,\n },\n })).run\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: run.id,\n currentRunProgressJobId: run.progressJobId ?? null,\n currentRunStatus: run.status,\n currentRunProgressPercent: null,\n currentRunProcessedCount: 0,\n currentRunTotalCount: null,\n }),\n },\n progressContext,\n )\n\n while (true) {\n em.clear()\n const currentRun = await syncRunService.getRun(run.id, scope)\n if (!currentRun) {\n throw new Error(`Sync run ${run.id} could not be loaded`)\n }\n\n const currentRunJob = currentRun.progressJobId\n ? await progressService.getJob(currentRun.progressJobId, progressContext)\n : null\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: currentRun.id,\n currentRunProgressJobId: currentRun.progressJobId ?? null,\n currentRunStatus: currentRun.status,\n currentRunProgressPercent: currentRunJob?.totalCount ? currentRunJob.progressPercent : null,\n currentRunProcessedCount: currentRunJob?.processedCount ?? null,\n currentRunTotalCount: currentRunJob?.totalCount ?? null,\n }),\n },\n progressContext,\n )\n\n if (currentRun.status === 'completed') {\n break\n }\n\n if (currentRun.status === 'failed') {\n throw new Error(currentRun.lastError ?? `${entityType} sync failed`)\n }\n\n if (currentRun.status === 'cancelled') {\n throw new Error(`${entityType} sync was cancelled`)\n }\n\n await sleep(1500)\n }\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex + 1,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: run.id,\n currentRunProgressJobId: run.progressJobId ?? null,\n currentRunStatus: 'completed',\n currentRunProgressPercent: 100,\n currentRunProcessedCount: null,\n currentRunTotalCount: null,\n }),\n },\n progressContext,\n )\n }\n\n await progressService.completeJob(\n progressJobId,\n {\n resultSummary: {\n message: 'The first full Akeneo import finished successfully.',\n },\n },\n progressContext,\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc,aAAa;AAGpC,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,mBAAmB;AAI5B,SAAS,wBAAwB;AAE1B,MAAM,4BAA4B;AAEzC,MAAM,qBAAqB,CAAC,cAAc,cAAc,UAAU;AA4BlE,SAAS,qBAAqB,OAAuD;AACnF,SAAO;AAAA,IACL,UAAU,MAAM;AAAA,IAChB,gBAAgB,MAAM;AAAA,IACtB,QAAQ,MAAM;AAAA,EAChB;AACF;AAEA,SAAS,kBAAkB,OAQE;AAC3B,SAAO;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,IACV,kBAAkB;AAAA,IAClB,aAAa,OAAO,eAAe;AAAA,IACnC,cAAc,OAAO,gBAAgB;AAAA,IACrC,yBA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W,WAAW,aAAa;AACrC,cAAM,IAAI,MAAM,GAAG,UAAU,qBAAqB;AAAA,MACpD;AAEA,YAAM,MAAM,IAAI;AAAA,IAClB;AAEA,UAAM,gBAAgB;AAAA,MACpB;AAAA,MACA;AAAA,QACE,YAAY,mBAAmB;AAAA,QAC/B,gBAAgB,YAAY;AAAA,QAC5B,MAAM,kBAAkB;AAAA,UACtB,aAAa;AAAA,UACb,cAAc,IAAI;AAAA,UAClB,yBAAyB,IAAI,iBAAiB;AAAA,UAC9C,kBAAkB;AAAA,UAClB,2BAA2B;AAAA,UAC3B,0BAA0B;AAAA,UAC1B,sBAAsB;AAAA,QACxB,CAAC;AAAA,MACH;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,MACE,eAAe;AAAA,QACb,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -570,7 +570,7 @@ function AkeneoConfigWidget({ context, data }) {
|
|
|
570
570
|
method: "POST"
|
|
571
571
|
});
|
|
572
572
|
if (!result.ok) {
|
|
573
|
-
if (result.status === 409) {
|
|
573
|
+
if (result.status === 409 && result.result?.code !== "integrationDisabled") {
|
|
574
574
|
await loadFirstImportStatus();
|
|
575
575
|
return;
|
|
576
576
|
}
|