@commercetools/sync-actions 5.13.0 → 5.15.0

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,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash.flatten'), require('lodash.isequal'), require('lodash.isnil'), require('lodash.foreach'), require('lodash.uniqwith'), require('lodash.sortby')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'lodash.flatten', 'lodash.isequal', 'lodash.isnil', 'lodash.foreach', 'lodash.uniqwith', 'lodash.sortby'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommercetoolsSyncActions = {}, global.flatten, global.isEqual, global.isNil, global.forEach, global.uniqWith, global.sortBy));
5
- })(this, (function (exports, flatten, isEqual, isNil, forEach, uniqWith, sortBy) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash.flatten'), require('lodash.isequal'), require('lodash.isnil'), require('lodash.foreach'), require('lodash.uniqwith'), require('lodash.intersection'), require('lodash.without'), require('lodash.sortby')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'lodash.flatten', 'lodash.isequal', 'lodash.isnil', 'lodash.foreach', 'lodash.uniqwith', 'lodash.intersection', 'lodash.without', 'lodash.sortby'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommercetoolsSyncActions = {}, global.flatten, global.isEqual, global.isNil, global.forEach, global.uniqWith, global.intersection, global.without, global.sortBy));
5
+ })(this, (function (exports, flatten, isEqual, isNil, forEach, uniqWith, intersection, without, sortBy) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -11,6 +11,8 @@
11
11
  var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
12
12
  var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
13
13
  var uniqWith__default = /*#__PURE__*/_interopDefaultLegacy(uniqWith);
14
+ var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
15
+ var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
14
16
  var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy);
15
17
 
16
18
  function ownKeys(object, enumerableOnly) {
@@ -680,7 +682,7 @@
680
682
  });
681
683
  }
682
684
 
