@softwear/latestcollectioncore 1.0.34 → 1.0.35

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, BrandSettingI } from "./index";
2
- export default function (brands: Array<BrandSettingI>): (sku: SkuI) => SkuI;
1
+ import { SkuI, BrandSettingI, mappingStrategyE } from "./index";
2
+ export default function (brands: Array<BrandSettingI>, strategy: mappingStrategyE): (sku: SkuI) => SkuI;
@@ -1,7 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_1 = require("./index");
4
- function default_1(brands) {
4
+ const mappingPairs = [
5
+ { category: "ColorCode", from: "colorCodeSupplier", to: "colorFamily" },
6
+ { category: "ColorDescription", from: "colorSupplier", to: "colorFamily" },
7
+ {
8
+ category: "ProductGroup",
9
+ from: "articleGroupSupplier",
10
+ to: "articleGroup",
11
+ },
12
+ {
13
+ category: "ProductGroup",
14
+ from: "articleGroupSupplier",
15
+ to: "articleGroup",
16
+ },
17
+ { category: "Collection", from: "collectionSupplier", to: "collection" },
18
+ { category: "CustomSize", from: "sizeSupplier", to: "_customsize" },
19
+ { category: "Size", from: "sizeSupplier", to: "size" },
20
+ { category: "Gender", from: "NOFROMFIELD", to: "_gender" },
21
+ ];
22
+ function default_1(brands, strategy) {
5
23
  // Helper function to convert all mapping rules for given category to an indexed object
6
24
  const indexedMapping = function (propertyMapping, category) {
7
25
  const filteredMappings = propertyMapping.filter((mapping) => mapping.category == category && mapping.from != undefined);
@@ -30,76 +48,30 @@ function default_1(brands) {
30
48
  Object.assign(acc[item.id], indexFn(item.propertyMapping));
31
49
  return acc;
32
50
  }, {});
51
+ if (strategy == "clean")
52
+ return function (sku) {
53
+ const brand = (0, index_1.hashBrand)(sku.brand);
54
+ const mapping = indexedPropertyMapping[brand];
55
+ mappingPairs.forEach((pair) => {
56
+ var _a;
57
+ const from = sku[pair.from] || "";
58
+ const to = (_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a[from];
59
+ if (to && sku[pair.to] == to)
60
+ delete sku[pair.to];
61
+ });
62
+ return sku;
63
+ };
33
64
  return function (sku) {
34
65
  const brand = (0, index_1.hashBrand)(sku.brand);
35
66
  const mapping = indexedPropertyMapping[brand];
36
- if (!mapping)
37
- return sku;
38
- if (mapping.ColorCode) {
39
- const from = sku.colorCodeSupplier;
40
- if (from) {
41
- const to = indexedPropertyMapping[brand].ColorCode[from];
42
- if (to && to != sku.colorFamily)
43
- sku.colorFamily = to;
44
- }
45
- }
46
- if (mapping.ColorDescription) {
47
- const from = sku.colorSupplier;
48
- if (from) {
49
- const to = indexedPropertyMapping[brand].ColorDescription[from];
50
- if (to && to != sku.colorFamily)
51
- sku.colorFamily = to;
52
- }
53
- }
54
- if (mapping.ProductGroup) {
55
- const from = sku.articleGroupSupplier;
56
- if (from) {
57
- const to = indexedPropertyMapping[brand].ProductGroup[from];
58
- if (to && to != sku.articleGroup)
59
- sku.articleGroup = to;
60
- }
61
- }
62
- if (mapping.Collection) {
63
- const from = sku.collectionSupplier;
64
- if (from) {
65
- const to = indexedPropertyMapping[brand].Collection[from];
66
- if (to && to != sku.collection)
67
- sku.collection = to;
68
- }
69
- }
70
- if (mapping.Size) {
71
- const from = sku.sizeSupplier;
72
- if (from) {
73
- const to = indexedPropertyMapping[brand].Size[from];
74
- if (to && to != sku.size) {
75
- sku.size = to;
76
- sku.mainSize = to;
77
- }
78
- }
79
- }
80
- if (mapping.SubSize) {
81
- const from = sku.sizeSupplier;
82
- if (from) {
83
- const to = indexedPropertyMapping[brand].SubSize[from];
84
- if (to && to != sku.subSize)
85
- sku.subSize = to;
86
- }
87
- }
88
- if (mapping.CustomSize) {
89
- const from = sku.sizeSupplier;
90
- if (from) {
91
- const to = indexedPropertyMapping[brand].CustomSize[from];
92
- if (to && to != sku["_customsize"])
93
- sku["_customsize"] = to;
94
- }
95
- }
96
- if (mapping.Gender) {
97
- // There is nothing to map 'from'
98
- // We only implement the fallback, this mapping is only usefull for brands where gender is constant
99
- const to = indexedPropertyMapping[brand].Gender[""];
100
- if (to && to != sku["_gender"])
101
- sku["_gender"] = to;
102
- }
67
+ mappingPairs.forEach((pair) => {
68
+ var _a;
69
+ if (sku[pair.to])
70
+ return; // Do not replace sku-level-user-supplied values
71
+ const from = sku[pair.from] || ""; // || "" allows mapping 'from nothing'. Useful to assign constants like Gender for single-gender-brands
72
+ const to = (_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a[from];
73
+ sku[pair.to] = to ? to : from;
74
+ });
103
75
  return sku;
104
76
  };
105
77
  }
package/dist/types.d.ts CHANGED
@@ -203,4 +203,8 @@ interface BrandSettingI {
203
203
  propertyMapping?: object[];
204
204
  fashionCloudId?: string;
205
205
  }
206
- export { RowI, StockTransferSelectionI, MarkedSkuI, vatCategoryE, tagTypeE, SkuI, GroupI, ProductI, ImageI, AttributeI, ColorI, MatrixI, StockTransferDataI, StockTransferMatrixI, BrandSettingI, };
206
+ declare enum mappingStrategyE {
207
+ MAP = "map",
208
+ CLEAN = "clean"
209
+ }
210
+ export { RowI, StockTransferSelectionI, MarkedSkuI, vatCategoryE, tagTypeE, SkuI, GroupI, ProductI, ImageI, AttributeI, ColorI, MatrixI, StockTransferDataI, StockTransferMatrixI, BrandSettingI, mappingStrategyE, };
package/dist/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tagTypeE = exports.vatCategoryE = void 0;
3
+ exports.mappingStrategyE = exports.tagTypeE = exports.vatCategoryE = void 0;
4
4
  var vatCategoryE;
5
5
  (function (vatCategoryE) {
6
6
  vatCategoryE["LOW"] = "low";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,33 @@
1
- import { hashBrand, SkuI, MAPPING_CATEGORIES, BrandSettingI } from "./index";
1
+ import {
2
+ hashBrand,
3
+ SkuI,
4
+ MAPPING_CATEGORIES,
5
+ BrandSettingI,
6
+ mappingStrategyE,
7
+ } from "./index";
2
8
 
3
- export default function (brands: Array<BrandSettingI>): (sku: SkuI) => SkuI {
9
+ const mappingPairs = [
10
+ { category: "ColorCode", from: "colorCodeSupplier", to: "colorFamily" },
11
+ { category: "ColorDescription", from: "colorSupplier", to: "colorFamily" },
12
+ {
13
+ category: "ProductGroup",
14
+ from: "articleGroupSupplier",
15
+ to: "articleGroup",
16
+ },
17
+ {
18
+ category: "ProductGroup",
19
+ from: "articleGroupSupplier",
20
+ to: "articleGroup",
21
+ },
22
+ { category: "Collection", from: "collectionSupplier", to: "collection" },
23
+ { category: "CustomSize", from: "sizeSupplier", to: "_customsize" },
24
+ { category: "Size", from: "sizeSupplier", to: "size" },
25
+ { category: "Gender", from: "NOFROMFIELD", to: "_gender" },
26
+ ];
27
+ export default function (
28
+ brands: Array<BrandSettingI>,
29
+ strategy: mappingStrategyE
30
+ ): (sku: SkuI) => SkuI {
4
31
  // Helper function to convert all mapping rules for given category to an indexed object
5
32
  const indexedMapping = function (propertyMapping, category) {
6
33
  const filteredMappings = propertyMapping.filter(
@@ -29,69 +56,26 @@ export default function (brands: Array<BrandSettingI>): (sku: SkuI) => SkuI {
29
56
  return acc;
30
57
  }, {});
31
58
 
59
+ if (strategy == "clean")
60
+ return function (sku: SkuI): SkuI {
61
+ const brand = hashBrand(sku.brand);
62
+ const mapping = indexedPropertyMapping[brand];
63
+ mappingPairs.forEach((pair) => {
64
+ const from = sku[pair.from] || "";
65
+ const to = mapping?.[pair.category]?.[from];
66
+ if (to && sku[pair.to] == to) delete sku[pair.to];
67
+ });
68
+ return sku;
69
+ };
32
70
  return function (sku: SkuI): SkuI {
33
71
  const brand = hashBrand(sku.brand);
34
72
  const mapping = indexedPropertyMapping[brand];
35
- if (!mapping) return sku;
36
-
37
- if (mapping.ColorCode) {
38
- const from = sku.colorCodeSupplier;
39
- if (from) {
40
- const to = indexedPropertyMapping[brand].ColorCode[from];
41
- if (to && to != sku.colorFamily) sku.colorFamily = to;
42
- }
43
- }
44
- if (mapping.ColorDescription) {
45
- const from = sku.colorSupplier;
46
- if (from) {
47
- const to = indexedPropertyMapping[brand].ColorDescription[from];
48
- if (to && to != sku.colorFamily) sku.colorFamily = to;
49
- }
50
- }
51
- if (mapping.ProductGroup) {
52
- const from = sku.articleGroupSupplier;
53
- if (from) {
54
- const to = indexedPropertyMapping[brand].ProductGroup[from];
55
- if (to && to != sku.articleGroup) sku.articleGroup = to;
56
- }
57
- }
58
- if (mapping.Collection) {
59
- const from = sku.collectionSupplier;
60
- if (from) {
61
- const to = indexedPropertyMapping[brand].Collection[from];
62
- if (to && to != sku.collection) sku.collection = to;
63
- }
64
- }
65
- if (mapping.Size) {
66
- const from = sku.sizeSupplier;
67
- if (from) {
68
- const to = indexedPropertyMapping[brand].Size[from];
69
- if (to && to != sku.size) {
70
- sku.size = to;
71
- sku.mainSize = to;
72
- }
73
- }
74
- }
75
- if (mapping.SubSize) {
76
- const from = sku.sizeSupplier;
77
- if (from) {
78
- const to = indexedPropertyMapping[brand].SubSize[from];
79
- if (to && to != sku.subSize) sku.subSize = to;
80
- }
81
- }
82
- if (mapping.CustomSize) {
83
- const from = sku.sizeSupplier;
84
- if (from) {
85
- const to = indexedPropertyMapping[brand].CustomSize[from];
86
- if (to && to != sku["_customsize"]) sku["_customsize"] = to;
87
- }
88
- }
89
- if (mapping.Gender) {
90
- // There is nothing to map 'from'
91
- // We only implement the fallback, this mapping is only usefull for brands where gender is constant
92
- const to = indexedPropertyMapping[brand].Gender[""];
93
- if (to && to != sku["_gender"]) sku["_gender"] = to;
94
- }
73
+ mappingPairs.forEach((pair) => {
74
+ if (sku[pair.to]) return; // Do not replace sku-level-user-supplied values
75
+ const from = sku[pair.from] || ""; // || "" allows mapping 'from nothing'. Useful to assign constants like Gender for single-gender-brands
76
+ const to = mapping?.[pair.category]?.[from];
77
+ sku[pair.to] = to ? to : from;
78
+ });
95
79
  return sku;
96
80
  };
97
81
  }
package/src/types.ts CHANGED
@@ -10,62 +10,62 @@ enum tagTypeE {
10
10
  }
11
11
 
12
12
  interface ImageI {
13
- name: string
14
- url: string
13
+ name: string;
14
+ url: string;
15
15
  }
16
16
 
17
17
  interface GroupI {
18
- name: string
19
- value: string
18
+ name: string;
19
+ value: string;
20
20
  }
21
21
 
22
22
  interface CareI {
23
- temperature: number
24
- bleach: number
25
- iron: number
26
- chemical: number
27
- dryer: number
23
+ temperature: number;
24
+ bleach: number;
25
+ iron: number;
26
+ chemical: number;
27
+ dryer: number;
28
28
  }
29
29
 
30
30
  interface AttributeI {
31
- key: string
32
- value: string
31
+ key: string;
32
+ value: string;
33
33
  }
34
34
  // better represents what the key is in MatrixI
35
- type barcode = string
35
+ type barcode = string;
36
36
 
37
37
  interface RowI {
38
- cells: { key?: barcode | undefined; value: number; state?: string }[] // uses the barcode for backtracking of each cell
39
- group: string // first column of a row, could be a grouper or a color
40
- initialIndex?: number // used for filtered data
41
- filteredOut?: boolean // used for filtered data
42
- warehouse?: string // used for stock management, the actual string might be in the group key as well
43
- selected?: boolean // used for UI
38
+ cells: { key?: barcode | undefined; value: number; state?: string }[]; // uses the barcode for backtracking of each cell
39
+ group: string; // first column of a row, could be a grouper or a color
40
+ initialIndex?: number; // used for filtered data
41
+ filteredOut?: boolean; // used for filtered data
42
+ warehouse?: string; // used for stock management, the actual string might be in the group key as well
43
+ selected?: boolean; // used for UI
44
44
  }
45
45
 
46
46
  interface MatrixI {
47
- matrixMetadata: string | string[]
48
- headers: string[]
49
- rows: RowI[]
47
+ matrixMetadata: string | string[];
48
+ headers: string[];
49
+ rows: RowI[];
50
50
  }
51
51
 
52
52
  interface StockTransferMatrixI {
53
- rows: RowI[]
54
- selection: StockTransferSelectionI
53
+ rows: RowI[];
54
+ selection: StockTransferSelectionI;
55
55
  }
56
56
 
57
57
  interface StockTransferDataI extends StockTransferMatrixI {
58
- rowIndex: number
59
- cellIndex: number | undefined
60
- value: number | undefined
58
+ rowIndex: number;
59
+ cellIndex: number | undefined;
60
+ value: number | undefined;
61
61
  }
62
62
 
63
63
  interface StockTransferSelectionI {
64
64
  cells: {
65
- cellIndex: number
66
- value: number
67
- }[]
68
- rowIndex: number | null
65
+ cellIndex: number;
66
+ value: number;
67
+ }[];
68
+ rowIndex: number | null;
69
69
  }
70
70
 
71
71
  /**
@@ -79,77 +79,77 @@ interface StockTransferSelectionI {
79
79
  * They are not part of the persistent data model
80
80
  */
81
81
  interface SkuI {
82
- barcode?: barcode
83
- id?: barcode
84
- primary: boolean
85
- articleCode: string
86
- articleDescription: string
87
- pricetagLayouts: string
88
- brand: string
89
- articleGroup: string
90
- articleGroupSupplier?: string
91
- campaigns?: string
92
- images?: string
93
- groups: Array<GroupI>
94
- vat: number
95
- vatCategory: vatCategoryE
96
- supplierName?: string
97
- size: string
98
- sizeSupplier?: string
99
- mainSize?: string
100
- subSize?: string
101
- subSizeSupplier?: string
102
- sizeIndex: number
103
- sizes?: Array<string>
104
- sizeRange?: string
105
- colorCode?: string
106
- colorDescription?: string
107
- colorSupplier?: string
108
- colorCodeSupplier?: string
109
- colorFamily: string
110
- mainColorCode: string
111
- mainColorDescription?: string
112
- subColorCode?: string
113
- subColorDescription?: string
114
- articleCodeSupplier?: string
115
- price: number
116
- buyPrice: number
117
- suggestedRetailPrice: number
118
- valuePrice: number
119
- salePrice: number
120
- prices?: unknown
121
- year?: string
122
- season?: string
123
- collection: string
124
- collectionSupplier?: string
125
- active: boolean
126
- skuActive: boolean
127
- warehouseLocation: string
128
- tagType?: tagTypeE
129
- directDelivery?: boolean
130
- care?: CareI
131
- BRANDHASH: string
132
- ATTRIBUTES?: object
133
- IMAGES?: Array<ImageI>
134
- SIZES?: unknown
135
- FOOTPRINT?: number
136
- quickPick?: number
82
+ barcode?: barcode;
83
+ id?: barcode;
84
+ primary: boolean;
85
+ articleCode: string;
86
+ articleDescription: string;
87
+ pricetagLayouts: string;
88
+ brand: string;
89
+ articleGroup: string;
90
+ articleGroupSupplier?: string;
91
+ campaigns?: string;
92
+ images?: string;
93
+ groups: Array<GroupI>;
94
+ vat: number;
95
+ vatCategory: vatCategoryE;
96
+ supplierName?: string;
97
+ size: string;
98
+ sizeSupplier?: string;
99
+ mainSize?: string;
100
+ subSize?: string;
101
+ subSizeSupplier?: string;
102
+ sizeIndex: number;
103
+ sizes?: Array<string>;
104
+ sizeRange?: string;
105
+ colorCode?: string;
106
+ colorDescription?: string;
107
+ colorSupplier?: string;
108
+ colorCodeSupplier?: string;
109
+ colorFamily: string;
110
+ mainColorCode: string;
111
+ mainColorDescription?: string;
112
+ subColorCode?: string;
113
+ subColorDescription?: string;
114
+ articleCodeSupplier?: string;
115
+ price: number;
116
+ buyPrice: number;
117
+ suggestedRetailPrice: number;
118
+ valuePrice: number;
119
+ salePrice: number;
120
+ prices?: unknown;
121
+ year?: string;
122
+ season?: string;
123
+ collection: string;
124
+ collectionSupplier?: string;
125
+ active: boolean;
126
+ skuActive: boolean;
127
+ warehouseLocation: string;
128
+ tagType?: tagTypeE;
129
+ directDelivery?: boolean;
130
+ care?: CareI;
131
+ BRANDHASH: string;
132
+ ATTRIBUTES?: object;
133
+ IMAGES?: Array<ImageI>;
134
+ SIZES?: unknown;
135
+ FOOTPRINT?: number;
136
+ quickPick?: number;
137
137
  }
138
138
 
139
139
  interface MarkedSkuI extends SkuI {
140
- source?: string
141
- usedByTenant?: boolean
142
- warehouse?: string
143
- qty?: number
140
+ source?: string;
141
+ usedByTenant?: boolean;
142
+ warehouse?: string;
143
+ qty?: number;
144
144
  }
145
145
 
146
146
  interface ColorI {
147
- color: string
148
- subColors: Array<string>
149
- IMAGES: Array<ImageI>
150
- colorCodeSupplier: string
151
- colorSupplier: string
152
- newColor?: boolean
147
+ color: string;
148
+ subColors: Array<string>;
149
+ IMAGES: Array<ImageI>;
150
+ colorCodeSupplier: string;
151
+ colorSupplier: string;
152
+ newColor?: boolean;
153
153
  }
154
154
 
155
155
  /**
@@ -159,63 +159,67 @@ interface ColorI {
159
159
  *
160
160
  */
161
161
  interface ProductI {
162
- ATTRIBUTES: object
163
- COLORS: Array<ColorI>
164
- IMAGES?: unknown
165
- INDEX: object
166
- MATRIX?: MatrixI
167
- SIZES: Array<string>
168
- SKUS: Array<MarkedSkuI>
169
- active: boolean
170
- articleCode: string
171
- articleCodeSupplier?: string
172
- articleDescription: string
173
- articleGroup: string
174
- articleGroupSupplier: string
175
- brand: string
176
- buyPrice: number
177
- care?: CareI
178
- collection: string
179
- collectionSupplier: string
180
- groups: Array<GroupI>
181
- price: number
182
- prices?: unknown
183
- pricetagLayouts: Array<string>
184
- season?: string
185
- suggestedRetailPrice: number
186
- supplierName?: string
187
- tagType?: tagTypeE
188
- valuePrice: number
189
- vat: number
190
- vatCategory: vatCategoryE
191
- warehouseLocation: string
192
- year?: string
162
+ ATTRIBUTES: object;
163
+ COLORS: Array<ColorI>;
164
+ IMAGES?: unknown;
165
+ INDEX: object;
166
+ MATRIX?: MatrixI;
167
+ SIZES: Array<string>;
168
+ SKUS: Array<MarkedSkuI>;
169
+ active: boolean;
170
+ articleCode: string;
171
+ articleCodeSupplier?: string;
172
+ articleDescription: string;
173
+ articleGroup: string;
174
+ articleGroupSupplier: string;
175
+ brand: string;
176
+ buyPrice: number;
177
+ care?: CareI;
178
+ collection: string;
179
+ collectionSupplier: string;
180
+ groups: Array<GroupI>;
181
+ price: number;
182
+ prices?: unknown;
183
+ pricetagLayouts: Array<string>;
184
+ season?: string;
185
+ suggestedRetailPrice: number;
186
+ supplierName?: string;
187
+ tagType?: tagTypeE;
188
+ valuePrice: number;
189
+ vat: number;
190
+ vatCategory: vatCategoryE;
191
+ warehouseLocation: string;
192
+ year?: string;
193
193
  }
194
194
 
195
195
  interface BrandSettingI {
196
- id: string
197
- name: string
198
- collection: string
199
- count?: number
200
- lasttime?: number
201
- hideBrand?: boolean
202
- dataProviders?: object[]
203
- url?: string
204
- www?: string
205
- externalLink?: string
206
- aliases?: string[]
207
- email?: string
208
- purchaseOrderEmail?: string
209
- gln?: string
210
- ownerTenantId?: string
211
- orderMethods?: string[]
212
- whiteListTenants?: string[]
213
- associates?: object[]
214
- authGroups?: string[]
215
- propertyMapping?: object[]
216
- fashionCloudId?: string
196
+ id: string;
197
+ name: string;
198
+ collection: string;
199
+ count?: number;
200
+ lasttime?: number;
201
+ hideBrand?: boolean;
202
+ dataProviders?: object[];
203
+ url?: string;
204
+ www?: string;
205
+ externalLink?: string;
206
+ aliases?: string[];
207
+ email?: string;
208
+ purchaseOrderEmail?: string;
209
+ gln?: string;
210
+ ownerTenantId?: string;
211
+ orderMethods?: string[];
212
+ whiteListTenants?: string[];
213
+ associates?: object[];
214
+ authGroups?: string[];
215
+ propertyMapping?: object[];
216
+ fashionCloudId?: string;
217
+ }
218
+
219
+ declare enum mappingStrategyE {
220
+ MAP = "map",
221
+ CLEAN = "clean",
217
222
  }
218
-
219
223
  export {
220
224
  RowI,
221
225
  StockTransferSelectionI,
@@ -232,4 +236,5 @@ export {
232
236
  StockTransferDataI,
233
237
  StockTransferMatrixI,
234
238
  BrandSettingI,
235
- }
239
+ mappingStrategyE,
240
+ };