@commercetools/sync-actions 5.19.1 → 5.19.2

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.
@@ -155,7 +155,7 @@ function _unsupportedIterableToArray(r, a) {
155
155
  }
156
156
  }
157
157
 
158
- var _excluded$1 = ["prices"];
158
+ var _excluded$2 = ["prices"];
159
159
  function applyOnBeforeDiff(before, now, fn) {
160
160
  return fn && typeof fn === 'function' ? fn(before, now) : [before, now];
161
161
  }
@@ -186,7 +186,7 @@ function extractPriceFromPreviousVariant(newPrice, previousVariant) {
186
186
  function injectMissingPriceIds(nextVariants, previousVariants) {
187
187
  return nextVariants.map(function (newVariant) {
188
188
  var prices = newVariant.prices,
189
- restOfVariant = _objectWithoutProperties(newVariant, _excluded$1);
189
+ restOfVariant = _objectWithoutProperties(newVariant, _excluded$2);
190
190
  if (!prices) return restOfVariant;
191
191
  var oldVariant = previousVariants.find(function (previousVariant) {
192
192
  return !isNil__default["default"](previousVariant.id) && previousVariant.id === newVariant.id || !isNil__default["default"](previousVariant.key) && previousVariant.key === newVariant.key || !isNil__default["default"](previousVariant.sku) && previousVariant.sku === newVariant.sku;
@@ -299,7 +299,7 @@ function getDeltaValue(arr, originalObject) {
299
299
  throw new Error("Got unsupported number ".concat(arr[2], " in delta value"));
300
300
  }
301
301
 
302
- var _excluded = ["actions"];
302
+ var _excluded$1 = ["actions"];
303
303
  var Actions = {
304
304
  setCustomType: 'setCustomType',
305
305
  setCustomField: 'setCustomField'
@@ -334,7 +334,7 @@ function actionsMapCustom(diff, newObj, oldObj) {
334
334
  };
335
335
  var actions = [];
336
336
  var customPropsActions = customProps.actions,
337
- options = _objectWithoutProperties(customProps, _excluded);
337
+ options = _objectWithoutProperties(customProps, _excluded$1);
338
338
  var actionGroup = _objectSpread2(_objectSpread2({}, Actions), customPropsActions);
339
339
  if (!diff.custom) return actions;
340
340
  if (hasSingleCustomFieldChanged(diff)) {
@@ -2368,406 +2368,104 @@ var cartDiscounts = (function (actionGroupList) {
2368
2368
  };
2369
2369
  });
2370
2370
 
2371
- var baseActionsList$b = [{
2372
- action: 'changeName',
2373
- key: 'name'
2374
- }, {
2375
- action: 'setKey',
2376
- key: 'key'
2377
- }, {
2378
- action: 'setDescription',
2379
- key: 'description'
2380
- }];
2381
- function actionsMapBase$b(diff, oldObj, newObj) {
2382
- var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2383
- return buildBaseAttributesActions({
2384
- actions: baseActionsList$b,
2385
- diff: diff,
2386
- oldObj: oldObj,
2387
- newObj: newObj,
2388
- shouldOmitEmptyString: config.shouldOmitEmptyString
2389
- });
2371
+ var HAS_WEAKSET_SUPPORT = typeof WeakSet === 'function';
2372
+ var keys = Object.keys;
2373
+ /**
2374
+ * are the values passed strictly equal or both NaN
2375
+ *
2376
+ * @param a the value to compare against
2377
+ * @param b the value to test
2378
+ * @returns are the values equal by the SameValueZero principle
2379
+ */
2380
+ function sameValueZeroEqual(a, b) {
2381
+ return a === b || a !== a && b !== b;
2390
2382
  }
2391
- function actionsMapRates(diff, oldObj, newObj) {
2392
- var handler = createBuildArrayActions('rates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newObject) {
2393
- return {
2394
- action: 'addTaxRate',
2395
- taxRate: newObject
2396
- };
2397
- }), REMOVE_ACTIONS, function (objectToRemove) {
2398
- return {
2399
- action: 'removeTaxRate',
2400
- taxRateId: objectToRemove.id
2401
- };
2402
- }), CHANGE_ACTIONS, function (oldObject, updatedObject) {
2403
- return {
2404
- action: 'replaceTaxRate',
2405
- taxRateId: oldObject.id === updatedObject.id ? oldObject.id : updatedObject.id,
2406
- taxRate: updatedObject
2407
- };
2408
- }));
2409
- return handler(diff, oldObj, newObj);
2383
+ /**
2384
+ * is the value a plain object
2385
+ *
2386
+ * @param value the value to test
2387
+ * @returns is the value a plain object
2388
+ */
2389
+ function isPlainObject(value) {
2390
+ return value.constructor === Object || value.constructor == null;
2410
2391
  }
2411
-
2412
- function createTaxCategoriesMapActions(mapActionGroup, syncActionConfig) {
2413
- return function doMapActions(diff, newObj, oldObj) {
2414
- var allActions = [];
2415
- allActions.push(mapActionGroup('base', function () {
2416
- return actionsMapBase$b(diff, oldObj, newObj, syncActionConfig);
2417
- }));
2418
- allActions.push(mapActionGroup('rates', function () {
2419
- return actionsMapRates(diff, oldObj, newObj);
2420
- }));
2421
- return flatten__default["default"](allActions);
2422
- };
2392
+ /**
2393
+ * is the value promise-like (meaning it is thenable)
2394
+ *
2395
+ * @param value the value to test
2396
+ * @returns is the value promise-like
2397
+ */
2398
+ function isPromiseLike(value) {
2399
+ return !!value && typeof value.then === 'function';
2423
2400
  }
2424
- var taxCategories = (function (actionGroupList, syncActionConfig) {
2425
- // config contains information about which action groups
2426
- // are allowed or ignored
2427
-
2428
- // createMapActionGroup returns function 'mapActionGroup' that takes params:
2429
- // - action group name
2430
- // - callback function that should return a list of actions that correspond
2431
- // to the for the action group
2432
-
2433
- // this resulting function mapActionGroup will call the callback function
2434
- // for allowed action groups and return the return value of the callback
2435
- // It will return an empty array for ignored action groups
2436
- var mapActionGroup = createMapActionGroup(actionGroupList);
2437
- var doMapActions = createTaxCategoriesMapActions(mapActionGroup, syncActionConfig);
2438
- var buildActions = createBuildActions(diff, doMapActions);
2401
+ /**
2402
+ * is the value passed a react element
2403
+ *
2404
+ * @param value the value to test
2405
+ * @returns is the value a react element
2406
+ */
2407
+ function isReactElement(value) {
2408
+ return !!(value && value.$$typeof);
2409
+ }
2410
+ /**
2411
+ * in cases where WeakSet is not supported, creates a new custom
2412
+ * object that mimics the necessary API aspects for cache purposes
2413
+ *
2414
+ * @returns the new cache object
2415
+ */
2416
+ function getNewCacheFallback() {
2417
+ var values = [];
2439
2418
  return {
2440
- buildActions: buildActions
2419
+ add: function add(value) {
2420
+ values.push(value);
2421
+ },
2422
+ has: function has(value) {
2423
+ return values.indexOf(value) !== -1;
2424
+ }
2441
2425
  };
2442
- });
2443
-
2444
- var baseActionsList$a = [{
2445
- action: 'changeName',
2446
- key: 'name'
2447
- }, {
2448
- action: 'setDescription',
2449
- key: 'description'
2450
- }, {
2451
- action: 'setKey',
2452
- key: 'key'
2453
- }];
2454
- var hasLocation = function hasLocation(locations, otherLocation) {
2455
- return locations.some(function (location) {
2456
- return location.country === otherLocation.country;
2457
- });
2458
- };
2459
- function actionsMapBase$a(diff, oldObj, newObj) {
2460
- var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2461
- return buildBaseAttributesActions({
2462
- actions: baseActionsList$a,
2463
- diff: diff,
2464
- oldObj: oldObj,
2465
- newObj: newObj,
2466
- shouldOmitEmptyString: config.shouldOmitEmptyString
2467
- });
2468
2426
  }
2469
- function actionsMapLocations(diff, oldObj, newObj) {
2470
- var handler = createBuildArrayActions('locations', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newLocation) {
2471
- return {
2472
- action: 'addLocation',
2473
- location: newLocation
2474
- };
2475
- }), REMOVE_ACTIONS, function (oldLocation) {
2476
- return (
2477
- // We only add the action if the location is not included in the new object.
2478
- !hasLocation(newObj.locations, oldLocation) ? {
2479
- action: 'removeLocation',
2480
- location: oldLocation
2481
- } : null
2482
- );
2483
- }), CHANGE_ACTIONS, function (oldLocation, newLocation) {
2484
- var result = [];
2485
-
2486
- // We only remove the location in case that the oldLocation is not
2487
- // included in the new object
2488
- if (!hasLocation(newObj.locations, oldLocation)) result.push({
2489
- action: 'removeLocation',
2490
- location: oldLocation
2491
- });
2492
-
2493
- // We only add the location in case that the newLocation was not
2494
- // included in the old object
2495
- if (!hasLocation(oldObj.locations, newLocation)) result.push({
2496
- action: 'addLocation',
2497
- location: newLocation
2498
- });
2499
- return result;
2500
- }));
2501
- return handler(diff, oldObj, newObj);
2502
- }
2503
-
2504
- function createZonesMapActions(mapActionGroup, syncActionConfig) {
2505
- return function doMapActions(diff, newObj, oldObj) {
2506
- var allActions = [];
2507
- allActions.push(mapActionGroup('base', function () {
2508
- return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
2509
- }));
2510
- allActions.push(flatten__default["default"](mapActionGroup('locations', function () {
2511
- return actionsMapLocations(diff, oldObj, newObj);
2512
- })));
2513
- return flatten__default["default"](allActions);
2514
- };
2515
- }
2516
- var zones = (function (actionGroupList, syncActionConfig) {
2517
- // config contains information about which action groups
2518
- // are allowed or ignored
2519
-
2520
- // createMapActionGroup returns function 'mapActionGroup' that takes params:
2521
- // - action group name
2522
- // - callback function that should return a list of actions that correspond
2523
- // to the for the action group
2524
-
2525
- // this resulting function mapActionGroup will call the callback function
2526
- // for allowed action groups and return the return value of the callback
2527
- // It will return an empty array for ignored action groups
2528
- var mapActionGroup = createMapActionGroup(actionGroupList);
2529
- var doMapActions = createZonesMapActions(mapActionGroup, syncActionConfig);
2530
- var buildActions = createBuildActions(diff, doMapActions);
2531
- return {
2532
- buildActions: buildActions
2533
- };
2534
- });
2535
-
2536
- var baseActionsList$9 = [{
2537
- action: 'setKey',
2538
- key: 'key'
2539
- }, {
2540
- action: 'changeName',
2541
- key: 'name'
2542
- }, {
2543
- action: 'setLocalizedName',
2544
- key: 'localizedName'
2545
- }, {
2546
- action: 'setDescription',
2547
- key: 'description'
2548
- }, {
2549
- action: 'setLocalizedDescription',
2550
- key: 'localizedDescription'
2551
- }, {
2552
- action: 'changeIsDefault',
2553
- key: 'isDefault'
2554
- }, {
2555
- action: 'setPredicate',
2556
- key: 'predicate'
2557
- }, {
2558
- action: 'changeTaxCategory',
2559
- key: 'taxCategory'
2560
- }, {
2561
- action: 'changeActive',
2562
- key: 'active'
2563
- }];
2564
- function actionsMapBase$9(diff, oldObj, newObj) {
2565
- var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2566
- return buildBaseAttributesActions({
2567
- actions: baseActionsList$9,
2568
- diff: diff,
2569
- oldObj: oldObj,
2570
- newObj: newObj,
2571
- shouldOmitEmptyString: config.shouldOmitEmptyString
2572
- });
2573
- }
2574
- var addShippingRates = function addShippingRates(newZoneRate) {
2575
- return newZoneRate.shippingRates ? newZoneRate.shippingRates.map(function (shippingRate) {
2576
- return {
2577
- action: 'addShippingRate',
2578
- zone: newZoneRate.zone,
2579
- shippingRate: shippingRate
2580
- };
2581
- }) : [];
2582
- };
2583
- function actionsMapZoneRatesShippingRates(diff, oldObj, newObj) {
2584
- var handler = createBuildArrayActions('shippingRates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newShippingRate) {
2585
- return {
2586
- action: 'addShippingRate',
2587
- zone: newObj.zone,
2588
- shippingRate: newShippingRate
2589
- };
2590
- }), REMOVE_ACTIONS, function (oldShippingRate) {
2591
- return {
2592
- action: 'removeShippingRate',
2593
- zone: oldObj.zone,
2594
- shippingRate: oldShippingRate
2595
- };
2596
- }), CHANGE_ACTIONS, function (oldShippingRate, newShippingRate) {
2597
- return [{
2598
- action: 'removeShippingRate',
2599
- zone: oldObj.zone,
2600
- shippingRate: oldShippingRate
2601
- }, {
2602
- action: 'addShippingRate',
2603
- zone: newObj.zone,
2604
- shippingRate: newShippingRate
2605
- }];
2606
- }));
2607
- return handler(diff, oldObj, newObj);
2608
- }
2609
- function actionsMapZoneRates(diff, oldObj, newObj) {
2610
- var handler = createBuildArrayActions('zoneRates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newZoneRate) {
2611
- return [{
2612
- action: 'addZone',
2613
- zone: newZoneRate.zone
2614
- }].concat(_toConsumableArray(addShippingRates(newZoneRate)));
2615
- }), REMOVE_ACTIONS, function (oldZoneRate) {
2616
- return {
2617
- action: 'removeZone',
2618
- zone: oldZoneRate.zone
2619
- };
2620
- }), CHANGE_ACTIONS, function (oldZoneRate, newZoneRate) {
2621
- var hasZoneActions = false;
2622
- var shippingRateActions = Object.keys(diff.zoneRates).reduce(function (actions, key) {
2623
- if (diff.zoneRates[key].zone) hasZoneActions = true;
2624
- if (diff.zoneRates[key].shippingRates) return [].concat(_toConsumableArray(actions), _toConsumableArray(actionsMapZoneRatesShippingRates(diff.zoneRates[key], oldZoneRate, newZoneRate)));
2625
- return actions;
2626
- }, []);
2627
- return flatten__default["default"](hasZoneActions ? [].concat(_toConsumableArray(shippingRateActions), [{
2628
- action: 'removeZone',
2629
- zone: oldZoneRate.zone
2630
- }, {
2631
- action: 'addZone',
2632
- zone: newZoneRate.zone
2633
- }]) : shippingRateActions);
2634
- }));
2635
- return handler(diff, oldObj, newObj);
2636
- }
2637
-
2638
- function createShippingMethodsMapActions(mapActionGroup, syncActionConfig) {
2639
- return function doMapActions(diff, newObj, oldObj) {
2640
- var allActions = [];
2641
- allActions.push(mapActionGroup('base', function () {
2642
- return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
2643
- }));
2644
- allActions.push(flatten__default["default"](mapActionGroup('zoneRates', function () {
2645
- return actionsMapZoneRates(diff, oldObj, newObj);
2646
- })));
2647
- allActions.push(mapActionGroup('custom', function () {
2648
- return actionsMapCustom(diff, newObj, oldObj);
2649
- }));
2650
- return flatten__default["default"](allActions);
2651
- };
2652
- }
2653
- var shippingMethods = (function (actionGroupList, syncActionConfig) {
2654
- // actionGroupList contains information about which action groups
2655
- // are allowed or ignored
2656
-
2657
- // createMapActionGroup returns function 'mapActionGroup' that takes params:
2658
- // - action group name
2659
- // - callback function that should return a list of actions that correspond
2660
- // to the for the action group
2661
-
2662
- // this resulting function mapActionGroup will call the callback function
2663
- // for allowed action groups and return the return value of the callback
2664
- // It will return an empty array for ignored action groups
2665
- var mapActionGroup = createMapActionGroup(actionGroupList);
2666
- var doMapActions = createShippingMethodsMapActions(mapActionGroup, syncActionConfig);
2667
- var buildActions = createBuildActions(diff, doMapActions);
2668
- return {
2669
- buildActions: buildActions
2670
- };
2671
- });
2672
-
2673
- var HAS_WEAKSET_SUPPORT = typeof WeakSet === 'function';
2674
- var keys = Object.keys;
2675
- /**
2676
- * are the values passed strictly equal or both NaN
2677
- *
2678
- * @param a the value to compare against
2679
- * @param b the value to test
2680
- * @returns are the values equal by the SameValueZero principle
2681
- */
2682
- function sameValueZeroEqual(a, b) {
2683
- return a === b || a !== a && b !== b;
2684
- }
2685
- /**
2686
- * is the value a plain object
2687
- *
2688
- * @param value the value to test
2689
- * @returns is the value a plain object
2690
- */
2691
- function isPlainObject(value) {
2692
- return value.constructor === Object || value.constructor == null;
2693
- }
2694
- /**
2695
- * is the value promise-like (meaning it is thenable)
2696
- *
2697
- * @param value the value to test
2698
- * @returns is the value promise-like
2699
- */
2700
- function isPromiseLike(value) {
2701
- return !!value && typeof value.then === 'function';
2702
- }
2703
- /**
2704
- * is the value passed a react element
2705
- *
2706
- * @param value the value to test
2707
- * @returns is the value a react element
2708
- */
2709
- function isReactElement(value) {
2710
- return !!(value && value.$$typeof);
2711
- }
2712
- /**
2713
- * in cases where WeakSet is not supported, creates a new custom
2714
- * object that mimics the necessary API aspects for cache purposes
2715
- *
2716
- * @returns the new cache object
2717
- */
2718
- function getNewCacheFallback() {
2719
- var values = [];
2720
- return {
2721
- add: function add(value) {
2722
- values.push(value);
2723
- },
2724
- has: function has(value) {
2725
- return values.indexOf(value) !== -1;
2726
- }
2727
- };
2728
- }
2729
- /**
2730
- * get a new cache object to prevent circular references
2731
- *
2732
- * @returns the new cache object
2733
- */
2734
- var getNewCache = function (canUseWeakMap) {
2735
- if (canUseWeakMap) {
2736
- return function _getNewCache() {
2737
- return new WeakSet();
2738
- };
2739
- }
2740
- return getNewCacheFallback;
2741
- }(HAS_WEAKSET_SUPPORT);
2742
- /**
2743
- * create a custom isEqual handler specific to circular objects
2744
- *
2745
- * @param [isEqual] the isEqual comparator to use instead of isDeepEqual
2746
- * @returns the method to create the `isEqual` function
2747
- */
2748
- function createCircularEqualCreator(isEqual) {
2749
- return function createCircularEqual(comparator) {
2750
- var _comparator = isEqual || comparator;
2751
- return function circularEqual(a, b, cache) {
2752
- if (cache === void 0) {
2753
- cache = getNewCache();
2754
- }
2755
- var isCacheableA = !!a && _typeof(a) === 'object';
2756
- var isCacheableB = !!b && _typeof(b) === 'object';
2757
- if (isCacheableA || isCacheableB) {
2758
- var hasA = isCacheableA && cache.has(a);
2759
- var hasB = isCacheableB && cache.has(b);
2760
- if (hasA || hasB) {
2761
- return hasA && hasB;
2762
- }
2763
- if (isCacheableA) {
2764
- cache.add(a);
2765
- }
2766
- if (isCacheableB) {
2767
- cache.add(b);
2768
- }
2769
- }
2770
- return _comparator(a, b, cache);
2427
+ /**
2428
+ * get a new cache object to prevent circular references
2429
+ *
2430
+ * @returns the new cache object
2431
+ */
2432
+ var getNewCache = function (canUseWeakMap) {
2433
+ if (canUseWeakMap) {
2434
+ return function _getNewCache() {
2435
+ return new WeakSet();
2436
+ };
2437
+ }
2438
+ return getNewCacheFallback;
2439
+ }(HAS_WEAKSET_SUPPORT);
2440
+ /**
2441
+ * create a custom isEqual handler specific to circular objects
2442
+ *
2443
+ * @param [isEqual] the isEqual comparator to use instead of isDeepEqual
2444
+ * @returns the method to create the `isEqual` function
2445
+ */
2446
+ function createCircularEqualCreator(isEqual) {
2447
+ return function createCircularEqual(comparator) {
2448
+ var _comparator = isEqual || comparator;
2449
+ return function circularEqual(a, b, cache) {
2450
+ if (cache === void 0) {
2451
+ cache = getNewCache();
2452
+ }
2453
+ var isCacheableA = !!a && _typeof(a) === 'object';
2454
+ var isCacheableB = !!b && _typeof(b) === 'object';
2455
+ if (isCacheableA || isCacheableB) {
2456
+ var hasA = isCacheableA && cache.has(a);
2457
+ var hasB = isCacheableB && cache.has(b);
2458
+ if (hasA || hasB) {
2459
+ return hasA && hasB;
2460
+ }
2461
+ if (isCacheableA) {
2462
+ cache.add(a);
2463
+ }
2464
+ if (isCacheableB) {
2465
+ cache.add(b);
2466
+ }
2467
+ }
2468
+ return _comparator(a, b, cache);
2771
2469
  };
2772
2470
  };
2773
2471
  }
@@ -2968,6 +2666,325 @@ createComparator(function () {
2968
2666
  createComparator(createCircularEqualCreator());
2969
2667
  createComparator(createCircularEqualCreator(sameValueZeroEqual));
2970
2668
 
2669
+ var _excluded = ["__typename"];
2670
+ function removeTypename(obj) {
2671
+ obj.__typename;
2672
+ var objWithoutTypename = _objectWithoutProperties(obj, _excluded);
2673
+ return objWithoutTypename;
2674
+ }
2675
+
2676
+ var baseActionsList$b = [{
2677
+ action: 'changeName',
2678
+ key: 'name'
2679
+ }, {
2680
+ action: 'setKey',
2681
+ key: 'key'
2682
+ }, {
2683
+ action: 'setDescription',
2684
+ key: 'description'
2685
+ }];
2686
+ function actionsMapBase$b(diff, oldObj, newObj) {
2687
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2688
+ return buildBaseAttributesActions({
2689
+ actions: baseActionsList$b,
2690
+ diff: diff,
2691
+ oldObj: oldObj,
2692
+ newObj: newObj,
2693
+ shouldOmitEmptyString: config.shouldOmitEmptyString
2694
+ });
2695
+ }
2696
+ function actionsMapRates(diff, oldObj, newObj) {
2697
+ var handler = createBuildArrayActions('rates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newObject) {
2698
+ return {
2699
+ action: 'addTaxRate',
2700
+ taxRate: newObject
2701
+ };
2702
+ }), REMOVE_ACTIONS, function (objectToRemove) {
2703
+ return {
2704
+ action: 'removeTaxRate',
2705
+ taxRateId: objectToRemove.id
2706
+ };
2707
+ }), CHANGE_ACTIONS, function (oldObject, updatedObject) {
2708
+ var _oldObject$subRates;
2709
+ // filter out taxRates that were not changed
2710
+ // so the API doesn't return it with a different id
2711
+ // we need to remove __typename from the object to compare them
2712
+ var taxCategoryWithoutTypeName = removeTypename(oldObject);
2713
+ var oldObjectSubRatesWithoutTypename = (_oldObject$subRates = oldObject.subRates) === null || _oldObject$subRates === void 0 ? void 0 : _oldObject$subRates.map(removeTypename);
2714
+ var oldObjectWithoutTypename = _objectSpread2(_objectSpread2({}, taxCategoryWithoutTypeName), {}, {
2715
+ subRates: oldObjectSubRatesWithoutTypename
2716
+ });
2717
+ if (deepEqual(oldObjectWithoutTypename, updatedObject)) return null;
2718
+ return {
2719
+ action: 'replaceTaxRate',
2720
+ taxRateId: oldObject.id === updatedObject.id ? oldObject.id : updatedObject.id,
2721
+ taxRate: updatedObject
2722
+ };
2723
+ }));
2724
+ return handler(diff, oldObj, newObj);
2725
+ }
2726
+
2727
+ function createTaxCategoriesMapActions(mapActionGroup, syncActionConfig) {
2728
+ return function doMapActions(diff, newObj, oldObj) {
2729
+ var allActions = [];
2730
+ allActions.push(mapActionGroup('base', function () {
2731
+ return actionsMapBase$b(diff, oldObj, newObj, syncActionConfig);
2732
+ }));
2733
+ allActions.push(mapActionGroup('rates', function () {
2734
+ return actionsMapRates(diff, oldObj, newObj);
2735
+ }));
2736
+ return flatten__default["default"](allActions);
2737
+ };
2738
+ }
2739
+ var taxCategories = (function (actionGroupList, syncActionConfig) {
2740
+ // config contains information about which action groups
2741
+ // are allowed or ignored
2742
+
2743
+ // createMapActionGroup returns function 'mapActionGroup' that takes params:
2744
+ // - action group name
2745
+ // - callback function that should return a list of actions that correspond
2746
+ // to the for the action group
2747
+
2748
+ // this resulting function mapActionGroup will call the callback function
2749
+ // for allowed action groups and return the return value of the callback
2750
+ // It will return an empty array for ignored action groups
2751
+ var mapActionGroup = createMapActionGroup(actionGroupList);
2752
+ var doMapActions = createTaxCategoriesMapActions(mapActionGroup, syncActionConfig);
2753
+ var buildActions = createBuildActions(diff, doMapActions);
2754
+ return {
2755
+ buildActions: buildActions
2756
+ };
2757
+ });
2758
+
2759
+ var baseActionsList$a = [{
2760
+ action: 'changeName',
2761
+ key: 'name'
2762
+ }, {
2763
+ action: 'setDescription',
2764
+ key: 'description'
2765
+ }, {
2766
+ action: 'setKey',
2767
+ key: 'key'
2768
+ }];
2769
+ var hasLocation = function hasLocation(locations, otherLocation) {
2770
+ return locations.some(function (location) {
2771
+ return location.country === otherLocation.country;
2772
+ });
2773
+ };
2774
+ function actionsMapBase$a(diff, oldObj, newObj) {
2775
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2776
+ return buildBaseAttributesActions({
2777
+ actions: baseActionsList$a,
2778
+ diff: diff,
2779
+ oldObj: oldObj,
2780
+ newObj: newObj,
2781
+ shouldOmitEmptyString: config.shouldOmitEmptyString
2782
+ });
2783
+ }
2784
+ function actionsMapLocations(diff, oldObj, newObj) {
2785
+ var handler = createBuildArrayActions('locations', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newLocation) {
2786
+ return {
2787
+ action: 'addLocation',
2788
+ location: newLocation
2789
+ };
2790
+ }), REMOVE_ACTIONS, function (oldLocation) {
2791
+ return (
2792
+ // We only add the action if the location is not included in the new object.
2793
+ !hasLocation(newObj.locations, oldLocation) ? {
2794
+ action: 'removeLocation',
2795
+ location: oldLocation
2796
+ } : null
2797
+ );
2798
+ }), CHANGE_ACTIONS, function (oldLocation, newLocation) {
2799
+ var result = [];
2800
+
2801
+ // We only remove the location in case that the oldLocation is not
2802
+ // included in the new object
2803
+ if (!hasLocation(newObj.locations, oldLocation)) result.push({
2804
+ action: 'removeLocation',
2805
+ location: oldLocation
2806
+ });
2807
+
2808
+ // We only add the location in case that the newLocation was not
2809
+ // included in the old object
2810
+ if (!hasLocation(oldObj.locations, newLocation)) result.push({
2811
+ action: 'addLocation',
2812
+ location: newLocation
2813
+ });
2814
+ return result;
2815
+ }));
2816
+ return handler(diff, oldObj, newObj);
2817
+ }
2818
+
2819
+ function createZonesMapActions(mapActionGroup, syncActionConfig) {
2820
+ return function doMapActions(diff, newObj, oldObj) {
2821
+ var allActions = [];
2822
+ allActions.push(mapActionGroup('base', function () {
2823
+ return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
2824
+ }));
2825
+ allActions.push(flatten__default["default"](mapActionGroup('locations', function () {
2826
+ return actionsMapLocations(diff, oldObj, newObj);
2827
+ })));
2828
+ return flatten__default["default"](allActions);
2829
+ };
2830
+ }
2831
+ var zones = (function (actionGroupList, syncActionConfig) {
2832
+ // config contains information about which action groups
2833
+ // are allowed or ignored
2834
+
2835
+ // createMapActionGroup returns function 'mapActionGroup' that takes params:
2836
+ // - action group name
2837
+ // - callback function that should return a list of actions that correspond
2838
+ // to the for the action group
2839
+
2840
+ // this resulting function mapActionGroup will call the callback function
2841
+ // for allowed action groups and return the return value of the callback
2842
+ // It will return an empty array for ignored action groups
2843
+ var mapActionGroup = createMapActionGroup(actionGroupList);
2844
+ var doMapActions = createZonesMapActions(mapActionGroup, syncActionConfig);
2845
+ var buildActions = createBuildActions(diff, doMapActions);
2846
+ return {
2847
+ buildActions: buildActions
2848
+ };
2849
+ });
2850
+
2851
+ var baseActionsList$9 = [{
2852
+ action: 'setKey',
2853
+ key: 'key'
2854
+ }, {
2855
+ action: 'changeName',
2856
+ key: 'name'
2857
+ }, {
2858
+ action: 'setLocalizedName',
2859
+ key: 'localizedName'
2860
+ }, {
2861
+ action: 'setDescription',
2862
+ key: 'description'
2863
+ }, {
2864
+ action: 'setLocalizedDescription',
2865
+ key: 'localizedDescription'
2866
+ }, {
2867
+ action: 'changeIsDefault',
2868
+ key: 'isDefault'
2869
+ }, {
2870
+ action: 'setPredicate',
2871
+ key: 'predicate'
2872
+ }, {
2873
+ action: 'changeTaxCategory',
2874
+ key: 'taxCategory'
2875
+ }, {
2876
+ action: 'changeActive',
2877
+ key: 'active'
2878
+ }];
2879
+ function actionsMapBase$9(diff, oldObj, newObj) {
2880
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2881
+ return buildBaseAttributesActions({
2882
+ actions: baseActionsList$9,
2883
+ diff: diff,
2884
+ oldObj: oldObj,
2885
+ newObj: newObj,
2886
+ shouldOmitEmptyString: config.shouldOmitEmptyString
2887
+ });
2888
+ }
2889
+ var addShippingRates = function addShippingRates(newZoneRate) {
2890
+ return newZoneRate.shippingRates ? newZoneRate.shippingRates.map(function (shippingRate) {
2891
+ return {
2892
+ action: 'addShippingRate',
2893
+ zone: newZoneRate.zone,
2894
+ shippingRate: shippingRate
2895
+ };
2896
+ }) : [];
2897
+ };
2898
+ function actionsMapZoneRatesShippingRates(diff, oldObj, newObj) {
2899
+ var handler = createBuildArrayActions('shippingRates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newShippingRate) {
2900
+ return {
2901
+ action: 'addShippingRate',
2902
+ zone: newObj.zone,
2903
+ shippingRate: newShippingRate
2904
+ };
2905
+ }), REMOVE_ACTIONS, function (oldShippingRate) {
2906
+ return {
2907
+ action: 'removeShippingRate',
2908
+ zone: oldObj.zone,
2909
+ shippingRate: oldShippingRate
2910
+ };
2911
+ }), CHANGE_ACTIONS, function (oldShippingRate, newShippingRate) {
2912
+ return [{
2913
+ action: 'removeShippingRate',
2914
+ zone: oldObj.zone,
2915
+ shippingRate: oldShippingRate
2916
+ }, {
2917
+ action: 'addShippingRate',
2918
+ zone: newObj.zone,
2919
+ shippingRate: newShippingRate
2920
+ }];
2921
+ }));
2922
+ return handler(diff, oldObj, newObj);
2923
+ }
2924
+ function actionsMapZoneRates(diff, oldObj, newObj) {
2925
+ var handler = createBuildArrayActions('zoneRates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newZoneRate) {
2926
+ return [{
2927
+ action: 'addZone',
2928
+ zone: newZoneRate.zone
2929
+ }].concat(_toConsumableArray(addShippingRates(newZoneRate)));
2930
+ }), REMOVE_ACTIONS, function (oldZoneRate) {
2931
+ return {
2932
+ action: 'removeZone',
2933
+ zone: oldZoneRate.zone
2934
+ };
2935
+ }), CHANGE_ACTIONS, function (oldZoneRate, newZoneRate) {
2936
+ var hasZoneActions = false;
2937
+ var shippingRateActions = Object.keys(diff.zoneRates).reduce(function (actions, key) {
2938
+ if (diff.zoneRates[key].zone) hasZoneActions = true;
2939
+ if (diff.zoneRates[key].shippingRates) return [].concat(_toConsumableArray(actions), _toConsumableArray(actionsMapZoneRatesShippingRates(diff.zoneRates[key], oldZoneRate, newZoneRate)));
2940
+ return actions;
2941
+ }, []);
2942
+ return flatten__default["default"](hasZoneActions ? [].concat(_toConsumableArray(shippingRateActions), [{
2943
+ action: 'removeZone',
2944
+ zone: oldZoneRate.zone
2945
+ }, {
2946
+ action: 'addZone',
2947
+ zone: newZoneRate.zone
2948
+ }]) : shippingRateActions);
2949
+ }));
2950
+ return handler(diff, oldObj, newObj);
2951
+ }
2952
+
2953
+ function createShippingMethodsMapActions(mapActionGroup, syncActionConfig) {
2954
+ return function doMapActions(diff, newObj, oldObj) {
2955
+ var allActions = [];
2956
+ allActions.push(mapActionGroup('base', function () {
2957
+ return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
2958
+ }));
2959
+ allActions.push(flatten__default["default"](mapActionGroup('zoneRates', function () {
2960
+ return actionsMapZoneRates(diff, oldObj, newObj);
2961
+ })));
2962
+ allActions.push(mapActionGroup('custom', function () {
2963
+ return actionsMapCustom(diff, newObj, oldObj);
2964
+ }));
2965
+ return flatten__default["default"](allActions);
2966
+ };
2967
+ }
2968
+ var shippingMethods = (function (actionGroupList, syncActionConfig) {
2969
+ // actionGroupList contains information about which action groups
2970
+ // are allowed or ignored
2971
+
2972
+ // createMapActionGroup returns function 'mapActionGroup' that takes params:
2973
+ // - action group name
2974
+ // - callback function that should return a list of actions that correspond
2975
+ // to the for the action group
2976
+
2977
+ // this resulting function mapActionGroup will call the callback function
2978
+ // for allowed action groups and return the return value of the callback
2979
+ // It will return an empty array for ignored action groups
2980
+ var mapActionGroup = createMapActionGroup(actionGroupList);
2981
+ var doMapActions = createShippingMethodsMapActions(mapActionGroup, syncActionConfig);
2982
+ var buildActions = createBuildActions(diff, doMapActions);
2983
+ return {
2984
+ buildActions: buildActions
2985
+ };
2986
+ });
2987
+
2971
2988
  var baseActionsList$8 = [{
2972
2989
  action: 'changeName',
2973
2990
  key: 'name'