@commercetools/sync-actions 6.0.0 → 6.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @commercetools/sync-actions
2
2
 
3
+ ## 6.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1921](https://github.com/commercetools/nodejs/pull/1921) [`c9d23e86`](https://github.com/commercetools/nodejs/commit/c9d23e86a6013aafb6a3c296121e1c5995d9eab6) Thanks [@kafis](https://github.com/kafis)! - Introducing configuration to control the behaviour regarding generation of UpdateActions in respect to unsetting fields
8
+
3
9
  ## 6.0.0
4
10
 
5
11
  ### Major Changes
@@ -2967,6 +2967,11 @@ var createIsEmptyValue = function createIsEmptyValue(emptyValues) {
2967
2967
  };
2968
2968
  };
2969
2969
 
2970
+ /* actions that start with 'set' can generate undefined valued */
2971
+ var isOptionalField = function isOptionalField(action) {
2972
+ return action.startsWith('set');
2973
+ };
2974
+
2970
2975
  /**
2971
2976
  * Builds actions for simple object properties, given a list of actions
2972
2977
  * E.g. [{ action: `changeName`, key: 'name' }]
@@ -2977,13 +2982,17 @@ var createIsEmptyValue = function createIsEmptyValue(emptyValues) {
2977
2982
  * @param {Object} options.oldObj - the object that needs to be updated
2978
2983
  * @param {Object} options.newObj - the new representation of the object
2979
2984
  * @param {Boolean} options.shouldOmitEmptyString - a flag to determine if we should treat an empty string a NON-value
2985
+ * @param {Boolean} options.shouldUnsetOmittedProperties - a flag to determine if we should unset fields which are omitted in the newObj
2986
+ * @param {Boolean} options.shouldPreventUnsettingRequiredFields - a flag to determine if required fields should be unset
2980
2987
  */
2981
2988
  function buildBaseAttributesActions(_ref) {
2982
2989
  var actions = _ref.actions,
2983
2990
  diff = _ref.diff,
2984
2991
  oldObj = _ref.oldObj,
2985
2992
  newObj = _ref.newObj,
2986
- shouldOmitEmptyString = _ref.shouldOmitEmptyString;
2993
+ shouldOmitEmptyString = _ref.shouldOmitEmptyString,
2994
+ shouldUnsetOmittedProperties = _ref.shouldUnsetOmittedProperties,
2995
+ shouldPreventUnsettingRequiredFields = _ref.shouldPreventUnsettingRequiredFields;
2987
2996
  var isEmptyValue = createIsEmptyValue(shouldOmitEmptyString ? [undefined, null, ''] : [undefined, null]);
2988
2997
  return actions.map(function (item) {
2989
2998
  var key = item.key; // e.g.: name, description, ...
@@ -2993,7 +3002,9 @@ function buildBaseAttributesActions(_ref) {
2993
3002
  var now = newObj[key];
2994
3003
  var isNotDefinedBefore = isEmptyValue(oldObj[key]);
2995
3004
  var isNotDefinedNow = isEmptyValue(newObj[key]);
3005
+ var isOmitted = !Object.keys(newObj).includes(key);
2996
3006
  if (!delta) return undefined;
3007
+ if (isNotDefinedNow && !isOptionalField(item.action) && shouldPreventUnsettingRequiredFields) return undefined;
2997
3008
  if (isNotDefinedNow && isNotDefinedBefore) return undefined;
2998
3009
  if (!isNotDefinedNow && isNotDefinedBefore)
2999
3010
  // no value previously set
@@ -3002,8 +3013,8 @@ function buildBaseAttributesActions(_ref) {
3002
3013
  }, actionKey, now);
3003
3014
 
3004
3015
  /* no new value */
3005
- if (isNotDefinedNow && !{}.hasOwnProperty.call(newObj, key)) return undefined;
3006
- if (isNotDefinedNow && {}.hasOwnProperty.call(newObj, key))
3016
+ if (isNotDefinedNow && isOmitted && !shouldUnsetOmittedProperties) return undefined;
3017
+ if (isNotDefinedNow)
3007
3018
  // value unset
3008
3019
  return {
3009
3020
  action: item.action
@@ -3113,7 +3124,9 @@ function actionsMapBase$k(diff, oldObj, newObj) {
3113
3124
  diff: diff,
3114
3125
  oldObj: oldObj,
3115
3126
  newObj: newObj,
3116
- shouldOmitEmptyString: config.shouldOmitEmptyString
3127
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3128
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3129
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3117
3130
  });
3118
3131
  }
3119
3132
  function actionsMapReferences$3(diff, oldObj, newObj) {
@@ -3315,7 +3328,9 @@ function actionsMapBase$j(diff, oldObj, newObj) {
3315
3328
  diff: diff,
3316
3329
  oldObj: oldObj,
3317
3330
  newObj: newObj,
3318
- shouldOmitEmptyString: config.shouldOmitEmptyString
3331
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3332
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3333
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3319
3334
  });
3320
3335
  }
3321
3336
  function actionsMapSetDefaultBase(diff, oldObj, newObj) {
@@ -3325,7 +3340,9 @@ function actionsMapSetDefaultBase(diff, oldObj, newObj) {
3325
3340
  diff: diff,
3326
3341
  oldObj: oldObj,
3327
3342
  newObj: newObj,
3328
- shouldOmitEmptyString: config.shouldOmitEmptyString
3343
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3344
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3345
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3329
3346
  });
3330
3347
  }
