@open-mercato/sync-akeneo 0.11.1-develop.9114.1.e26ee64834 → 0.11.1-develop.9117.1.64991d6651
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.
|
@@ -2,6 +2,9 @@ import { parseBooleanToken } from "@open-mercato/shared/lib/boolean";
|
|
|
2
2
|
import { findOneWithDecryption, findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
3
3
|
import { CatalogPriceKind } from "@open-mercato/core/modules/catalog/data/entities";
|
|
4
4
|
import { SyncMapping } from "@open-mercato/core/modules/data_sync/data/entities";
|
|
5
|
+
import {
|
|
6
|
+
inspectStoredCredentials
|
|
7
|
+
} from "@open-mercato/core/modules/integrations/lib/credentials-service";
|
|
5
8
|
import { SalesChannel } from "@open-mercato/core/modules/sales/data/entities";
|
|
6
9
|
import { areSalesChannelsAvailable } from "./salesChannelsAvailability.js";
|
|
7
10
|
import { createAkeneoClient } from "./client.js";
|
|
@@ -308,7 +311,7 @@ async function upsertSyncMapping(em, entityType, mapping, scope) {
|
|
|
308
311
|
}
|
|
309
312
|
async function hasExistingAkeneoConfiguration(em, credentialsService, scope) {
|
|
310
313
|
const [credentials, mappings] = await Promise.all([
|
|
311
|
-
credentialsService
|
|
314
|
+
inspectStoredCredentials(credentialsService, AKENEO_INTEGRATION_ID, scope, { via: "getRaw" }),
|
|
312
315
|
findOneWithDecryption(em, SyncMapping, {
|
|
313
316
|
integrationId: AKENEO_INTEGRATION_ID,
|
|
314
317
|
organizationId: scope.organizationId,
|
|
@@ -317,7 +320,7 @@ async function hasExistingAkeneoConfiguration(em, credentialsService, scope) {
|
|
|
317
320
|
fields: ["id"]
|
|
318
321
|
}, scope)
|
|
319
322
|
]);
|
|
320
|
-
return
|
|
323
|
+
return credentials.state !== "absent" || Boolean(mappings);
|
|
321
324
|
}
|
|
322
325
|
async function applyAkeneoEnvPreset(params) {
|
|
323
326
|
const preset = readAkeneoEnvPreset(params.env);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sync_akeneo/lib/preset.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\nimport { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { CatalogPriceKind } from '@open-mercato/core/modules/catalog/data/entities'\nimport { SyncMapping } from '@open-mercato/core/modules/data_sync/data/entities'\nimport type { CredentialsService } from '@open-mercato/core/modules/integrations/lib/credentials-service'\nimport type { IntegrationLogService } from '@open-mercato/core/modules/integrations/lib/log-service'\nimport type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport { SalesChannel } from '@open-mercato/core/modules/sales/data/entities'\nimport { areSalesChannelsAvailable } from './salesChannelsAvailability'\nimport { createAkeneoClient } from './client'\nimport { inferAkeneoProductMapping } from './inference'\nimport {\n buildAkeneoFieldsetCode,\n buildDefaultAkeneoMapping,\n buildProductFieldMappings,\n normalizeAkeneoMapping,\n type AkeneoCredentialShape,\n} from './shared'\n\nconst AKENEO_INTEGRATION_ID = 'sync_akeneo'\n\ntype IntegrationScope = {\n organizationId: string\n tenantId: string\n}\n\ntype LocalChannelOption = {\n code: string\n name: string\n}\n\ntype PriceKindOption = {\n code: string\n title: string\n displayMode: string\n}\n\ntype DiscoverySnapshot = {\n locales: Array<{ code: string; label: string; enabled?: boolean }>\n channels: Array<{ code: string; label: string; locales: string[] }>\n attributes: Array<{\n code: string\n type: string\n label: string\n localizable: boolean\n scopable: boolean\n group?: string\n metricFamily?: string\n }>\n families: Array<{ code: string; label: string; attributeCount: number }>\n familyVariants: Array<{ familyCode: string; code: string; label: string; axes: string[]; attributes: string[] }>\n}\n\ntype AkeneoEnvPreset = {\n credentials: AkeneoCredentialShape\n force: boolean\n productLocale?: string\n categoryLocale?: string\n productChannel?: string | null\n productChannels?: string[]\n importAllChannels?: boolean\n createMissingChannels?: boolean\n syncAssociations?: boolean\n familyCodeFilter?: string[]\n productsSettingsOverride?: Record<string, unknown>\n categoriesSettingsOverride?: Record<string, unknown>\n attributesSettingsOverride?: Record<string, unknown>\n}\n\nexport type ApplyAkeneoPresetResult =\n | { status: 'skipped'; reason: string }\n | { status: 'configured'; discoveryApplied: true }\n\nfunction readEnvValue(env: NodeJS.ProcessEnv, keys: string[]): string | undefined {\n for (const key of keys) {\n const value = env[key]?.trim()\n if (value) return value\n }\n return undefined\n}\n\nfunction readCsvEnv(env: NodeJS.ProcessEnv, keys: string[]): string[] | undefined {\n const raw = readEnvValue(env, keys)\n if (!raw) return undefined\n const values = raw\n .split(',')\n .map((value) => value.trim())\n .filter((value) => value.length > 0)\n return values.length > 0 ? Array.from(new Set(values)) : undefined\n}\n\nfunction readBooleanEnv(env: NodeJS.ProcessEnv, keys: string[]): boolean | undefined {\n for (const key of keys) {\n const parsed = parseBooleanToken(env[key])\n if (parsed !== null) return parsed\n }\n return undefined\n}\n\nfunction readJsonEnv(env: NodeJS.ProcessEnv, keys: string[], label: string): Record<string, unknown> | undefined {\n const raw = readEnvValue(env, keys)\n if (!raw) return undefined\n let parsed: unknown\n try {\n parsed = JSON.parse(raw)\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Invalid JSON'\n throw new Error(`[sync_akeneo] ${label} is not valid JSON: ${message}`)\n }\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new Error(`[sync_akeneo] ${label} must be a JSON object.`)\n }\n return parsed as Record<string, unknown>\n}\n\nexport function readAkeneoEnvPreset(env: NodeJS.ProcessEnv = process.env): AkeneoEnvPreset | null {\n const credentialKeys = {\n apiUrl: ['OM_INTEGRATION_AKENEO_API_URL', 'OPENMERCATO_AKENEO_API_URL', 'AKENEO_API_URL'],\n clientId: ['OM_INTEGRATION_AKENEO_CLIENT_ID', 'OPENMERCATO_AKENEO_CLIENT_ID', 'AKENEO_CLIENT_ID'],\n clientSecret: ['OM_INTEGRATION_AKENEO_CLIENT_SECRET', 'OPENMERCATO_AKENEO_CLIENT_SECRET', 'AKENEO_CLIENT_SECRET'],\n username: ['OM_INTEGRATION_AKENEO_USERNAME', 'OPENMERCATO_AKENEO_USERNAME', 'AKENEO_USERNAME'],\n password: ['OM_INTEGRATION_AKENEO_PASSWORD', 'OPENMERCATO_AKENEO_PASSWORD', 'AKENEO_PASSWORD'],\n } as const\n\n const anyCredentialProvided = Object.values(credentialKeys).some((keys) => Boolean(readEnvValue(env, [...keys])))\n if (!anyCredentialProvided) {\n return null\n }\n\n const apiUrl = readEnvValue(env, [...credentialKeys.apiUrl])\n const clientId = readEnvValue(env, [...credentialKeys.clientId])\n const clientSecret = readEnvValue(env, [...credentialKeys.clientSecret])\n const username = readEnvValue(env, [...credentialKeys.username])\n const password = readEnvValue(env, [...credentialKeys.password])\n\n if (!apiUrl || !clientId || !clientSecret || !username || !password) {\n throw new Error(\n '[sync_akeneo] Incomplete Akeneo env preset. Set OM_INTEGRATION_AKENEO_API_URL, OM_INTEGRATION_AKENEO_CLIENT_ID, OM_INTEGRATION_AKENEO_CLIENT_SECRET, OM_INTEGRATION_AKENEO_USERNAME, and OM_INTEGRATION_AKENEO_PASSWORD.',\n )\n }\n\n return {\n credentials: {\n apiUrl,\n clientId,\n clientSecret,\n username,\n password,\n },\n force: readBooleanEnv(env, ['OM_INTEGRATION_AKENEO_FORCE_PRECONFIGURE', 'OPENMERCATO_AKENEO_FORCE_PRECONFIGURE', 'AKENEO_FORCE_PRECONFIGURE']) ?? false,\n productLocale: readEnvValue(env, ['OM_INTEGRATION_AKENEO_PRODUCT_LOCALE', 'OPENMERCATO_AKENEO_PRODUCT_LOCALE', 'AKENEO_PRODUCT_LOCALE']),\n categoryLocale: readEnvValue(env, ['OM_INTEGRATION_AKENEO_CATEGORY_LOCALE', 'OPENMERCATO_AKENEO_CATEGORY_LOCALE', 'AKENEO_CATEGORY_LOCALE']),\n productChannel: readEnvValue(env, ['OM_INTEGRATION_AKENEO_PRODUCT_CHANNEL', 'OPENMERCATO_AKENEO_PRODUCT_CHANNEL', 'AKENEO_PRODUCT_CHANNEL']) ?? undefined,\n productChannels: readCsvEnv(env, ['OM_INTEGRATION_AKENEO_IMPORT_CHANNELS', 'OPENMERCATO_AKENEO_IMPORT_CHANNELS', 'AKENEO_IMPORT_CHANNELS']),\n importAllChannels: readBooleanEnv(env, ['OM_INTEGRATION_AKENEO_IMPORT_ALL_CHANNELS', 'OPENMERCATO_AKENEO_IMPORT_ALL_CHANNELS', 'AKENEO_IMPORT_ALL_CHANNELS']),\n createMissingChannels: readBooleanEnv(env, ['OM_INTEGRATION_AKENEO_CREATE_MISSING_CHANNELS', 'OPENMERCATO_AKENEO_CREATE_MISSING_CHANNELS', 'AKENEO_CREATE_MISSING_CHANNELS']),\n syncAssociations: readBooleanEnv(env, ['OM_INTEGRATION_AKENEO_SYNC_ASSOCIATIONS', 'OPENMERCATO_AKENEO_SYNC_ASSOCIATIONS', 'AKENEO_SYNC_ASSOCIATIONS']),\n familyCodeFilter: readCsvEnv(env, ['OM_INTEGRATION_AKENEO_ATTRIBUTE_FAMILY_FILTER', 'OPENMERCATO_AKENEO_ATTRIBUTE_FAMILY_FILTER', 'AKENEO_ATTRIBUTE_FAMILY_FILTER']),\n productsSettingsOverride: readJsonEnv(\n env,\n ['OM_INTEGRATION_AKENEO_PRODUCTS_SETTINGS_JSON', 'OPENMERCATO_AKENEO_PRODUCTS_SETTINGS_JSON', 'AKENEO_PRODUCTS_SETTINGS_JSON'],\n 'OM_INTEGRATION_AKENEO_PRODUCTS_SETTINGS_JSON',\n ),\n categoriesSettingsOverride: readJsonEnv(\n env,\n ['OM_INTEGRATION_AKENEO_CATEGORIES_SETTINGS_JSON', 'OPENMERCATO_AKENEO_CATEGORIES_SETTINGS_JSON', 'AKENEO_CATEGORIES_SETTINGS_JSON'],\n 'OM_INTEGRATION_AKENEO_CATEGORIES_SETTINGS_JSON',\n ),\n attributesSettingsOverride: readJsonEnv(\n env,\n ['OM_INTEGRATION_AKENEO_ATTRIBUTES_SETTINGS_JSON', 'OPENMERCATO_AKENEO_ATTRIBUTES_SETTINGS_JSON', 'AKENEO_ATTRIBUTES_SETTINGS_JSON'],\n 'OM_INTEGRATION_AKENEO_ATTRIBUTES_SETTINGS_JSON',\n ),\n }\n}\n\nfunction inferPriceKindCode(attributeCode: string): string {\n const normalized = attributeCode.trim().toLowerCase()\n return normalized.includes('sale')\n || normalized.includes('promo')\n || normalized.includes('special')\n || normalized.includes('discount')\n ? 'sale'\n : 'regular'\n}\n\nfunction buildDiscoveredFieldsetMappings(discovery: DiscoverySnapshot): Array<{\n sourceType: 'family' | 'familyVariant'\n sourceCode: string\n target: 'product' | 'variant'\n fieldsetCode: string\n fieldsetLabel: string\n description: string\n}> {\n const familyRows = discovery.families.flatMap((family) => {\n const fieldsetCode = buildAkeneoFieldsetCode('product', family.code)\n if (!fieldsetCode) return []\n return [{\n sourceType: 'family' as const,\n sourceCode: family.code,\n target: 'product' as const,\n fieldsetCode,\n fieldsetLabel: family.label || family.code,\n description: `Akeneo family ${family.code}`,\n }]\n })\n\n const familyVariantRows = discovery.familyVariants.flatMap((familyVariant) => {\n const fieldsetCode = buildAkeneoFieldsetCode('variant', familyVariant.code)\n if (!fieldsetCode) return []\n return [{\n sourceType: 'familyVariant' as const,\n sourceCode: familyVariant.code,\n target: 'variant' as const,\n fieldsetCode,\n fieldsetLabel: familyVariant.label || familyVariant.code,\n description: `Akeneo family variant ${familyVariant.code} from family ${familyVariant.familyCode}`,\n }]\n })\n\n return [...familyRows, ...familyVariantRows]\n}\n\nexport function buildAkeneoMappingsFromPreset(input: {\n preset: AkeneoEnvPreset\n discovery: DiscoverySnapshot\n localChannels: LocalChannelOption[]\n priceKinds: PriceKindOption[]\n}): {\n productsMapping: ReturnType<typeof buildDefaultAkeneoMapping>\n categoriesMapping: ReturnType<typeof buildDefaultAkeneoMapping>\n attributesMapping: ReturnType<typeof buildDefaultAkeneoMapping>\n} {\n const { preset, discovery, localChannels, priceKinds } = input\n const baseProducts = buildDefaultAkeneoMapping('products')\n const productSettings = baseProducts.settings?.products\n if (!productSettings) {\n throw new Error('[sync_akeneo] Failed to resolve default product mapping settings.')\n }\n\n const discoveredFamilyVariant = discovery.familyVariants.length > 0\n ? {\n code: '__discovery__',\n variant_attribute_sets: discovery.familyVariants.map((familyVariant, index) => ({\n level: index + 1,\n axes: familyVariant.axes,\n attributes: familyVariant.attributes,\n })),\n }\n : null\n\n const inferred = inferAkeneoProductMapping({\n attributes: discovery.attributes.map((attribute) => ({\n code: attribute.code,\n type: attribute.type,\n labels: attribute.label ? { inferred: attribute.label } : undefined,\n localizable: attribute.localizable,\n scopable: attribute.scopable,\n group: attribute.group,\n metric_family: attribute.metricFamily,\n })),\n family: null,\n familyVariant: discoveredFamilyVariant,\n fieldMap: productSettings.fieldMap,\n explicitCustomFieldMappings: [],\n explicitMediaMappings: [],\n })\n\n const preferredLocale = preset.productLocale\n ?? productSettings.locale\n ?? discovery.locales.find((locale) => locale.enabled)?.code\n ?? discovery.locales[0]?.code\n const preferredAkeneoChannel = preset.productChannel\n ?? discovery.channels[0]?.code\n ?? productSettings.channel\n const preferredLocalChannel = localChannels.find((channel) => ['web', 'online', 'ecommerce', 'default'].includes(channel.code.trim().toLowerCase()))\n ?? localChannels[0]\n ?? null\n const selectedChannels = preset.productChannels\n ?? (preferredAkeneoChannel ? [preferredAkeneoChannel] : [])\n\n const discoveredPriceMappings = preferredLocalChannel\n ? inferred.autoPriceAttributeCodes.map((attributeCode) => {\n const inferredKind = inferPriceKindCode(attributeCode)\n const matchedPriceKind = priceKinds.find((priceKind) => priceKind.code === inferredKind)\n return {\n attributeCode,\n priceKindCode: matchedPriceKind?.code ?? inferredKind,\n akeneoChannel: preferredAkeneoChannel ?? null,\n localChannelCode: preferredLocalChannel.code,\n }\n })\n : []\n\n const productsOverride = preset.productsSettingsOverride ?? {}\n const overrideFieldMap = productsOverride.fieldMap && typeof productsOverride.fieldMap === 'object' && !Array.isArray(productsOverride.fieldMap)\n ? productsOverride.fieldMap as Record<string, unknown>\n : null\n const overrideReconciliation = productsOverride.reconciliation && typeof productsOverride.reconciliation === 'object' && !Array.isArray(productsOverride.reconciliation)\n ? productsOverride.reconciliation as Record<string, unknown>\n : null\n const {\n fieldMap: _ignoredFieldMap,\n reconciliation: _ignoredReconciliation,\n ...productsOverrideShallow\n } = productsOverride\n\n const rawProductsMapping = {\n ...baseProducts,\n settings: {\n products: {\n ...productSettings,\n locale: preferredLocale,\n channel: preferredAkeneoChannel ?? null,\n channels: selectedChannels,\n importAllChannels: preset.importAllChannels ?? productSettings.importAllChannels,\n customFieldMappings: inferred.autoCustomFieldMappings.map((mapping) => ({\n attributeCode: mapping.attributeCode,\n target: mapping.target,\n fieldKey: mapping.fieldKey,\n kind: mapping.kind ?? null,\n skip: mapping.skip ?? false,\n })),\n mediaMappings: inferred.autoMediaMappings.map((mapping) => ({\n attributeCode: mapping.attributeCode,\n target: mapping.target,\n kind: mapping.kind,\n })),\n priceMappings: discoveredPriceMappings,\n fieldsetMappings: buildDiscoveredFieldsetMappings(discovery),\n createMissingChannels: preset.createMissingChannels ?? productSettings.createMissingChannels,\n syncAssociations: preset.syncAssociations ?? productSettings.syncAssociations,\n ...productsOverrideShallow,\n fieldMap: {\n ...inferred.fieldMap,\n ...(overrideFieldMap ?? {}),\n },\n reconciliation: {\n ...productSettings.reconciliation,\n ...(overrideReconciliation ?? {}),\n },\n },\n },\n }\n const productsMapping = normalizeAkeneoMapping('products', rawProductsMapping as Record<string, unknown>)\n if (productsMapping.settings?.products) {\n productsMapping.fields = buildProductFieldMappings(productsMapping.settings.products)\n }\n\n const baseCategories = buildDefaultAkeneoMapping('categories')\n const categoriesMapping = normalizeAkeneoMapping('categories', {\n ...baseCategories,\n settings: {\n categories: {\n locale: preset.categoryLocale ?? preferredLocale,\n ...(preset.categoriesSettingsOverride ?? {}),\n },\n },\n })\n\n const baseAttributes = buildDefaultAkeneoMapping('attributes')\n const attributesMapping = normalizeAkeneoMapping('attributes', {\n ...baseAttributes,\n settings: {\n attributes: {\n ...baseAttributes.settings?.attributes,\n familyCodeFilter: preset.familyCodeFilter ?? baseAttributes.settings?.attributes?.familyCodeFilter ?? [],\n ...(preset.attributesSettingsOverride ?? {}),\n },\n },\n })\n\n return {\n productsMapping,\n categoriesMapping,\n attributesMapping,\n }\n}\n\nasync function loadLocalDiscoveryContext(em: EntityManager, scope: IntegrationScope): Promise<{\n localChannels: LocalChannelOption[]\n priceKinds: PriceKindOption[]\n}> {\n const [channels, priceKinds] = await Promise.all([\n areSalesChannelsAvailable(em)\n ? findWithDecryption(em, SalesChannel, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n isActive: true,\n }, {\n fields: ['code', 'name'],\n orderBy: { name: 'asc' },\n }, scope)\n : Promise.resolve<SalesChannel[]>([]),\n findWithDecryption(em, CatalogPriceKind, {\n tenantId: scope.tenantId,\n deletedAt: null,\n isActive: true,\n }, {\n fields: ['code', 'title', 'displayMode'],\n orderBy: { title: 'asc' },\n }, scope),\n ])\n\n return {\n localChannels: channels\n .filter((channel) => typeof channel.code === 'string' && channel.code.trim().length > 0)\n .map((channel) => ({ code: String(channel.code), name: channel.name })),\n priceKinds: priceKinds.map((priceKind) => ({\n code: priceKind.code,\n title: priceKind.title,\n displayMode: priceKind.displayMode,\n })),\n }\n}\n\nasync function upsertSyncMapping(\n em: EntityManager,\n entityType: 'products' | 'categories' | 'attributes',\n mapping: Record<string, unknown>,\n scope: IntegrationScope,\n): Promise<void> {\n const existing = await findOneWithDecryption(em, SyncMapping, {\n integrationId: AKENEO_INTEGRATION_ID,\n entityType,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n }, undefined, scope)\n\n if (existing) {\n existing.mapping = mapping\n await em.flush()\n return\n }\n\n const created = em.create(SyncMapping, {\n integrationId: AKENEO_INTEGRATION_ID,\n entityType,\n mapping,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n })\n await em.persist(created).flush()\n}\n\nasync function hasExistingAkeneoConfiguration(\n em: EntityManager,\n credentialsService: CredentialsService,\n scope: IntegrationScope,\n): Promise<boolean> {\n const [credentials, mappings] = await Promise.all([\n credentialsService.getRaw(AKENEO_INTEGRATION_ID, scope),\n findOneWithDecryption(em, SyncMapping, {\n integrationId: AKENEO_INTEGRATION_ID,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n }, {\n fields: ['id'],\n }, scope),\n ])\n return Boolean(credentials) || Boolean(mappings)\n}\n\nexport async function applyAkeneoEnvPreset(params: {\n em: EntityManager\n credentialsService: CredentialsService\n integrationStateService: IntegrationStateService\n integrationLogService?: IntegrationLogService\n scope: IntegrationScope\n force?: boolean\n env?: NodeJS.ProcessEnv\n}): Promise<ApplyAkeneoPresetResult> {\n const preset = readAkeneoEnvPreset(params.env)\n if (!preset) {\n return { status: 'skipped', reason: 'No Akeneo preset env variables were provided.' }\n }\n\n const force = params.force ?? preset.force\n if (!force && await hasExistingAkeneoConfiguration(params.em, params.credentialsService, params.scope)) {\n return { status: 'skipped', reason: 'Akeneo credentials or mappings already exist. Use force to overwrite them.' }\n }\n\n await params.credentialsService.save(AKENEO_INTEGRATION_ID, preset.credentials, params.scope)\n\n const client = createAkeneoClient(preset.credentials)\n const [discovery, localContext] = await Promise.all([\n client.collectDiscoveryData(),\n loadLocalDiscoveryContext(params.em, params.scope),\n ])\n\n const mappings = buildAkeneoMappingsFromPreset({\n preset,\n discovery,\n localChannels: localContext.localChannels,\n priceKinds: localContext.priceKinds,\n })\n\n await upsertSyncMapping(params.em, 'products', mappings.productsMapping as unknown as Record<string, unknown>, params.scope)\n await upsertSyncMapping(params.em, 'categories', mappings.categoriesMapping as unknown as Record<string, unknown>, params.scope)\n await upsertSyncMapping(params.em, 'attributes', mappings.attributesMapping as unknown as Record<string, unknown>, params.scope)\n await params.integrationStateService.upsert(AKENEO_INTEGRATION_ID, { isEnabled: true }, params.scope)\n\n if (params.integrationLogService) {\n await params.integrationLogService.scoped(AKENEO_INTEGRATION_ID, params.scope).info(\n 'Akeneo integration was preconfigured from environment variables.',\n {\n locale: mappings.productsMapping.settings?.products?.locale ?? null,\n channel: mappings.productsMapping.settings?.products?.channel ?? null,\n importAllChannels: mappings.productsMapping.settings?.products?.importAllChannels ?? null,\n },\n )\n }\n\n return { status: 'configured', discoveryApplied: true }\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\nimport { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { CatalogPriceKind } from '@open-mercato/core/modules/catalog/data/entities'\nimport { SyncMapping } from '@open-mercato/core/modules/data_sync/data/entities'\nimport {\n inspectStoredCredentials,\n type CredentialsService,\n} from '@open-mercato/core/modules/integrations/lib/credentials-service'\nimport type { IntegrationLogService } from '@open-mercato/core/modules/integrations/lib/log-service'\nimport type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport { SalesChannel } from '@open-mercato/core/modules/sales/data/entities'\nimport { areSalesChannelsAvailable } from './salesChannelsAvailability'\nimport { createAkeneoClient } from './client'\nimport { inferAkeneoProductMapping } from './inference'\nimport {\n buildAkeneoFieldsetCode,\n buildDefaultAkeneoMapping,\n buildProductFieldMappings,\n normalizeAkeneoMapping,\n type AkeneoCredentialShape,\n} from './shared'\n\nconst AKENEO_INTEGRATION_ID = 'sync_akeneo'\n\ntype IntegrationScope = {\n organizationId: string\n tenantId: string\n}\n\ntype LocalChannelOption = {\n code: string\n name: string\n}\n\ntype PriceKindOption = {\n code: string\n title: string\n displayMode: string\n}\n\ntype DiscoverySnapshot = {\n locales: Array<{ code: string; label: string; enabled?: boolean }>\n channels: Array<{ code: string; label: string; locales: string[] }>\n attributes: Array<{\n code: string\n type: string\n label: string\n localizable: boolean\n scopable: boolean\n group?: string\n metricFamily?: string\n }>\n families: Array<{ code: string; label: string; attributeCount: number }>\n familyVariants: Array<{ familyCode: string; code: string; label: string; axes: string[]; attributes: string[] }>\n}\n\ntype AkeneoEnvPreset = {\n credentials: AkeneoCredentialShape\n force: boolean\n productLocale?: string\n categoryLocale?: string\n productChannel?: string | null\n productChannels?: string[]\n importAllChannels?: boolean\n createMissingChannels?: boolean\n syncAssociations?: boolean\n familyCodeFilter?: string[]\n productsSettingsOverride?: Record<string, unknown>\n categoriesSettingsOverride?: Record<string, unknown>\n attributesSettingsOverride?: Record<string, unknown>\n}\n\nexport type ApplyAkeneoPresetResult =\n | { status: 'skipped'; reason: string }\n | { status: 'configured'; discoveryApplied: true }\n\nfunction readEnvValue(env: NodeJS.ProcessEnv, keys: string[]): string | undefined {\n for (const key of keys) {\n const value = env[key]?.trim()\n if (value) return value\n }\n return undefined\n}\n\nfunction readCsvEnv(env: NodeJS.ProcessEnv, keys: string[]): string[] | undefined {\n const raw = readEnvValue(env, keys)\n if (!raw) return undefined\n const values = raw\n .split(',')\n .map((value) => value.trim())\n .filter((value) => value.length > 0)\n return values.length > 0 ? Array.from(new Set(values)) : undefined\n}\n\nfunction readBooleanEnv(env: NodeJS.ProcessEnv, keys: string[]): boolean | undefined {\n for (const key of keys) {\n const parsed = parseBooleanToken(env[key])\n if (parsed !== null) return parsed\n }\n return undefined\n}\n\nfunction readJsonEnv(env: NodeJS.ProcessEnv, keys: string[], label: string): Record<string, unknown> | undefined {\n const raw = readEnvValue(env, keys)\n if (!raw) return undefined\n let parsed: unknown\n try {\n parsed = JSON.parse(raw)\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Invalid JSON'\n throw new Error(`[sync_akeneo] ${label} is not valid JSON: ${message}`)\n }\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new Error(`[sync_akeneo] ${label} must be a JSON object.`)\n }\n return parsed as Record<string, unknown>\n}\n\nexport function readAkeneoEnvPreset(env: NodeJS.ProcessEnv = process.env): AkeneoEnvPreset | null {\n const credentialKeys = {\n apiUrl: ['OM_INTEGRATION_AKENEO_API_URL', 'OPENMERCATO_AKENEO_API_URL', 'AKENEO_API_URL'],\n clientId: ['OM_INTEGRATION_AKENEO_CLIENT_ID', 'OPENMERCATO_AKENEO_CLIENT_ID', 'AKENEO_CLIENT_ID'],\n clientSecret: ['OM_INTEGRATION_AKENEO_CLIENT_SECRET', 'OPENMERCATO_AKENEO_CLIENT_SECRET', 'AKENEO_CLIENT_SECRET'],\n username: ['OM_INTEGRATION_AKENEO_USERNAME', 'OPENMERCATO_AKENEO_USERNAME', 'AKENEO_USERNAME'],\n password: ['OM_INTEGRATION_AKENEO_PASSWORD', 'OPENMERCATO_AKENEO_PASSWORD', 'AKENEO_PASSWORD'],\n } as const\n\n const anyCredentialProvided = Object.values(credentialKeys).some((keys) => Boolean(readEnvValue(env, [...keys])))\n if (!anyCredentialProvided) {\n return null\n }\n\n const apiUrl = readEnvValue(env, [...credentialKeys.apiUrl])\n const clientId = readEnvValue(env, [...credentialKeys.clientId])\n const clientSecret = readEnvValue(env, [...credentialKeys.clientSecret])\n const username = readEnvValue(env, [...credentialKeys.username])\n const password = readEnvValue(env, [...credentialKeys.password])\n\n if (!apiUrl || !clientId || !clientSecret || !username || !password) {\n throw new Error(\n '[sync_akeneo] Incomplete Akeneo env preset. Set OM_INTEGRATION_AKENEO_API_URL, OM_INTEGRATION_AKENEO_CLIENT_ID, OM_INTEGRATION_AKENEO_CLIENT_SECRET, OM_INTEGRATION_AKENEO_USERNAME, and OM_INTEGRATION_AKENEO_PASSWORD.',\n )\n }\n\n return {\n credentials: {\n apiUrl,\n clientId,\n clientSecret,\n username,\n password,\n },\n force: readBooleanEnv(env, ['OM_INTEGRATION_AKENEO_FORCE_PRECONFIGURE', 'OPENMERCATO_AKENEO_FORCE_PRECONFIGURE', 'AKENEO_FORCE_PRECONFIGURE']) ?? false,\n productLocale: readEnvValue(env, ['OM_INTEGRATION_AKENEO_PRODUCT_LOCALE', 'OPENMERCATO_AKENEO_PRODUCT_LOCALE', 'AKENEO_PRODUCT_LOCALE']),\n categoryLocale: readEnvValue(env, ['OM_INTEGRATION_AKENEO_CATEGORY_LOCALE', 'OPENMERCATO_AKENEO_CATEGORY_LOCALE', 'AKENEO_CATEGORY_LOCALE']),\n productChannel: readEnvValue(env, ['OM_INTEGRATION_AKENEO_PRODUCT_CHANNEL', 'OPENMERCATO_AKENEO_PRODUCT_CHANNEL', 'AKENEO_PRODUCT_CHANNEL']) ?? undefined,\n productChannels: readCsvEnv(env, ['OM_INTEGRATION_AKENEO_IMPORT_CHANNELS', 'OPENMERCATO_AKENEO_IMPORT_CHANNELS', 'AKENEO_IMPORT_CHANNELS']),\n importAllChannels: readBooleanEnv(env, ['OM_INTEGRATION_AKENEO_IMPORT_ALL_CHANNELS', 'OPENMERCATO_AKENEO_IMPORT_ALL_CHANNELS', 'AKENEO_IMPORT_ALL_CHANNELS']),\n createMissingChannels: readBooleanEnv(env, ['OM_INTEGRATION_AKENEO_CREATE_MISSING_CHANNELS', 'OPENMERCATO_AKENEO_CREATE_MISSING_CHANNELS', 'AKENEO_CREATE_MISSING_CHANNELS']),\n syncAssociations: readBooleanEnv(env, ['OM_INTEGRATION_AKENEO_SYNC_ASSOCIATIONS', 'OPENMERCATO_AKENEO_SYNC_ASSOCIATIONS', 'AKENEO_SYNC_ASSOCIATIONS']),\n familyCodeFilter: readCsvEnv(env, ['OM_INTEGRATION_AKENEO_ATTRIBUTE_FAMILY_FILTER', 'OPENMERCATO_AKENEO_ATTRIBUTE_FAMILY_FILTER', 'AKENEO_ATTRIBUTE_FAMILY_FILTER']),\n productsSettingsOverride: readJsonEnv(\n env,\n ['OM_INTEGRATION_AKENEO_PRODUCTS_SETTINGS_JSON', 'OPENMERCATO_AKENEO_PRODUCTS_SETTINGS_JSON', 'AKENEO_PRODUCTS_SETTINGS_JSON'],\n 'OM_INTEGRATION_AKENEO_PRODUCTS_SETTINGS_JSON',\n ),\n categoriesSettingsOverride: readJsonEnv(\n env,\n ['OM_INTEGRATION_AKENEO_CATEGORIES_SETTINGS_JSON', 'OPENMERCATO_AKENEO_CATEGORIES_SETTINGS_JSON', 'AKENEO_CATEGORIES_SETTINGS_JSON'],\n 'OM_INTEGRATION_AKENEO_CATEGORIES_SETTINGS_JSON',\n ),\n attributesSettingsOverride: readJsonEnv(\n env,\n ['OM_INTEGRATION_AKENEO_ATTRIBUTES_SETTINGS_JSON', 'OPENMERCATO_AKENEO_ATTRIBUTES_SETTINGS_JSON', 'AKENEO_ATTRIBUTES_SETTINGS_JSON'],\n 'OM_INTEGRATION_AKENEO_ATTRIBUTES_SETTINGS_JSON',\n ),\n }\n}\n\nfunction inferPriceKindCode(attributeCode: string): string {\n const normalized = attributeCode.trim().toLowerCase()\n return normalized.includes('sale')\n || normalized.includes('promo')\n || normalized.includes('special')\n || normalized.includes('discount')\n ? 'sale'\n : 'regular'\n}\n\nfunction buildDiscoveredFieldsetMappings(discovery: DiscoverySnapshot): Array<{\n sourceType: 'family' | 'familyVariant'\n sourceCode: string\n target: 'product' | 'variant'\n fieldsetCode: string\n fieldsetLabel: string\n description: string\n}> {\n const familyRows = discovery.families.flatMap((family) => {\n const fieldsetCode = buildAkeneoFieldsetCode('product', family.code)\n if (!fieldsetCode) return []\n return [{\n sourceType: 'family' as const,\n sourceCode: family.code,\n target: 'product' as const,\n fieldsetCode,\n fieldsetLabel: family.label || family.code,\n description: `Akeneo family ${family.code}`,\n }]\n })\n\n const familyVariantRows = discovery.familyVariants.flatMap((familyVariant) => {\n const fieldsetCode = buildAkeneoFieldsetCode('variant', familyVariant.code)\n if (!fieldsetCode) return []\n return [{\n sourceType: 'familyVariant' as const,\n sourceCode: familyVariant.code,\n target: 'variant' as const,\n fieldsetCode,\n fieldsetLabel: familyVariant.label || familyVariant.code,\n description: `Akeneo family variant ${familyVariant.code} from family ${familyVariant.familyCode}`,\n }]\n })\n\n return [...familyRows, ...familyVariantRows]\n}\n\nexport function buildAkeneoMappingsFromPreset(input: {\n preset: AkeneoEnvPreset\n discovery: DiscoverySnapshot\n localChannels: LocalChannelOption[]\n priceKinds: PriceKindOption[]\n}): {\n productsMapping: ReturnType<typeof buildDefaultAkeneoMapping>\n categoriesMapping: ReturnType<typeof buildDefaultAkeneoMapping>\n attributesMapping: ReturnType<typeof buildDefaultAkeneoMapping>\n} {\n const { preset, discovery, localChannels, priceKinds } = input\n const baseProducts = buildDefaultAkeneoMapping('products')\n const productSettings = baseProducts.settings?.products\n if (!productSettings) {\n throw new Error('[sync_akeneo] Failed to resolve default product mapping settings.')\n }\n\n const discoveredFamilyVariant = discovery.familyVariants.length > 0\n ? {\n code: '__discovery__',\n variant_attribute_sets: discovery.familyVariants.map((familyVariant, index) => ({\n level: index + 1,\n axes: familyVariant.axes,\n attributes: familyVariant.attributes,\n })),\n }\n : null\n\n const inferred = inferAkeneoProductMapping({\n attributes: discovery.attributes.map((attribute) => ({\n code: attribute.code,\n type: attribute.type,\n labels: attribute.label ? { inferred: attribute.label } : undefined,\n localizable: attribute.localizable,\n scopable: attribute.scopable,\n group: attribute.group,\n metric_family: attribute.metricFamily,\n })),\n family: null,\n familyVariant: discoveredFamilyVariant,\n fieldMap: productSettings.fieldMap,\n explicitCustomFieldMappings: [],\n explicitMediaMappings: [],\n })\n\n const preferredLocale = preset.productLocale\n ?? productSettings.locale\n ?? discovery.locales.find((locale) => locale.enabled)?.code\n ?? discovery.locales[0]?.code\n const preferredAkeneoChannel = preset.productChannel\n ?? discovery.channels[0]?.code\n ?? productSettings.channel\n const preferredLocalChannel = localChannels.find((channel) => ['web', 'online', 'ecommerce', 'default'].includes(channel.code.trim().toLowerCase()))\n ?? localChannels[0]\n ?? null\n const selectedChannels = preset.productChannels\n ?? (preferredAkeneoChannel ? [preferredAkeneoChannel] : [])\n\n const discoveredPriceMappings = preferredLocalChannel\n ? inferred.autoPriceAttributeCodes.map((attributeCode) => {\n const inferredKind = inferPriceKindCode(attributeCode)\n const matchedPriceKind = priceKinds.find((priceKind) => priceKind.code === inferredKind)\n return {\n attributeCode,\n priceKindCode: matchedPriceKind?.code ?? inferredKind,\n akeneoChannel: preferredAkeneoChannel ?? null,\n localChannelCode: preferredLocalChannel.code,\n }\n })\n : []\n\n const productsOverride = preset.productsSettingsOverride ?? {}\n const overrideFieldMap = productsOverride.fieldMap && typeof productsOverride.fieldMap === 'object' && !Array.isArray(productsOverride.fieldMap)\n ? productsOverride.fieldMap as Record<string, unknown>\n : null\n const overrideReconciliation = productsOverride.reconciliation && typeof productsOverride.reconciliation === 'object' && !Array.isArray(productsOverride.reconciliation)\n ? productsOverride.reconciliation as Record<string, unknown>\n : null\n const {\n fieldMap: _ignoredFieldMap,\n reconciliation: _ignoredReconciliation,\n ...productsOverrideShallow\n } = productsOverride\n\n const rawProductsMapping = {\n ...baseProducts,\n settings: {\n products: {\n ...productSettings,\n locale: preferredLocale,\n channel: preferredAkeneoChannel ?? null,\n channels: selectedChannels,\n importAllChannels: preset.importAllChannels ?? productSettings.importAllChannels,\n customFieldMappings: inferred.autoCustomFieldMappings.map((mapping) => ({\n attributeCode: mapping.attributeCode,\n target: mapping.target,\n fieldKey: mapping.fieldKey,\n kind: mapping.kind ?? null,\n skip: mapping.skip ?? false,\n })),\n mediaMappings: inferred.autoMediaMappings.map((mapping) => ({\n attributeCode: mapping.attributeCode,\n target: mapping.target,\n kind: mapping.kind,\n })),\n priceMappings: discoveredPriceMappings,\n fieldsetMappings: buildDiscoveredFieldsetMappings(discovery),\n createMissingChannels: preset.createMissingChannels ?? productSettings.createMissingChannels,\n syncAssociations: preset.syncAssociations ?? productSettings.syncAssociations,\n ...productsOverrideShallow,\n fieldMap: {\n ...inferred.fieldMap,\n ...(overrideFieldMap ?? {}),\n },\n reconciliation: {\n ...productSettings.reconciliation,\n ...(overrideReconciliation ?? {}),\n },\n },\n },\n }\n const productsMapping = normalizeAkeneoMapping('products', rawProductsMapping as Record<string, unknown>)\n if (productsMapping.settings?.products) {\n productsMapping.fields = buildProductFieldMappings(productsMapping.settings.products)\n }\n\n const baseCategories = buildDefaultAkeneoMapping('categories')\n const categoriesMapping = normalizeAkeneoMapping('categories', {\n ...baseCategories,\n settings: {\n categories: {\n locale: preset.categoryLocale ?? preferredLocale,\n ...(preset.categoriesSettingsOverride ?? {}),\n },\n },\n })\n\n const baseAttributes = buildDefaultAkeneoMapping('attributes')\n const attributesMapping = normalizeAkeneoMapping('attributes', {\n ...baseAttributes,\n settings: {\n attributes: {\n ...baseAttributes.settings?.attributes,\n familyCodeFilter: preset.familyCodeFilter ?? baseAttributes.settings?.attributes?.familyCodeFilter ?? [],\n ...(preset.attributesSettingsOverride ?? {}),\n },\n },\n })\n\n return {\n productsMapping,\n categoriesMapping,\n attributesMapping,\n }\n}\n\nasync function loadLocalDiscoveryContext(em: EntityManager, scope: IntegrationScope): Promise<{\n localChannels: LocalChannelOption[]\n priceKinds: PriceKindOption[]\n}> {\n const [channels, priceKinds] = await Promise.all([\n areSalesChannelsAvailable(em)\n ? findWithDecryption(em, SalesChannel, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n isActive: true,\n }, {\n fields: ['code', 'name'],\n orderBy: { name: 'asc' },\n }, scope)\n : Promise.resolve<SalesChannel[]>([]),\n findWithDecryption(em, CatalogPriceKind, {\n tenantId: scope.tenantId,\n deletedAt: null,\n isActive: true,\n }, {\n fields: ['code', 'title', 'displayMode'],\n orderBy: { title: 'asc' },\n }, scope),\n ])\n\n return {\n localChannels: channels\n .filter((channel) => typeof channel.code === 'string' && channel.code.trim().length > 0)\n .map((channel) => ({ code: String(channel.code), name: channel.name })),\n priceKinds: priceKinds.map((priceKind) => ({\n code: priceKind.code,\n title: priceKind.title,\n displayMode: priceKind.displayMode,\n })),\n }\n}\n\nasync function upsertSyncMapping(\n em: EntityManager,\n entityType: 'products' | 'categories' | 'attributes',\n mapping: Record<string, unknown>,\n scope: IntegrationScope,\n): Promise<void> {\n const existing = await findOneWithDecryption(em, SyncMapping, {\n integrationId: AKENEO_INTEGRATION_ID,\n entityType,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n }, undefined, scope)\n\n if (existing) {\n existing.mapping = mapping\n await em.flush()\n return\n }\n\n const created = em.create(SyncMapping, {\n integrationId: AKENEO_INTEGRATION_ID,\n entityType,\n mapping,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n })\n await em.persist(created).flush()\n}\n\nasync function hasExistingAkeneoConfiguration(\n em: EntityManager,\n credentialsService: CredentialsService,\n scope: IntegrationScope,\n): Promise<boolean> {\n const [credentials, mappings] = await Promise.all([\n inspectStoredCredentials(credentialsService, AKENEO_INTEGRATION_ID, scope, { via: 'getRaw' }),\n findOneWithDecryption(em, SyncMapping, {\n integrationId: AKENEO_INTEGRATION_ID,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n }, {\n fields: ['id'],\n }, scope),\n ])\n return credentials.state !== 'absent' || Boolean(mappings)\n}\n\nexport async function applyAkeneoEnvPreset(params: {\n em: EntityManager\n credentialsService: CredentialsService\n integrationStateService: IntegrationStateService\n integrationLogService?: IntegrationLogService\n scope: IntegrationScope\n force?: boolean\n env?: NodeJS.ProcessEnv\n}): Promise<ApplyAkeneoPresetResult> {\n const preset = readAkeneoEnvPreset(params.env)\n if (!preset) {\n return { status: 'skipped', reason: 'No Akeneo preset env variables were provided.' }\n }\n\n const force = params.force ?? preset.force\n if (!force && await hasExistingAkeneoConfiguration(params.em, params.credentialsService, params.scope)) {\n return { status: 'skipped', reason: 'Akeneo credentials or mappings already exist. Use force to overwrite them.' }\n }\n\n await params.credentialsService.save(AKENEO_INTEGRATION_ID, preset.credentials, params.scope)\n\n const client = createAkeneoClient(preset.credentials)\n const [discovery, localContext] = await Promise.all([\n client.collectDiscoveryData(),\n loadLocalDiscoveryContext(params.em, params.scope),\n ])\n\n const mappings = buildAkeneoMappingsFromPreset({\n preset,\n discovery,\n localChannels: localContext.localChannels,\n priceKinds: localContext.priceKinds,\n })\n\n await upsertSyncMapping(params.em, 'products', mappings.productsMapping as unknown as Record<string, unknown>, params.scope)\n await upsertSyncMapping(params.em, 'categories', mappings.categoriesMapping as unknown as Record<string, unknown>, params.scope)\n await upsertSyncMapping(params.em, 'attributes', mappings.attributesMapping as unknown as Record<string, unknown>, params.scope)\n await params.integrationStateService.upsert(AKENEO_INTEGRATION_ID, { isEnabled: true }, params.scope)\n\n if (params.integrationLogService) {\n await params.integrationLogService.scoped(AKENEO_INTEGRATION_ID, params.scope).info(\n 'Akeneo integration was preconfigured from environment variables.',\n {\n locale: mappings.productsMapping.settings?.products?.locale ?? null,\n channel: mappings.productsMapping.settings?.products?.channel ?? null,\n importAllChannels: mappings.productsMapping.settings?.products?.importAllChannels ?? null,\n },\n )\n }\n\n return { status: 'configured', discoveryApplied: true }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,OAEK;AAGP,SAAS,oBAAoB;AAC7B,SAAS,iCAAiC;AAC1C,SAAS,0BAA0B;AACnC,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,MAAM,wBAAwB;AAsD9B,SAAS,aAAa,KAAwB,MAAoC;AAChF,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,IAAI,GAAG,GAAG,KAAK;AAC7B,QAAI,MAAO,QAAO;AAAA,EACpB;AACA,SAAO;AACT;AAEA,SAAS,WAAW,KAAwB,MAAsC;AAChF,QAAM,MAAM,aAAa,KAAK,IAAI;AAClC,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,SAAS,IACZ,MAAM,GAAG,EACT,IAAI,CAAC,UAAU,MAAM,KAAK,CAAC,EAC3B,OAAO,CAAC,UAAU,MAAM,SA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,cAAc,SAAS,mBAAyD,OAAO,KAAK;AAC/H,QAAM,kBAAkB,OAAO,IAAI,cAAc,SAAS,mBAAyD,OAAO,KAAK;AAC/H,QAAM,OAAO,wBAAwB,OAAO,uBAAuB,EAAE,WAAW,KAAK,GAAG,OAAO,KAAK;AAEpG,MAAI,OAAO,uBAAuB;AAChC,UAAM,OAAO,sBAAsB,OAAO,uBAAuB,OAAO,KAAK,EAAE;AAAA,MAC7E;AAAA,MACA;AAAA,QACE,QAAQ,SAAS,gBAAgB,UAAU,UAAU,UAAU;AAAA,QAC/D,SAAS,SAAS,gBAAgB,UAAU,UAAU,WAAW;AAAA,QACjE,mBAAmB,SAAS,gBAAgB,UAAU,UAAU,qBAAqB;AAAA,MACvF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,QAAQ,cAAc,kBAAkB,KAAK;AACxD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/sync-akeneo",
|
|
3
|
-
"version": "0.11.1-develop.
|
|
3
|
+
"version": "0.11.1-develop.9117.1.64991d6651",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,21 +53,21 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@open-mercato/core": "0.11.1-develop.
|
|
57
|
-
"@open-mercato/ui": "0.11.1-develop.
|
|
56
|
+
"@open-mercato/core": "0.11.1-develop.9117.1.64991d6651",
|
|
57
|
+
"@open-mercato/ui": "0.11.1-develop.9117.1.64991d6651",
|
|
58
58
|
"node-html-markdown": "^2.0.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@mikro-orm/postgresql": "^7.0.14",
|
|
62
|
-
"@open-mercato/ai-assistant": "0.11.1-develop.
|
|
63
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
62
|
+
"@open-mercato/ai-assistant": "0.11.1-develop.9117.1.64991d6651",
|
|
63
|
+
"@open-mercato/shared": "0.11.1-develop.9117.1.64991d6651",
|
|
64
64
|
"react": "^19.0.0",
|
|
65
65
|
"react-dom": "^19.0.0",
|
|
66
66
|
"react-is": ">=18.0.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@open-mercato/ai-assistant": "0.11.1-develop.
|
|
70
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
69
|
+
"@open-mercato/ai-assistant": "0.11.1-develop.9117.1.64991d6651",
|
|
70
|
+
"@open-mercato/shared": "0.11.1-develop.9117.1.64991d6651",
|
|
71
71
|
"@types/jest": "^30.0.0",
|
|
72
72
|
"@types/react": "^19.2.18",
|
|
73
73
|
"@types/react-dom": "^19.2.5",
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CredentialsEncryptionUnavailableError,
|
|
3
|
+
type CredentialsService,
|
|
4
|
+
} from '@open-mercato/core/modules/integrations/lib/credentials-service'
|
|
5
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
6
|
+
import type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'
|
|
7
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
8
|
+
import { createAkeneoClient } from '../lib/client'
|
|
9
|
+
import { applyAkeneoEnvPreset } from '../lib/preset'
|
|
10
|
+
|
|
11
|
+
jest.mock('@open-mercato/shared/lib/encryption/find', () => ({
|
|
12
|
+
findOneWithDecryption: jest.fn(async () => null),
|
|
13
|
+
findWithDecryption: jest.fn(async () => []),
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
jest.mock('../lib/client', () => ({
|
|
17
|
+
createAkeneoClient: jest.fn(),
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
const DISCOVERY_STOPPED = '[internal] discovery stopped by the test'
|
|
21
|
+
|
|
22
|
+
describe('sync_akeneo preset over stored credentials it cannot read (D19/D23)', () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
jest.clearAllMocks()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const scope = { tenantId: 'tenant-1', organizationId: 'org-1' }
|
|
28
|
+
const env = {
|
|
29
|
+
OM_INTEGRATION_AKENEO_API_URL: 'https://example.akeneo.com',
|
|
30
|
+
OM_INTEGRATION_AKENEO_CLIENT_ID: 'client-id',
|
|
31
|
+
OM_INTEGRATION_AKENEO_CLIENT_SECRET: 'client-secret',
|
|
32
|
+
OM_INTEGRATION_AKENEO_USERNAME: 'api-user',
|
|
33
|
+
OM_INTEGRATION_AKENEO_PASSWORD: 'api-pass',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function services(reason: 'undecryptable' | 'no-dek') {
|
|
37
|
+
const save = jest.fn(async () => undefined)
|
|
38
|
+
const getRaw = jest.fn().mockRejectedValue(new CredentialsEncryptionUnavailableError(scope.tenantId, reason))
|
|
39
|
+
return {
|
|
40
|
+
save,
|
|
41
|
+
getRaw,
|
|
42
|
+
params: {
|
|
43
|
+
credentialsService: { getRaw, save } as unknown as CredentialsService,
|
|
44
|
+
em: {} as EntityManager,
|
|
45
|
+
integrationStateService: {
|
|
46
|
+
get: jest.fn().mockResolvedValue(null),
|
|
47
|
+
upsert: jest.fn(async (_integrationId: string, input: unknown) => input),
|
|
48
|
+
} as unknown as IntegrationStateService,
|
|
49
|
+
scope,
|
|
50
|
+
env,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
it('skips without force and leaves a blob no key opens unchanged', async () => {
|
|
56
|
+
const { save, getRaw, params } = services('undecryptable')
|
|
57
|
+
|
|
58
|
+
const result = await applyAkeneoEnvPreset(params)
|
|
59
|
+
|
|
60
|
+
expect(result.status).toBe('skipped')
|
|
61
|
+
expect(getRaw).toHaveBeenCalledWith('sync_akeneo', scope)
|
|
62
|
+
expect(save).not.toHaveBeenCalled()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('fails without force during a key outage instead of saving over the blob', async () => {
|
|
66
|
+
const { save, params } = services('no-dek')
|
|
67
|
+
|
|
68
|
+
await expect(applyAkeneoEnvPreset(params)).rejects.toBeInstanceOf(CredentialsEncryptionUnavailableError)
|
|
69
|
+
expect(save).not.toHaveBeenCalled()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('replaces the credentials under force without reading them', async () => {
|
|
73
|
+
const { save, getRaw, params } = services('undecryptable')
|
|
74
|
+
jest.mocked(createAkeneoClient).mockImplementation(() => {
|
|
75
|
+
throw new Error(DISCOVERY_STOPPED)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
await expect(applyAkeneoEnvPreset({ ...params, force: true })).rejects.toThrow(DISCOVERY_STOPPED)
|
|
79
|
+
|
|
80
|
+
expect(getRaw).not.toHaveBeenCalled()
|
|
81
|
+
expect(findOneWithDecryption).not.toHaveBeenCalled()
|
|
82
|
+
expect(save).toHaveBeenCalledTimes(1)
|
|
83
|
+
expect(save).toHaveBeenCalledWith('sync_akeneo', expect.any(Object), scope)
|
|
84
|
+
})
|
|
85
|
+
})
|
|
@@ -3,7 +3,10 @@ import { parseBooleanToken } from '@open-mercato/shared/lib/boolean'
|
|
|
3
3
|
import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
4
4
|
import { CatalogPriceKind } from '@open-mercato/core/modules/catalog/data/entities'
|
|
5
5
|
import { SyncMapping } from '@open-mercato/core/modules/data_sync/data/entities'
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
inspectStoredCredentials,
|
|
8
|
+
type CredentialsService,
|
|
9
|
+
} from '@open-mercato/core/modules/integrations/lib/credentials-service'
|
|
7
10
|
import type { IntegrationLogService } from '@open-mercato/core/modules/integrations/lib/log-service'
|
|
8
11
|
import type { IntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'
|
|
9
12
|
import { SalesChannel } from '@open-mercato/core/modules/sales/data/entities'
|
|
@@ -451,7 +454,7 @@ async function hasExistingAkeneoConfiguration(
|
|
|
451
454
|
scope: IntegrationScope,
|
|
452
455
|
): Promise<boolean> {
|
|
453
456
|
const [credentials, mappings] = await Promise.all([
|
|
454
|
-
credentialsService
|
|
457
|
+
inspectStoredCredentials(credentialsService, AKENEO_INTEGRATION_ID, scope, { via: 'getRaw' }),
|
|
455
458
|
findOneWithDecryption(em, SyncMapping, {
|
|
456
459
|
integrationId: AKENEO_INTEGRATION_ID,
|
|
457
460
|
organizationId: scope.organizationId,
|
|
@@ -460,7 +463,7 @@ async function hasExistingAkeneoConfiguration(
|
|
|
460
463
|
fields: ['id'],
|
|
461
464
|
}, scope),
|
|
462
465
|
])
|
|
463
|
-
return
|
|
466
|
+
return credentials.state !== 'absent' || Boolean(mappings)
|
|
464
467
|
}
|
|
465
468
|
|
|
466
469
|
export async function applyAkeneoEnvPreset(params: {
|