@softwear/latestcollectioncore 1.0.64 → 1.0.66

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.
@@ -22,42 +22,23 @@ const evaluateFromExpr = function (sku, from) {
22
22
  return from.map((field) => sku[field] || '').join('.');
23
23
  };
24
24
  function default_1(brands, strategy) {
25
- // Helper function to convert all mapping rules for given category to an indexed object
26
- const indexedMapping = function (propertyMapping, category) {
27
- const filteredMappings = propertyMapping.filter((mapping) => mapping.category == category && mapping.from != undefined);
28
- if (filteredMappings.length == 0)
29
- return undefined;
30
- return filteredMappings.reduce((acc, item) => {
31
- acc[item.from] = item.to;
32
- return acc;
33
- }, {});
34
- };
35
- // Helper function to convert all mapping rules to an indexed object
36
- const indexFn = function (propertyMapping) {
37
- if (!propertyMapping)
38
- return {};
39
- const maps = {};
40
- index_1.MAPPING_CATEGORIES.forEach((category) => {
41
- const map = indexedMapping(propertyMapping, category);
42
- if (map !== undefined)
43
- maps[category] = map;
25
+ const indexedByBrandPropertyMapping = {};
26
+ brands.forEach(({ id, propertyMapping }) => {
27
+ if (!indexedByBrandPropertyMapping[id])
28
+ indexedByBrandPropertyMapping[id] = {};
29
+ propertyMapping?.forEach((mapping) => {
30
+ if (!indexedByBrandPropertyMapping[id][mapping.category])
31
+ indexedByBrandPropertyMapping[id][mapping.category] = {};
32
+ indexedByBrandPropertyMapping[id][mapping.category][mapping.from] = mapping.to;
44
33
  });
45
- return maps;
46
- };
47
- const indexedByBrandPropertyMapping = brands.reduce((acc, item) => {
48
- if (!acc[item.id])
49
- acc[item.id] = {};
50
- Object.assign(acc[item.id], indexFn(item.propertyMapping));
51
- return acc;
52
- }, {});
34
+ });
53
35
  if (strategy == 'clean')
54
36
  return function (sku) {
55
37
  const brand = sku.BRANDHASH || (0, index_1.hashBrand)(sku.brand);
56
38
  const mapping = indexedByBrandPropertyMapping[brand];
57
39
  mappingPairs.forEach((pair) => {
58
- var _a;
59
40
  const from = evaluateFromExpr(sku, pair.from) || '';
60
- const to = (_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a[from];
41
+ const to = mapping?.[pair.category]?.[from];
61
42
  if (!from || !to)
62
43
  return;
63
44
  if (sku[pair.to] == to || from == sku[pair.to])
@@ -70,11 +51,10 @@ function default_1(brands, strategy) {
70
51
  const brand = sku.BRANDHASH || (0, index_1.hashBrand)(sku.brand);
71
52
  const mapping = indexedByBrandPropertyMapping[brand];
72
53
  mappingPairs.forEach((pair) => {
73
- var _a, _b, _c, _d, _e;
74
54
  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;
55
+ const redirectedMappingSource = mapping?.[pair.category]?.['~~'] || pair.defaultMappingSource;
76
56
  const redirectedMapping = redirectedMappingSource ? indexedByBrandPropertyMapping[redirectedMappingSource] : {};
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['']);
57
+ const to = mapping?.[pair.category]?.[from] || mapping?.[pair.category]?.[''] || redirectedMapping?.[pair.category]?.[from] || redirectedMapping?.[pair.category]?.[''];
78
58
  if (to == undefined)
79
59
  sku[pair.to] = '***';
80
60
  });
@@ -84,13 +64,12 @@ function default_1(brands, strategy) {
84
64
  const brand = sku.BRANDHASH || (0, index_1.hashBrand)(sku.brand);
85
65
  const mapping = indexedByBrandPropertyMapping[brand];
86
66
  mappingPairs.forEach((pair) => {
87
- var _a, _b, _c, _d, _e;
88
67
  if (sku[pair.to])
89
68
  return; // Do not replace sku-level-user-supplied values
90
69
  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;
70
+ const redirectedMappingSource = mapping?.[pair.category]?.['~~'] || pair.defaultMappingSource;
92
71
  const redirectedMapping = redirectedMappingSource ? indexedByBrandPropertyMapping[redirectedMappingSource] : {};
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['']);
72
+ const to = mapping?.[pair.category]?.[from] || mapping?.[pair.category]?.[''] || redirectedMapping?.[pair.category]?.[from] || redirectedMapping?.[pair.category]?.[''];
94
73
  if (!from && !to)
95
74
  return;
96
75
  if (pair.mustMatch) {
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // This function combined the 3 levels of property mapping into one mapping object
4
4
  // Each level can be opted in/out in the tenantPreferences defined in the activeConfig parameter
5
5
  function default_1(activeConfig, metaBrandSetting, dataProviderBrandSetting, tenantBrandSetting) {
6
- var _a, _b, _c, _d, _e, _f;
7
6
  let allMappings = [];
8
- if ((_b = (_a = activeConfig === null || activeConfig === void 0 ? void 0 : activeConfig.products) === null || _a === void 0 ? void 0 : _a.applyLatestCollectionMapping) === null || _b === void 0 ? void 0 : _b.value)
7
+ if (activeConfig?.products?.applyLatestCollectionMapping?.value)
9
8
  allMappings = metaBrandSetting;
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)
9
+ if (activeConfig?.products?.applyDataProviderMapping?.value)
11
10
  activeConfig.products.applyDataProviderMapping.value.forEach((provider) => {
12
- allMappings = allMappings.concat(dataProviderBrandSetting.filter((s) => s.dataProvider == provider).map((s) => (Object.assign(Object.assign({}, s), { id: s.id.split(":")[0] }))));
11
+ allMappings = allMappings.concat(dataProviderBrandSetting.filter((s) => s.dataProvider == provider).map((s) => ({ ...s, id: s.id.split(":")[0] })));
13
12
  });
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)
13
+ if (activeConfig?.products?.applyTenantMapping?.value)
15
14
  allMappings = allMappings.concat(tenantBrandSetting);
16
15
  return allMappings;
17
16
  }
package/dist/index.d.ts CHANGED
@@ -4,5 +4,6 @@ export { default as ean13 } from './ean13';
4
4
  export { default as getPreferedPropertyMappings } from './getPreferedPropertyMappings';
5
5
  export { default as hashBrand } from './hashBrand';
6
6
  export { default as hasOnlyDigits } from './hasOnlyDigits';
7
+ export { default as sizeToMap } from './sizeToMap';
7
8
  export * from './types';
8
9
  export * from './consts';
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ 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.hasOnlyDigits = exports.hashBrand = exports.getPreferedPropertyMappings = exports.ean13 = exports.deepCopy = exports.buildPropertyMappingFn = void 0;
20
+ exports.sizeToMap = exports.hasOnlyDigits = exports.hashBrand = exports.getPreferedPropertyMappings = exports.ean13 = exports.deepCopy = exports.buildPropertyMappingFn = void 0;
21
21
  var buildPropertyMappingFn_1 = require("./buildPropertyMappingFn");
22
22
  Object.defineProperty(exports, "buildPropertyMappingFn", { enumerable: true, get: function () { return __importDefault(buildPropertyMappingFn_1).default; } });
23
23
  var deepCopy_1 = require("./deepCopy");
@@ -30,5 +30,7 @@ var hashBrand_1 = require("./hashBrand");
30
30
  Object.defineProperty(exports, "hashBrand", { enumerable: true, get: function () { return __importDefault(hashBrand_1).default; } });
31
31
  var hasOnlyDigits_1 = require("./hasOnlyDigits");
32
32
  Object.defineProperty(exports, "hasOnlyDigits", { enumerable: true, get: function () { return __importDefault(hasOnlyDigits_1).default; } });
33
+ var sizeToMap_1 = require("./sizeToMap");
34
+ Object.defineProperty(exports, "sizeToMap", { enumerable: true, get: function () { return __importDefault(sizeToMap_1).default; } });
33
35
  __exportStar(require("./types"), exports);
34
36
  __exportStar(require("./consts"), exports);
@@ -0,0 +1 @@
1
+ export default function (size: String): String;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function default_1(size) {
4
+ if (typeof size != 'string')
5
+ return '';
6
+ return size.replaceAll(' ', '').replaceAll(',', '.').toUpperCase();
7
+ }
8
+ exports.default = default_1;
package/dist/types.d.ts CHANGED
@@ -191,6 +191,11 @@ interface ProductI {
191
191
  warehouseLocation: string;
192
192
  year?: string;
193
193
  }
194
+ interface PropertyMappingI {
195
+ category: string;
196
+ from: string;
197
+ to: string;
198
+ }
194
199
  interface BrandSettingI {
195
200
  id: string;
196
201
  name: string;
@@ -211,7 +216,7 @@ interface BrandSettingI {
211
216
  whiteListTenants?: string[];
212
217
  associates?: object[];
213
218
  authGroups?: string[];
214
- propertyMapping?: object[];
219
+ propertyMapping?: PropertyMappingI[];
215
220
  fashionCloudId?: string;
216
221
  }
217
222
  declare enum mappingStrategyE {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.64",
3
+ "version": "1.0.66",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { hashBrand, SkuI, MAPPING_CATEGORIES, BrandSettingI, mappingStrategyE } from './index'
1
+ import { hashBrand, SkuI, BrandSettingI, mappingStrategyE } from './index'
2
2
 
3
3
  // The order of the following mappingPairs is significant.
4
4
  // The ERM mapping relies on the Gender and ProductGroup mapping to have been evaluated first
@@ -20,33 +20,24 @@ const evaluateFromExpr = function (sku: SkuI, from: string | string[]): string {
20
20
  if (typeof from == 'string') return sku[from]
21
21
  return from.map((field) => sku[field] || '').join('.')
22
22
  }
23
- export default function (brands: Array<BrandSettingI>, strategy: mappingStrategyE): (sku: SkuI) => SkuI {
24
- // Helper function to convert all mapping rules for given category to an indexed object
25
- const indexedMapping = function (propertyMapping, category) {
26
- const filteredMappings = propertyMapping.filter((mapping) => mapping.category == category && mapping.from != undefined)
27
23
 
28
- if (filteredMappings.length == 0) return undefined
29
- return filteredMappings.reduce((acc, item) => {
30
- acc[item.from] = item.to
31
- return acc
32
- }, {})
33
- }
34
- // Helper function to convert all mapping rules to an indexed object
35
- const indexFn = function (propertyMapping) {
36
- if (!propertyMapping) return {}
37
- const maps = {}
38
- MAPPING_CATEGORIES.forEach((category) => {
39
- const map = indexedMapping(propertyMapping, category)
40
- if (map !== undefined) maps[category] = map
41
- })
42
- return maps
24
+ interface propertyMappingI {
25
+ [brandId: string]: {
26
+ [category: string]: {
27
+ [from: string]: string
28
+ }
43
29
  }
44
- const indexedByBrandPropertyMapping = brands.reduce((acc, item) => {
45
- if (!acc[item.id]) acc[item.id] = {}
46
- Object.assign(acc[item.id], indexFn(item.propertyMapping))
47
- return acc
48
- }, {})
30
+ }
49
31
 
32
+ export default function (brands: Array<BrandSettingI>, strategy: mappingStrategyE): (sku: SkuI) => SkuI {
33
+ const indexedByBrandPropertyMapping = {} as propertyMappingI
34
+ brands.forEach(({ id, propertyMapping }) => {
35
+ if (!indexedByBrandPropertyMapping[id]) indexedByBrandPropertyMapping[id] = {}
36
+ propertyMapping?.forEach((mapping) => {
37
+ if (!indexedByBrandPropertyMapping[id][mapping.category]) indexedByBrandPropertyMapping[id][mapping.category] = {}
38
+ indexedByBrandPropertyMapping[id][mapping.category][mapping.from] = mapping.to
39
+ })
40
+ })
50
41
  if (strategy == 'clean')
51
42
  return function (sku: SkuI): SkuI {
52
43
  const brand = sku.BRANDHASH || hashBrand(sku.brand)
package/src/index.ts CHANGED
@@ -4,5 +4,6 @@ export { default as ean13 } from './ean13'
4
4
  export { default as getPreferedPropertyMappings } from './getPreferedPropertyMappings'
5
5
  export { default as hashBrand } from './hashBrand'
6
6
  export { default as hasOnlyDigits } from './hasOnlyDigits'
7
+ export { default as sizeToMap } from './sizeToMap'
7
8
  export * from './types'
8
9
  export * from './consts'
@@ -0,0 +1,4 @@
1
+ export default function (size: String): String {
2
+ if (typeof size != 'string') return ''
3
+ return size.replaceAll(' ', '').replaceAll(',', '.').toUpperCase()
4
+ }
package/src/types.ts CHANGED
@@ -204,6 +204,11 @@ interface ProductI {
204
204
  year?: string
205
205
  }
206
206
 
207
+ interface PropertyMappingI {
208
+ category: string
209
+ from: string
210
+ to: string
211
+ }
207
212
  interface BrandSettingI {
208
213
  id: string
209
214
  name: string
@@ -224,7 +229,7 @@ interface BrandSettingI {
224
229
  whiteListTenants?: string[]
225
230
  associates?: object[]
226
231
  authGroups?: string[]
227
- propertyMapping?: object[]
232
+ propertyMapping?: PropertyMappingI[]
228
233
  fashionCloudId?: string
229
234
  }
230
235
 
@@ -233,6 +238,7 @@ enum mappingStrategyE {
233
238
  CLEAN = 'clean',
234
239
  MARK = 'markMissingMapping',
235
240
  }
241
+
236
242
  export {
237
243
  RowI,
238
244
  StockTransferSelectionI,
@@ -107,6 +107,16 @@ const skus = [
107
107
  collection: '22zomer',
108
108
  _customsize: 'medium',
109
109
  },
110
+ {
111
+ id: '1234567890138',
112
+ articleGroupSupplier: '11111',
113
+ brand: 'gstar',
114
+ collectionSupplier: 'SUMMER 2022',
115
+ colorCodeSupplier: '200',
116
+ colorFamily: 'Blue',
117
+ size: 'L',
118
+ sizeSupplier: 'L',
119
+ },
110
120
  ]
111
121
 
112
122
  const articleGroupMapping = [
@@ -190,6 +200,36 @@ const fallbackMapping = [
190
200
  ],
191
201
  },
192
202
  ]
203
+
204
+ const stackedMapping = [
205
+ {
206
+ id: 'gstar',
207
+ comment: 'LatestCollection level mapping',
208
+ propertyMapping: [
209
+ {
210
+ category: 'ProductGroup',
211
+ from: '12345',
212
+ to: 'LAT-articleGroupMapping',
213
+ },
214
+ {
215
+ category: 'ProductGroup',
216
+ from: '11111',
217
+ to: 'LAT-articleGroupMapping',
218
+ },
219
+ ],
220
+ },
221
+ {
222
+ id: 'gstar',
223
+ comment: 'Tenant level mapping',
224
+ propertyMapping: [
225
+ {
226
+ category: 'ProductGroup',
227
+ from: '12345',
228
+ to: 'TENANT-articleGroupMapping',
229
+ },
230
+ ],
231
+ },
232
+ ]
193
233
  describe('applyPropertyMapping', () => {
194
234
  it('returns empty array on an empty array', function () {
195
235
  expect(applyPropertyMapping([], []).length).to.equal(0)
@@ -345,4 +385,10 @@ describe('applyPropertyMapping', () => {
345
385
  expect(cleanedSkus[9]._customsize).to.equal(undefined)
346
386
  expect(cleanedSkus[9].collection).to.equal(undefined)
347
387
  })
388
+
389
+ it('applies mapping from different sources', function () {
390
+ const mappedSkus = applyPropertyMapping(deepCopy(skus), stackedMapping)
391
+ expect(mappedSkus[6].articleGroup).to.equal('TENANT-articleGroupMapping')
392
+ expect(mappedSkus[10].articleGroup).to.equal('LAT-articleGroupMapping')
393
+ })
348
394
  })
@@ -0,0 +1,17 @@
1
+ const { sizeToMap } = require('../dist/index')
2
+ const { expect } = require('chai')
3
+
4
+ describe('sizeToMap function', function () {
5
+ it('should return an empty string on non-string inputs', function () {
6
+ expect(sizeToMap(3)).to.equal('')
7
+ })
8
+ it('should return the input with spaces spaces', function () {
9
+ expect(sizeToMap(' 65 B ')).to.equal('65B')
10
+ })
11
+ it("should return the input with comma's replaced with dots", function () {
12
+ expect(sizeToMap('32,32')).to.equal('32.32')
13
+ })
14
+ it('should return the input as uppercase', function () {
15
+ expect(sizeToMap('xxl')).to.equal('XXL')
16
+ })
17
+ })
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
4
  /* Basic Options */
5
5
  // "incremental": true, /* Enable incremental compilation */
6
- "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
6
+ "target": "es2021" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
7
7
  "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
8
8
  // "lib": [], /* Specify library files to be included in the compilation. */
9
9
  // "allowJs": true, /* Allow javascript files to be compiled. */