@softwear/latestcollectioncore 1.0.173 → 1.0.174
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.
|
@@ -28,16 +28,23 @@ const evaluateFromExpr = function (sku, from) {
|
|
|
28
28
|
return sku[from];
|
|
29
29
|
return from.map((field) => sku[field] || '').join('.');
|
|
30
30
|
};
|
|
31
|
+
const indexBrandMappings = function (index, key, propertyMapping) {
|
|
32
|
+
if (!key)
|
|
33
|
+
return;
|
|
34
|
+
if (!index[key])
|
|
35
|
+
index[key] = {};
|
|
36
|
+
propertyMapping === null || propertyMapping === void 0 ? void 0 : propertyMapping.forEach((mapping) => {
|
|
37
|
+
if (!index[key][mapping.category])
|
|
38
|
+
index[key][mapping.category] = {};
|
|
39
|
+
index[key][mapping.category][mapping.from] = mapping.to;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
31
42
|
function default_1(brands, strategy) {
|
|
32
43
|
const indexedByBrandPropertyMapping = {};
|
|
33
|
-
brands.forEach(({ id, propertyMapping }) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!indexedByBrandPropertyMapping[id][mapping.category])
|
|
38
|
-
indexedByBrandPropertyMapping[id][mapping.category] = {};
|
|
39
|
-
indexedByBrandPropertyMapping[id][mapping.category][mapping.from] = mapping.to;
|
|
40
|
-
});
|
|
44
|
+
brands.forEach(({ id, collection, aliases, propertyMapping }) => {
|
|
45
|
+
indexBrandMappings(indexedByBrandPropertyMapping, id, propertyMapping);
|
|
46
|
+
// Alias-aware indexing prevents missing mappings when SKU brandhash resolves to an alias hash.
|
|
47
|
+
aliases === null || aliases === void 0 ? void 0 : aliases.forEach((alias) => indexBrandMappings(indexedByBrandPropertyMapping, alias, propertyMapping));
|
|
41
48
|
});
|
|
42
49
|
if (strategy == 'clean')
|
|
43
50
|
return function (sku) {
|
package/package.json
CHANGED
|
@@ -36,14 +36,21 @@ interface propertyMappingI {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
const indexBrandMappings = function (index: propertyMappingI, key: string | undefined, propertyMapping: BrandSettingI['propertyMapping']) {
|
|
40
|
+
if (!key) return
|
|
41
|
+
if (!index[key]) index[key] = {}
|
|
42
|
+
propertyMapping?.forEach((mapping) => {
|
|
43
|
+
if (!index[key][mapping.category]) index[key][mapping.category] = {}
|
|
44
|
+
index[key][mapping.category][mapping.from] = mapping.to
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
39
48
|
export default function (brands: Array<BrandSettingI>, strategy: mappingStrategyE): (sku: SkuI) => SkuI {
|
|
40
49
|
const indexedByBrandPropertyMapping = {} as propertyMappingI
|
|
41
|
-
brands.forEach(({ id, propertyMapping }) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
indexedByBrandPropertyMapping[id][mapping.category][mapping.from] = mapping.to
|
|
46
|
-
})
|
|
50
|
+
brands.forEach(({ id, collection, aliases, propertyMapping }) => {
|
|
51
|
+
indexBrandMappings(indexedByBrandPropertyMapping, id, propertyMapping)
|
|
52
|
+
// Alias-aware indexing prevents missing mappings when SKU brandhash resolves to an alias hash.
|
|
53
|
+
aliases?.forEach((alias) => indexBrandMappings(indexedByBrandPropertyMapping, alias, propertyMapping))
|
|
47
54
|
})
|
|
48
55
|
if (strategy == 'clean')
|
|
49
56
|
return function (sku: SkuI): SkuI {
|
|
@@ -451,4 +451,26 @@ describe('applyPropertyMapping', () => {
|
|
|
451
451
|
const mappedSkus = applyPropertyMapping(deepCopy(skus), dtbMapping)
|
|
452
452
|
expect(mappedSkus[11].DTBGROUP).toBe('77777')
|
|
453
453
|
})
|
|
454
|
+
|
|
455
|
+
it('applies mapping when sku.brandhash matches an alias', function () {
|
|
456
|
+
const aliasSkus = [
|
|
457
|
+
{
|
|
458
|
+
id: 'alias-1',
|
|
459
|
+
brand: 'SummumWomen',
|
|
460
|
+
brandhash: 'summumwomen',
|
|
461
|
+
colorCodeSupplier: '100',
|
|
462
|
+
colorSupplier: 'Black',
|
|
463
|
+
},
|
|
464
|
+
]
|
|
465
|
+
const aliasMapping = [
|
|
466
|
+
{
|
|
467
|
+
id: 'summum',
|
|
468
|
+
collection: 'summum',
|
|
469
|
+
aliases: ['summumwomen'],
|
|
470
|
+
propertyMapping: [{ category: 'ColorCode', from: '100', to: 'AliasColor' }],
|
|
471
|
+
},
|
|
472
|
+
]
|
|
473
|
+
const mappedSkus = applyPropertyMapping(deepCopy(aliasSkus), aliasMapping)
|
|
474
|
+
expect(mappedSkus[0].colorFamily).toBe('AliasColor')
|
|
475
|
+
})
|
|
454
476
|
})
|