@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.
@@ -7,6 +7,8 @@ var isEqual = require('lodash.isequal');
7
7
  var isNil = require('lodash.isnil');
8
8
  var forEach = require('lodash.foreach');
9
9
  var uniqWith = require('lodash.uniqwith');
10
+ var intersection = require('lodash.intersection');
11
+ var without = require('lodash.without');
10
12
  var sortBy = require('lodash.sortby');
11
13
 
12
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -16,6 +18,8 @@ var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
16
18
  var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
17
19
  var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
18
20
  var uniqWith__default = /*#__PURE__*/_interopDefaultLegacy(uniqWith);
21
+ var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
22
+ var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
19
23
  var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy);
20
24
 
21
25
  function ownKeys(object, enumerableOnly) {
@@ -685,7 +689,7 @@ function buildReferenceActions(_ref4) {
685
689
  });
686
690
  }
687
691
 
688
- var baseActionsList$j = [{
692
+ var baseActionsList$k = [{
689
693
  action: 'changeName',
690
694
  key: 'name'
691
695
  }, {
@@ -722,10 +726,10 @@ var referenceActionsList$3 = [{
722
726
  * SYNC FUNCTIONS
723
727
  */
724
728
 
725
- function actionsMapBase$j(diff, oldObj, newObj) {
729
+ function actionsMapBase$k(diff, oldObj, newObj) {
726
730
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
727
731
  return buildBaseAttributesActions({
728
- actions: baseActionsList$j,
732
+ actions: baseActionsList$k,
729
733
  diff: diff,
730
734
  oldObj: oldObj,
731
735
  newObj: newObj,
@@ -833,7 +837,7 @@ function createCategoryMapActions(mapActionGroup, syncActionConfig) {
833
837
  return function doMapActions(diff, newObj, oldObj) {
834
838
  var allActions = [];
835
839
  allActions.push(mapActionGroup('base', function () {
836
- return actionsMapBase$j(diff, oldObj, newObj, syncActionConfig);
840
+ return actionsMapBase$k(diff, oldObj, newObj, syncActionConfig);
837
841
  }));
838
842
  allActions.push(mapActionGroup('references', function () {
839
843
  return actionsMapReferences$3(diff, oldObj, newObj);
@@ -870,7 +874,7 @@ var categories = (function (actionGroupList, syncActionConfig) {
870
874
  });
871
875
 
872
876
  var isEmptyValue = createIsEmptyValue([undefined, null, '']);
873
- var baseActionsList$i = [{
877
+ var baseActionsList$j = [{
874
878
  action: 'setSalutation',
875
879
  key: 'salutation'
876
880
  }, {
@@ -935,10 +939,10 @@ var authenticationModeActionsList = [{
935
939
  * SYNC FUNCTIONS
936
940
  */
937
941
 
938
- function actionsMapBase$i(diff, oldObj, newObj) {
942
+ function actionsMapBase$j(diff, oldObj, newObj) {
939
943
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
940
944
  return buildBaseAttributesActions({
941
- actions: baseActionsList$i,
945
+ actions: baseActionsList$j,
942
946
  diff: diff,
943
947
  oldObj: oldObj,
944
948
  newObj: newObj,
@@ -1082,7 +1086,7 @@ function createCustomerMapActions(mapActionGroup, syncActionConfig) {
1082
1086
  return function doMapActions(diff, newObj, oldObj) {
1083
1087
  var allActions = [];
1084
1088
  allActions.push(mapActionGroup('base', function () {
1085
- return actionsMapBase$i(diff, oldObj, newObj, syncActionConfig);
1089
+ return actionsMapBase$j(diff, oldObj, newObj, syncActionConfig);
1086
1090
  }));
1087
1091
  allActions.push(mapActionGroup('references', function () {
1088
1092
  return actionsMapReferences$2(diff, oldObj, newObj);
@@ -1127,7 +1131,7 @@ var customers = (function (actionGroupList, syncActionConfig) {
1127
1131
  };
1128
1132
  });
1129
1133
 
1130
- var baseActionsList$h = [{
1134
+ var baseActionsList$i = [{
1131
1135
  action: 'changeQuantity',
1132
1136
  key: 'quantityOnStock',
1133
1137
  actionKey: 'quantity'
@@ -1146,10 +1150,10 @@ var referenceActionsList$1 = [{
1146
1150
  * SYNC FUNCTIONS
1147
1151
  */
1148
1152
 
1149
- function actionsMapBase$h(diff, oldObj, newObj) {
1153
+ function actionsMapBase$i(diff, oldObj, newObj) {
1150
1154
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1151
1155
  return buildBaseAttributesActions({
1152
- actions: baseActionsList$h,
1156
+ actions: baseActionsList$i,
1153
1157
  diff: diff,
1154
1158
  oldObj: oldObj,
1155
1159
  newObj: newObj,
@@ -1169,7 +1173,7 @@ function createInventoryMapActions(mapActionGroup, syncActionConfig) {
1169
1173
  return function doMapActions(diff, newObj, oldObj) {
1170
1174
  var allActions = [];
1171
1175
  allActions.push(mapActionGroup('base', function () {
1172
- return actionsMapBase$h(diff, oldObj, newObj, syncActionConfig);
1176
+ return actionsMapBase$i(diff, oldObj, newObj, syncActionConfig);
1173
1177
  }));
1174
1178
  allActions.push(mapActionGroup('references', function () {
1175
1179
  return actionsMapReferences$1(diff, oldObj, newObj);
@@ -1264,7 +1268,7 @@ function findMatchingPairs(diff) {
1264
1268
 
1265
1269
  var REGEX_NUMBER$2 = new RegExp(/^\d+$/);
1266
1270
  var REGEX_UNDERSCORE_NUMBER$2 = new RegExp(/^_\d+$/);
1267
- var baseActionsList$g = [{
1271
+ var baseActionsList$h = [{
1268
1272
  action: 'changeName',
1269
1273
  key: 'name'
1270
1274
  }, {
@@ -1333,6 +1337,10 @@ var getIsRemoveAction = function getIsRemoveAction(key, resource) {
1333
1337
  return REGEX_UNDERSCORE_NUMBER$2.test(key) && Number(resource[2]) === 0;
1334
1338
  };
1335
1339
 
1340
+ var getIsItemMovedAction = function getIsItemMovedAction(key, resource) {
1341
+ return REGEX_UNDERSCORE_NUMBER$2.test(key) && Number(resource[2]) === 3;
1342
+ };
1343
+
1336
1344
  function _buildSkuActions(variantDiff, oldVariant) {
1337
1345
  if ({}.hasOwnProperty.call(variantDiff, 'sku')) {
1338
1346
  var newValue = getDeltaValue(variantDiff.sku);
@@ -1607,6 +1615,34 @@ function toVariantIdentifier(variant) {
1607
1615
  };
1608
1616
  }
1609
1617
 
1618
+ function _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant) {
1619
+ var isAssetOrderChanged = Object.entries(diffAssets).find(function (entry) {
1620
+ return getIsItemMovedAction(entry[0], entry[1]);
1621
+ });
1622
+
1623
+ if (!isAssetOrderChanged) {
1624
+ return [];
1625
+ }
1626
+
1627
+ var assetIdsBefore = oldVariant.assets.map(function (_) {
1628
+ return _.id;
1629
+ });
1630
+ var assetIdsCurrent = newVariant.assets.map(function (_) {
1631
+ return _.id;
1632
+ }).filter(function (_) {
1633
+ return _ !== undefined;
1634
+ });
1635
+ var assetIdsToKeep = intersection__default["default"](assetIdsCurrent, assetIdsBefore);
1636
+ var assetIdsToRemove = without__default["default"].apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
1637
+
1638
+ var changeAssetOrderAction = _objectSpread2({
1639
+ action: 'changeAssetOrder',
1640
+ assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
1641
+ }, toVariantIdentifier(oldVariant));
1642
+
1643
+ return [changeAssetOrderAction];
1644
+ }
1645
+
1610
1646
  function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
1611
1647
  var assetActions = []; // generate a hashMap to be able to reference the right asset from both ends
1612
1648
 
@@ -1664,17 +1700,20 @@ function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
1664
1700
  }, toAssetIdentifier(oldAsset)), toVariantIdentifier(oldVariant)));
1665
1701
  }
1666
1702
  });
1667
- return assetActions;
1703
+
1704
+ var changedAssetOrderAction = _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant);
1705
+
1706
+ return [].concat(_toConsumableArray(changedAssetOrderAction), assetActions);
1668
1707
  }
1669
1708
  /**
1670
1709
  * SYNC FUNCTIONS
1671
1710
  */
1672
1711
 
1673
1712
 
1674
- function actionsMapBase$g(diff, oldObj, newObj) {
1713
+ function actionsMapBase$h(diff, oldObj, newObj) {
1675
1714
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1676
1715
  return buildBaseAttributesActions({
1677
- actions: baseActionsList$g,
1716
+ actions: baseActionsList$h,
1678
1717
  diff: diff,
1679
1718
  oldObj: oldObj,
1680
1719
  newObj: newObj,
@@ -1774,7 +1813,7 @@ function actionsMapAssets(diff, oldObj, newObj, variantHashMap) {
1774
1813
  });
1775
1814
  return allAssetsActions;
1776
1815
  }
1777
- function actionsMapAttributes(diff, oldObj, newObj) {
1816
+ function actionsMapAttributes$1(diff, oldObj, newObj) {
1778
1817
  var sameForAllAttributeNames = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
1779
1818
  var variantHashMap = arguments.length > 4 ? arguments[4] : undefined;
1780
1819
  var actions = [];
@@ -1905,7 +1944,7 @@ function createProductMapActions(mapActionGroup, syncActionConfig) {
1905
1944
  staged = newObj.staged;
1906
1945
  var variantHashMap = findMatchingPairs(diff.variants, oldObj.variants, newObj.variants);
1907
1946
  allActions.push(mapActionGroup('attributes', function () {
1908
- return actionsMapAttributes(diff, oldObj, newObj, sameForAllAttributeNames || [], variantHashMap);
1947
+ return actionsMapAttributes$1(diff, oldObj, newObj, sameForAllAttributeNames || [], variantHashMap);
1909
1948
  }));
1910
1949
  allActions.push(mapActionGroup('variants', function () {
1911
1950
  return actionsMapAddVariants(diff, oldObj, newObj);
@@ -1915,7 +1954,7 @@ function createProductMapActions(mapActionGroup, syncActionConfig) {
1915
1954
  return actionsMapRemoveVariants(diff, oldObj, newObj);
1916
1955
  }));
1917
1956
  allActions.push(mapActionGroup('base', function () {
1918
- return actionsMapBase$g(diff, oldObj, newObj, syncActionConfig);
1957
+ return actionsMapBase$h(diff, oldObj, newObj, syncActionConfig);
1919
1958
  }));
1920
1959
  allActions.push(mapActionGroup('meta', function () {
1921
1960
  return actionsMapMeta(diff, oldObj, newObj);
@@ -1990,7 +2029,7 @@ var isRemoveAction = function isRemoveAction(key, resource) {
1990
2029
  return REGEX_UNDERSCORE_NUMBER$1.test(key) && Number(resource[2]) === 0;
1991
2030
  };
1992
2031
 
1993
- var baseActionsList$f = [{
2032
+ var baseActionsList$g = [{
1994
2033
  action: 'changeOrderState',
1995
2034
  key: 'orderState'
1996
2035
  }, {
@@ -2004,10 +2043,10 @@ var baseActionsList$f = [{
2004
2043
  * SYNC FUNCTIONS
2005
2044
  */
2006
2045
 
2007
- function actionsMapBase$f(diff, oldObj, newObj) {
2046
+ function actionsMapBase$g(diff, oldObj, newObj) {
2008
2047
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2009
2048
  return buildBaseAttributesActions({
2010
- actions: baseActionsList$f,
2049
+ actions: baseActionsList$g,
2011
2050
  diff: diff,
2012
2051
  oldObj: oldObj,
2013
2052
  newObj: newObj,
@@ -2174,7 +2213,7 @@ function createOrderMapActions(mapActionGroup, syncActionConfig) {
2174
2213
  }
2175
2214
 
2176
2215
  allActions.push(mapActionGroup('base', function () {
2177
- return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
2216
+ return actionsMapBase$g(diff, oldObj, newObj, syncActionConfig);
2178
2217
  }));
2179
2218
  allActions.push(mapActionGroup('deliveries', function () {
2180
2219
  return actionsMapDeliveries(diff, oldObj, newObj);
@@ -2213,7 +2252,7 @@ var orders = (function (actionGroupList, syncActionConfig) {
2213
2252
  };
2214
2253
  });
2215
2254
 
2216
- var baseActionsList$e = [{
2255
+ var baseActionsList$f = [{
2217
2256
  action: 'changeIsActive',
2218
2257
  key: 'isActive'
2219
2258
  }, {
@@ -2241,10 +2280,10 @@ var baseActionsList$e = [{
2241
2280
  action: 'setKey',
2242
2281
  key: 'key'
2243
2282
  }];
2244
- function actionsMapBase$e(diff, oldObj, newObj) {
2283
+ function actionsMapBase$f(diff, oldObj, newObj) {
2245
2284
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2246
2285
  return buildBaseAttributesActions({
2247
- actions: baseActionsList$e,
2286
+ actions: baseActionsList$f,
2248
2287
  diff: diff,
2249
2288
  oldObj: oldObj,
2250
2289
  newObj: newObj,
@@ -2285,7 +2324,7 @@ function createProductDiscountsMapActions(mapActionGroup, syncActionConfig) {
2285
2324
  return function doMapActions(diff, newObj, oldObj) {
2286
2325
  var allActions = [];
2287
2326
  allActions.push(mapActionGroup('base', function () {
2288
- return actionsMapBase$e(diff, oldObj, newObj, syncActionConfig);
2327
+ return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
2289
2328
  }));
2290
2329
  return combineValidityActions(flatten__default["default"](allActions));
2291
2330
  };
@@ -2301,7 +2340,7 @@ var productDiscounts = (function (actionGroupList) {
2301
2340
  };
2302
2341
  });
2303
2342
 
2304
- var baseActionsList$d = [{
2343
+ var baseActionsList$e = [{
2305
2344
  action: 'changeIsActive',
2306
2345
  key: 'isActive'
2307
2346
  }, {
@@ -2332,10 +2371,10 @@ var baseActionsList$d = [{
2332
2371
  action: 'changeGroups',
2333
2372
  key: 'groups'
2334
2373
  }];
2335
- function actionsMapBase$d(diff, oldObj, newObj) {
2374
+ function actionsMapBase$e(diff, oldObj, newObj) {
2336
2375
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2337
2376
  return buildBaseAttributesActions({
2338
- actions: baseActionsList$d,
2377
+ actions: baseActionsList$e,
2339
2378
  diff: diff,
2340
2379
  oldObj: oldObj,
2341
2380
  newObj: newObj,
@@ -2347,7 +2386,7 @@ function createDiscountCodesMapActions(mapActionGroup, syncActionConfig) {
2347
2386
  return function doMapActions(diff, newObj, oldObj) {
2348
2387
  var allActions = [];
2349
2388
  allActions.push(mapActionGroup('base', function () {
2350
- return actionsMapBase$d(diff, oldObj, newObj, syncActionConfig);
2389
+ return actionsMapBase$e(diff, oldObj, newObj, syncActionConfig);
2351
2390
  }));
2352
2391
  allActions.push(mapActionGroup('custom', function () {
2353
2392
  return actionsMapCustom(diff, newObj, oldObj);
@@ -2375,17 +2414,17 @@ var discountCodes = (function (actionGroupList) {
2375
2414
  };
2376
2415
  });
2377
2416
 
2378
- var baseActionsList$c = [{
2417
+ var baseActionsList$d = [{
2379
2418
  action: 'changeName',
2380
2419
  key: 'name'
2381
2420
  }, {
2382
2421
  action: 'setKey',
2383
2422
  key: 'key'
2384
2423
  }];
2385
- function actionsMapBase$c(diff, oldObj, newObj) {
2424
+ function actionsMapBase$d(diff, oldObj, newObj) {
2386
2425
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2387
2426
  return buildBaseAttributesActions({
2388
- actions: baseActionsList$c,
2427
+ actions: baseActionsList$d,
2389
2428
  diff: diff,
2390
2429
  oldObj: oldObj,
2391
2430
  newObj: newObj,
@@ -2397,7 +2436,7 @@ function createCustomerGroupMapActions(mapActionGroup, syncActionConfig) {
2397
2436
  return function doMapActions(diff, newObj, oldObj) {
2398
2437
  var allActions = [];
2399
2438
  allActions.push(mapActionGroup('base', function () {
2400
- return actionsMapBase$c(diff, oldObj, newObj, syncActionConfig);
2439
+ return actionsMapBase$d(diff, oldObj, newObj, syncActionConfig);
2401
2440
  }));
2402
2441
  allActions.push(mapActionGroup('custom', function () {
2403
2442
  return actionsMapCustom(diff, newObj, oldObj);
@@ -2416,7 +2455,7 @@ var customerGroup = (function (actionGroupList) {
2416
2455
  };
2417
2456
  });
2418
2457
 
2419
- var baseActionsList$b = [{
2458
+ var baseActionsList$c = [{
2420
2459
  action: 'changeIsActive',
2421
2460
  key: 'isActive'
2422
2461
  }, {
@@ -2453,10 +2492,10 @@ var baseActionsList$b = [{
2453
2492
  action: 'setKey',
2454
2493
  key: 'key'
2455
2494
  }];
2456
- function actionsMapBase$b(diff, oldObj, newObj) {
2495
+ function actionsMapBase$c(diff, oldObj, newObj) {
2457
2496
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2458
2497
  return buildBaseAttributesActions({
2459
- actions: baseActionsList$b,
2498
+ actions: baseActionsList$c,
2460
2499
  diff: diff,
2461
2500
  oldObj: oldObj,
2462
2501
  newObj: newObj,
@@ -2468,7 +2507,7 @@ function createCartDiscountsMapActions(mapActionGroup, syncActionConfig) {
2468
2507
  return function doMapActions(diff, newObj, oldObj) {
2469
2508
  var allActions = [];
2470
2509
  allActions.push(mapActionGroup('base', function () {
2471
- return actionsMapBase$b(diff, oldObj, newObj, syncActionConfig);
2510
+ return actionsMapBase$c(diff, oldObj, newObj, syncActionConfig);
2472
2511
  }));
2473
2512
  allActions.push(mapActionGroup('custom', function () {
2474
2513
  return actionsMapCustom(diff, newObj, oldObj);
@@ -2487,7 +2526,7 @@ var cartDiscounts = (function (actionGroupList) {
2487
2526
  };
2488
2527
  });
2489
2528
 
2490
- var baseActionsList$a = [{
2529
+ var baseActionsList$b = [{
2491
2530
  action: 'changeName',
2492
2531
  key: 'name'
2493
2532
  }, {
@@ -2497,10 +2536,10 @@ var baseActionsList$a = [{
2497
2536
  action: 'setDescription',
2498
2537
  key: 'description'
2499
2538
  }];
2500
- function actionsMapBase$a(diff, oldObj, newObj) {
2539
+ function actionsMapBase$b(diff, oldObj, newObj) {
2501
2540
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2502
2541
  return buildBaseAttributesActions({
2503
- actions: baseActionsList$a,
2542
+ actions: baseActionsList$b,
2504
2543
  diff: diff,
2505
2544
  oldObj: oldObj,
2506
2545
  newObj: newObj,
@@ -2534,7 +2573,7 @@ function createTaxCategoriesMapActions(mapActionGroup, syncActionConfig) {
2534
2573
  return function doMapActions(diff, newObj, oldObj) {
2535
2574
  var allActions = [];
2536
2575
  allActions.push(mapActionGroup('base', function () {
2537
- return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
2576
+ return actionsMapBase$b(diff, oldObj, newObj, syncActionConfig);
2538
2577
  }));
2539
2578
  allActions.push(mapActionGroup('rates', function () {
2540
2579
  return actionsMapRates(diff, oldObj, newObj);
@@ -2561,7 +2600,7 @@ var taxCategories = (function (actionGroupList, syncActionConfig) {
2561
2600
  };
2562
2601
  });
2563
2602
 
2564
- var baseActionsList$9 = [{
2603
+ var baseActionsList$a = [{
2565
2604
  action: 'changeName',
2566
2605
  key: 'name'
2567
2606
  }, {
@@ -2578,10 +2617,10 @@ var hasLocation = function hasLocation(locations, otherLocation) {
2578
2617
  });
2579
2618
  };
2580
2619
 
2581
- function actionsMapBase$9(diff, oldObj, newObj) {
2620
+ function actionsMapBase$a(diff, oldObj, newObj) {
2582
2621
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2583
2622
  return buildBaseAttributesActions({
2584
- actions: baseActionsList$9,
2623
+ actions: baseActionsList$a,
2585
2624
  diff: diff,
2586
2625
  oldObj: oldObj,
2587
2626
  newObj: newObj,
@@ -2626,7 +2665,7 @@ function createZonesMapActions(mapActionGroup, syncActionConfig) {
2626
2665
  return function doMapActions(diff, newObj, oldObj) {
2627
2666
  var allActions = [];
2628
2667
  allActions.push(mapActionGroup('base', function () {
2629
- return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
2668
+ return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
2630
2669
  }));
2631
2670
  allActions.push(flatten__default["default"](mapActionGroup('locations', function () {
2632
2671
  return actionsMapLocations(diff, oldObj, newObj);
@@ -2653,7 +2692,7 @@ var zones = (function (actionGroupList, syncActionConfig) {
2653
2692
  };
2654
2693
  });
2655
2694
 
2656
- var baseActionsList$8 = [{
2695
+ var baseActionsList$9 = [{
2657
2696
  action: 'setKey',
2658
2697
  key: 'key'
2659
2698
  }, {
@@ -2678,10 +2717,10 @@ var baseActionsList$8 = [{
2678
2717
  action: 'changeTaxCategory',
2679
2718
  key: 'taxCategory'
2680
2719
  }];
2681
- function actionsMapBase$8(diff, oldObj, newObj) {
2720
+ function actionsMapBase$9(diff, oldObj, newObj) {
2682
2721
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2683
2722
  return buildBaseAttributesActions({
2684
- actions: baseActionsList$8,
2723
+ actions: baseActionsList$9,
2685
2724
  diff: diff,
2686
2725
  oldObj: oldObj,
2687
2726
  newObj: newObj,
@@ -2763,7 +2802,7 @@ function createShippingMethodsMapActions(mapActionGroup, syncActionConfig) {
2763
2802
  return function doMapActions(diff, newObj, oldObj) {
2764
2803
  var allActions = [];
2765
2804
  allActions.push(mapActionGroup('base', function () {
2766
- return actionsMapBase$8(diff, oldObj, newObj, syncActionConfig);
2805
+ return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
2767
2806
  }));
2768
2807
  allActions.push(flatten__default["default"](mapActionGroup('zoneRates', function () {
2769
2808
  return actionsMapZoneRates(diff, oldObj, newObj);
@@ -3161,7 +3200,7 @@ createComparator(function () {
3161
3200
  createComparator(createCircularEqualCreator());
3162
3201
  createComparator(createCircularEqualCreator(sameValueZeroEqual));
3163
3202
 
3164
- var baseActionsList$7 = [{
3203
+ var baseActionsList$8 = [{
3165
3204
  action: 'changeName',
3166
3205
  key: 'name'
3167
3206
  }, {
@@ -3171,7 +3210,7 @@ var baseActionsList$7 = [{
3171
3210
  action: 'changeDescription',
3172
3211
  key: 'description'
3173
3212
  }];
3174
- function actionsMapBase$7(diff, previous, next) {
3213
+ function actionsMapBase$8(diff, previous, next) {
3175
3214
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3176
3215
  // when `diff` is undefined, then the underlying `buildActions` has returned any diff
3177
3216
  // which given in product-types would mean that `buildActions` has run with `nestedValuesChanges` applied
@@ -3179,7 +3218,7 @@ function actionsMapBase$7(diff, previous, next) {
3179
3218
  if (!diff) return [];
3180
3219
  return buildBaseAttributesActions({
3181
3220
  diff: diff,
3182
- actions: baseActionsList$7,
3221
+ actions: baseActionsList$8,
3183
3222
  oldObj: previous,
3184
3223
  newObj: next,
3185
3224
  shouldOmitEmptyString: config.shouldOmitEmptyString
@@ -3405,7 +3444,7 @@ function createProductTypeMapActions(mapActionGroup, syncActionConfig) {
3405
3444
  return flatten__default["default"]([// we support only base fields for the product type,
3406
3445
  // for attributes, applying hints would be recommended
3407
3446
  mapActionGroup('base', function () {
3408
- return actionsMapBase$7(diff, previous, next, syncActionConfig);
3447
+ return actionsMapBase$8(diff, previous, next, syncActionConfig);
3409
3448
  }), actionsMapForHints(options.nestedValuesChanges, previous, next)]);
3410
3449
  };
3411
3450
  }
@@ -3422,7 +3461,7 @@ var productTypes = (function (actionGroupList, syncActionConfig) {
3422
3461
  };
3423
3462
  });
3424
3463
 
3425
- var baseActionsList$6 = [{
3464
+ var baseActionsList$7 = [{
3426
3465
  action: 'changeKey',
3427
3466
  key: 'key'
3428
3467
  }, {
@@ -3441,10 +3480,10 @@ var baseActionsList$6 = [{
3441
3480
  action: 'setTransitions',
3442
3481
  key: 'transitions'
3443
3482
  }];
3444
- function actionsMapBase$6(diff, oldObj, newObj) {
3483
+ function actionsMapBase$7(diff, oldObj, newObj) {
3445
3484
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3446
3485
  return buildBaseAttributesActions({
3447
- actions: baseActionsList$6,
3486
+ actions: baseActionsList$7,
3448
3487
  diff: diff,
3449
3488
  oldObj: oldObj,
3450
3489
  newObj: newObj,
@@ -3494,7 +3533,7 @@ function createStatesMapActions(mapActionGroup, syncActionConfig) {
3494
3533
  var baseActions = [];
3495
3534
  var roleActions = [];
3496
3535
  baseActions.push(mapActionGroup('base', function () {
3497
- return actionsMapBase$6(diff, oldObj, newObj, syncActionConfig);
3536
+ return actionsMapBase$7(diff, oldObj, newObj, syncActionConfig);
3498
3537
  }));
3499
3538
  roleActions.push(mapActionGroup('roles', function () {
3500
3539
  return actionsMapRoles(diff, oldObj, newObj);
@@ -3512,7 +3551,7 @@ var states = (function (actionGroupList, syncActionConfig) {
3512
3551
  };
3513
3552
  });
3514
3553
 
3515
- var baseActionsList$5 = [{
3554
+ var baseActionsList$6 = [{
3516
3555
  action: 'changeKey',
3517
3556
  key: 'key'
3518
3557
  }, {
@@ -3531,10 +3570,10 @@ var baseActionsList$5 = [{
3531
3570
  action: 'setRoles',
3532
3571
  key: 'roles'
3533
3572
  }];
3534
- function actionsMapBase$5(diff, oldObj, newObj) {
3573
+ function actionsMapBase$6(diff, oldObj, newObj) {
3535
3574
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3536
3575
  return buildBaseAttributesActions({
3537
- actions: baseActionsList$5,
3576
+ actions: baseActionsList$6,
3538
3577
  diff: diff,
3539
3578
  oldObj: oldObj,
3540
3579
  newObj: newObj,
@@ -3546,7 +3585,7 @@ function createChannelsMapActions$1(mapActionGroup, syncActionConfig) {
3546
3585
  return function doMapActions(diff, newObj, oldObj) {
3547
3586
  var allActions = [];
3548
3587
  allActions.push(mapActionGroup('base', function () {
3549
- return actionsMapBase$5(diff, oldObj, newObj, syncActionConfig);
3588
+ return actionsMapBase$6(diff, oldObj, newObj, syncActionConfig);
3550
3589
  }));
3551
3590
  allActions.push(mapActionGroup('custom', function () {
3552
3591
  return actionsMapCustom(diff, newObj, oldObj);
@@ -3576,7 +3615,7 @@ var getIsRemovedOperation = function getIsRemovedOperation(key) {
3576
3615
  return REGEX_UNDERSCORE_NUMBER.test(key);
3577
3616
  };
3578
3617
 
3579
- var baseActionsList$4 = [{
3618
+ var baseActionsList$5 = [{
3580
3619
  action: 'changeKey',
3581
3620
  key: 'key'
3582
3621
  }, {
@@ -3586,10 +3625,10 @@ var baseActionsList$4 = [{
3586
3625
  action: 'setDescription',
3587
3626
  key: 'description'
3588
3627
  }];
3589
- function actionsMapBase$4(diff, oldObj, newObj) {
3628
+ function actionsMapBase$5(diff, oldObj, newObj) {
3590
3629
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3591
3630
  return buildBaseAttributesActions({
3592
- actions: baseActionsList$4,
3631
+ actions: baseActionsList$5,
3593
3632
  diff: diff,
3594
3633
  oldObj: oldObj,
3595
3634
  newObj: newObj,
@@ -3738,7 +3777,7 @@ function createTypeMapActions(mapActionGroup, syncActionConfig) {
3738
3777
  return function doMapActions(diff, next, previous) {
3739
3778
  var allActions = [];
3740
3779
  allActions.push(mapActionGroup('base', function () {
3741
- return actionsMapBase$4(diff, previous, next, syncActionConfig);
3780
+ return actionsMapBase$5(diff, previous, next, syncActionConfig);
3742
3781
  }), mapActionGroup('fieldDefinitions', function () {
3743
3782
  return actionsMapFieldDefinitions(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, findMatchingPairs(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, 'name'));
3744
3783
  }));
@@ -3755,7 +3794,7 @@ var types = (function (actionGroupList, syncActionConfig) {
3755
3794
  };
3756
3795
  });
3757
3796
 
3758
- var baseActionsList$3 = [{
3797
+ var baseActionsList$4 = [{
3759
3798
  action: 'changeName',
3760
3799
  key: 'name'
3761
3800
  }, {
@@ -3774,10 +3813,10 @@ var baseActionsList$3 = [{
3774
3813
  action: 'setShippingRateInputType',
3775
3814
  key: 'shippingRateInputType'
3776
3815
  }];
3777
- function actionsMapBase$3(diff, oldObj, newObj) {
3816
+ function actionsMapBase$4(diff, oldObj, newObj) {
3778
3817
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3779
3818
  return buildBaseAttributesActions({
3780
- actions: baseActionsList$3,
3819
+ actions: baseActionsList$4,
3781
3820
  diff: diff,
3782
3821
  oldObj: oldObj,
3783
3822
  newObj: newObj,
@@ -3789,7 +3828,7 @@ function createChannelsMapActions(mapActionGroup, syncActionConfig) {
3789
3828
  return function doMapActions(diff, newObj, oldObj) {
3790
3829
  var allActions = [];
3791
3830
  allActions.push(mapActionGroup('base', function () {
3792
- return actionsMapBase$3(diff, oldObj, newObj, syncActionConfig);
3831
+ return actionsMapBase$4(diff, oldObj, newObj, syncActionConfig);
3793
3832
  }));
3794
3833
  return flatten__default["default"](allActions);
3795
3834
  };
@@ -3805,7 +3844,7 @@ var projects = (function (actionGroupList) {
3805
3844
  };
3806
3845
  });
3807
3846
 
3808
- var baseActionsList$2 = [{
3847
+ var baseActionsList$3 = [{
3809
3848
  action: 'setName',
3810
3849
  key: 'name'
3811
3850
  }, {
@@ -3818,9 +3857,9 @@ var baseActionsList$2 = [{
3818
3857
  action: 'setSupplyChannels',
3819
3858
  key: 'supplyChannels'
3820
3859
  }];
3821
- function actionsMapBase$2(diff, oldObj, newObj) {
3860
+ function actionsMapBase$3(diff, oldObj, newObj) {
3822
3861
  return buildBaseAttributesActions({
3823
- actions: baseActionsList$2,
3862
+ actions: baseActionsList$3,
3824
3863
  diff: diff,
3825
3864
  oldObj: oldObj,
3826
3865
  newObj: newObj
@@ -3831,7 +3870,7 @@ function createStoresMapActions(mapActionGroup) {
3831
3870
  return function doMapActions(diff, next, previous) {
3832
3871
  var allActions = [];
3833
3872
  allActions.push(mapActionGroup('base', function () {
3834
- return actionsMapBase$2(diff, previous, next);
3873
+ return actionsMapBase$3(diff, previous, next);
3835
3874
  }));
3836
3875
  allActions.push(mapActionGroup('custom', function () {
3837
3876
  return actionsMapCustom(diff, next, previous);
@@ -3850,16 +3889,16 @@ var stores = (function (actionGroupList) {
3850
3889
  };
3851
3890
  });
3852
3891
 
3853
- var baseActionsList$1 = [{
3892
+ var baseActionsList$2 = [{
3854
3893
  action: 'changeName',
3855
3894
  key: 'name'
3856
3895
  }, {
3857
3896
  action: 'setKey',
3858
3897
  key: 'key'
3859
3898
  }];
3860
- function actionsMapBase$1(diff, oldObj, newObj) {
3899
+ function actionsMapBase$2(diff, oldObj, newObj) {
3861
3900
  return buildBaseAttributesActions({
3862
- actions: baseActionsList$1,
3901
+ actions: baseActionsList$2,
3863
3902
  diff: diff,
3864
3903
  oldObj: oldObj,
3865
3904
  newObj: newObj
@@ -3870,7 +3909,7 @@ function createProductSelectionsMapActions(mapActionGroup) {
3870
3909
  return function doMapActions(diff, next, previous) {
3871
3910
  var allActions = [];
3872
3911
  allActions.push(mapActionGroup('base', function () {
3873
- return actionsMapBase$1(diff, previous, next);
3912
+ return actionsMapBase$2(diff, previous, next);
3874
3913
  }));
3875
3914
  allActions.push(mapActionGroup('custom', function () {
3876
3915
  return actionsMapCustom(diff, next, previous);
@@ -3889,7 +3928,7 @@ var productSelections = (function (actionGroupList) {
3889
3928
  };
3890
3929
  });
3891
3930
 
3892
- var baseActionsList = [{
3931
+ var baseActionsList$1 = [{
3893
3932
  action: 'changeValue',
3894
3933
  key: 'value'
3895
3934
  }, {
@@ -3912,10 +3951,10 @@ var baseActionsList = [{
3912
3951
  action: 'changeActive',
3913
3952
  key: 'active'
3914
3953
  }];
3915
- function actionsMapBase(diff, oldObj, newObj) {
3954
+ function actionsMapBase$1(diff, oldObj, newObj) {
3916
3955
  var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3917
3956
  return buildBaseAttributesActions({
3918
- actions: baseActionsList,
3957
+ actions: baseActionsList$1,
3919
3958
  diff: diff,
3920
3959
  oldObj: oldObj,
3921
3960
  newObj: newObj,
@@ -3926,7 +3965,7 @@ function actionsMapBase(diff, oldObj, newObj) {
3926
3965
  function createPriceMapActions(mapActionGroup, syncActionConfig) {
3927
3966
  return function doMapActions(diff, newObj, oldObj) {
3928
3967
  var baseActions = mapActionGroup('base', function () {
3929
- return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
3968
+ return actionsMapBase$1(diff, oldObj, newObj, syncActionConfig);
3930
3969
  });
3931
3970
  var customActions = mapActionGroup('custom', function () {
3932
3971
  return actionsMapCustom(diff, newObj, oldObj);
@@ -3944,6 +3983,88 @@ var prices = (function (actionGroupList, syncActionConfig) {
3944
3983
  };
3945
3984
  });
3946
3985
 
3986
+ var hasAttribute = function hasAttribute(attributes, newValue) {
3987
+ return attributes.some(function (attribute) {
3988
+ return attribute.key === newValue.key;
3989
+ });
3990
+ };
3991
+
3992
+ var baseActionsList = [{
3993
+ action: 'changeName',
3994
+ key: 'name'
3995
+ }, {
3996
+ action: 'setKey',
3997
+ key: 'key'
3998
+ }, {
3999
+ action: 'setDescription',
4000
+ key: 'description'
4001
+ }];
4002
+ function actionsMapBase(diff, oldObj, newObj) {
4003
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
4004
+ return buildBaseAttributesActions({
4005
+ actions: baseActionsList,
4006
+ diff: diff,
4007
+ oldObj: oldObj,
4008
+ newObj: newObj,
4009
+ shouldOmitEmptyString: config.shouldOmitEmptyString
4010
+ });
4011
+ }
4012
+ function actionsMapAttributes(diff, oldObj, newObj) {
4013
+ var _createBuildArrayActi;
4014
+
4015
+ var handler = createBuildArrayActions('attributes', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newAttribute) {
4016
+ return {
4017
+ action: 'addAttribute',
4018
+ attribute: newAttribute
4019
+ };
4020
+ }), _defineProperty(_createBuildArrayActi, REMOVE_ACTIONS, function (oldAttribute) {
4021
+ // We only add the action if the attribute is not included in the new object.
4022
+ return !hasAttribute(newObj.attributes, oldAttribute) ? {
4023
+ action: 'removeAttribute',
4024
+ attribute: oldAttribute
4025
+ } : null;
4026
+ }), _defineProperty(_createBuildArrayActi, CHANGE_ACTIONS, function (oldAttribute, newAttribute) {
4027
+ var result = []; // We only remove the attribute in case that the oldAttribute is not
4028
+ // included in the new object
4029
+
4030
+ if (!hasAttribute(newObj.attributes, oldAttribute)) result.push({
4031
+ action: 'removeAttribute',
4032
+ attribute: oldAttribute
4033
+ }); // We only add the attribute in case that the newAttribute was not
4034
+ // included in the old object
4035
+
4036
+ if (!hasAttribute(oldObj.attributes, newAttribute)) result.push({
4037
+ action: 'addAttribute',
4038
+ attribute: newAttribute
4039
+ });
4040
+ return result;
4041
+ }), _createBuildArrayActi));
4042
+ return handler(diff, oldObj, newObj);
4043
+ }
4044
+
4045
+ function createAttributeGroupsMapActions(mapActionGroup, syncActionConfig) {
4046
+ return function doMapActions(diff, newObj, oldObj) {
4047
+ var allActions = [];
4048
+ allActions.push(mapActionGroup('base', function () {
4049
+ return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
4050
+ }));
4051
+ allActions.push(flatten__default["default"](mapActionGroup('attributes', function () {
4052
+ return actionsMapAttributes(diff, oldObj, newObj);
4053
+ })));
4054
+ return flatten__default["default"](allActions);
4055
+ };
4056
+ }
4057
+
4058
+ var attributeGroups = (function (actionGroupList, syncActionConfig) {
4059
+ var mapActionGroup = createMapActionGroup(actionGroupList);
4060
+ var doMapActions = createAttributeGroupsMapActions(mapActionGroup, syncActionConfig);
4061
+ var buildActions = createBuildActions(diff, doMapActions);
4062
+ return {
4063
+ buildActions: buildActions
4064
+ };
4065
+ });
4066
+
4067
+ exports.createSyncAttributeGroups = attributeGroups;
3947
4068
  exports.createSyncCartDiscounts = cartDiscounts;
3948
4069
  exports.createSyncCategories = categories;
3949
4070
  exports.createSyncChannels = channels;