@softwear/latestcollectioncore 1.0.62 → 1.0.64

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,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_1 = require("./index");
4
+ // The order of the following mappingPairs is significant.
5
+ // The ERM mapping relies on the Gender and ProductGroup mapping to have been evaluated first
4
6
  const mappingPairs = [
5
7
  { category: 'ColorCode', from: 'colorCodeSupplier', to: 'colorFamily' },
6
8
  { category: 'ColorDescription', from: 'colorSupplier', to: 'colorFamily' },
@@ -12,7 +14,13 @@ const mappingPairs = [
12
14
  { category: 'CustomSize', from: 'sizeSupplier', to: '_customsize' },
13
15
  { category: 'Size', from: 'sizeSupplier', to: 'size' },
14
16
  { category: 'Gender', from: 'articleGroupSupplier', to: '_gender', mustMatch: true },
17
+ { category: 'ERM', from: ['_gender', 'articleGroup'], to: '_erm-code', mustMatch: true, defaultMappingSource: 'ermmapping' },
15
18
  ];
19
+ const evaluateFromExpr = function (sku, from) {
20
+ if (typeof from == 'string')
21
+ return sku[from];
22
+ return from.map((field) => sku[field] || '').join('.');
23
+ };
16
24
  function default_1(brands, strategy) {
17
25
  // Helper function to convert all mapping rules for given category to an indexed object
18
26
  const indexedMapping = function (propertyMapping, category) {
@@ -48,7 +56,7 @@ function default_1(brands, strategy) {
48
56
  const mapping = indexedByBrandPropertyMapping[brand];
49
57
  mappingPairs.forEach((pair) => {
50
58
  var _a;
51
- const from = sku[pair.from] || '';
59
+ const from = evaluateFromExpr(sku, pair.from) || '';
52
60
  const to = (_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a[from];
53
61
  if (!from || !to)
54
62
  return;
@@ -63,8 +71,8 @@ function default_1(brands, strategy) {
63
71
  const mapping = indexedByBrandPropertyMapping[brand];
64
72
  mappingPairs.forEach((pair) => {
65
73
  var _a, _b, _c, _d, _e;
66
- const from = sku[pair.from] || '';
67
- const redirectedMappingSource = (_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a['~~'];
74
+ const from = evaluateFromExpr(sku, pair.from) || '';
75
+ const redirectedMappingSource = ((_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a['~~']) || pair.defaultMappingSource;
68
76
  const redirectedMapping = redirectedMappingSource ? indexedByBrandPropertyMapping[redirectedMappingSource] : {};
69
77
  const to = ((_b = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _b === void 0 ? void 0 : _b[from]) || ((_c = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _c === void 0 ? void 0 : _c['']) || ((_d = redirectedMapping === null || redirectedMapping === void 0 ? void 0 : redirectedMapping[pair.category]) === null || _d === void 0 ? void 0 : _d[from]) || ((_e = redirectedMapping === null || redirectedMapping === void 0 ? void 0 : redirectedMapping[pair.category]) === null || _e === void 0 ? void 0 : _e['']);
70
78
  if (to == undefined)
@@ -79,8 +87,8 @@ function default_1(brands, strategy) {
79
87
  var _a, _b, _c, _d, _e;
80
88
  if (sku[pair.to])
81
89
  return; // Do not replace sku-level-user-supplied values
82
- const from = sku[pair.from];
83
- const redirectedMappingSource = (_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a['~~'];
90
+ const from = evaluateFromExpr(sku, pair.from);
91
+ const redirectedMappingSource = ((_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a['~~']) || pair.defaultMappingSource;
84
92
  const redirectedMapping = redirectedMappingSource ? indexedByBrandPropertyMapping[redirectedMappingSource] : {};
85
93
  const to = ((_b = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _b === void 0 ? void 0 : _b[from]) || ((_c = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _c === void 0 ? void 0 : _c['']) || ((_d = redirectedMapping === null || redirectedMapping === void 0 ? void 0 : redirectedMapping[pair.category]) === null || _d === void 0 ? void 0 : _d[from]) || ((_e = redirectedMapping === null || redirectedMapping === void 0 ? void 0 : redirectedMapping[pair.category]) === null || _e === void 0 ? void 0 : _e['']);
86
94
  if (!from && !to)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.62",
3
+ "version": "1.0.64",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,7 @@
1
1
  import { hashBrand, SkuI, MAPPING_CATEGORIES, BrandSettingI, mappingStrategyE } from './index'
2
2
 
3
+ // The order of the following mappingPairs is significant.
4
+ // The ERM mapping relies on the Gender and ProductGroup mapping to have been evaluated first
3
5
  const mappingPairs = [
4
6
  { category: 'ColorCode', from: 'colorCodeSupplier', to: 'colorFamily' },
5
7
  { category: 'ColorDescription', from: 'colorSupplier', to: 'colorFamily' },
@@ -11,7 +13,13 @@ const mappingPairs = [
11
13
  { category: 'CustomSize', from: 'sizeSupplier', to: '_customsize' },
12
14
  { category: 'Size', from: 'sizeSupplier', to: 'size' },
13
15
  { category: 'Gender', from: 'articleGroupSupplier', to: '_gender', mustMatch: true },
16
+ { category: 'ERM', from: ['_gender', 'articleGroup'], to: '_erm-code', mustMatch: true, defaultMappingSource: 'ermmapping' },
14
17
  ]
18
+
19
+ const evaluateFromExpr = function (sku: SkuI, from: string | string[]): string {
20
+ if (typeof from == 'string') return sku[from]
21
+ return from.map((field) => sku[field] || '').join('.')
22
+ }
15
23
  export default function (brands: Array<BrandSettingI>, strategy: mappingStrategyE): (sku: SkuI) => SkuI {
16
24
  // Helper function to convert all mapping rules for given category to an indexed object
17
25
  const indexedMapping = function (propertyMapping, category) {
@@ -44,7 +52,7 @@ export default function (brands: Array<BrandSettingI>, strategy: mappingStrategy
44
52
  const brand = sku.BRANDHASH || hashBrand(sku.brand)
45
53
  const mapping = indexedByBrandPropertyMapping[brand]
46
54
  mappingPairs.forEach((pair) => {
47
- const from = sku[pair.from] || ''
55
+ const from = evaluateFromExpr(sku, pair.from) || ''
48
56
  const to = mapping?.[pair.category]?.[from]
49
57
  if (!from || !to) return
50
58
  if (sku[pair.to] == to || from == sku[pair.to]) delete sku[pair.to]
@@ -56,8 +64,8 @@ export default function (brands: Array<BrandSettingI>, strategy: mappingStrategy
56
64
  const brand = sku.BRANDHASH || hashBrand(sku.brand)
57
65
  const mapping = indexedByBrandPropertyMapping[brand]
58
66
  mappingPairs.forEach((pair) => {
59
- const from = sku[pair.from] || ''
60
- const redirectedMappingSource = mapping?.[pair.category]?.['~~']
67
+ const from = evaluateFromExpr(sku, pair.from) || ''
68
+ const redirectedMappingSource = mapping?.[pair.category]?.['~~'] || pair.defaultMappingSource
61
69
  const redirectedMapping = redirectedMappingSource ? indexedByBrandPropertyMapping[redirectedMappingSource] : {}
62
70
 
63
71
  const to = mapping?.[pair.category]?.[from] || mapping?.[pair.category]?.[''] || redirectedMapping?.[pair.category]?.[from] || redirectedMapping?.[pair.category]?.['']
@@ -70,8 +78,8 @@ export default function (brands: Array<BrandSettingI>, strategy: mappingStrategy
70
78
  const mapping = indexedByBrandPropertyMapping[brand]
71
79
  mappingPairs.forEach((pair) => {
72
80
  if (sku[pair.to]) return // Do not replace sku-level-user-supplied values
73
- const from = sku[pair.from]
74
- const redirectedMappingSource = mapping?.[pair.category]?.['~~']
81
+ const from = evaluateFromExpr(sku, pair.from)
82
+ const redirectedMappingSource = mapping?.[pair.category]?.['~~'] || pair.defaultMappingSource
75
83
  const redirectedMapping = redirectedMappingSource ? indexedByBrandPropertyMapping[redirectedMappingSource] : {}
76
84
 
77
85
  const to = mapping?.[pair.category]?.[from] || mapping?.[pair.category]?.[''] || redirectedMapping?.[pair.category]?.[from] || redirectedMapping?.[pair.category]?.['']
@@ -18,6 +18,7 @@ const skus = [
18
18
  colorCodeSupplier: '100',
19
19
  size: 'S',
20
20
  sizeSupplier: 'S',
21
+ articleGroupSupplier: '10000',
21
22
  },
22
23
  {
23
24
  id: '1234567890129',
@@ -26,6 +27,7 @@ const skus = [
26
27
  colorCodeSupplier: '100',
27
28
  size: 'M',
28
29
  sizeSupplier: 'M',
30
+ articleGroupSupplier: '10000',
29
31
  },
30
32
  {
31
33
  id: '1234567890130',
@@ -34,6 +36,7 @@ const skus = [
34
36
  colorCodeSupplier: '100',
35
37
  size: 'L',
36
38
  sizeSupplier: 'L',
39
+ articleGroupSupplier: '10000',
37
40
  },
38
41
  {
39
42
  id: '1234567890131',
@@ -42,6 +45,7 @@ const skus = [
42
45
  colorCodeSupplier: '200',
43
46
  size: 'S',
44
47
  sizeSupplier: 'S',
48
+ articleGroupSupplier: '10000',
45
49
  },
46
50
  {
47
51
  id: '1234567890132',
@@ -50,6 +54,7 @@ const skus = [
50
54
  colorCodeSupplier: '200',
51
55
  size: 'M',
52
56
  sizeSupplier: 'M',
57
+ articleGroupSupplier: '10000',
53
58
  },
54
59
  {
55
60
  id: '1234567890133',
@@ -58,6 +63,7 @@ const skus = [
58
63
  colorCodeSupplier: '200',
59
64
  size: 'L',
60
65
  sizeSupplier: 'L',
66
+ articleGroupSupplier: '10000',
61
67
  },
62
68
  {
63
69
  id: '1234567890134',
@@ -157,6 +163,9 @@ const fullMapping = [
157
163
  from: 'SUMMER 2022',
158
164
  to: '22zomer-fullMapping',
159
165
  },
166
+ { category: 'Gender', from: '10000', to: 'Women' },
167
+ { category: 'ProductGroup', from: '10000', to: 'JEANS' },
168
+ { category: 'ERM', from: 'Women.JEANS', to: '10000 - Women - Dresses' },
160
169
  ],
161
170
  },
162
171
  {
@@ -198,17 +207,19 @@ describe('applyPropertyMapping', () => {
198
207
  colorFamily: '100',
199
208
  collection: 'SUMMER 2022',
200
209
  _customsize: 'S',
210
+ articleGroup: '10000',
211
+ articleGroupSupplier: '10000',
201
212
  })
202
213
  })
203
214
 
204
215
  it('returns mapped articleGroups on a articlegroup mapping', function () {
205
216
  const mappedSkus = applyPropertyMapping(deepCopy(skus), articleGroupMapping)
206
- expect(mappedSkus[0].articleGroup).to.equal(undefined)
207
- expect(mappedSkus[1].articleGroup).to.equal(undefined)
208
- expect(mappedSkus[2].articleGroup).to.equal(undefined)
209
- expect(mappedSkus[3].articleGroup).to.equal(undefined)
210
- expect(mappedSkus[4].articleGroup).to.equal(undefined)
211
- expect(mappedSkus[5].articleGroup).to.equal(undefined)
217
+ expect(mappedSkus[0].articleGroup).to.equal('10000')
218
+ expect(mappedSkus[1].articleGroup).to.equal('10000')
219
+ expect(mappedSkus[2].articleGroup).to.equal('10000')
220
+ expect(mappedSkus[3].articleGroup).to.equal('10000')
221
+ expect(mappedSkus[4].articleGroup).to.equal('10000')
222
+ expect(mappedSkus[5].articleGroup).to.equal('10000')
212
223
  expect(mappedSkus[6].articleGroup).to.equal('PANTS-articleGroupMapping')
213
224
  expect(mappedSkus[7].articleGroup).to.equal('PANTS-articleGroupMapping')
214
225
  expect(mappedSkus[8].articleGroup).to.equal('PANTS-articleGroupMapping')
@@ -294,7 +305,6 @@ describe('applyPropertyMapping', () => {
294
305
  expect(mappedSkus[1]._customsize).to.equal('M')
295
306
  expect(mappedSkus[7]._customsize).to.equal('medium')
296
307
 
297
- expect(mappedSkus[1]._gender).to.equal(undefined)
298
308
  expect(mappedSkus[7]._gender).to.equal('uni')
299
309
 
300
310
  expect(mappedSkus[0].FEDASGROUP).to.equal(undefined)
@@ -310,6 +320,10 @@ describe('applyPropertyMapping', () => {
310
320
  expect(mappedSkus[9].FEDASGROUP).to.equal(undefined)
311
321
  expect(mappedSkus[9].BTEGROUP).to.equal(undefined)
312
322
  expect(mappedSkus[9].DTBGROUP).to.equal(undefined)
323
+
324
+ expect(mappedSkus[0].articleGroup).to.equal('JEANS')
325
+ expect(mappedSkus[0]._gender).to.equal('Women')
326
+ expect(mappedSkus[0]['_erm-code']).to.equal('10000 - Women - Dresses')
313
327
  })
314
328
 
315
329
  it('returns mapped skus on a default mapping rules', function () {