3331
3348
  function actionsMapReferences$2(diff, oldObj, newObj) {
@@ -3521,7 +3538,9 @@ function actionsMapBase$i(diff, oldObj, newObj) {
3521
3538
  diff: diff,
3522
3539
  oldObj: oldObj,
3523
3540
  newObj: newObj,
3524
- shouldOmitEmptyString: config.shouldOmitEmptyString
3541
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3542
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3543
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3525
3544
  });
3526
3545
  }
3527
3546
  function actionsMapReferences$1(diff, oldObj, newObj) {
@@ -4038,15 +4057,19 @@ function actionsMapBase$h(diff, oldObj, newObj) {
4038
4057
  diff: diff,
4039
4058
  oldObj: oldObj,
4040
4059
  newObj: newObj,
4041
- shouldOmitEmptyString: config.shouldOmitEmptyString
4060
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4061
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
4042
4062
  });
4043
4063
  }
4044
4064
  function actionsMapMeta(diff, oldObj, newObj) {
4065
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
4045
4066
  return buildBaseAttributesActions({
4046
4067
  actions: metaActionsList,
4047
4068
  diff: diff,
4048
4069
  oldObj: oldObj,
4049
- newObj: newObj
4070
+ newObj: newObj,
4071
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4072
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
4050
4073
  });
4051
4074
  }
4052
4075
  function actionsMapAddVariants(diff, oldObj, newObj) {
@@ -4356,7 +4379,9 @@ function actionsMapBase$g(diff, oldObj, newObj) {
4356
4379
  diff: diff,
4357
4380
  oldObj: oldObj,
4358
4381
  newObj: newObj,
4359
- shouldOmitEmptyString: config.shouldOmitEmptyString
4382
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4383
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
4384
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4360
4385
  });
4361
4386
  }
4362
4387
  function actionsMapDeliveries(diff, oldObj, newObj) {
@@ -4575,7 +4600,9 @@ function actionsMapBase$f(diff, oldObj, newObj) {
4575
4600
  diff: diff,
4576
4601
  oldObj: oldObj,
4577
4602
  newObj: newObj,
4578
- shouldOmitEmptyString: config.shouldOmitEmptyString
4603
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4604
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
4605
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4579
4606
  });
4580
4607
  }
4581
4608
 
@@ -4663,7 +4690,9 @@ function actionsMapBase$e(diff, oldObj, newObj) {
4663
4690
  diff: diff,
4664
4691
  oldObj: oldObj,
4665
4692
  newObj: newObj,
4666
- shouldOmitEmptyString: config.shouldOmitEmptyString
4693
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4694
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
4695
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4667
4696
  });
4668
4697
  }
4669
4698
 
