feed-common 1.49.2 → 1.49.3

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/constants/profile.constants.d.ts +1 -2
  3. package/dist/constants/profile.constants.d.ts.map +1 -1
  4. package/dist/constants/profile.constants.js +145 -145
  5. package/dist/constants/profile.constants.js.map +1 -1
  6. package/dist/types/profile.types.d.ts +3 -5
  7. package/dist/types/profile.types.d.ts.map +1 -1
  8. package/dist/utils/feed-templates/facebook.template.d.ts.map +1 -1
  9. package/dist/utils/feed-templates/facebook.template.js +2 -0
  10. package/dist/utils/feed-templates/facebook.template.js.map +1 -1
  11. package/dist/utils/feed-templates/google-api.template.d.ts.map +1 -1
  12. package/dist/utils/feed-templates/google-api.template.js +8 -0
  13. package/dist/utils/feed-templates/google-api.template.js.map +1 -1
  14. package/dist/utils/feed-templates/google.template.d.ts.map +1 -1
  15. package/dist/utils/feed-templates/google.template.js +10 -0
  16. package/dist/utils/feed-templates/google.template.js.map +1 -1
  17. package/dist/utils/feed-templates/microsoft.template.d.ts.map +1 -1
  18. package/dist/utils/feed-templates/microsoft.template.js +3 -0
  19. package/dist/utils/feed-templates/microsoft.template.js.map +1 -1
  20. package/dist/utils/feed-templates/tiktok.template.d.ts.map +1 -1
  21. package/dist/utils/feed-templates/tiktok.template.js +2 -0
  22. package/dist/utils/feed-templates/tiktok.template.js.map +1 -1
  23. package/dist/utils/profile.d.ts +0 -7
  24. package/dist/utils/profile.d.ts.map +1 -1
  25. package/dist/utils/profile.js +57 -52
  26. package/dist/utils/profile.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/constants/profile.constants.ts +147 -146
  29. package/src/types/profile.types.ts +3 -5
  30. package/src/utils/feed-templates/facebook.template.ts +2 -0
  31. package/src/utils/feed-templates/google-api.template.ts +8 -0
  32. package/src/utils/feed-templates/google.template.ts +10 -0
  33. package/src/utils/feed-templates/microsoft.template.ts +3 -0
  34. package/src/utils/feed-templates/tiktok.template.ts +2 -0
  35. package/src/utils/profile.ts +62 -62
  36. package/tests/profile.spec.ts +765 -755
@@ -38,6 +38,7 @@ const availabilityMapping: ProductUploadMapSource = {
38
38
  validateIfNoMacro(v, z.enum(['in_stock', 'out_of_stock', 'preorder', 'backorder'])),
39
39
  rules: { sections: [] },
40
40
  baseMode: true,
41
+ defaultValue: '',
41
42
  };
42
43
 
