@softwear/latestcollectioncore 1.0.32 → 1.0.34

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,2 +1,2 @@
1
- import { SkuI } from "./index";
2
- export default function (brands: Array<any>): (sku: SkuI) => SkuI;
1
+ import { SkuI, BrandSettingI } from "./index";
2
+ export default function (brands: Array<BrandSettingI>): (sku: SkuI) => SkuI;
@@ -27,22 +27,12 @@ function default_1(brands) {
27
27
  const indexedPropertyMapping = brands.reduce((acc, item) => {
28
28
  if (!acc[item.id])
29
29
  acc[item.id] = {};
30
- // acc[item.id] = { ...acc[item.id], ...indexFn(item.propertyMapping) };
31
- Object.entries(indexFn(item.propertyMapping)).forEach((m) => {
32
- const category = m[0];
33
- const mappings = m[1];
34
- if (!acc[item.id])
35
- acc[item.id] = {};
36
- if (!acc[item.id][category])
37
- acc[item.id][category] = {};
38
- acc[item.id][category] = Object.assign(Object.assign({}, acc[item.id][category]), mappings);
39
- });
30
+ Object.assign(acc[item.id], indexFn(item.propertyMapping));
40
31
  return acc;
41
32
  }, {});
42
33
  return function (sku) {
43
34
  const brand = (0, index_1.hashBrand)(sku.brand);
44
35
  const mapping = indexedPropertyMapping[brand];
45
- // console.log("!!!!", sku.brand, mapping);
46
36
  if (!mapping)
47
37
  return sku;
48
38
  if (mapping.ColorCode) {
@@ -9,9 +9,7 @@ function default_1(activeConfig, metaBrandSetting, dataProviderBrandSetting, ten
9
9
  allMappings = metaBrandSetting;
10
10
  if ((_d = (_c = activeConfig === null || activeConfig === void 0 ? void 0 : activeConfig.products) === null || _c === void 0 ? void 0 : _c.applyDataProviderMapping) === null || _d === void 0 ? void 0 : _d.value)
11
11
  activeConfig.products.applyDataProviderMapping.value.forEach((provider) => {
12
- allMappings = allMappings.concat(dataProviderBrandSetting
13
- .filter((s) => s.dataProvider == provider)
14
- .map((s) => (Object.assign(Object.assign({}, s), { id: s.id.split(":")[0] }))));
12
+ allMappings = allMappings.concat(dataProviderBrandSetting.filter((s) => s.dataProvider == provider).map((s) => (Object.assign(Object.assign({}, s), { id: s.id.split(":")[0] }))));
15
13
  });
16
14
  if ((_f = (_e = activeConfig === null || activeConfig === void 0 ? void 0 : activeConfig.products) === null || _e === void 0 ? void 0 : _e.applyTenantMapping) === null || _f === void 0 ? void 0 : _f.value)
17
15
  allMappings = allMappings.concat(tenantBrandSetting);
package/dist/hashBrand.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function default_1(brand = "") {
4
4
  if (typeof brand != "string")
5
5
  return "";
6
- const charactersToRemove = "~<>!@#$%^&*():'\"? ";
6
+ const charactersToRemove = "~.<>!@#$%^&*():'\"? ";
7
7
  const l = brand.length;
8
8
  let result = "";
9
9
  for (let i = 0; i < l; i++) {
package/dist/types.d.ts CHANGED
@@ -73,60 +73,59 @@ interface StockTransferSelectionI {
73
73
  interface SkuI {
74
74
  barcode?: barcode;
75
75
  id?: barcode;
76
- primary?: boolean;
76
+ primary: boolean;
77
77
  articleCode: string;
78
- articleDescription?: string;
79
- pricetagLayouts?: string;
78
+ articleDescription: string;
79
+ pricetagLayouts: string;
80
80
  brand: string;
81
81
  articleGroup: string;
82
82
  articleGroupSupplier?: string;
83
83
  campaigns?: string;
84
84
  images?: string;
85
- groups?: Array<GroupI>;
86
- vat?: number;
87
- vatCategory?: vatCategoryE;
85
+ groups: Array<GroupI>;
86
+ vat: number;
87
+ vatCategory: vatCategoryE;
88
88
  supplierName?: string;
89
- size?: string;
89
+ size: string;
90
90
  sizeSupplier?: string;
91
91
  mainSize?: string;
92
92
  subSize?: string;
93
93
  subSizeSupplier?: string;
94
- sizeIndex?: number;
94
+ sizeIndex: number;
95
95
  sizes?: Array<string>;
96
96
  sizeRange?: string;
97
97
  colorCode?: string;
98
98
  colorDescription?: string;
99
99
  colorSupplier?: string;
100
100
  colorCodeSupplier?: string;
101
- colorFamily?: string;
102
- mainColorCode?: string;
101
+ colorFamily: string;
102
+ mainColorCode: string;
103
103
  mainColorDescription?: string;
104
104
  subColorCode?: string;
105
105
  subColorDescription?: string;
106
106
  articleCodeSupplier?: string;
107
- price?: number;
108
- buyPrice?: number;
109
- suggestedRetailPrice?: number;
110
- valuePrice?: number;
111
- salePrice?: number;
107
+ price: number;
108
+ buyPrice: number;
109
+ suggestedRetailPrice: number;
110
+ valuePrice: number;
111
+ salePrice: number;
112
112
  prices?: unknown;
113
113
  year?: string;
114
114
  season?: string;
115
- collection?: string;
115
+ collection: string;
116
116
  collectionSupplier?: string;
117
- active?: boolean;
118
- skuActive?: boolean;
119
- warehouseLocation?: string;
117
+ active: boolean;
118
+ skuActive: boolean;
119
+ warehouseLocation: string;
120
120
  tagType?: tagTypeE;
121
121
  directDelivery?: boolean;
122
122
  care?: CareI;
123
- BRANDHASH?: string;
123
+ BRANDHASH: string;
124
124
  ATTRIBUTES?: object;
125
125
  IMAGES?: Array<ImageI>;
126
126
  SIZES?: unknown;
127
127
  FOOTPRINT?: number;
128
128
  quickPick?: number;
129
- erpSource?: string;
130
129
  }
131
130
  interface MarkedSkuI extends SkuI {
132
131
  source?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,105 +1,97 @@
1
- import { hashBrand, SkuI, MAPPING_CATEGORIES } from "./index"
1
+ import { hashBrand, SkuI, MAPPING_CATEGORIES, BrandSettingI } from "./index";
2
2
 
3
- export default function (brands: Array<any>): (sku: SkuI) => SkuI {
3
+ export default function (brands: Array<BrandSettingI>): (sku: SkuI) => SkuI {
4
4
  // Helper function to convert all mapping rules for given category to an indexed object
5
5
  const indexedMapping = function (propertyMapping, category) {
6
6
  const filteredMappings = propertyMapping.filter(
7
7
  (mapping) => mapping.category == category && mapping.from != undefined
8
- )
8
+ );
9
9
 
10
- if (filteredMappings.length == 0) return undefined
10
+ if (filteredMappings.length == 0) return undefined;
11
11
  return filteredMappings.reduce((acc, item) => {
12
- acc[item.from] = item.to
13
- return acc
14
- }, {})
15
- }
12
+ acc[item.from] = item.to;
13
+ return acc;
14
+ }, {});
15
+ };
16
16
  // Helper function to convert all mapping rules to an indexed object
17
- const indexFn = function (propertyMapping): object {
18
- if (!propertyMapping) return {}
19
- const maps = {}
17
+ const indexFn = function (propertyMapping) {
18
+ if (!propertyMapping) return {};
19
+ const maps = {};
20
20
  MAPPING_CATEGORIES.forEach((category) => {
21
- const map = indexedMapping(propertyMapping, category)
22
- if (map !== undefined) maps[category] = map
23
- })
24
- return maps
25
- }
21
+ const map = indexedMapping(propertyMapping, category);
22
+ if (map !== undefined) maps[category] = map;
23
+ });
24
+ return maps;
25
+ };
26
26
  const indexedPropertyMapping = brands.reduce((acc, item) => {
27
- if (!acc[item.id]) acc[item.id] = {}
28
- // acc[item.id] = { ...acc[item.id], ...indexFn(item.propertyMapping) };
29
- Object.entries(indexFn(item.propertyMapping)).forEach((m) => {
30
- const category = m[0]
31
- const mappings = m[1]
32
- if (!acc[item.id]) acc[item.id] = {}
33
- if (!acc[item.id][category]) acc[item.id][category] = {}
34
- acc[item.id][category] = { ...acc[item.id][category], ...mappings }
35
- })
36
- return acc
37
- }, {})
27
+ if (!acc[item.id]) acc[item.id] = {};
28
+ Object.assign(acc[item.id], indexFn(item.propertyMapping));
29
+ return acc;
30
+ }, {});
38
31
 
39
32
  return function (sku: SkuI): SkuI {
40
- const brand = hashBrand(sku.brand)
41
- const mapping = indexedPropertyMapping[brand]
42
- // console.log("!!!!", sku.brand, mapping);
43
- if (!mapping) return sku
33
+ const brand = hashBrand(sku.brand);
34
+ const mapping = indexedPropertyMapping[brand];
35
+ if (!mapping) return sku;
44
36
 
45
37
  if (mapping.ColorCode) {
46
- const from = sku.colorCodeSupplier
38
+ const from = sku.colorCodeSupplier;
47
39
  if (from) {
48
- const to = indexedPropertyMapping[brand].ColorCode[from]
49
- if (to && to != sku.colorFamily) sku.colorFamily = to
40
+ const to = indexedPropertyMapping[brand].ColorCode[from];
41
+ if (to && to != sku.colorFamily) sku.colorFamily = to;
50
42
  }
51
43
  }
52
44
  if (mapping.ColorDescription) {
53
- const from = sku.colorSupplier
45
+ const from = sku.colorSupplier;
54
46
  if (from) {
55
- const to = indexedPropertyMapping[brand].ColorDescription[from]
56
- if (to && to != sku.colorFamily) sku.colorFamily = to
47
+ const to = indexedPropertyMapping[brand].ColorDescription[from];
48
+ if (to && to != sku.colorFamily) sku.colorFamily = to;
57
49
  }
58
50
  }
59
51
  if (mapping.ProductGroup) {
60
- const from = sku.articleGroupSupplier
52
+ const from = sku.articleGroupSupplier;
61
53
  if (from) {
62
- const to = indexedPropertyMapping[brand].ProductGroup[from]
63
- if (to && to != sku.articleGroup) sku.articleGroup = to
54
+ const to = indexedPropertyMapping[brand].ProductGroup[from];
55
+ if (to && to != sku.articleGroup) sku.articleGroup = to;
64
56
  }
65
57
  }
66
58
  if (mapping.Collection) {
67
- const from = sku.collectionSupplier
59
+ const from = sku.collectionSupplier;
68
60
  if (from) {
69
- const to = indexedPropertyMapping[brand].Collection[from]
70
- if (to && to != sku.collection) sku.collection = to
61
+ const to = indexedPropertyMapping[brand].Collection[from];
62
+ if (to && to != sku.collection) sku.collection = to;
71
63
  }
72
64
  }
73
65
  if (mapping.Size) {
74
- const from = sku.sizeSupplier
66
+ const from = sku.sizeSupplier;
75
67
  if (from) {
76
- const to = indexedPropertyMapping[brand].Size[from]
68
+ const to = indexedPropertyMapping[brand].Size[from];
77
69
  if (to && to != sku.size) {
78
- sku.size = to
79
- sku.mainSize = to
70
+ sku.size = to;
71
+ sku.mainSize = to;
80
72
  }
81
73
  }
82
74
  }
83
75
  if (mapping.SubSize) {
84
- const from = sku.sizeSupplier
76
+ const from = sku.sizeSupplier;
85
77
  if (from) {
86
- const to = indexedPropertyMapping[brand].SubSize[from]
87
- if (to && to != sku.subSize) sku.subSize = to
78
+ const to = indexedPropertyMapping[brand].SubSize[from];
79
+ if (to && to != sku.subSize) sku.subSize = to;
88
80
  }
89
81
  }
90
82
  if (mapping.CustomSize) {
91
- const from = sku.sizeSupplier
83
+ const from = sku.sizeSupplier;
92
84
  if (from) {
93
- const to = indexedPropertyMapping[brand].CustomSize[from]
94
- if (to && to != sku["_customsize"]) sku["_customsize"] = to
85
+ const to = indexedPropertyMapping[brand].CustomSize[from];
86
+ if (to && to != sku["_customsize"]) sku["_customsize"] = to;
95
87
  }
96
88
  }
97
89
  if (mapping.Gender) {
98
90
  // There is nothing to map 'from'
99
91
  // We only implement the fallback, this mapping is only usefull for brands where gender is constant
100
- const to = indexedPropertyMapping[brand].Gender[""]
101
- if (to && to != sku["_gender"]) sku["_gender"] = to
92
+ const to = indexedPropertyMapping[brand].Gender[""];
93
+ if (to && to != sku["_gender"]) sku["_gender"] = to;
102
94
  }
103
- return sku
104
- }
95
+ return sku;
96
+ };
105
97
  }