@@ -4714,7 +4743,9 @@ function actionsMapBase$d(diff, oldObj, newObj) {
4714
4743
  diff: diff,
4715
4744
  oldObj: oldObj,
4716
4745
  newObj: newObj,
4717
- shouldOmitEmptyString: config.shouldOmitEmptyString
4746
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4747
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
4748
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4718
4749
  });
4719
4750
  }
4720
4751
 
@@ -4784,7 +4815,9 @@ function actionsMapBase$c(diff, oldObj, newObj) {
4784
4815
  diff: diff,
4785
4816
  oldObj: oldObj,
4786
4817
  newObj: newObj,
4787
- shouldOmitEmptyString: config.shouldOmitEmptyString
4818
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4819
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
4820
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4788
4821
  });
4789
4822
  }
4790
4823
 
@@ -5132,7 +5165,9 @@ function actionsMapBase$b(diff, oldObj, newObj) {
5132
5165
  diff: diff,
5133
5166
  oldObj: oldObj,
5134
5167
  newObj: newObj,
5135
- shouldOmitEmptyString: config.shouldOmitEmptyString
5168
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
5169
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
5170
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5136
5171
  });
5137
5172
  }
5138
5173
  function actionsMapRates(diff, oldObj, newObj) {
@@ -5220,7 +5255,9 @@ function actionsMapBase$a(diff, oldObj, newObj) {
5220
5255
  diff: diff,
5221
5256
  oldObj: oldObj,
5222
5257
  newObj: newObj,
5223
- shouldOmitEmptyString: config.shouldOmitEmptyString
5258
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
5259
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
5260
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5224
5261
  });
5225
5262
  }
5226
5263
  function actionsMapLocations(diff, oldObj, newObj) {
@@ -5325,7 +5362,9 @@ function actionsMapBase$9(diff, oldObj, newObj) {
5325
5362
  diff: diff,
5326
5363
  oldObj: oldObj,
5327
5364
  newObj: newObj,
5328
- shouldOmitEmptyString: config.shouldOmitEmptyString
5365
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
5366
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
5367
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5329
5368
  });
5330
5369
  }
5331
5370
  var addShippingRates = function addShippingRates(newZoneRate) {
@@ -5448,7 +5487,8 @@ function actionsMapBase$8(diff, previous, next) {
5448
5487
  actions: baseActionsList$8,
5449
5488
  oldObj: previous,
5450
5489
  newObj: next,
5451
- shouldOmitEmptyString: config.shouldOmitEmptyString
5490
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
5491
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
5452
5492
  });
5453
5493
  }
5454
5494
 
@@ -5705,7 +5745,9 @@ function actionsMapBase$7(diff, oldObj, newObj) {
5705
5745
  diff: diff,
5706
5746
  oldObj: oldObj,
5707
5747
  newObj: newObj,
5708
- shouldOmitEmptyString: config.shouldOmitEmptyString
5748
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
5749
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
5750
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5709
5751
  });
5710
5752
  }
5711
5753
  function actionsMapRoles(diff, oldObj, newObj) {
@@ -5791,7 +5833,9 @@ function actionsMapBase$6(diff, oldObj, newObj) {
5791
5833
  diff: diff,
5792
5834
  oldObj: oldObj,
5793
5835
  newObj: newObj,
5794
- shouldOmitEmptyString: config.shouldOmitEmptyString
5836
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
5837
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
5838
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5795
5839
  });
5796
5840
  }
5797
5841
 
@@ -5842,7 +5886,9 @@ function actionsMapBase$5(diff, oldObj, newObj) {
5842
5886
  diff: diff,
5843
5887
  oldObj: oldObj,
5844
5888
  newObj: newObj,
5845
- shouldOmitEmptyString: config.shouldOmitEmptyString
5889
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
5890
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
5891
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5846
5892
  });
5847
5893
  }
5848
5894
  function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next) {
@@ -6037,6 +6083,7 @@ function actionsMapBase$4(diff, oldObj, newObj) {
6037
6083
  });
6038
6084
  }
