@open-mercato/sync-akeneo 0.9.1-develop.7574.1.837288eec1 → 0.10.0
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/cli.js +2 -19
- package/dist/modules/sync_akeneo/cli.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/catalog-importer.js +42 -25
- package/dist/modules/sync_akeneo/lib/catalog-importer.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/first-import.js +1 -2
- package/dist/modules/sync_akeneo/lib/first-import.js.map +2 -2
- package/jest.config.cjs +1 -1
- package/package.json +12 -9
- package/src/modules/sync_akeneo/__tests__/catalog-importer.custom-fields.test.ts +419 -0
- package/src/modules/sync_akeneo/__tests__/catalog-importer.media.test.ts +193 -0
- package/src/modules/sync_akeneo/__tests__/catalog-importer.numeric-values.test.ts +292 -0
- package/src/modules/sync_akeneo/__tests__/catalog-importer.prices.test.ts +47 -0
- package/src/modules/sync_akeneo/__tests__/first-import.test.ts +82 -0
- package/src/modules/sync_akeneo/cli.ts +2 -24
- package/src/modules/sync_akeneo/i18n/de.json +10 -0
- package/src/modules/sync_akeneo/i18n/en.json +10 -0
- package/src/modules/sync_akeneo/i18n/es.json +10 -0
- package/src/modules/sync_akeneo/i18n/ko.json +10 -0
- package/src/modules/sync_akeneo/i18n/pl.json +10 -0
- package/src/modules/sync_akeneo/lib/catalog-importer.ts +51 -28
- package/src/modules/sync_akeneo/lib/first-import.ts +0 -1
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
+
"sync_akeneo.credentials.apiUrl.helpText": "Use the base Akeneo PIM URL, without a trailing slash.",
|
|
3
|
+
"sync_akeneo.credentials.apiUrl.label": "Akeneo URL",
|
|
4
|
+
"sync_akeneo.credentials.clientId.helpText": "Create a connected app or API client in Akeneo and copy its client id.",
|
|
5
|
+
"sync_akeneo.credentials.clientId.label": "Client ID",
|
|
6
|
+
"sync_akeneo.credentials.clientSecret.helpText": "Use the client secret generated for the Akeneo API connection.",
|
|
7
|
+
"sync_akeneo.credentials.clientSecret.label": "Client Secret",
|
|
8
|
+
"sync_akeneo.credentials.password.helpText": "Use the password for the dedicated Akeneo API user.",
|
|
9
|
+
"sync_akeneo.credentials.password.label": "API Password",
|
|
10
|
+
"sync_akeneo.credentials.username.helpText": "Create a dedicated Akeneo user for synchronization and grant only the product/catalog permissions it needs.",
|
|
11
|
+
"sync_akeneo.credentials.username.label": "API Username",
|
|
2
12
|
"sync_akeneo.customFields.actions.add": "Add row",
|
|
3
13
|
"sync_akeneo.customFields.actions.createMissing": "Pre-create missing fields now",
|
|
4
14
|
"sync_akeneo.customFields.actions.creating": "Creating...",
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
+
"sync_akeneo.credentials.apiUrl.helpText": "Use the base Akeneo PIM URL, without a trailing slash.",
|
|
3
|
+
"sync_akeneo.credentials.apiUrl.label": "Akeneo URL",
|
|
4
|
+
"sync_akeneo.credentials.clientId.helpText": "Create a connected app or API client in Akeneo and copy its client id.",
|
|
5
|
+
"sync_akeneo.credentials.clientId.label": "Client ID",
|
|
6
|
+
"sync_akeneo.credentials.clientSecret.helpText": "Use the client secret generated for the Akeneo API connection.",
|
|
7
|
+
"sync_akeneo.credentials.clientSecret.label": "Client Secret",
|
|
8
|
+
"sync_akeneo.credentials.password.helpText": "Use the password for the dedicated Akeneo API user.",
|
|
9
|
+
"sync_akeneo.credentials.password.label": "API Password",
|
|
10
|
+
"sync_akeneo.credentials.username.helpText": "Create a dedicated Akeneo user for synchronization and grant only the product/catalog permissions it needs.",
|
|
11
|
+
"sync_akeneo.credentials.username.label": "API Username",
|
|
2
12
|
"sync_akeneo.customFields.actions.add": "Agregar fila",
|
|
3
13
|
"sync_akeneo.customFields.actions.createMissing": "Crear campos faltantes ahora",
|
|
4
14
|
"sync_akeneo.customFields.actions.creating": "Creando...",
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
+
"sync_akeneo.credentials.apiUrl.helpText": "Use the base Akeneo PIM URL, without a trailing slash.",
|
|
3
|
+
"sync_akeneo.credentials.apiUrl.label": "Akeneo URL",
|
|
4
|
+
"sync_akeneo.credentials.clientId.helpText": "Create a connected app or API client in Akeneo and copy its client id.",
|
|
5
|
+
"sync_akeneo.credentials.clientId.label": "Client ID",
|
|
6
|
+
"sync_akeneo.credentials.clientSecret.helpText": "Use the client secret generated for the Akeneo API connection.",
|
|
7
|
+
"sync_akeneo.credentials.clientSecret.label": "Client Secret",
|
|
8
|
+
"sync_akeneo.credentials.password.helpText": "Use the password for the dedicated Akeneo API user.",
|
|
9
|
+
"sync_akeneo.credentials.password.label": "API Password",
|
|
10
|
+
"sync_akeneo.credentials.username.helpText": "Create a dedicated Akeneo user for synchronization and grant only the product/catalog permissions it needs.",
|
|
11
|
+
"sync_akeneo.credentials.username.label": "API Username",
|
|
2
12
|
"sync_akeneo.customFields.actions.add": "행 추가",
|
|
3
13
|
"sync_akeneo.customFields.actions.createMissing": "지금 누락된 필드 미리 생성",
|
|
4
14
|
"sync_akeneo.customFields.actions.creating": "생성 중...",
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
+
"sync_akeneo.credentials.apiUrl.helpText": "Użyj bazowego adresu URL Akeneo PIM, bez ukośnika na końcu.",
|
|
3
|
+
"sync_akeneo.credentials.apiUrl.label": "Adres URL Akeneo",
|
|
4
|
+
"sync_akeneo.credentials.clientId.helpText": "Utwórz połączoną aplikację lub klienta API w Akeneo i skopiuj jego identyfikator klienta.",
|
|
5
|
+
"sync_akeneo.credentials.clientId.label": "Identyfikator klienta",
|
|
6
|
+
"sync_akeneo.credentials.clientSecret.helpText": "Użyj sekretu klienta wygenerowanego dla połączenia z API Akeneo.",
|
|
7
|
+
"sync_akeneo.credentials.clientSecret.label": "Sekret klienta",
|
|
8
|
+
"sync_akeneo.credentials.password.helpText": "Użyj hasła osobnego użytkownika API Akeneo.",
|
|
9
|
+
"sync_akeneo.credentials.password.label": "Hasło API",
|
|
10
|
+
"sync_akeneo.credentials.username.helpText": "Utwórz osobnego użytkownika Akeneo do synchronizacji i nadaj mu tylko niezbędne uprawnienia do produktów i katalogu.",
|
|
11
|
+
"sync_akeneo.credentials.username.label": "Nazwa użytkownika API",
|
|
2
12
|
"sync_akeneo.customFields.actions.add": "Dodaj wiersz",
|
|
3
13
|
"sync_akeneo.customFields.actions.createMissing": "Utwórz brakujące pola",
|
|
4
14
|
"sync_akeneo.customFields.actions.creating": "Tworzenie...",
|
|
@@ -4,6 +4,7 @@ import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
|
4
4
|
import type { DataEngine } from '@open-mercato/shared/lib/data/engine'
|
|
5
5
|
import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
|
|
6
6
|
import { emitCrudSideEffects, setCustomFieldsIfAny } from '@open-mercato/shared/lib/commands/helpers'
|
|
7
|
+
import { loadCustomFieldSnapshot } from '@open-mercato/shared/lib/commands/customFieldSnapshots'
|
|
7
8
|
import { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'
|
|
8
9
|
import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
9
10
|
import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
@@ -61,6 +62,7 @@ import {
|
|
|
61
62
|
import { isAkeneoResponseTooLargeError, type AkeneoClient } from './client'
|
|
62
63
|
import { inferAkeneoProductMapping } from './inference'
|
|
63
64
|
import { normalizeMarkdownText } from './markdown'
|
|
65
|
+
import { decimalToString, parseDecimal } from '@open-mercato/shared/lib/decimal'
|
|
64
66
|
|
|
65
67
|
type ImportScope = {
|
|
66
68
|
organizationId: string
|
|
@@ -113,7 +115,7 @@ type DesiredPrice = {
|
|
|
113
115
|
priceKindId: string
|
|
114
116
|
channelId: string
|
|
115
117
|
currencyCode: string
|
|
116
|
-
amount:
|
|
118
|
+
amount: string
|
|
117
119
|
variantId: string
|
|
118
120
|
}
|
|
119
121
|
|
|
@@ -487,17 +489,17 @@ function resolvePriceVariantId(price: Pick<CatalogProductPrice, 'variant'>): str
|
|
|
487
489
|
return price.variant?.id ?? null
|
|
488
490
|
}
|
|
489
491
|
|
|
490
|
-
function parsePriceCollection(value: unknown): Array<{ currencyCode: string; amount:
|
|
492
|
+
function parsePriceCollection(value: unknown): Array<{ currencyCode: string; amount: string }> {
|
|
491
493
|
if (!Array.isArray(value)) return []
|
|
492
494
|
return value
|
|
493
495
|
.map((entry) => {
|
|
494
496
|
const record = safeRecord(entry)
|
|
495
497
|
const currencyCode = typeof record?.currency === 'string' ? record.currency.trim().toUpperCase() : ''
|
|
496
|
-
const amount =
|
|
498
|
+
const amount = parseDecimal(record?.amount)
|
|
497
499
|
if (!currencyCode || amount === null) return null
|
|
498
|
-
return { currencyCode, amount }
|
|
500
|
+
return { currencyCode, amount: decimalToString(amount) }
|
|
499
501
|
})
|
|
500
|
-
.filter((entry): entry is { currencyCode: string; amount:
|
|
502
|
+
.filter((entry): entry is { currencyCode: string; amount: string } => Boolean(entry))
|
|
501
503
|
}
|
|
502
504
|
|
|
503
505
|
function collectMediaReferences(value: unknown): MediaReference[] {
|
|
@@ -551,6 +553,10 @@ export function resolveAkeneoMediaTarget(params: {
|
|
|
551
553
|
return params.mappingTarget
|
|
552
554
|
}
|
|
553
555
|
|
|
556
|
+
function isEmptyCustomFieldValue(value: unknown): boolean {
|
|
557
|
+
return value === null || value === undefined || (Array.isArray(value) && value.length === 0)
|
|
558
|
+
}
|
|
559
|
+
|
|
554
560
|
function resolveCustomFieldValue(value: unknown, attribute: AkeneoAttribute, kind: AkeneoCustomFieldKind): unknown {
|
|
555
561
|
if (kind === 'boolean') return coerceBoolean(value)
|
|
556
562
|
if (kind === 'integer') return coerceNumber(value) === null ? null : Math.trunc(Number(value))
|
|
@@ -2022,6 +2028,23 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2022
2028
|
}
|
|
2023
2029
|
}
|
|
2024
2030
|
|
|
2031
|
+
async function omitClearsOfEmptyFields(
|
|
2032
|
+
entityId: string,
|
|
2033
|
+
recordId: string,
|
|
2034
|
+
values: Record<string, unknown>,
|
|
2035
|
+
): Promise<Record<string, unknown>> {
|
|
2036
|
+
if (!Object.values(values).some((value) => value === null)) return values
|
|
2037
|
+
const current = await loadCustomFieldSnapshot(em, {
|
|
2038
|
+
entityId,
|
|
2039
|
+
recordId,
|
|
2040
|
+
tenantId: scope.tenantId,
|
|
2041
|
+
organizationId: scope.organizationId,
|
|
2042
|
+
})
|
|
2043
|
+
return Object.fromEntries(
|
|
2044
|
+
Object.entries(values).filter(([key, value]) => value !== null || !isEmptyCustomFieldValue(current[key])),
|
|
2045
|
+
)
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2025
2048
|
async function applyCustomFieldMappings(params: {
|
|
2026
2049
|
mapping: AkeneoDataMapping
|
|
2027
2050
|
hierarchy: ResolvedHierarchy
|
|
@@ -2048,8 +2071,8 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2048
2071
|
? [params.hierarchy.rootValues, params.hierarchy.mergedValues]
|
|
2049
2072
|
: [params.product.values ?? {}, params.hierarchy.mergedValues]
|
|
2050
2073
|
const rawValue = readLayeredAkeneoValue(sourceLayers, fieldMapping.attributeCode, settings.locale, settings.channel ?? null)
|
|
2051
|
-
const
|
|
2052
|
-
|
|
2074
|
+
const resolved = resolveCustomFieldValue(rawValue, attribute, kind)
|
|
2075
|
+
const value = isEmptyCustomFieldValue(resolved) ? null : resolved
|
|
2053
2076
|
if (fieldMapping.target === 'product') {
|
|
2054
2077
|
productCustomFields[normalizeFieldKey(fieldMapping.fieldKey)] = value
|
|
2055
2078
|
} else {
|
|
@@ -2057,24 +2080,24 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2057
2080
|
}
|
|
2058
2081
|
}
|
|
2059
2082
|
|
|
2060
|
-
await
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2083
|
+
const productValues = await omitClearsOfEmptyFields(PRODUCT_ENTITY_ID, params.localProductId, productCustomFields)
|
|
2084
|
+
await setCustomFieldsIfAny({
|
|
2085
|
+
dataEngine,
|
|
2086
|
+
entityId: PRODUCT_ENTITY_ID,
|
|
2087
|
+
recordId: params.localProductId,
|
|
2088
|
+
organizationId: scope.organizationId,
|
|
2089
|
+
tenantId: scope.tenantId,
|
|
2090
|
+
values: productValues,
|
|
2091
|
+
})
|
|
2092
|
+
const variantValues = await omitClearsOfEmptyFields(VARIANT_ENTITY_ID, params.localVariantId, variantCustomFields)
|
|
2093
|
+
await setCustomFieldsIfAny({
|
|
2094
|
+
dataEngine,
|
|
2095
|
+
entityId: VARIANT_ENTITY_ID,
|
|
2096
|
+
recordId: params.localVariantId,
|
|
2097
|
+
organizationId: scope.organizationId,
|
|
2098
|
+
tenantId: scope.tenantId,
|
|
2099
|
+
values: variantValues,
|
|
2100
|
+
})
|
|
2078
2101
|
|
|
2079
2102
|
await Promise.all([
|
|
2080
2103
|
params.fieldsetPlan?.product?.code
|
|
@@ -2091,7 +2114,7 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2091
2114
|
: Promise.resolve(),
|
|
2092
2115
|
])
|
|
2093
2116
|
|
|
2094
|
-
if (Object.keys(
|
|
2117
|
+
if (Object.keys(productValues).length > 0) {
|
|
2095
2118
|
await emitCatalogQueryIndexEvent(buildCommandContext(), {
|
|
2096
2119
|
entityType: PRODUCT_ENTITY_ID,
|
|
2097
2120
|
recordId: params.localProductId,
|
|
@@ -2101,7 +2124,7 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2101
2124
|
})
|
|
2102
2125
|
}
|
|
2103
2126
|
|
|
2104
|
-
if (Object.keys(
|
|
2127
|
+
if (Object.keys(variantValues).length > 0) {
|
|
2105
2128
|
await emitCatalogQueryIndexEvent(buildCommandContext(), {
|
|
2106
2129
|
entityType: VARIANT_ENTITY_ID,
|
|
2107
2130
|
recordId: params.localVariantId,
|
|
@@ -2405,7 +2428,7 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2405
2428
|
})
|
|
2406
2429
|
return true
|
|
2407
2430
|
} catch (error) {
|
|
2408
|
-
if (isCrudHttpError(error) && error.status === 409) return false
|
|
2431
|
+
if (isCrudHttpError(error) && (error.status === 409 || error.status === 404)) return false
|
|
2409
2432
|
throw error
|
|
2410
2433
|
}
|
|
2411
2434
|
}
|