@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.
@@ -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: number
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: number }> {
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 = coerceNumber(record?.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: number } => Boolean(entry))
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 value = resolveCustomFieldValue(rawValue, attribute, kind)
2052
- if (value === null || value === undefined || (Array.isArray(value) && value.length === 0)) continue
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 Promise.all([
2061
- setCustomFieldsIfAny({
2062
- dataEngine,
2063
- entityId: PRODUCT_ENTITY_ID,
2064
- recordId: params.localProductId,
2065
- organizationId: scope.organizationId,
2066
- tenantId: scope.tenantId,
2067
- values: productCustomFields,
2068
- }),
2069
- setCustomFieldsIfAny({
2070
- dataEngine,
2071
- entityId: VARIANT_ENTITY_ID,
2072
- recordId: params.localVariantId,
2073
- organizationId: scope.organizationId,
2074
- tenantId: scope.tenantId,
2075
- values: variantCustomFields,
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(productCustomFields).length > 0) {
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(variantCustomFields).length > 0) {
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
  }
@@ -167,7 +167,6 @@ export async function runAkeneoFirstImportSequence(params: {
167
167
  entityType,
168
168
  direction: 'import',
169
169
  triggeredBy: scope.userId ?? null,
170
- batchSize: 100,
171
170
  },
172
171
  })).run
173
172