@@ -1,24 +1,13 @@
1
1
  // This function combined the 3 levels of property mapping into one mapping object
2
2
  // Each level can be opted in/out in the tenantPreferences defined in the activeConfig parameter
3
- export default function (
4
- activeConfig,
5
- metaBrandSetting,
6
- dataProviderBrandSetting,
7
- tenantBrandSetting
8
- ) {
3
+ export default function (activeConfig, metaBrandSetting, dataProviderBrandSetting, tenantBrandSetting) {
9
4
  let allMappings = []
10
- if (activeConfig?.products?.applyLatestCollectionMapping?.value)
11
- allMappings = metaBrandSetting
5
+ if (activeConfig?.products?.applyLatestCollectionMapping?.value) allMappings = metaBrandSetting
12
6
  if (activeConfig?.products?.applyDataProviderMapping?.value)
13
7
  activeConfig.products.applyDataProviderMapping.value.forEach((provider) => {
14
- allMappings = allMappings.concat(
15
- dataProviderBrandSetting
16
- .filter((s) => s.dataProvider == provider)
17
- .map((s) => ({ ...s, id: s.id.split(":")[0] }))
18
- )
8
+ allMappings = allMappings.concat(dataProviderBrandSetting.filter((s) => s.dataProvider == provider).map((s) => ({ ...s, id: s.id.split(":")[0] })))
19
9
  })
20
10
 
21
- if (activeConfig?.products?.applyTenantMapping?.value)
22
- allMappings = allMappings.concat(tenantBrandSetting)
11
+ if (activeConfig?.products?.applyTenantMapping?.value) allMappings = allMappings.concat(tenantBrandSetting)
23
12
  return allMappings
24
13
  }
package/src/hashBrand.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export default function (brand = ""): string {
2
2
  if (typeof brand != "string") return ""
3
- const charactersToRemove = "~<>!@#$%^&*():'\"? "
3
+ const charactersToRemove = "~.<>!@#$%^&*():'\"? "
4
4
  const l = brand.length
5
5
  let result = ""
6
6
  for (let i = 0; i < l; i++) {
package/src/types.ts CHANGED
@@ -81,60 +81,59 @@ interface StockTransferSelectionI {
81
81
  interface SkuI {
82
82
  barcode?: barcode
83
83
  id?: barcode
84
- primary?: boolean
84
+ primary: boolean
85
85
  articleCode: string
86
- articleDescription?: string
87
- pricetagLayouts?: string
86
+ articleDescription: string
87
+ pricetagLayouts: string
88
88
  brand: string
89
89
  articleGroup: string
90
90
  articleGroupSupplier?: string
91
91
  campaigns?: string
92
92
  images?: string
93
- groups?: Array<GroupI>
94
- vat?: number
95
- vatCategory?: vatCategoryE
93
+ groups: Array<GroupI>
94
+ vat: number
95
+ vatCategory: vatCategoryE
96
96
  supplierName?: string
97
- size?: string
97
+ size: string
98
98
  sizeSupplier?: string
99
99
  mainSize?: string
100
100
  subSize?: string
101
101
  subSizeSupplier?: string
102
- sizeIndex?: number
102
+ sizeIndex: number
103
103
  sizes?: Array<string>
104
104
  sizeRange?: string
105
105
  colorCode?: string
106
106
  colorDescription?: string
107
107
  colorSupplier?: string
108
108
  colorCodeSupplier?: string
109
- colorFamily?: string
110
- mainColorCode?: string
109
+ colorFamily: string
110
+ mainColorCode: string
111
111
  mainColorDescription?: string
112
112
  subColorCode?: string
113
113
  subColorDescription?: string
114
114
  articleCodeSupplier?: string
115
- price?: number
116
- buyPrice?: number
117
- suggestedRetailPrice?: number
118
- valuePrice?: number
119
- salePrice?: number
115
+ price: number
116
+ buyPrice: number
117
+ suggestedRetailPrice: number
118
+ valuePrice: number
119
+ salePrice: number
120
120
  prices?: unknown
121
121
  year?: string
122
122
  season?: string
123
- collection?: string
123
+ collection: string
124
124
  collectionSupplier?: string
125
- active?: boolean
126
- skuActive?: boolean
127
- warehouseLocation?: string
125
+ active: boolean
126
+ skuActive: boolean
127
+ warehouseLocation: string
128
128
  tagType?: tagTypeE
129
129
  directDelivery?: boolean
130
130
  care?: CareI
131
- BRANDHASH?: string
131
+ BRANDHASH: string
132
132
  ATTRIBUTES?: object
133
133
  IMAGES?: Array<ImageI>
134
134
  SIZES?: unknown
135
135
  FOOTPRINT?: number
136
136
  quickPick?: number
137
- erpSource?: string
138
137
  }
139
138
 
140
139
  interface MarkedSkuI extends SkuI {
@@ -107,6 +107,7 @@ const dataProviderMapping = [
107
107
  dataProvider: "linolux",
108
108
  propertyMapping: [
109
109
  { category: "ColorCode", from: "200", to: "Blauwer" },
110
+ { category: "ColorCode", from: "100", to: "Witter" },
110
111
  { category: "Collection", from: "SUMMER 2022", to: "22zomer" },
111
112
  ],
112
113
  },
@@ -115,10 +116,7 @@ const dataProviderMapping = [
115
116
  const tenantMapping = [
116
117
  {
117
118
  id: "levis",
118
- propertyMapping: [
119
- { category: "ColorCode", from: "200", to: "Blauwst" },
120
- { category: "Collection", from: "SUMMER 2022", to: "22zomer" },
121
- ],
119
+ propertyMapping: [{ category: "Collection", from: "SUMMER 2022", to: "22zomer" }],
122
120
  },
123
121
  {
124
122
  id: "gstar",
@@ -207,9 +205,9 @@ describe("applyPreferedPropertyMappings", () => {
207
205
 
208
206
  it("returns skus with LatestCollection and dataProvider mapping applied", function () {
209
207
  const mappedSkus = applyPreferedPropertyMappings(deepCopy(skus), twoMappingsActive, metaDataMapping, dataProviderMapping, tenantMapping)
210
- expect(mappedSkus[0].colorFamily).to.equal("Wit")
211
- expect(mappedSkus[1].colorFamily).to.equal("Wit")
212
- expect(mappedSkus[2].colorFamily).to.equal("Wit")
208
+ expect(mappedSkus[0].colorFamily).to.equal("Witter")
209
+ expect(mappedSkus[1].colorFamily).to.equal("Witter")
210
+ expect(mappedSkus[2].colorFamily).to.equal("Witter")
213
211
  expect(mappedSkus[3].colorFamily).to.equal("Blauwer")
214
212
  expect(mappedSkus[4].colorFamily).to.equal("Blauwer")
215
213
  expect(mappedSkus[5].colorFamily).to.equal("Blauwer")
@@ -230,12 +228,12 @@ describe("applyPreferedPropertyMappings", () => {
230
228
 
231
229
  it("returns fully mapped skus on a full mapping", function () {
232
230
  const mappedSkus = applyPreferedPropertyMappings(deepCopy(skus), allMappingsActive, metaDataMapping, dataProviderMapping, tenantMapping)
233
- expect(mappedSkus[0].colorFamily).to.equal("Wit")
234
- expect(mappedSkus[1].colorFamily).to.equal("Wit")
235
- expect(mappedSkus[2].colorFamily).to.equal("Wit")
236
- expect(mappedSkus[3].colorFamily).to.equal("Blauwst")
237
- expect(mappedSkus[4].colorFamily).to.equal("Blauwst")
238
- expect(mappedSkus[5].colorFamily).to.equal("Blauwst")
231
+ expect(mappedSkus[0].colorFamily).to.equal("Witter")
232
+ expect(mappedSkus[1].colorFamily).to.equal("Witter")
233
+ expect(mappedSkus[2].colorFamily).to.equal("Witter")
234
+ expect(mappedSkus[3].colorFamily).to.equal("Blauwer")
235
+ expect(mappedSkus[4].colorFamily).to.equal("Blauwer")
236
+ expect(mappedSkus[5].colorFamily).to.equal("Blauwer")
239
237
  expect(mappedSkus[6].colorFamily).to.equal("Blue")
240
238
  expect(mappedSkus[7].colorFamily).to.equal("Blue")
241
239
  expect(mappedSkus[8].colorFamily).to.equal("Blue")
@@ -12,6 +12,6 @@ describe("hashBrand function", function () {
12
12
  expect(hashBrand("Marie Jo")).to.equal("mariejo")
13
13
  })
14
14
  it("should return the input stripped from non characters", function () {
15
- expect(hashBrand("Cl ~<>!@#$%^&*():'\"? ean")).to.equal("clean")
15
+ expect(hashBrand("Cl ~<>!@#$%.^&*():'\"? ean")).to.equal("clean")
16
16
  })
17
17
  })
package/.prettierrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "semi": false,
3
- "printWidth": 180
4
- }