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