43
44
  const customLabelMapping: ProductUploadMapSource = {
@@ -49,6 +50,7 @@ const customLabelMapping: ProductUploadMapSource = {
49
50
  type: 'macro-input' as any,
50
51
  validator: (v: string | number) => validateIfNoMacro(v, z.string().max(100)),
51
52
  rules: { sections: [] },
53
+ defaultValue: '',
52
54
  };
53
55
 
54
56
  export const googleFeedTemplate: XmlFeedTemplateType = {
@@ -375,6 +377,7 @@ export const googleFeedTemplate: XmlFeedTemplateType = {
375
377
  required: false,
376
378
  type: 'macro-input',
377
379
  rules: { sections: [] },
380
+ defaultValue: '',
378
381
  },
379
382
  {
380
383
  attribute: 'auto_pricing_min_price',
@@ -540,6 +543,7 @@ export const googleFeedTemplate: XmlFeedTemplateType = {
540
543
  // TODO: add to check if product is apparel
541
544
  validator: (v: string | number) => validateIfNoMacro(v, z.string().max(100)),
542
545
  rules: { sections: [] },
546
+ defaultValue: '',
543
547
  },
544
548
  {
545
549
  attribute: 'gender',
@@ -551,6 +555,7 @@ export const googleFeedTemplate: XmlFeedTemplateType = {
551
555
  // TODO: add to check if product is apparel
552
556
  validator: (v: string | number) => validateIfNoMacro(v, z.enum(['male', 'female', 'unisex', ''])),
553
557
  rules: { sections: [] },
558
+ defaultValue: '',
554
559
  },
555
560
  {
556
561
  attribute: 'material',
@@ -561,6 +566,7 @@ export const googleFeedTemplate: XmlFeedTemplateType = {
561
566
  type: 'macro-input',
562
567
  validator: (v: string | number) => validateIfNoMacro(v, z.string().max(200)),
563
568
  rules: { sections: [] },
569
+ defaultValue: '',
564
570
  },
565
571
  {
566
572
  attribute: 'pattern',
@@ -571,6 +577,7 @@ export const googleFeedTemplate: XmlFeedTemplateType = {
571
577
  type: 'macro-input',
572
578
  validator: (v: string | number) => validateIfNoMacro(v, z.string().max(100)),
573
579
  rules: { sections: [] },
580
+ defaultValue: '',
574
581
  },
575
582
  {
576
583
  attribute: 'size',
@@ -582,6 +589,7 @@ export const googleFeedTemplate: XmlFeedTemplateType = {
582
589
  // TODO: add to check if product is apparel
583
590
  validator: (v: string | number) => validateIfNoMacro(v, z.string().max(100)),
584
591
  rules: { sections: [] },
592
+ defaultValue: '',
585
593
  },
586
594
  {
587
595
  attribute: 'size_type',
@@ -610,6 +618,7 @@ export const googleFeedTemplate: XmlFeedTemplateType = {
610
618
  )
611
619
  ),
612
620
  rules: { sections: [] },
621
+ defaultValue: '',
613
622
  },
614
623
  {
615
624
  attribute: 'size_system',
@@ -621,6 +630,7 @@ export const googleFeedTemplate: XmlFeedTemplateType = {
621
630
  validator: (v: string | number) =>
622
631
  validateIfNoMacro(v, z.enum(['US', 'EU', 'UK', 'DE', 'FR', 'JP', 'CN', 'IT', 'BR', 'MEX', 'AU', ''])),
623
632
  rules: { sections: [] },
633
+ defaultValue: '',
624
634
  },
625
635
  {
626
636
  attribute: 'item_group_id',
@@ -15,6 +15,7 @@ const availabilityMapping = {
15
15
  validator: (v: string | number) =>
16
16
  validateIfNoMacro(v, z.enum(['in stock', 'available for order', 'preorder', 'out of stock', 'discontinued'])),
17
17
  baseMode: true,
18
+ defaultValue: '',
18
19
  };
19
20
 
20
21
  const customLabelMapping: ProductUploadMapSource = {
@@ -26,6 +27,7 @@ const customLabelMapping: ProductUploadMapSource = {
26
27
  type: 'macro-input' as any,
27
28
  validator: (v: string | number) => validateIfNoMacro(v, z.string().max(100)),
28
29
  rules: { sections: [] },
30
+ defaultValue: '',
29
31
  };
30
32
 
31
33
  export const microsoftTemplate: XmlFeedTemplateType = {
@@ -465,6 +467,7 @@ export const microsoftTemplate: XmlFeedTemplateType = {
465
467
  .optional()
466
468
  ),
467
469
  rules: { sections: [] },
470
+ defaultValue: '',
468
471
  },
469
472
  {
470
473
  attribute: 'product_category',
@@ -17,6 +17,7 @@ const availabilityMapping = {
17
17
  validator: (v: string | number) =>
18
18
  validateIfNoMacro(v, z.enum(['in stock', 'available for order', 'preorder', 'out of stock', 'discontinued'])),
19
19
  baseMode: true,
20
+ defaultValue: '',
20
21
  };
21
22
 
22
23
  const conditionMapping = {
@@ -28,6 +29,7 @@ const conditionMapping = {
28
29
  type: 'macro-input' as any,
29
30
  validator: (v: string | number) => validateIfNoMacro(v, z.enum(['new', 'refurbished', 'used'])),
30
31
  baseMode: true,
32
+ defaultValue: '',
31
33
  };
32
34
 
33
35
  const customLabelMapping = {
@@ -11,7 +11,7 @@ import {
11
11
  ProductUploadRuleSection,
12
12
  ProductUploadRules,
13
13
  } from '../types/profile.types.js';
14
- import { MappingSourceValueType, ProductUploadMappings, RULES_OPERATORS } from '../constants/profile.constants.js';
14
+ import { MappingSourceValueType, RULES_OPERATORS } from '../constants/profile.constants.js';
15
15
  import { code } from './utils.js';
16
16
 
17
17
  /**
@@ -138,36 +138,36 @@ export function getEmptyRuleItem(attribute: ProductUploadRuleFilterType['value']
138
138
  return { attribute, operator: '', value: '', id: code() };
139
139
  }
140
140
 
141
- export function sortMappings(a: ProductUploadMapping, b: ProductUploadMapping): number {
142
- if (!a.attribute) {
143
- return 1;
144
- }
141
+ // export function sortMappings(a: ProductUploadMapping, b: ProductUploadMapping): number {
142
+ // if (!a.attribute) {
143
+ // return 1;
144
+ // }
145
145
 
146
- if (!b.attribute) {
147
- return -1;
148
- }
146
+ // if (!b.attribute) {
147
+ // return -1;
148
+ // }
149
149
 
150
- const sourceA = ProductUploadMappings.find(m => m.attribute === a.attribute);
151
- const sourceB = ProductUploadMappings.find(m => m.attribute === b.attribute);
150
+ // const sourceA = ProductUploadMappings.find(m => m.attribute === a.attribute);
151
+ // const sourceB = ProductUploadMappings.find(m => m.attribute === b.attribute);
152
152
 
153
- if (sourceA?.required && !sourceB?.required) {
154
- return -1;
155
- }
153
+ // if (sourceA?.required && !sourceB?.required) {
154
+ // return -1;
155
+ // }
156
156
 
157
- if (sourceB?.required && !sourceA?.required) {
158
- return 1;
159
- }
157
+ // if (sourceB?.required && !sourceA?.required) {
158
+ // return 1;
159
+ // }
160
160
 
161
- if (a.attribute < b.attribute) {
162
- return -1;
163
- }
161
+ // if (a.attribute < b.attribute) {
162
+ // return -1;
163
+ // }
164
164
 
165
- if (a.attribute > b.attribute) {
166
- return 1;
167
- }
165
+ // if (a.attribute > b.attribute) {
166
+ // return 1;
167
+ // }
168
168
 
169
- return 0;
170
- }
169
+ // return 0;
170
+ // }
171
171
 
172
172
  export function hasRules(rules: ProductUploadRules): boolean {
173
173
  return Array.isArray(rules?.sections) && rules.sections.some(section => section.ruleItems.length > 0);
@@ -270,44 +270,44 @@ export function optionIsGroup(option: OptionType): option is OptionTypeGroup {
270
270
  return typeof option !== 'string' && 'options' in option;
271
271
  }
272
272
 
273
- export function detectProfileChange(
274
- a: ProductUploadProfile,
275
- b: ProductUploadProfile
276
- ): { name: boolean; rules: boolean; mappings: boolean; id: boolean } {
277
- const changes = {
278
- name: false,
279
- rules: false,
280
- mappings: false,
281
- id: false,
282
- };
283
-
284
- if (a.name !== b.name) {
285
- changes.name = true;
286
- }
287
-
288
- if (
289
- ProductUploadMappings.filter(m => m.required)
290
- .map(m => m.attribute)
291
- .some(key => {
292
- const mappingA = a.mappings?.filter(m => m.attribute === key) ?? [];
293
- const mappingB = b.mappings?.filter(m => m.attribute === key) ?? [];
294
- return !compareMappings(mappingA, mappingB);
295
- })
296
- ) {
297
- changes.id = true;
298
- }
299
-
300
- const requiredAttrs = ProductUploadMappings.filter(m => m.required).map(m => m.attribute);
301
- const mappingsA = a.mappings?.filter(m => !requiredAttrs.includes(m.attribute));
302
- const mappingsB = b.mappings?.filter(m => !requiredAttrs.includes(m.attribute));
303
- changes.mappings = !compareMappings(mappingsA, mappingsB);
304
-
305
- if (!compareRules(a.rules, b.rules)) {
306
- changes.rules = true;
307
- }
308
-
309
- return changes;
310
- }
273
+ // export function detectProfileChange(
274
+ // a: ProductUploadProfile,
275
+ // b: ProductUploadProfile
276
+ // ): { name: boolean; rules: boolean; mappings: boolean; id: boolean } {
277
+ // const changes = {
278
+ // name: false,
279
+ // rules: false,
280
+ // mappings: false,
281
+ // id: false,
282
+ // };
283
+
284
+ // if (a.name !== b.name) {
285
+ // changes.name = true;
286
+ // }
287
+
288
+ // if (
289
+ // ProductUploadMappings.filter(m => m.required)
290
+ // .map(m => m.attribute)
291
+ // .some(key => {
292
+ // const mappingA = a.mappings?.filter(m => m.attribute === key) ?? [];
293
+ // const mappingB = b.mappings?.filter(m => m.attribute === key) ?? [];
294
+ // return !compareMappings(mappingA, mappingB);
295
+ // })
296
+ // ) {
297
+ // changes.id = true;
298
+ // }
299
+
300
+ // const requiredAttrs = ProductUploadMappings.filter(m => m.required).map(m => m.attribute);
301
+ // const mappingsA = a.mappings?.filter(m => !requiredAttrs.includes(m.attribute));
302
+ // const mappingsB = b.mappings?.filter(m => !requiredAttrs.includes(m.attribute));
303
+ // changes.mappings = !compareMappings(mappingsA, mappingsB);
304
+
305
+ // if (!compareRules(a.rules, b.rules)) {
306
+ // changes.rules = true;
307
+ // }
308
+
309
+ // return changes;
310
+ // }
311
311
 
312
312
  export function sanitizeUploadProfile(profile: ProductUploadProfile): ProductUploadProfile {
313
313
  if (profile.rules?.sections) {