6039
6085
  var actionsMapBusinessUnit = function actionsMapBusinessUnit(diff, oldObj, newObj) {
6086
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6040
6087
  var businessUnits = diff.businessUnits;
6041
6088
  if (!businessUnits) {
6042
6089
  return [];
@@ -6045,10 +6092,13 @@ var actionsMapBusinessUnit = function actionsMapBusinessUnit(diff, oldObj, newOb
6045
6092
  actions: myBusinessUnitActionsList,
6046
6093
  diff: businessUnits,
6047
6094
  oldObj: oldObj.businessUnits,
6048
- newObj: newObj.businessUnits
6095
+ newObj: newObj.businessUnits,
6096
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
6097
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
6049
6098
  });
6050
6099
  };
6051
6100
  function actionsMapSearchIndexingConfiguration(diff, oldObj, newObj) {
6101
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6052
6102
  var searchIndexing = diff.searchIndexing;
6053
6103
  if (!searchIndexing) {
6054
6104
  return [];
@@ -6061,7 +6111,10 @@ function actionsMapSearchIndexingConfiguration(diff, oldObj, newObj) {
6061
6111
  actions: customerSearchActionsList,
6062
6112
  diff: diff.searchIndexing.customers,
6063
6113
  oldObj: oldObj.searchIndexing.customers,
6064
- newObj: newObj.searchIndexing.customers
6114
+ newObj: newObj.searchIndexing.customers,
6115
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
6116
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
6117
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6065
6118
  });
6066
6119
  }
6067
6120
 
@@ -6104,11 +6157,15 @@ var baseActionsList$3 = [{
6104
6157
  key: 'supplyChannels'
6105
6158
  }];
6106
6159
  function actionsMapBase$3(diff, oldObj, newObj) {
6160
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6107
6161
  return buildBaseAttributesActions({
6108
6162
  actions: baseActionsList$3,
6109
6163
  diff: diff,
6110
6164
  oldObj: oldObj,
6111
- newObj: newObj
6165
+ newObj: newObj,
6166
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
6167
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
6168
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6112
6169
  });
6113
6170
  }
6114
6171
 
@@ -6125,10 +6182,11 @@ function createStoresMapActions(mapActionGroup) {
6125
6182
  };
6126
6183
  }
6127
6184
  var stores = (function (actionGroupList) {
6185
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6128
6186
  var mapActionGroup = createMapActionGroup(actionGroupList);
6129
6187
  var doMapActions = createStoresMapActions(mapActionGroup);
6130
6188
  var onBeforeApplyingDiff = null;
6131
- var buildActions = createBuildActions(diff, doMapActions, onBeforeApplyingDiff);
6189
+ var buildActions = createBuildActions(diff, doMapActions, onBeforeApplyingDiff, options);
6132
6190
  return {
6133
6191
  buildActions: buildActions
6134
6192
  };
@@ -6142,11 +6200,15 @@ var baseActionsList$2 = [{
6142
6200
  key: 'key'
6143
6201
  }];
6144
6202
  function actionsMapBase$2(diff, oldObj, newObj) {
6203
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6145
6204
  return buildBaseAttributesActions({
6146
6205
  actions: baseActionsList$2,
6147
6206
  diff: diff,
6148
6207
  oldObj: oldObj,
6149
- newObj: newObj
6208
+ newObj: newObj,
6209
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
6210
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
6211
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6150
6212
  });
6151
6213
  }
6152
6214
 
@@ -6203,7 +6265,9 @@ function actionsMapBase$1(diff, oldObj, newObj) {
6203
6265
  diff: diff,
6204
6266
  oldObj: oldObj,
6205
6267
  newObj: newObj,
6206
- shouldOmitEmptyString: config.shouldOmitEmptyString
6268
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
6269
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
6270
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6207
6271
  });
6208
6272
  }
6209
6273
 
@@ -6249,7 +6313,9 @@ function actionsMapBase(diff, oldObj, newObj) {
6249
6313
  diff: diff,
6250
6314
  oldObj: oldObj,
6251
6315
  newObj: newObj,
6252
- shouldOmitEmptyString: config.shouldOmitEmptyString
6316
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
6317
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
6318
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6253
6319
  });
6254
6320
  }
6255
6321
  function actionsMapAttributes(diff, oldObj, newObj) {