@softwear/latestcollectioncore 1.0.7 → 1.0.8
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/applyPropertyMapping.d.ts +2 -0
- package/dist/applyPropertyMapping.js +97 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/src/applyPropertyMapping.ts +80 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
function default_1(skus, brands) {
|
|
5
|
+
// Helper function to convert all mapping rules for given category to an indexed object
|
|
6
|
+
const indexedMapping = function (propertyMapping, category) {
|
|
7
|
+
const filteredMappings = propertyMapping.filter((mapping) => mapping.category == category && mapping.from);
|
|
8
|
+
if (filteredMappings.length == 0)
|
|
9
|
+
return undefined;
|
|
10
|
+
return filteredMappings.reduce((acc, item) => {
|
|
11
|
+
acc[item.from] = item.to;
|
|
12
|
+
return acc;
|
|
13
|
+
}, {});
|
|
14
|
+
};
|
|
15
|
+
// Helper function to convert all mapping rules to an indexed object
|
|
16
|
+
const indexFn = function (propertyMapping) {
|
|
17
|
+
if (!propertyMapping)
|
|
18
|
+
return {};
|
|
19
|
+
const maps = {};
|
|
20
|
+
index_1.MAPPING_CATEGORIES.forEach((category) => {
|
|
21
|
+
const map = indexedMapping(propertyMapping, category);
|
|
22
|
+
if (map !== undefined)
|
|
23
|
+
maps[category] = map;
|
|
24
|
+
});
|
|
25
|
+
return maps;
|
|
26
|
+
};
|
|
27
|
+
const indexedPropertyMapping = brands.reduce((acc, item) => {
|
|
28
|
+
acc[item.id] = indexFn(item.propertyMapping);
|
|
29
|
+
return acc;
|
|
30
|
+
}, {});
|
|
31
|
+
return skus.map((sku) => {
|
|
32
|
+
const brand = (0, index_1.hashBrand)(sku.brand);
|
|
33
|
+
const mapping = indexedPropertyMapping[brand];
|
|
34
|
+
if (!mapping)
|
|
35
|
+
return sku;
|
|
36
|
+
if (mapping.ColorCode) {
|
|
37
|
+
const from = sku.colorCodeSupplier;
|
|
38
|
+
if (!from)
|
|
39
|
+
return;
|
|
40
|
+
const to = indexedPropertyMapping[brand].ColorCode[from];
|
|
41
|
+
if (to && to != sku.colorFamily)
|
|
42
|
+
sku.colorFamily = to;
|
|
43
|
+
}
|
|
44
|
+
if (mapping.ColorDescription) {
|
|
45
|
+
const from = sku.colorSupplier;
|
|
46
|
+
if (!from)
|
|
47
|
+
return;
|
|
48
|
+
const to = indexedPropertyMapping[brand].ColorDescription[from];
|
|
49
|
+
if (to && to != sku.colorFamily)
|
|
50
|
+
sku.colorFamily = to;
|
|
51
|
+
}
|
|
52
|
+
if (mapping.ProductGroup) {
|
|
53
|
+
const from = sku.articleGroupSupplier;
|
|
54
|
+
if (!from)
|
|
55
|
+
return;
|
|
56
|
+
const to = indexedPropertyMapping[brand].ProductGroup[from];
|
|
57
|
+
if (to && to != sku.articleGroup)
|
|
58
|
+
sku.articleGroup = to;
|
|
59
|
+
}
|
|
60
|
+
if (mapping.Collection) {
|
|
61
|
+
const from = sku.collectionSupplier;
|
|
62
|
+
if (!from)
|
|
63
|
+
return;
|
|
64
|
+
const to = indexedPropertyMapping[brand].Collection[from];
|
|
65
|
+
if (to && to != sku.collection)
|
|
66
|
+
sku.collection = to;
|
|
67
|
+
}
|
|
68
|
+
if (mapping.Size) {
|
|
69
|
+
const from = sku.sizeSupplier;
|
|
70
|
+
if (!from)
|
|
71
|
+
return;
|
|
72
|
+
const to = indexedPropertyMapping[brand].Size[from];
|
|
73
|
+
if (to && to != sku.size) {
|
|
74
|
+
sku.size = to;
|
|
75
|
+
sku.mainSize = to;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (mapping.SubSize) {
|
|
79
|
+
const from = sku.sizeSupplier;
|
|
80
|
+
if (!from)
|
|
81
|
+
return;
|
|
82
|
+
const to = indexedPropertyMapping[brand].SubSize[from];
|
|
83
|
+
if (to && to != sku.subSize)
|
|
84
|
+
sku.subSize = to;
|
|
85
|
+
}
|
|
86
|
+
if (mapping.CustomSize) {
|
|
87
|
+
const from = sku.sizeSupplier;
|
|
88
|
+
if (!from)
|
|
89
|
+
return;
|
|
90
|
+
const to = indexedPropertyMapping[brand].CustomSize[from];
|
|
91
|
+
if (to && to != sku["_customSize"])
|
|
92
|
+
sku["_customSize"] = to;
|
|
93
|
+
}
|
|
94
|
+
return sku;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exports.default = default_1;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,7 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.hashBrand = exports.ean13 = void 0;
|
|
20
|
+
exports.hashBrand = exports.ean13 = exports.applyPropertyMapping = void 0;
|
|
21
|
+
var applyPropertyMapping_1 = require("./applyPropertyMapping");
|
|
22
|
+
Object.defineProperty(exports, "applyPropertyMapping", { enumerable: true, get: function () { return __importDefault(applyPropertyMapping_1).default; } });
|
|
21
23
|
var ean13_1 = require("./ean13");
|
|
22
24
|
Object.defineProperty(exports, "ean13", { enumerable: true, get: function () { return __importDefault(ean13_1).default; } });
|
|
23
25
|
var hashBrand_1 = require("./hashBrand");
|
package/package.json
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { hashBrand, SkuI, MAPPING_CATEGORIES } from "./index"
|
|
2
|
+
|
|
3
|
+
export default function (skus: Array<SkuI>, brands: Array<any>): any {
|
|
4
|
+
// Helper function to convert all mapping rules for given category to an indexed object
|
|
5
|
+
const indexedMapping = function (propertyMapping, category) {
|
|
6
|
+
const filteredMappings = propertyMapping.filter((mapping) => mapping.category == category && mapping.from)
|
|
7
|
+
|
|
8
|
+
if (filteredMappings.length == 0) return undefined
|
|
9
|
+
return filteredMappings.reduce((acc, item) => {
|
|
10
|
+
acc[item.from] = item.to
|
|
11
|
+
return acc
|
|
12
|
+
}, {})
|
|
13
|
+
}
|
|
14
|
+
// Helper function to convert all mapping rules to an indexed object
|
|
15
|
+
const indexFn = function (propertyMapping) {
|
|
16
|
+
if (!propertyMapping) return {}
|
|
17
|
+
const maps = {}
|
|
18
|
+
MAPPING_CATEGORIES.forEach((category) => {
|
|
19
|
+
const map = indexedMapping(propertyMapping, category)
|
|
20
|
+
if (map !== undefined) maps[category] = map
|
|
21
|
+
})
|
|
22
|
+
return maps
|
|
23
|
+
}
|
|
24
|
+
const indexedPropertyMapping = brands.reduce((acc, item) => {
|
|
25
|
+
acc[item.id] = indexFn(item.propertyMapping)
|
|
26
|
+
return acc
|
|
27
|
+
}, {})
|
|
28
|
+
return skus.map((sku: SkuI) => {
|
|
29
|
+
const brand = hashBrand(sku.brand)
|
|
30
|
+
const mapping = indexedPropertyMapping[brand]
|
|
31
|
+
if (!mapping) return sku
|
|
32
|
+
|
|
33
|
+
if (mapping.ColorCode) {
|
|
34
|
+
const from = sku.colorCodeSupplier
|
|
35
|
+
if (!from) return
|
|
36
|
+
const to = indexedPropertyMapping[brand].ColorCode[from]
|
|
37
|
+
if (to && to != sku.colorFamily) sku.colorFamily = to
|
|
38
|
+
}
|
|
39
|
+
if (mapping.ColorDescription) {
|
|
40
|
+
const from = sku.colorSupplier
|
|
41
|
+
if (!from) return
|
|
42
|
+
const to = indexedPropertyMapping[brand].ColorDescription[from]
|
|
43
|
+
if (to && to != sku.colorFamily) sku.colorFamily = to
|
|
44
|
+
}
|
|
45
|
+
if (mapping.ProductGroup) {
|
|
46
|
+
const from = sku.articleGroupSupplier
|
|
47
|
+
if (!from) return
|
|
48
|
+
const to = indexedPropertyMapping[brand].ProductGroup[from]
|
|
49
|
+
if (to && to != sku.articleGroup) sku.articleGroup = to
|
|
50
|
+
}
|
|
51
|
+
if (mapping.Collection) {
|
|
52
|
+
const from = sku.collectionSupplier
|
|
53
|
+
if (!from) return
|
|
54
|
+
const to = indexedPropertyMapping[brand].Collection[from]
|
|
55
|
+
if (to && to != sku.collection) sku.collection = to
|
|
56
|
+
}
|
|
57
|
+
if (mapping.Size) {
|
|
58
|
+
const from = sku.sizeSupplier
|
|
59
|
+
if (!from) return
|
|
60
|
+
const to = indexedPropertyMapping[brand].Size[from]
|
|
61
|
+
if (to && to != sku.size) {
|
|
62
|
+
sku.size = to
|
|
63
|
+
sku.mainSize = to
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (mapping.SubSize) {
|
|
67
|
+
const from = sku.sizeSupplier
|
|
68
|
+
if (!from) return
|
|
69
|
+
const to = indexedPropertyMapping[brand].SubSize[from]
|
|
70
|
+
if (to && to != sku.subSize) sku.subSize = to
|
|
71
|
+
}
|
|
72
|
+
if (mapping.CustomSize) {
|
|
73
|
+
const from = sku.sizeSupplier
|
|
74
|
+
if (!from) return
|
|
75
|
+
const to = indexedPropertyMapping[brand].CustomSize[from]
|
|
76
|
+
if (to && to != sku["_customSize"]) sku["_customSize"] = to
|
|
77
|
+
}
|
|
78
|
+
return sku
|
|
79
|
+
})
|
|
80
|
+
}
|
package/src/index.ts
CHANGED