683
- var baseActionsList$j = [{
685
+ var baseActionsList$k = [{
684
686
  action: 'changeName',
685
687
  key: 'name'
686
688
  }, {
@@ -717,10 +719,10 @@
717
719
  * SYNC FUNCTIONS
718
720
  */
719
721
 
720
- function actionsMapBase$j(diff, oldObj, newObj) {
722
+ function actionsMapBase$k(diff, oldObj, newObj) {
721
723
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
722
724
  return buildBaseAttributesActions({
723
- actions: baseActionsList$j,
725
+ actions: baseActionsList$k,
724
726
  diff: diff,
725
727
  oldObj: oldObj,
726
728
  newObj: newObj,
@@ -828,7 +830,7 @@
828
830
  return function doMapActions(diff, newObj, oldObj) {
829
831
  var allActions = [];
830
832
  allActions.push(mapActionGroup('base', function () {
831
- return actionsMapBase$j(diff, oldObj, newObj, syncActionConfig);
833
+ return actionsMapBase$k(diff, oldObj, newObj, syncActionConfig);
832
834
  }));
833
835
  allActions.push(mapActionGroup('references', function () {
834
836
  return actionsMapReferences$3(diff, oldObj, newObj);
@@ -865,7 +867,7 @@
865
867
  });
866
868
 
867
869
  var isEmptyValue = createIsEmptyValue([undefined, null, '']);
868
- var baseActionsList$i = [{
870
+ var baseActionsList$j = [{
869
871
  action: 'setSalutation',
870
872
  key: 'salutation'
871
873
  }, {
@@ -930,10 +932,10 @@
930
932
  * SYNC FUNCTIONS
931
933
  */
932
934
 
933
- function actionsMapBase$i(diff, oldObj, newObj) {
935
+ function actionsMapBase$j(diff, oldObj, newObj) {
934
936
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
935
937
  return buildBaseAttributesActions({
936
- actions: baseActionsList$i,
938
+ actions: baseActionsList$j,
937
939
  diff: diff,
938
940
  oldObj: oldObj,
939
941
  newObj: newObj,
@@ -1077,7 +1079,7 @@
1077
1079
  return function doMapActions(diff, newObj, oldObj) {
1078
1080
  var allActions = [];
1079
1081
  allActions.push(mapActionGroup('base', function () {
1080
- return actionsMapBase$i(diff, oldObj, newObj, syncActionConfig);
1082
+ return actionsMapBase$j(diff, oldObj, newObj, syncActionConfig);
1081
1083
  }));
1082
1084
  allActions.push(mapActionGroup('references', function () {
1083
1085
  return actionsMapReferences$2(diff, oldObj, newObj);
@@ -1122,7 +1124,7 @@
1122
1124
  };
1123
1125
  });
1124
1126
 
1125
- var baseActionsList$h = [{
1127
+ var baseActionsList$i = [{
1126
1128
  action: 'changeQuantity',
1127
1129
  key: 'quantityOnStock',
1128
1130
  actionKey: 'quantity'
@@ -1141,10 +1143,10 @@
1141
1143
  * SYNC FUNCTIONS
1142
1144
  */
1143
1145
 
1144
- function actionsMapBase$h(diff, oldObj, newObj) {
1146
+ function actionsMapBase$i(diff, oldObj, newObj) {
1145
1147
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1146
1148
  return buildBaseAttributesActions({
1147
- actions: baseActionsList$h,
1149
+ actions: baseActionsList$i,
1148
1150
  diff: diff,
1149
1151
  oldObj: oldObj,
1150
1152
  newObj: newObj,
@@ -1164,7 +1166,7 @@
1164
1166
  return function doMapActions(diff, newObj, oldObj) {
1165
1167
  var allActions = [];
1166
1168
  allActions.push(mapActionGroup('base', function () {
1167
- return actionsMapBase$h(diff, oldObj, newObj, syncActionConfig);
1169
+ return actionsMapBase$i(diff, oldObj, newObj, syncActionConfig);
1168
1170
  }));
1169
1171
  allActions.push(mapActionGroup('references', function () {
1170
1172
  return actionsMapReferences$1(diff, oldObj, newObj);
@@ -1259,7 +1261,7 @@
1259
1261
 
1260
1262
  var REGEX_NUMBER$2 = new RegExp(/^\d+$/);
1261
1263
  var REGEX_UNDERSCORE_NUMBER$2 = new RegExp(/^_\d+$/);
1262
- var baseActionsList$g = [{
1264
+ var baseActionsList$h = [{
1263
1265
  action: 'changeName',
1264
1266
  key: 'name'
1265
1267
  }, {
@@ -1328,6 +1330,10 @@
1328
1330
  return REGEX_UNDERSCORE_NUMBER$2.test(key) && Number(resource[2]) === 0;
1329
1331
  };
1330
1332
 
1333
+ var getIsItemMovedAction = function getIsItemMovedAction(key, resource) {
1334
+ return REGEX_UNDERSCORE_NUMBER$2.test(key) && Number(resource[2]) === 3;
1335
+ };
1336
+
1331
1337
  function _buildSkuActions(variantDiff, oldVariant) {
1332
1338
  if ({}.hasOwnProperty.call(variantDiff, 'sku')) {
1333
1339
  var newValue = getDeltaValue(variantDiff.sku);
@@ -1602,6 +1608,34 @@
1602
1608
  };
1603
1609
  }
1604
1610
 
1611
+ function _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant) {
1612
+ var isAssetOrderChanged = Object.entries(diffAssets).find(function (entry) {
1613
+ return getIsItemMovedAction(entry[0], entry[1]);
1614
+ });
1615
+
1616
+ if (!isAssetOrderChanged) {
1617
+ return [];
1618
+ }
1619
+
1620
+ var assetIdsBefore = oldVariant.assets.map(function (_) {
1621
+ return _.id;
1622
+ });
1623
+ var assetIdsCurrent = newVariant.assets.map(function (_) {
1624
+ return _.id;
1625
+ }).filter(function (_) {
1626
+ return _ !== undefined;
1627
+ });
1628
+ var assetIdsToKeep = intersection__default["default"](assetIdsCurrent, assetIdsBefore);
1629
+ var assetIdsToRemove = without__default["default"].apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
1630
+
1631
+ var changeAssetOrderAction = _objectSpread2({
1632
+ action: 'changeAssetOrder',
1633
+ assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
1634
+ }, toVariantIdentifier(oldVariant));
1635
+
1636
+ return [changeAssetOrderAction];
1637
+ }
1638
+
1605
1639
  function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
1606
1640
  var assetActions = []; // generate a hashMap to be able to reference the right asset from both ends
1607
1641
 
@@ -1659,17 +1693,20 @@
1659
1693
  }, toAssetIdentifier(oldAsset)), toVariantIdentifier(oldVariant)));
1660
1694
  }
1661
1695
  });
1662
- return assetActions;
1696
+
1697
+ var changedAssetOrderAction = _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant);
1698
+
1699
+ return [].concat(_toConsumableArray(changedAssetOrderAction), assetActions);
1663
1700
  }
1664
1701
  /**
1665
1702
  * SYNC FUNCTIONS
1666
1703
  */
1667
1704
 
1668
1705
 
1669
- function actionsMapBase$g(diff, oldObj, newObj) {
1706
+ function actionsMapBase$h(diff, oldObj, newObj) {
1670
1707
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1671
1708
  return buildBaseAttributesActions({
1672
- actions: baseActionsList$g,
1709
+ actions: baseActionsList$h,
1673
1710
  diff: diff,
1674
1711
  oldObj: oldObj,
1675
1712
  newObj: newObj,
@@ -1769,7 +1806,7 @@
1769
1806
  });
1770
1807
  return allAssetsActions;
1771
1808
  }
1772
- function actionsMapAttributes(diff, oldObj, newObj) {
1809
+ function actionsMapAttributes$1(diff, oldObj, newObj) {
1773
1810
  var sameForAllAttributeNames = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
1774
1811
  var variantHashMap = arguments.length > 4 ? arguments[4] : undefined;
1775
1812
  var actions = [];
@@ -1900,7 +1937,7 @@
1900
1937
  staged = newObj.staged;
1901
1938
  var variantHashMap = findMatchingPairs(diff.variants, oldObj.variants, newObj.variants);
1902
1939
  allActions.push(mapActionGroup('attributes', function () {
1903
- return actionsMapAttributes(diff, oldObj, newObj, sameForAllAttributeNames || [], variantHashMap);
1940
+ return actionsMapAttributes$1(diff, oldObj, newObj, sameForAllAttributeNames || [], variantHashMap);
1904
1941
  }));
1905
1942
  allActions.push(mapActionGroup('variants', function () {
1906
1943
  return actionsMapAddVariants(diff, oldObj, newObj);
@@ -1910,7 +1947,7 @@
1910
1947
  return actionsMapRemoveVariants(diff, oldObj, newObj);
1911
1948
  }));
1912
1949
  allActions.push(mapActionGroup('base', function () {
1913
- return actionsMapBase$g(diff, oldObj, newObj, syncActionConfig);
1950
+ return actionsMapBase$h(diff, oldObj, newObj, syncActionConfig);
1914
1951
  }));
1915
1952
  allActions.push(mapActionGroup('meta', function () {
1916
1953
  return actionsMapMeta(diff, oldObj, newObj);
@@ -1985,7 +2022,7 @@
1985
2022
  return REGEX_UNDERSCORE_NUMBER$1.test(key) && Number(resource[2]) === 0;
1986
2023
  };
1987
2024
 
1988
- var baseActionsList$f = [{
2025
+ var baseActionsList$g = [{
1989
2026
  action: 'changeOrderState',
1990
2027
  key: 'orderState'
1991
2028
  }, {
@@ -1999,10 +2036,10 @@
1999
2036
  * SYNC FUNCTIONS
2000
2037
  */
2001
2038
 
2002
- function actionsMapBase$f(diff, oldObj, newObj) {
2039
+ function actionsMapBase$g(diff, oldObj, newObj) {
2003
2040
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2004
2041
  return buildBaseAttributesActions({
2005
- actions: baseActionsList$f,
2042
+ actions: baseActionsList$g,
2006
2043
  diff: diff,
2007
2044
  oldObj: oldObj,
2008
2045
  newObj: newObj,
@@ -2169,7 +2206,7 @@
2169
2206
  }
2170
2207
 
2171
2208
  allActions.push(mapActionGroup('base', function () {
2172
- return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
2209
+ return actionsMapBase$g(diff, oldObj, newObj, syncActionConfig);
2173
2210
  }));
2174
2211
  allActions.push(mapActionGroup('deliveries', function () {
2175
2212
  return actionsMapDeliveries(diff, oldObj, newObj);
@@ -2208,7 +2245,7 @@
2208
2245
  };
2209
2246
  });
2210
2247
 
2211
- var baseActionsList$e = [{
2248
+ var baseActionsList$f = [{
2212
2249
  action: 'changeIsActive',
2213
2250
  key: 'isActive'
2214
2251
  }, {
@@ -2236,10 +2273,10 @@
2236
2273
  action: 'setKey',
2237
2274
  key: 'key'
2238
2275
  }];
2239
- function actionsMapBase$e(diff, oldObj, newObj) {
2276
+ function actionsMapBase$f(diff, oldObj, newObj) {
2240
2277
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2241
2278
  return buildBaseAttributesActions({
2242
- actions: baseActionsList$e,
2279
+ actions: baseActionsList$f,
2243
2280
  diff: diff,
2244
2281
  oldObj: oldObj,
2245
2282
  newObj: newObj,
@@ -2280,7 +2317,7 @@
2280
2317
  return function doMapActions(diff, newObj, oldObj) {
2281
2318
  var allActions = [];
2282
2319
  allActions.push(mapActionGroup('base', function () {
2283
- return actionsMapBase$e(diff, oldObj, newObj, syncActionConfig);
2320
+ return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
2284
2321
  }));
2285
2322
  return combineValidityActions(flatten__default["default"](allActions));
2286
2323
  };
@@ -2296,7 +2333,7 @@
2296
2333
  };
2297
2334
  });
2298
2335
 
2299
- var baseActionsList$d = [{
2336
+ var baseActionsList$e = [{
2300
2337
  action: 'changeIsActive',
2301
2338
  key: 'isActive'
2302
2339
  }, {
@@ -2327,10 +2364,10 @@
2327
2364
  action: 'changeGroups',
2328
2365
  key: 'groups'
2329
2366
  }];
2330
- function actionsMapBase$d(diff, oldObj, newObj) {
2367
+ function actionsMapBase$e(diff, oldObj, newObj) {
2331
2368
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2332
2369
  return buildBaseAttributesActions({
2333
- actions: baseActionsList$d,
2370
+ actions: baseActionsList$e,
2334
2371
  diff: diff,
2335
2372
  oldObj: oldObj,
2336
2373
  newObj: newObj,
@@ -2342,7 +2379,7 @@
2342
2379
  return function doMapActions(diff, newObj, oldObj) {
2343
2380
  var allActions = [];
2344
2381
  allActions.push(mapActionGroup('base', function () {
2345
- return actionsMapBase$d(diff, oldObj, newObj, syncActionConfig);
2382
+ return actionsMapBase$e(diff, oldObj, newObj, syncActionConfig);
2346
2383
  }));
2347
2384
  allActions.push(mapActionGroup('custom', function () {
2348
2385
  return actionsMapCustom(diff, newObj, oldObj);
@@ -2370,17 +2407,17 @@
2370
2407
  };
2371
2408
  });
2372
2409
 
2373
- var baseActionsList$c = [{
2410
+ var baseActionsList$d = [{
2374
2411
  action: 'changeName',
2375
2412
  key: 'name'
2376
2413
  }, {
2377
2414
  action: 'setKey',
2378
2415
  key: 'key'
2379
2416
  }];
2380
- function actionsMapBase$c(diff, oldObj, newObj) {
2417
+ function actionsMapBase$d(diff, oldObj, newObj) {
2381
2418
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2382
2419
  return buildBaseAttributesActions({
2383
- actions: baseActionsList$c,
2420
+ actions: baseActionsList$d,
2384
2421
  diff: diff,
2385
2422
  oldObj: oldObj,
2386
2423
  newObj: newObj,
@@ -2392,7 +2429,7 @@
2392
2429
  return function doMapActions(diff, newObj, oldObj) {
2393
2430
  var allActions = [];
2394
2431
  allActions.push(mapActionGroup('base', function () {
2395
- return actionsMapBase$c(diff, oldObj, newObj, syncActionConfig);
2432
+ return actionsMapBase$d(diff, oldObj, newObj, syncActionConfig);
2396
2433
  }));
2397
2434
  allActions.push(mapActionGroup('custom', function () {
2398
2435
  return actionsMapCustom(diff, newObj, oldObj);
@@ -2411,7 +2448,7 @@
2411
2448
  };
2412
2449
  });
2413
2450
 
2414
- var baseActionsList$b = [{
2451
+ var baseActionsList$c = [{
2415
2452
  action: 'changeIsActive',
2416
2453
  key: 'isActive'
2417
2454
  }, {
@@ -2448,10 +2485,10 @@
2448
2485
  action: 'setKey',
2449
2486
  key: 'key'
2450
2487
  }];
2451
- function actionsMapBase$b(diff, oldObj, newObj) {
2488
+ function actionsMapBase$c(diff, oldObj, newObj) {
2452
2489
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2453
2490
  return buildBaseAttributesActions({
2454
- actions: baseActionsList$b,
2491
+ actions: baseActionsList$c,
2455
2492
  diff: diff,
2456
2493
  oldObj: oldObj,
2457
2494
  newObj: newObj,
@@ -2463,7 +2500,7 @@
2463
2500
  return function doMapActions(diff, newObj, oldObj) {
2464
2501
  var allActions = [];
2465
2502
  allActions.push(mapActionGroup('base', function () {
2466
- return actionsMapBase$b(diff, oldObj, newObj, syncActionConfig);
2503
+ return actionsMapBase$c(diff, oldObj, newObj, syncActionConfig);
2467
2504
  }));
2468
2505
  allActions.push(mapActionGroup('custom', function () {
2469
2506
  return actionsMapCustom(diff, newObj, oldObj);
@@ -2482,7 +2519,7 @@
2482
2519
  };
2483
2520
  });
2484
2521
 
2485
- var baseActionsList$a = [{
2522
+ var baseActionsList$b = [{
2486
2523
  action: 'changeName',
2487
2524
  key: 'name'
2488
2525
  }, {
@@ -2492,10 +2529,10 @@
2492
2529
  action: 'setDescription',
2493
2530
  key: 'description'
2494
2531
  }];
2495
- function actionsMapBase$a(diff, oldObj, newObj) {
2532
+ function actionsMapBase$b(diff, oldObj, newObj) {
2496
2533
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2497
2534
  return buildBaseAttributesActions({
2498
- actions: baseActionsList$a,
2535
+ actions: baseActionsList$b,
2499
2536
  diff: diff,
2500
2537
  oldObj: oldObj,
2501
2538
  newObj: newObj,
@@ -2529,7 +2566,7 @@
2529
2566
  return function doMapActions(diff, newObj, oldObj) {
2530
2567
  var allActions = [];
2531
2568
  allActions.push(mapActionGroup('base', function () {
2532
- return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
2569
+ return actionsMapBase$b(diff, oldObj, newObj, syncActionConfig);
2533
2570
  }));
2534
2571
  allActions.push(mapActionGroup('rates', function () {
2535
2572
  return actionsMapRates(diff, oldObj, newObj);
@@ -2556,7 +2593,7 @@
2556
2593
  };
2557
2594
  });
2558
2595
 
2559
- var baseActionsList$9 = [{
2596
+ var baseActionsList$a = [{
2560
2597
  action: 'changeName',
2561
2598
  key: 'name'
2562
2599
  }, {
@@ -2573,10 +2610,10 @@
2573
2610
  });
2574
2611
  };
2575
2612
 
2576
- function actionsMapBase$9(diff, oldObj, newObj) {
2613
+ function actionsMapBase$a(diff, oldObj, newObj) {
2577
2614
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2578
2615
  return buildBaseAttributesActions({
2579
- actions: baseActionsList$9,
2616
+ actions: baseActionsList$a,
2580
2617
  diff: diff,
2581
2618
  oldObj: oldObj,
2582
2619
  newObj: newObj,
@@ -2621,7 +2658,7 @@
2621
2658
  return function doMapActions(diff, newObj, oldObj) {
2622
2659
  var allActions = [];
2623
2660
  allActions.push(mapActionGroup('base', function () {
2624
- return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
2661
+ return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
2625
2662
  }));
2626
2663
  allActions.push(flatten__default["default"](mapActionGroup('locations', function () {
2627
2664
  return actionsMapLocations(diff, oldObj, newObj);
@@ -2648,7 +2685,7 @@
2648
2685
  };
2649
2686
  });
2650
2687
 
2651
- var baseActionsList$8 = [{
2688
+ var baseActionsList$9 = [{
2652
2689
  action: 'setKey',
2653
2690
  key: 'key'
2654
2691
  }, {
@@ -2673,10 +2710,10 @@
2673
2710
  action: 'changeTaxCategory',
2674
2711
  key: 'taxCategory'
2675
2712
  }];
2676
- function actionsMapBase$8(diff, oldObj, newObj) {
2713
+ function actionsMapBase$9(diff, oldObj, newObj) {
2677
2714
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2678
2715
  return buildBaseAttributesActions({
2679
- actions: baseActionsList$8,
2716
+ actions: baseActionsList$9,
2680
2717
  diff: diff,
2681
2718
  oldObj: oldObj,
2682
2719
  newObj: newObj,
@@ -2758,7 +2795,7 @@
2758
2795
  return function doMapActions(diff, newObj, oldObj) {
2759
2796
  var allActions = [];
2760
2797
  allActions.push(mapActionGroup('base', function () {
2761
- return actionsMapBase$8(diff, oldObj, newObj, syncActionConfig);
2798
+ return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
2762
2799
  }));
2763
2800
  allActions.push(flatten__default["default"](mapActionGroup('zoneRates', function () {
2764
2801
  return actionsMapZoneRates(diff, oldObj, newObj);
@@ -3156,7 +3193,7 @@
3156
3193
  createComparator(createCircularEqualCreator());
3157
3194
  createComparator(createCircularEqualCreator(sameValueZeroEqual));
3158
3195
 
3159
- var baseActionsList$7 = [{
3196
+ var baseActionsList$8 = [{
3160
3197
  action: 'changeName',
3161
3198
  key: 'name'
3162
3199
  }, {
@@ -3166,7 +3203,7 @@
3166
3203
  action: 'changeDescription',
3167
3204
  key: 'description'
3168
3205
  }];
3169
- function actionsMapBase$7(diff, previous, next) {
3206
+ function actionsMapBase$8(diff, previous, next) {
3170
3207
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3171
3208
  // when `diff` is undefined, then the underlying `buildActions` has returned any diff
3172
3209
  // which given in product-types would mean that `buildActions` has run with `nestedValuesChanges` applied
@@ -3174,7 +3211,7 @@
3174
3211
  if (!diff) return [];
3175
3212
  return buildBaseAttributesActions({
3176
3213
  diff: diff,
3177
- actions: baseActionsList$7,
3214
+ actions: baseActionsList$8,
3178
3215
  oldObj: previous,
3179
3216
  newObj: next,
3180
3217
  shouldOmitEmptyString: config.shouldOmitEmptyString
@@ -3400,7 +3437,7 @@
3400
3437
  return flatten__default["default"]([// we support only base fields for the product type,
3401
3438
  // for attributes, applying hints would be recommended
3402
3439
  mapActionGroup('base', function () {
3403
- return actionsMapBase$7(diff, previous, next, syncActionConfig);
3440
+ return actionsMapBase$8(diff, previous, next, syncActionConfig);
3404
3441
  }), actionsMapForHints(options.nestedValuesChanges, previous, next)]);
3405
3442
  };
3406
3443
  }
@@ -3417,7 +3454,7 @@
3417
3454
  };
3418
3455
  });
3419
3456
 
3420
- var baseActionsList$6 = [{
3457
+ var baseActionsList$7 = [{
3421
3458
  action: 'changeKey',
3422
3459
  key: 'key'
3423
3460
  }, {
@@ -3436,10 +3473,10 @@
3436
3473
  action: 'setTransitions',
3437
3474
  key: 'transitions'
3438
3475
  }];
3439
- function actionsMapBase$6(diff, oldObj, newObj) {
3476
+ function actionsMapBase$7(diff, oldObj, newObj) {
3440
3477
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3441
3478
  return buildBaseAttributesActions({
3442
- actions: baseActionsList$6,
3479
+ actions: baseActionsList$7,
3443
3480
  diff: diff,
3444
3481
  oldObj: oldObj,
3445
3482
  newObj: newObj,
@@ -3489,7 +3526,7 @@
3489
3526
  var baseActions = [];
3490
3527
  var roleActions = [];
3491
3528
  baseActions.push(mapActionGroup('base', function () {
3492
- return actionsMapBase$6(diff, oldObj, newObj, syncActionConfig);
3529
+ return actionsMapBase$7(diff, oldObj, newObj, syncActionConfig);
3493
3530
  }));
3494
3531
  roleActions.push(mapActionGroup('roles', function () {
3495
3532
  return actionsMapRoles(diff, oldObj, newObj);
@@ -3507,7 +3544,7 @@
3507
3544
  };
3508
3545
  });
3509
3546
 
3510
- var baseActionsList$5 = [{
3547
+ var baseActionsList$6 = [{
3511
3548
  action: 'changeKey',
3512
3549
  key: 'key'
3513
3550
  }, {
@@ -3526,10 +3563,10 @@
3526
3563
  action: 'setRoles',
3527
3564
  key: 'roles'
3528
3565
  }];
3529
- function actionsMapBase$5(diff, oldObj, newObj) {
3566
+ function actionsMapBase$6(diff, oldObj, newObj) {
3530
3567
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3531
3568
  return buildBaseAttributesActions({
3532
- actions: baseActionsList$5,
3569
+ actions: baseActionsList$6,
3533
3570
  diff: diff,
3534
3571
  oldObj: oldObj,
3535
3572
  newObj: newObj,
@@ -3541,7 +3578,7 @@
3541
3578
  return function doMapActions(diff, newObj, oldObj) {
3542
3579
  var allActions = [];
3543
3580
  allActions.push(mapActionGroup('base', function () {
3544
- return actionsMapBase$5(diff, oldObj, newObj, syncActionConfig);
3581
+ return actionsMapBase$6(diff, oldObj, newObj, syncActionConfig);
3545
3582
  }));
3546
3583
  allActions.push(mapActionGroup('custom', function () {
3547
3584
  return actionsMapCustom(diff, newObj, oldObj);
@@ -3571,7 +3608,7 @@
3571
3608
  return REGEX_UNDERSCORE_NUMBER.test(key);
3572
3609
  };
3573
3610
 
3574
- var baseActionsList$4 = [{
3611
+ var baseActionsList$5 = [{
3575
3612
  action: 'changeKey',
3576
3613
  key: 'key'
3577
3614
  }, {
@@ -3581,10 +3618,10 @@
3581
3618
  action: 'setDescription',
3582
3619
  key: 'description'
3583
3620
  }];
3584
- function actionsMapBase$4(diff, oldObj, newObj) {
3621
+ function actionsMapBase$5(diff, oldObj, newObj) {
3585
3622
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3586
3623
  return buildBaseAttributesActions({
3587
- actions: baseActionsList$4,
3624
+ actions: baseActionsList$5,
3588
3625
  diff: diff,
3589
3626
  oldObj: oldObj,
3590
3627
  newObj: newObj,
@@ -3733,7 +3770,7 @@
3733
3770
  return function doMapActions(diff, next, previous) {
3734
3771
  var allActions = [];
3735
3772
  allActions.push(mapActionGroup('base', function () {
3736
- return actionsMapBase$4(diff, previous, next, syncActionConfig);
3773
+ return actionsMapBase$5(diff, previous, next, syncActionConfig);
3737
3774
  }), mapActionGroup('fieldDefinitions', function () {
3738
3775
  return actionsMapFieldDefinitions(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, findMatchingPairs(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, 'name'));
3739
3776
  }));
@@ -3750,7 +3787,7 @@
3750
3787
  };
3751
3788
  });
3752
3789
 
3753
- var baseActionsList$3 = [{
3790
+ var baseActionsList$4 = [{
3754
3791
  action: 'changeName',
3755
3792
  key: 'name'
3756
3793
  }, {
@@ -3769,10 +3806,10 @@
3769
3806
  action: 'setShippingRateInputType',
3770
3807
  key: 'shippingRateInputType'
3771
3808
  }];
3772
- function actionsMapBase$3(diff, oldObj, newObj) {
3809
+ function actionsMapBase$4(diff, oldObj, newObj) {
3773
3810
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3774
3811
  return buildBaseAttributesActions({
3775
- actions: baseActionsList$3,
3812
+ actions: baseActionsList$4,
3776
3813
  diff: diff,
3777
3814
  oldObj: oldObj,
3778
3815
  newObj: newObj,
@@ -3784,7 +3821,7 @@
3784
3821
  return function doMapActions(diff, newObj, oldObj) {
3785
3822
  var allActions = [];
3786
3823
  allActions.push(mapActionGroup('base', function () {
3787
- return actionsMapBase$3(diff, oldObj, newObj, syncActionConfig);
3824
+ return actionsMapBase$4(diff, oldObj, newObj, syncActionConfig);
3788
3825
  }));
3789
3826
  return flatten__default["default"](allActions);
3790
3827
  };
@@ -3800,7 +3837,7 @@
3800
3837
  };
3801
3838
  });
3802
3839
 
3803
- var baseActionsList$2 = [{
3840
+ var baseActionsList$3 = [{
3804
3841
  action: 'setName',
3805
3842
  key: 'name'
3806
3843
  }, {
@@ -3813,9 +3850,9 @@
3813
3850
  action: 'setSupplyChannels',
3814
3851
  key: 'supplyChannels'
3815
3852
  }];
3816
- function actionsMapBase$2(diff, oldObj, newObj) {
3853
+ function actionsMapBase$3(diff, oldObj, newObj) {
3817
3854
  return buildBaseAttributesActions({
3818
- actions: baseActionsList$2,
3855
+ actions: baseActionsList$3,
3819
3856
  diff: diff,
3820
3857
  oldObj: oldObj,
3821
3858
  newObj: newObj
@@ -3826,7 +3863,7 @@
3826
3863
  return function doMapActions(diff, next, previous) {
3827
3864
  var allActions = [];
3828
3865
  allActions.push(mapActionGroup('base', function () {
3829
- return actionsMapBase$2(diff, previous, next);
3866
+ return actionsMapBase$3(diff, previous, next);
3830
3867
  }));
3831
3868
  allActions.push(mapActionGroup('custom', function () {
3832
3869
  return actionsMapCustom(diff, next, previous);
@@ -3845,16 +3882,16 @@
3845
3882
  };
3846
3883
  });
3847
3884
 
3848
- var baseActionsList$1 = [{
3885
+ var baseActionsList$2 = [{
3849
3886
  action: 'changeName',
3850
3887
  key: 'name'
3851
3888
  }, {
3852
3889
  action: 'setKey',
3853
3890
  key: 'key'
3854
3891
  }];
3855
- function actionsMapBase$1(diff, oldObj, newObj) {
3892
+ function actionsMapBase$2(diff, oldObj, newObj) {
3856
3893
  return buildBaseAttributesActions({
3857
- actions: baseActionsList$1,
3894
+ actions: baseActionsList$2,
3858
3895
  diff: diff,
3859
3896
  oldObj: oldObj,
3860
3897
  newObj: newObj
@@ -3865,7 +3902,7 @@
3865
3902
  return function doMapActions(diff, next, previous) {
3866
3903
  var allActions = [];
3867
3904
  allActions.push(mapActionGroup('base', function () {
3868
- return actionsMapBase$1(diff, previous, next);
3905
+ return actionsMapBase$2(diff, previous, next);
3869
3906
  }));
3870
3907
  allActions.push(mapActionGroup('custom', function () {
3871
3908
  return actionsMapCustom(diff, next, previous);
@@ -3884,7 +3921,7 @@
3884
3921
  };
3885
3922
  });
3886
3923
 
3887
- var baseActionsList = [{
3924
+ var baseActionsList$1 = [{
3888
3925
  action: 'changeValue',
3889
3926
  key: 'value'
3890
3927
  }, {
@@ -3907,10 +3944,10 @@
3907
3944
  action: 'changeActive',
3908
3945
  key: 'active'
3909
3946
  }];
3910
- function actionsMapBase(diff, oldObj, newObj) {
3947
+ function actionsMapBase$1(diff, oldObj, newObj) {
3911
3948
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3912
3949
  return buildBaseAttributesActions({
3913
- actions: baseActionsList,
3950
+ actions: baseActionsList$1,
3914
3951
  diff: diff,
3915
3952
  oldObj: oldObj,
3916
3953
  newObj: newObj,
@@ -3921,7 +3958,7 @@
3921
3958
  function createPriceMapActions(mapActionGroup, syncActionConfig) {
3922
3959
  return function doMapActions(diff, newObj, oldObj) {
3923
3960
  var baseActions = mapActionGroup('base', function () {
3924
- return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
3961
+ return actionsMapBase$1(diff, oldObj, newObj, syncActionConfig);
3925
3962
  });
3926
3963
  var customActions = mapActionGroup('custom', function () {
3927
3964
  return actionsMapCustom(diff, newObj, oldObj);
@@ -3939,6 +3976,88 @@
3939
3976
  };
3940
3977
  });
3941
3978
 
3979
+ var hasAttribute = function hasAttribute(attributes, newValue) {
3980
+ return attributes.some(function (attribute) {
3981
+ return attribute.key === newValue.key;
3982
+ });
3983
+ };
3984
+
3985
+ var baseActionsList = [{
3986
+ action: 'changeName',
3987
+ key: 'name'
3988
+ }, {
3989
+ action: 'setKey',
3990
+ key: 'key'
3991
+ }, {
3992
+ action: 'setDescription',
3993
+ key: 'description'
3994
+ }];
3995
+ function actionsMapBase(diff, oldObj, newObj) {
3996
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3997
+ return buildBaseAttributesActions({
3998
+ actions: baseActionsList,
3999
+ diff: diff,
4000
+ oldObj: oldObj,
4001
+ newObj: newObj,
4002
+ shouldOmitEmptyString: config.shouldOmitEmptyString
4003
+ });
4004
+ }
4005
+ function actionsMapAttributes(diff, oldObj, newObj) {
4006
+ var _createBuildArrayActi;
4007
+
4008
+ var handler = createBuildArrayActions('attributes', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newAttribute) {
4009
+ return {
4010
+ action: 'addAttribute',
4011
+ attribute: newAttribute
4012
+ };
4013
+ }), _defineProperty(_createBuildArrayActi, REMOVE_ACTIONS, function (oldAttribute) {
4014
+ // We only add the action if the attribute is not included in the new object.
4015
+ return !hasAttribute(newObj.attributes, oldAttribute) ? {
4016
+ action: 'removeAttribute',
4017
+ attribute: oldAttribute
4018
+ } : null;
4019
+ }), _defineProperty(_createBuildArrayActi, CHANGE_ACTIONS, function (oldAttribute, newAttribute) {
4020
+ var result = []; // We only remove the attribute in case that the oldAttribute is not
4021
+ // included in the new object
4022
+
4023
+ if (!hasAttribute(newObj.attributes, oldAttribute)) result.push({
4024
+ action: 'removeAttribute',
4025
+ attribute: oldAttribute
4026
+ }); // We only add the attribute in case that the newAttribute was not
4027
+ // included in the old object
4028
+
4029
+ if (!hasAttribute(oldObj.attributes, newAttribute)) result.push({
4030
+ action: 'addAttribute',
4031
+ attribute: newAttribute
4032
+ });
4033
+ return result;
4034
+ }), _createBuildArrayActi));
4035
+ return handler(diff, oldObj, newObj);
4036
+ }
4037
+
4038
+ function createAttributeGroupsMapActions(mapActionGroup, syncActionConfig) {
4039
+ return function doMapActions(diff, newObj, oldObj) {
4040
+ var allActions = [];
4041
+ allActions.push(mapActionGroup('base', function () {
4042
+ return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
4043
+ }));
4044
+ allActions.push(flatten__default["default"](mapActionGroup('attributes', function () {
4045
+ return actionsMapAttributes(diff, oldObj, newObj);
4046
+ })));
4047
+ return flatten__default["default"](allActions);
4048
+ };
4049
+ }
4050
+
4051
+ var attributeGroups = (function (actionGroupList, syncActionConfig) {
4052
+ var mapActionGroup = createMapActionGroup(actionGroupList);
4053
+ var doMapActions = createAttributeGroupsMapActions(mapActionGroup, syncActionConfig);
4054
+ var buildActions = createBuildActions(diff, doMapActions);
4055
+ return {
4056
+ buildActions: buildActions
4057
+ };
4058
+ });
4059
+
4060
+ exports.createSyncAttributeGroups = attributeGroups;
3942
4061
  exports.createSyncCartDiscounts = cartDiscounts;
3943
4062
  exports.createSyncCategories = categories;
3944
4063
  exports.createSyncChannels = channels;