@commercetools/sync-actions 5.16.0 → 5.18.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 +12 -0
- package/dist/sync-actions.cjs.js +388 -647
- package/dist/sync-actions.es.js +388 -647
- package/dist/sync-actions.umd.js +388 -647
- package/dist/sync-actions.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/sync-actions.cjs.js
CHANGED
|
@@ -22,174 +22,143 @@ var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
|
|
|
22
22
|
var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
|
|
23
23
|
var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy);
|
|
24
24
|
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
function _arrayLikeToArray(r, a) {
|
|
26
|
+
(null == a || a > r.length) && (a = r.length);
|
|
27
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
function _arrayWithHoles(r) {
|
|
31
|
+
if (Array.isArray(r)) return r;
|
|
32
|
+
}
|
|
33
|
+
function _arrayWithoutHoles(r) {
|
|
34
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
35
|
+
}
|
|
36
|
+
function _defineProperty(e, r, t) {
|
|
37
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
38
|
+
value: t,
|
|
39
|
+
enumerable: !0,
|
|
40
|
+
configurable: !0,
|
|
41
|
+
writable: !0
|
|
42
|
+
}) : e[r] = t, e;
|
|
43
|
+
}
|
|
44
|
+
function _iterableToArray(r) {
|
|
45
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
46
|
+
}
|
|
47
|
+
function _iterableToArrayLimit(r, l) {
|
|
48
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
49
|
+
if (null != t) {
|
|
50
|
+
var e,
|
|
51
|
+
n,
|
|
52
|
+
i,
|
|
53
|
+
u,
|
|
54
|
+
a = [],
|
|
55
|
+
f = !0,
|
|
56
|
+
o = !1;
|
|
57
|
+
try {
|
|
58
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
59
|
+
if (Object(t) !== t) return;
|
|
60
|
+
f = !1;
|
|
61
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
62
|
+
} catch (r) {
|
|
63
|
+
o = !0, n = r;
|
|
64
|
+
} finally {
|
|
65
|
+
try {
|
|
66
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
67
|
+
} finally {
|
|
68
|
+
if (o) throw n;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return a;
|
|
33
72
|
}
|
|
34
|
-
|
|
35
|
-
return keys;
|
|
36
73
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
40
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
41
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
42
|
-
_defineProperty(target, key, source[key]);
|
|
43
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
44
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return target;
|
|
74
|
+
function _nonIterableRest() {
|
|
75
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
49
76
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"@babel/helpers - typeof";
|
|
53
|
-
|
|
54
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
55
|
-
return typeof obj;
|
|
56
|
-
} : function (obj) {
|
|
57
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
58
|
-
}, _typeof(obj);
|
|
77
|
+
function _nonIterableSpread() {
|
|
78
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
59
79
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
Object.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
writable: true
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
obj[key] = value;
|
|
80
|
+
function ownKeys(e, r) {
|
|
81
|
+
var t = Object.keys(e);
|
|
82
|
+
if (Object.getOwnPropertySymbols) {
|
|
83
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
84
|
+
r && (o = o.filter(function (r) {
|
|
85
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
86
|
+
})), t.push.apply(t, o);
|
|
71
87
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
83
|
-
key = sourceKeys[i];
|
|
84
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
85
|
-
target[key] = source[key];
|
|
88
|
+
return t;
|
|
89
|
+
}
|
|
90
|
+
function _objectSpread2(e) {
|
|
91
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
92
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
93
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
94
|
+
_defineProperty(e, r, t[r]);
|
|
95
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
96
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
97
|
+
});
|
|
86
98
|
}
|
|
87
|
-
|
|
88
|
-
return target;
|
|
99
|
+
return e;
|
|
89
100
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var key, i;
|
|
97
|
-
|
|
101
|
+
function _objectWithoutProperties(e, t) {
|
|
102
|
+
if (null == e) return {};
|
|
103
|
+
var o,
|
|
104
|
+
r,
|
|
105
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
98
106
|
if (Object.getOwnPropertySymbols) {
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
102
|
-
key = sourceSymbolKeys[i];
|
|
103
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
104
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
105
|
-
target[key] = source[key];
|
|
106
|
-
}
|
|
107
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
108
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
107
109
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return
|
|
110
|
+
return i;
|
|
111
|
+
}
|
|
112
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
113
|
+
if (null == r) return {};
|
|
114
|
+
var t = {};
|
|
115
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
116
|
+
if (e.includes(n)) continue;
|
|
117
|
+
t[n] = r[n];
|
|
118
|
+
}
|
|
119
|
+
return t;
|
|
118
120
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
121
|
+
function _slicedToArray(r, e) {
|
|
122
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
122
123
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (Array.isArray(arr)) return arr;
|
|
124
|
+
function _toConsumableArray(r) {
|
|
125
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (_i == null) return;
|
|
136
|
-
var _arr = [];
|
|
137
|
-
var _n = true;
|
|
138
|
-
var _d = false;
|
|
139
|
-
|
|
140
|
-
var _s, _e;
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
144
|
-
_arr.push(_s.value);
|
|
145
|
-
|
|
146
|
-
if (i && _arr.length === i) break;
|
|
147
|
-
}
|
|
148
|
-
} catch (err) {
|
|
149
|
-
_d = true;
|
|
150
|
-
_e = err;
|
|
151
|
-
} finally {
|
|
152
|
-
try {
|
|
153
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
154
|
-
} finally {
|
|
155
|
-
if (_d) throw _e;
|
|
156
|
-
}
|
|
127
|
+
function _toPrimitive(t, r) {
|
|
128
|
+
if ("object" != typeof t || !t) return t;
|
|
129
|
+
var e = t[Symbol.toPrimitive];
|
|
130
|
+
if (void 0 !== e) {
|
|
131
|
+
var i = e.call(t, r || "default");
|
|
132
|
+
if ("object" != typeof i) return i;
|
|
133
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
157
134
|
}
|
|
158
|
-
|
|
159
|
-
return _arr;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
163
|
-
if (!o) return;
|
|
164
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
165
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
166
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
167
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
168
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function _arrayLikeToArray(arr, len) {
|
|
172
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
173
|
-
|
|
174
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
175
|
-
|
|
176
|
-
return arr2;
|
|
135
|
+
return ("string" === r ? String : Number)(t);
|
|
177
136
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
137
|
+
function _toPropertyKey(t) {
|
|
138
|
+
var i = _toPrimitive(t, "string");
|
|
139
|
+
return "symbol" == typeof i ? i : i + "";
|
|
181
140
|
}
|
|
141
|
+
function _typeof(o) {
|
|
142
|
+
"@babel/helpers - typeof";
|
|
182
143
|
|
|
183
|
-
function
|
|
184
|
-
|
|
144
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
145
|
+
return typeof o;
|
|
146
|
+
} : function (o) {
|
|
147
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
148
|
+
}, _typeof(o);
|
|
149
|
+
}
|
|
150
|
+
function _unsupportedIterableToArray(r, a) {
|
|
151
|
+
if (r) {
|
|
152
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
153
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
154
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
155
|
+
}
|
|
185
156
|
}
|
|
186
157
|
|
|
187
158
|
var _excluded$1 = ["prices"];
|
|
188
|
-
|
|
189
159
|
function applyOnBeforeDiff(before, now, fn) {
|
|
190
160
|
return fn && typeof fn === 'function' ? fn(before, now) : [before, now];
|
|
191
161
|
}
|
|
192
|
-
|
|
193
162
|
var createPriceComparator = function createPriceComparator(price) {
|
|
194
163
|
return {
|
|
195
164
|
value: {
|
|
@@ -202,13 +171,11 @@ var createPriceComparator = function createPriceComparator(price) {
|
|
|
202
171
|
validUntil: price.validUntil
|
|
203
172
|
};
|
|
204
173
|
};
|
|
205
|
-
|
|
206
174
|
function arePricesStructurallyEqual(oldPrice, newPrice) {
|
|
207
175
|
var oldPriceComparison = createPriceComparator(oldPrice);
|
|
208
176
|
var newPriceComparison = createPriceComparator(newPrice);
|
|
209
177
|
return isEqual__default["default"](newPriceComparison, oldPriceComparison);
|
|
210
178
|
}
|
|
211
|
-
|
|
212
179
|
function extractPriceFromPreviousVariant(newPrice, previousVariant) {
|
|
213
180
|
if (!previousVariant) return null;
|
|
214
181
|
var price = previousVariant.prices.find(function (oldPrice) {
|
|
@@ -216,12 +183,10 @@ function extractPriceFromPreviousVariant(newPrice, previousVariant) {
|
|
|
216
183
|
});
|
|
217
184
|
return price || null;
|
|
218
185
|
}
|
|
219
|
-
|
|
220
186
|
function injectMissingPriceIds(nextVariants, previousVariants) {
|
|
221
187
|
return nextVariants.map(function (newVariant) {
|
|
222
188
|
var prices = newVariant.prices,
|
|
223
|
-
|
|
224
|
-
|
|
189
|
+
restOfVariant = _objectWithoutProperties(newVariant, _excluded$1);
|
|
225
190
|
if (!prices) return restOfVariant;
|
|
226
191
|
var oldVariant = previousVariants.find(function (previousVariant) {
|
|
227
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;
|
|
@@ -229,33 +194,27 @@ function injectMissingPriceIds(nextVariants, previousVariants) {
|
|
|
229
194
|
return _objectSpread2(_objectSpread2({}, restOfVariant), {}, {
|
|
230
195
|
prices: prices.map(function (price) {
|
|
231
196
|
var newPrice = _objectSpread2({}, price);
|
|
232
|
-
|
|
233
197
|
var oldPrice = extractPriceFromPreviousVariant(price, oldVariant);
|
|
234
|
-
|
|
235
198
|
if (oldPrice) {
|
|
236
199
|
// copy ID if not provided
|
|
237
200
|
if (!newPrice.id) newPrice.id = oldPrice.id;
|
|
238
201
|
if (isNil__default["default"](newPrice.value.type)) newPrice.value.type = oldPrice.value.type;
|
|
239
202
|
if (isNil__default["default"](newPrice.value.fractionDigits)) newPrice.value.fractionDigits = oldPrice.value.fractionDigits;
|
|
240
203
|
}
|
|
241
|
-
|
|
242
204
|
return newPrice;
|
|
243
205
|
})
|
|
244
206
|
});
|
|
245
207
|
});
|
|
246
208
|
}
|
|
247
|
-
|
|
248
209
|
function createBuildActions(differ, doMapActions, onBeforeDiff) {
|
|
249
210
|
var buildActionsConfig = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
250
211
|
return function buildActions(now, before) {
|
|
251
212
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
252
213
|
if (!now || !before) throw new Error('Missing either `newObj` or `oldObj` ' + 'in order to build update actions');
|
|
253
|
-
|
|
254
214
|
var _applyOnBeforeDiff = applyOnBeforeDiff(before, now, onBeforeDiff),
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
215
|
+
_applyOnBeforeDiff2 = _slicedToArray(_applyOnBeforeDiff, 2),
|
|
216
|
+
processedBefore = _applyOnBeforeDiff2[0],
|
|
217
|
+
processedNow = _applyOnBeforeDiff2[1];
|
|
259
218
|
if (processedNow.variants && processedBefore.variants) processedNow.variants = injectMissingPriceIds(processedNow.variants, processedBefore.variants);
|
|
260
219
|
var diffed = differ(processedBefore, processedNow);
|
|
261
220
|
if (!buildActionsConfig.withHints && !diffed) return [];
|
|
@@ -277,10 +236,11 @@ function createMapActionGroup() {
|
|
|
277
236
|
var found = actionGroups.find(function (c) {
|
|
278
237
|
return c.type === type;
|
|
279
238
|
});
|
|
280
|
-
if (!found) return [];
|
|
281
|
-
|
|
282
|
-
if (found.group === 'ignore' || found.group === 'black') return []; // Keep `white` for backwards compatibility.
|
|
239
|
+
if (!found) return [];
|
|
283
240
|
|
|
241
|
+
// Keep `black` for backwards compatibility.
|
|
242
|
+
if (found.group === 'ignore' || found.group === 'black') return [];
|
|
243
|
+
// Keep `white` for backwards compatibility.
|
|
284
244
|
if (found.group === 'allow' || found.group === 'white') return fn();
|
|
285
245
|
throw new Error("Action group '".concat(found.group, "' not supported. Use either \"allow\" or \"ignore\"."));
|
|
286
246
|
};
|
|
@@ -290,7 +250,6 @@ function createMapActionGroup() {
|
|
|
290
250
|
// with es6 modules so we use require instead below
|
|
291
251
|
// TODO create an issue here https://github.com/benjamine/jsondiffpatch/issues/new
|
|
292
252
|
var DiffPatcher = require('jsondiffpatch').DiffPatcher;
|
|
293
|
-
|
|
294
253
|
function objectHash(obj, index) {
|
|
295
254
|
var objIndex = "$$index:".concat(index);
|
|
296
255
|
return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
|
|
@@ -330,12 +289,12 @@ function getDeltaValue(arr, originalObject) {
|
|
|
330
289
|
|
|
331
290
|
if (arr.length === 3 && arr[2] === 2) {
|
|
332
291
|
// text diff
|
|
333
|
-
if (!originalObject) throw new Error('Cannot apply patch to long text diff. Missing original object.');
|
|
334
|
-
|
|
292
|
+
if (!originalObject) throw new Error('Cannot apply patch to long text diff. Missing original object.');
|
|
293
|
+
// try to apply patch to given object based on delta value
|
|
335
294
|
return patch(originalObject, arr);
|
|
336
295
|
}
|
|
337
|
-
|
|
338
|
-
|
|
296
|
+
if (arr.length === 3 && arr[2] === 3)
|
|
297
|
+
// array move
|
|
339
298
|
throw new Error('Detected an array move, it should not happen as ' + '`includeValueOnMove` should be set to false');
|
|
340
299
|
throw new Error("Got unsupported number ".concat(arr[2], " in delta value"));
|
|
341
300
|
}
|
|
@@ -345,52 +304,39 @@ var Actions = {
|
|
|
345
304
|
setCustomType: 'setCustomType',
|
|
346
305
|
setCustomField: 'setCustomField'
|
|
347
306
|
};
|
|
348
|
-
|
|
349
307
|
var hasSingleCustomFieldChanged = function hasSingleCustomFieldChanged(diff) {
|
|
350
308
|
return Array.isArray(diff.custom);
|
|
351
309
|
};
|
|
352
|
-
|
|
353
310
|
var haveMultipleCustomFieldsChanged = function haveMultipleCustomFieldsChanged(diff) {
|
|
354
311
|
return Boolean(diff.custom.fields);
|
|
355
312
|
};
|
|
356
|
-
|
|
357
313
|
var hasCustomTypeChanged = function hasCustomTypeChanged(diff) {
|
|
358
314
|
return Boolean(diff.custom.type);
|
|
359
315
|
};
|
|
360
|
-
|
|
361
316
|
var extractCustomType = function extractCustomType(diff, previousObject) {
|
|
362
317
|
return Array.isArray(diff.custom.type) ? getDeltaValue(diff.custom.type, previousObject) : diff.custom.type;
|
|
363
318
|
};
|
|
364
|
-
|
|
365
319
|
var extractTypeId = function extractTypeId(type, nextObject) {
|
|
366
320
|
return Array.isArray(type.id) ? getDeltaValue(type.id) : nextObject.custom.type.id;
|
|
367
321
|
};
|
|
368
|
-
|
|
369
322
|
var extractTypeKey = function extractTypeKey(type, nextObject) {
|
|
370
323
|
return Array.isArray(type.key) ? getDeltaValue(type.key) : nextObject.custom.type.key;
|
|
371
324
|
};
|
|
372
|
-
|
|
373
325
|
var extractTypeFields = function extractTypeFields(diffedFields, nextFields) {
|
|
374
326
|
return Array.isArray(diffedFields) ? getDeltaValue(diffedFields) : nextFields;
|
|
375
327
|
};
|
|
376
|
-
|
|
377
328
|
var extractFieldValue = function extractFieldValue(newFields, fieldName) {
|
|
378
329
|
return newFields[fieldName];
|
|
379
330
|
};
|
|
380
|
-
|
|
381
331
|
function actionsMapCustom(diff, newObj, oldObj) {
|
|
382
332
|
var customProps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
383
333
|
actions: {}
|
|
384
334
|
};
|
|
385
335
|
var actions = [];
|
|
386
|
-
|
|
387
336
|
var customPropsActions = customProps.actions,
|
|
388
|
-
|
|
389
|
-
|
|
337
|
+
options = _objectWithoutProperties(customProps, _excluded);
|
|
390
338
|
var actionGroup = _objectSpread2(_objectSpread2({}, Actions), customPropsActions);
|
|
391
|
-
|
|
392
339
|
if (!diff.custom) return actions;
|
|
393
|
-
|
|
394
340
|
if (hasSingleCustomFieldChanged(diff)) {
|
|
395
341
|
// If custom is not defined on the new or old category
|
|
396
342
|
var custom = getDeltaValue(diff.custom, oldObj);
|
|
@@ -430,7 +376,6 @@ function actionsMapCustom(diff, newObj, oldObj) {
|
|
|
430
376
|
});
|
|
431
377
|
actions.push.apply(actions, _toConsumableArray(customFieldsActions));
|
|
432
378
|
}
|
|
433
|
-
|
|
434
379
|
return actions;
|
|
435
380
|
}
|
|
436
381
|
|
|
@@ -439,6 +384,7 @@ var REGEX_UNDERSCORE_NUMBER$4 = new RegExp(/^_\d+$/);
|
|
|
439
384
|
var ADD_ACTIONS = 'create';
|
|
440
385
|
var REMOVE_ACTIONS = 'remove';
|
|
441
386
|
var CHANGE_ACTIONS = 'change';
|
|
387
|
+
|
|
442
388
|
/**
|
|
443
389
|
* Tests a delta to see if it represents a create action.
|
|
444
390
|
* eg. delta:
|
|
@@ -451,10 +397,10 @@ var CHANGE_ACTIONS = 'change';
|
|
|
451
397
|
* @return {Boolean} Returns true if delta represents a create action,
|
|
452
398
|
* false otherwise
|
|
453
399
|
*/
|
|
454
|
-
|
|
455
400
|
function isCreateAction(obj, key) {
|
|
456
401
|
return REGEX_NUMBER$4.test(key) && Array.isArray(obj[key]) && obj[key].length === 1;
|
|
457
402
|
}
|
|
403
|
+
|
|
458
404
|
/**
|
|
459
405
|
* Tests a delta to see if it represents a change action.
|
|
460
406
|
* eg. delta:
|
|
@@ -469,11 +415,10 @@ function isCreateAction(obj, key) {
|
|
|
469
415
|
* @return {Boolean} Returns true if delta represents a change action,
|
|
470
416
|
* false otherwise
|
|
471
417
|
*/
|
|
472
|
-
|
|
473
|
-
|
|
474
418
|
function isChangeAction(obj, key) {
|
|
475
419
|
return REGEX_NUMBER$4.test(key) && (_typeof(obj[key]) === 'object' || typeof obj[key] === 'string');
|
|
476
420
|
}
|
|
421
|
+
|
|
477
422
|
/**
|
|
478
423
|
* Tests a delta to see if it represents a remove action.
|
|
479
424
|
* eg. delta:
|
|
@@ -486,11 +431,10 @@ function isChangeAction(obj, key) {
|
|
|
486
431
|
* @return {Boolean} Returns true if delta represents a remove action,
|
|
487
432
|
* false otherwise
|
|
488
433
|
*/
|
|
489
|
-
|
|
490
|
-
|
|
491
434
|
function isRemoveAction$1(obj, key) {
|
|
492
435
|
return REGEX_UNDERSCORE_NUMBER$4.test(key) && Array.isArray(obj[key]) && obj[key].length === 3 && (_typeof(obj[key][0]) === 'object' || typeof obj[key][0] === 'string') && obj[key][1] === 0 && obj[key][2] === 0;
|
|
493
436
|
}
|
|
437
|
+
|
|
494
438
|
/**
|
|
495
439
|
* Generate + configure a function to build actions for nested objects
|
|
496
440
|
* @param {string} key key of the attribute containing the array of
|
|
@@ -501,39 +445,33 @@ function isRemoveAction$1(obj, key) {
|
|
|
501
445
|
* return an action object.
|
|
502
446
|
* @return {Array} The generated array of actions
|
|
503
447
|
*/
|
|
504
|
-
|
|
505
|
-
|
|
506
448
|
function createBuildArrayActions(key, config) {
|
|
507
449
|
return function buildArrayActions(diff, oldObj, newObj) {
|
|
508
450
|
var addActions = [];
|
|
509
451
|
var removeActions = [];
|
|
510
452
|
var changeActions = [];
|
|
511
|
-
|
|
512
453
|
if (diff[key]) {
|
|
513
454
|
var arrayDelta = diff[key];
|
|
514
455
|
Object.keys(arrayDelta).forEach(function (index) {
|
|
515
456
|
if (config[ADD_ACTIONS] && isCreateAction(arrayDelta, index)) {
|
|
516
|
-
var actionGenerator = config[ADD_ACTIONS];
|
|
517
|
-
|
|
457
|
+
var actionGenerator = config[ADD_ACTIONS];
|
|
458
|
+
// When adding a new element you don't need the oldObj
|
|
518
459
|
var action = actionGenerator(newObj[key][index], parseInt(index, 10));
|
|
519
460
|
if (action) addActions.push(action);
|
|
520
461
|
} else if (config[CHANGE_ACTIONS] && isChangeAction(arrayDelta, index)) {
|
|
521
|
-
var _actionGenerator = config[CHANGE_ACTIONS];
|
|
522
|
-
|
|
462
|
+
var _actionGenerator = config[CHANGE_ACTIONS];
|
|
463
|
+
// When changing an existing element you need both old + new
|
|
523
464
|
var _action = _actionGenerator(oldObj[key][index], newObj[key][index], parseInt(index, 10));
|
|
524
|
-
|
|
525
465
|
if (_action) changeActions.push(_action);
|
|
526
466
|
} else if (config[REMOVE_ACTIONS] && isRemoveAction$1(arrayDelta, index)) {
|
|
527
467
|
var realIndex = index.replace('_', '');
|
|
528
|
-
var _actionGenerator2 = config[REMOVE_ACTIONS];
|
|
529
|
-
|
|
468
|
+
var _actionGenerator2 = config[REMOVE_ACTIONS];
|
|
469
|
+
// When removing an existing element you don't need the newObj
|
|
530
470
|
var _action2 = _actionGenerator2(oldObj[key][realIndex], parseInt(realIndex, 10));
|
|
531
|
-
|
|
532
471
|
if (_action2) removeActions.push(_action2);
|
|
533
472
|
}
|
|
534
473
|
});
|
|
535
474
|
}
|
|
536
|
-
|
|
537
475
|
return changeActions.concat(removeActions, addActions);
|
|
538
476
|
};
|
|
539
477
|
}
|
|
@@ -546,21 +484,19 @@ function toAssetIdentifier$1(asset) {
|
|
|
546
484
|
};
|
|
547
485
|
return assetIdentifier;
|
|
548
486
|
}
|
|
549
|
-
|
|
550
487
|
function actionsMapAssets$1(diff, oldObj, newObj) {
|
|
551
|
-
var
|
|
552
|
-
|
|
553
|
-
var handler = createBuildArrayActions('assets', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newAsset) {
|
|
488
|
+
var handler = createBuildArrayActions('assets', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newAsset) {
|
|
554
489
|
return {
|
|
555
490
|
action: 'addAsset',
|
|
556
491
|
asset: newAsset
|
|
557
492
|
};
|
|
558
|
-
}),
|
|
493
|
+
}), REMOVE_ACTIONS, function (oldAsset) {
|
|
559
494
|
return _objectSpread2({
|
|
560
495
|
action: 'removeAsset'
|
|
561
496
|
}, toAssetIdentifier$1(oldAsset));
|
|
562
|
-
}),
|
|
563
|
-
return (
|
|
497
|
+
}), CHANGE_ACTIONS, function (oldAsset, newAsset) {
|
|
498
|
+
return (
|
|
499
|
+
// here we could use more atomic update actions (e.g. changeAssetName)
|
|
564
500
|
// but for now we use the simpler approach to first remove and then
|
|
565
501
|
// re-add the asset - which reduces the code complexity
|
|
566
502
|
[_objectSpread2({
|
|
@@ -570,7 +506,7 @@ function actionsMapAssets$1(diff, oldObj, newObj) {
|
|
|
570
506
|
asset: newAsset
|
|
571
507
|
}]
|
|
572
508
|
);
|
|
573
|
-
})
|
|
509
|
+
}));
|
|
574
510
|
return handler(diff, oldObj, newObj);
|
|
575
511
|
}
|
|
576
512
|
|
|
@@ -581,7 +517,6 @@ function clone(obj) {
|
|
|
581
517
|
var normalizeValue = function normalizeValue(value) {
|
|
582
518
|
return typeof value === 'string' ? value.trim() : value;
|
|
583
519
|
};
|
|
584
|
-
|
|
585
520
|
var createIsEmptyValue = function createIsEmptyValue(emptyValues) {
|
|
586
521
|
return function (value) {
|
|
587
522
|
return emptyValues.some(function (emptyValue) {
|
|
@@ -589,6 +524,7 @@ var createIsEmptyValue = function createIsEmptyValue(emptyValues) {
|
|
|
589
524
|
});
|
|
590
525
|
};
|
|
591
526
|
};
|
|
527
|
+
|
|
592
528
|
/**
|
|
593
529
|
* Builds actions for simple object properties, given a list of actions
|
|
594
530
|
* E.g. [{ action: `changeName`, key: 'name' }]
|
|
@@ -600,17 +536,15 @@ var createIsEmptyValue = function createIsEmptyValue(emptyValues) {
|
|
|
600
536
|
* @param {Object} options.newObj - the new representation of the object
|
|
601
537
|
* @param {Boolean} options.shouldOmitEmptyString - a flag to determine if we should treat an empty string a NON-value
|
|
602
538
|
*/
|
|
603
|
-
|
|
604
539
|
function buildBaseAttributesActions(_ref) {
|
|
605
540
|
var actions = _ref.actions,
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
541
|
+
diff = _ref.diff,
|
|
542
|
+
oldObj = _ref.oldObj,
|
|
543
|
+
newObj = _ref.newObj,
|
|
544
|
+
shouldOmitEmptyString = _ref.shouldOmitEmptyString;
|
|
610
545
|
var isEmptyValue = createIsEmptyValue(shouldOmitEmptyString ? [undefined, null, ''] : [undefined, null]);
|
|
611
546
|
return actions.map(function (item) {
|
|
612
547
|
var key = item.key; // e.g.: name, description, ...
|
|
613
|
-
|
|
614
548
|
var actionKey = item.actionKey || item.key;
|
|
615
549
|
var delta = diff[key];
|
|
616
550
|
var before = oldObj[key];
|
|
@@ -619,18 +553,21 @@ function buildBaseAttributesActions(_ref) {
|
|
|
619
553
|
var isNotDefinedNow = isEmptyValue(newObj[key]);
|
|
620
554
|
if (!delta) return undefined;
|
|
621
555
|
if (isNotDefinedNow && isNotDefinedBefore) return undefined;
|
|
622
|
-
if (!isNotDefinedNow && isNotDefinedBefore)
|
|
556
|
+
if (!isNotDefinedNow && isNotDefinedBefore)
|
|
557
|
+
// no value previously set
|
|
623
558
|
return _defineProperty({
|
|
624
559
|
action: item.action
|
|
625
560
|
}, actionKey, now);
|
|
626
|
-
/* no new value */
|
|
627
561
|
|
|
562
|
+
/* no new value */
|
|
628
563
|
if (isNotDefinedNow && !{}.hasOwnProperty.call(newObj, key)) return undefined;
|
|
629
|
-
if (isNotDefinedNow && {}.hasOwnProperty.call(newObj, key))
|
|
564
|
+
if (isNotDefinedNow && {}.hasOwnProperty.call(newObj, key))
|
|
565
|
+
// value unset
|
|
630
566
|
return {
|
|
631
567
|
action: item.action
|
|
632
|
-
};
|
|
568
|
+
};
|
|
633
569
|
|
|
570
|
+
// We need to clone `before` as `patch` will mutate it
|
|
634
571
|
var patched = patch(clone(before), delta);
|
|
635
572
|
return _defineProperty({
|
|
636
573
|
action: item.action
|
|
@@ -639,6 +576,7 @@ function buildBaseAttributesActions(_ref) {
|
|
|
639
576
|
return !isNil__default["default"](action);
|
|
640
577
|
});
|
|
641
578
|
}
|
|
579
|
+
|
|
642
580
|
/**
|
|
643
581
|
* Builds actions for simple reference objects, given a list of actions
|
|
644
582
|
* E.g. [{ action: `setTaxCategory`, key: 'taxCategory' }]
|
|
@@ -649,23 +587,24 @@ function buildBaseAttributesActions(_ref) {
|
|
|
649
587
|
* @param {Object} options.oldObj - the object that needs to be updated
|
|
650
588
|
* @param {Object} options.newObj - the new representation of the object
|
|
651
589
|
*/
|
|
652
|
-
|
|
653
590
|
function buildReferenceActions(_ref4) {
|
|
654
591
|
var actions = _ref4.actions,
|
|
655
|
-
|
|
656
|
-
|
|
592
|
+
diff = _ref4.diff,
|
|
593
|
+
newObj = _ref4.newObj;
|
|
657
594
|
return actions.map(function (item) {
|
|
658
595
|
var action = item.action;
|
|
659
596
|
var key = item.key;
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
Array.isArray(diff[key]) ||
|
|
597
|
+
if (diff[key] && (
|
|
598
|
+
// The `key` value was added or removed
|
|
599
|
+
Array.isArray(diff[key]) ||
|
|
600
|
+
// The `key` value id changed
|
|
663
601
|
diff[key].id)) {
|
|
664
602
|
var newValue = Array.isArray(diff[key]) ? getDeltaValue(diff[key]) : newObj[key];
|
|
665
603
|
if (!newValue) return {
|
|
666
604
|
action: action
|
|
667
|
-
};
|
|
605
|
+
};
|
|
668
606
|
|
|
607
|
+
// When the `id` of the object is undefined
|
|
669
608
|
if (!newValue.id) {
|
|
670
609
|
return _defineProperty({
|
|
671
610
|
action: action
|
|
@@ -674,7 +613,6 @@ function buildReferenceActions(_ref4) {
|
|
|
674
613
|
key: newValue.key
|
|
675
614
|
});
|
|
676
615
|
}
|
|
677
|
-
|
|
678
616
|
return _defineProperty({
|
|
679
617
|
action: action
|
|
680
618
|
}, key, {
|
|
@@ -682,7 +620,6 @@ function buildReferenceActions(_ref4) {
|
|
|
682
620
|
id: newValue.id
|
|
683
621
|
});
|
|
684
622
|
}
|
|
685
|
-
|
|
686
623
|
return undefined;
|
|
687
624
|
}).filter(function (action) {
|
|
688
625
|
return action;
|
|
@@ -722,6 +659,7 @@ var referenceActionsList$3 = [{
|
|
|
722
659
|
action: 'changeParent',
|
|
723
660
|
key: 'parent'
|
|
724
661
|
}];
|
|
662
|
+
|
|
725
663
|
/**
|
|
726
664
|
* SYNC FUNCTIONS
|
|
727
665
|
*/
|
|
@@ -754,6 +692,7 @@ function actionsMapMeta$1(diff, oldObj, newObj) {
|
|
|
754
692
|
}
|
|
755
693
|
|
|
756
694
|
var CUSTOM = 'custom';
|
|
695
|
+
|
|
757
696
|
/**
|
|
758
697
|
* @function copyEmptyArrayProps
|
|
759
698
|
* @description Create new key with empty array value on `newobj` for the arrays exist on `oldObj` and doesnt exist on `newobj`
|
|
@@ -762,74 +701,60 @@ var CUSTOM = 'custom';
|
|
|
762
701
|
* @param {Object} newObj
|
|
763
702
|
* @returns {Array} Ordered Array [oldObj, newObj]
|
|
764
703
|
*/
|
|
765
|
-
|
|
766
704
|
function copyEmptyArrayProps() {
|
|
767
705
|
var oldObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
768
706
|
var newObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
769
|
-
|
|
770
707
|
if (!isNil__default["default"](oldObj) && !isNil__default["default"](newObj)) {
|
|
771
708
|
var nextObjectWithEmptyArray = Object.entries(oldObj).reduce(function (merged, _ref) {
|
|
772
709
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
710
|
+
key = _ref2[0],
|
|
711
|
+
value = _ref2[1];
|
|
776
712
|
// Ignore CUSTOM key as this object is dynamic and its up to the user to dynamically change it
|
|
777
713
|
// todo, it would be better if we pass it as ignored keys param
|
|
778
714
|
if (key === CUSTOM) return merged;
|
|
779
|
-
|
|
780
715
|
if (Array.isArray(value) && newObj[key] && newObj[key].length >= 1) {
|
|
781
716
|
/* eslint-disable no-plusplus */
|
|
782
717
|
var hashMapValue = value.reduce(function (acc, val) {
|
|
783
718
|
acc[val.id] = val;
|
|
784
719
|
return acc;
|
|
785
720
|
}, {});
|
|
786
|
-
|
|
787
721
|
for (var i = 0; i < newObj[key].length; i++) {
|
|
788
722
|
if (!isNil__default["default"](newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil__default["default"](newObj[key][i].id)) {
|
|
789
723
|
// Since its unordered array elements then check if the element on `oldObj` exists by id
|
|
790
724
|
var foundObject = hashMapValue[newObj[key][i].id];
|
|
791
|
-
|
|
792
725
|
if (!isNil__default["default"](foundObject)) {
|
|
793
726
|
var _copyEmptyArrayProps = copyEmptyArrayProps(foundObject, newObj[key][i]),
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
727
|
+
_copyEmptyArrayProps2 = _slicedToArray(_copyEmptyArrayProps, 2),
|
|
728
|
+
nestedObject = _copyEmptyArrayProps2[1];
|
|
797
729
|
if (Object.isFrozen(merged[key])) {
|
|
798
730
|
/* eslint-disable no-param-reassign */
|
|
799
731
|
merged[key] = merged[key].slice();
|
|
800
732
|
}
|
|
801
733
|
/* eslint-disable no-param-reassign */
|
|
802
|
-
|
|
803
|
-
|
|
804
734
|
merged[key][i] = nestedObject;
|
|
805
735
|
}
|
|
806
736
|
}
|
|
807
737
|
}
|
|
808
|
-
|
|
809
738
|
return merged;
|
|
810
739
|
}
|
|
811
|
-
|
|
812
740
|
if (Array.isArray(value)) {
|
|
813
741
|
merged[key] = isNil__default["default"](newObj[key]) ? [] : newObj[key];
|
|
814
742
|
return merged;
|
|
815
743
|
}
|
|
816
|
-
|
|
817
|
-
|
|
744
|
+
if (!isNil__default["default"](newObj[key]) && _typeof(value) === 'object' &&
|
|
745
|
+
// Ignore Date as this will create invalid object since typeof date === 'object' return true
|
|
818
746
|
// ex: {date: new Date()} will result {date: {}}
|
|
819
747
|
!(value instanceof Date)) {
|
|
820
748
|
var _copyEmptyArrayProps3 = copyEmptyArrayProps(value, newObj[key]),
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
749
|
+
_copyEmptyArrayProps4 = _slicedToArray(_copyEmptyArrayProps3, 2),
|
|
750
|
+
_nestedObject = _copyEmptyArrayProps4[1];
|
|
824
751
|
merged[key] = _nestedObject;
|
|
825
752
|
return merged;
|
|
826
753
|
}
|
|
827
|
-
|
|
828
754
|
return merged;
|
|
829
755
|
}, _objectSpread2({}, newObj));
|
|
830
756
|
return [oldObj, nextObjectWithEmptyArray];
|
|
831
757
|
}
|
|
832
|
-
|
|
833
758
|
return [oldObj, newObj];
|
|
834
759
|
}
|
|
835
760
|
|
|
@@ -854,14 +779,15 @@ function createCategoryMapActions(mapActionGroup, syncActionConfig) {
|
|
|
854
779
|
return flatten__default["default"](allActions);
|
|
855
780
|
};
|
|
856
781
|
}
|
|
857
|
-
|
|
858
782
|
var categories = (function (actionGroupList, syncActionConfig) {
|
|
859
783
|
// actionGroupList contains information about which action groups
|
|
860
784
|
// are allowed or ignored
|
|
785
|
+
|
|
861
786
|
// createMapActionGroup returns function 'mapActionGroup' that takes params:
|
|
862
787
|
// - action group name
|
|
863
788
|
// - callback function that should return a list of actions that correspond
|
|
864
789
|
// to the for the action group
|
|
790
|
+
|
|
865
791
|
// this resulting function mapActionGroup will call the callback function
|
|
866
792
|
// for allowed action groups and return the return value of the callback
|
|
867
793
|
// It will return an empty array for ignored action groups
|
|
@@ -935,6 +861,7 @@ var authenticationModeActionsList = [{
|
|
|
935
861
|
key: 'authenticationMode',
|
|
936
862
|
value: 'password'
|
|
937
863
|
}];
|
|
864
|
+
|
|
938
865
|
/**
|
|
939
866
|
* SYNC FUNCTIONS
|
|
940
867
|
*/
|
|
@@ -968,57 +895,51 @@ function actionsMapReferences$2(diff, oldObj, newObj) {
|
|
|
968
895
|
});
|
|
969
896
|
}
|
|
970
897
|
function actionsMapAddresses(diff, oldObj, newObj) {
|
|
971
|
-
var
|
|
972
|
-
|
|
973
|
-
var handler = createBuildArrayActions('addresses', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newObject) {
|
|
898
|
+
var handler = createBuildArrayActions('addresses', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newObject) {
|
|
974
899
|
return {
|
|
975
900
|
action: 'addAddress',
|
|
976
901
|
address: newObject
|
|
977
902
|
};
|
|
978
|
-
}),
|
|
903
|
+
}), REMOVE_ACTIONS, function (objectToRemove) {
|
|
979
904
|
return {
|
|
980
905
|
action: 'removeAddress',
|
|
981
906
|
addressId: objectToRemove.id
|
|
982
907
|
};
|
|
983
|
-
}),
|
|
908
|
+
}), CHANGE_ACTIONS, function (oldObject, updatedObject) {
|
|
984
909
|
return {
|
|
985
910
|
action: 'changeAddress',
|
|
986
911
|
addressId: oldObject.id,
|
|
987
912
|
address: updatedObject
|
|
988
913
|
};
|
|
989
|
-
})
|
|
914
|
+
}));
|
|
990
915
|
return handler(diff, oldObj, newObj);
|
|
991
916
|
}
|
|
992
917
|
function actionsMapBillingAddresses(diff, oldObj, newObj) {
|
|
993
|
-
var
|
|
994
|
-
|
|
995
|
-
var handler = createBuildArrayActions('billingAddressIds', (_createBuildArrayActi2 = {}, _defineProperty(_createBuildArrayActi2, ADD_ACTIONS, function (addressId) {
|
|
918
|
+
var handler = createBuildArrayActions('billingAddressIds', _defineProperty(_defineProperty({}, ADD_ACTIONS, function (addressId) {
|
|
996
919
|
return {
|
|
997
920
|
action: 'addBillingAddressId',
|
|
998
921
|
addressId: addressId
|
|
999
922
|
};
|
|
1000
|
-
}),
|
|
923
|
+
}), REMOVE_ACTIONS, function (addressId) {
|
|
1001
924
|
return {
|
|
1002
925
|
action: 'removeBillingAddressId',
|
|
1003
926
|
addressId: addressId
|
|
1004
927
|
};
|
|
1005
|
-
})
|
|
928
|
+
}));
|
|
1006
929
|
return handler(diff, oldObj, newObj);
|
|
1007
930
|
}
|
|
1008
931
|
function actionsMapShippingAddresses(diff, oldObj, newObj) {
|
|
1009
|
-
var
|
|
1010
|
-
|
|
1011
|
-
var handler = createBuildArrayActions('shippingAddressIds', (_createBuildArrayActi3 = {}, _defineProperty(_createBuildArrayActi3, ADD_ACTIONS, function (addressId) {
|
|
932
|
+
var handler = createBuildArrayActions('shippingAddressIds', _defineProperty(_defineProperty({}, ADD_ACTIONS, function (addressId) {
|
|
1012
933
|
return {
|
|
1013
934
|
action: 'addShippingAddressId',
|
|
1014
935
|
addressId: addressId
|
|
1015
936
|
};
|
|
1016
|
-
}),
|
|
937
|
+
}), REMOVE_ACTIONS, function (addressId) {
|
|
1017
938
|
return {
|
|
1018
939
|
action: 'removeShippingAddressId',
|
|
1019
940
|
addressId: addressId
|
|
1020
941
|
};
|
|
1021
|
-
})
|
|
942
|
+
}));
|
|
1022
943
|
return handler(diff, oldObj, newObj);
|
|
1023
944
|
}
|
|
1024
945
|
function actionsMapAuthenticationModes(diff, oldObj, newObj) {
|
|
@@ -1030,12 +951,11 @@ function actionsMapAuthenticationModes(diff, oldObj, newObj) {
|
|
|
1030
951
|
newObj: newObj
|
|
1031
952
|
});
|
|
1032
953
|
}
|
|
1033
|
-
|
|
1034
954
|
function buildAuthenticationModeActions(_ref) {
|
|
1035
955
|
var actions = _ref.actions,
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
956
|
+
diff = _ref.diff,
|
|
957
|
+
oldObj = _ref.oldObj,
|
|
958
|
+
newObj = _ref.newObj;
|
|
1039
959
|
return actions.map(function (item) {
|
|
1040
960
|
var key = item.key;
|
|
1041
961
|
var value = item.value || item.key;
|
|
@@ -1049,7 +969,6 @@ function buildAuthenticationModeActions(_ref) {
|
|
|
1049
969
|
if (isNotDefinedNow && isNotDefinedBefore) return undefined;
|
|
1050
970
|
if (newObj.authenticationMode === 'Password' && !newObj.password) throw new Error('Cannot set to Password authentication mode without password');
|
|
1051
971
|
if ('authenticationMode' in newObj && !authenticationModes.includes(newObj.authenticationMode)) throw new Error('Invalid Authentication Mode');
|
|
1052
|
-
|
|
1053
972
|
if (!isNotDefinedNow && isNotDefinedBefore) {
|
|
1054
973
|
// no value previously set
|
|
1055
974
|
if (newObj.authenticationMode === 'ExternalAuth') return {
|
|
@@ -1061,13 +980,14 @@ function buildAuthenticationModeActions(_ref) {
|
|
|
1061
980
|
authMode: now
|
|
1062
981
|
}, value, newObj.password);
|
|
1063
982
|
}
|
|
1064
|
-
/* no new value */
|
|
1065
|
-
|
|
1066
983
|
|
|
984
|
+
/* no new value */
|
|
1067
985
|
if (isNotDefinedNow && !{}.hasOwnProperty.call(newObj, key)) return undefined;
|
|
1068
|
-
if (isNotDefinedNow && {}.hasOwnProperty.call(newObj, key))
|
|
1069
|
-
|
|
986
|
+
if (isNotDefinedNow && {}.hasOwnProperty.call(newObj, key))
|
|
987
|
+
// value unset
|
|
988
|
+
return undefined;
|
|
1070
989
|
|
|
990
|
+
// We need to clone `before` as `patch` will mutate it
|
|
1071
991
|
var patched = patch(clone(before), delta);
|
|
1072
992
|
if (newObj.authenticationMode === 'ExternalAuth') return {
|
|
1073
993
|
action: item.action,
|
|
@@ -1112,14 +1032,15 @@ function createCustomerMapActions(mapActionGroup, syncActionConfig) {
|
|
|
1112
1032
|
return flatten__default["default"](allActions);
|
|
1113
1033
|
};
|
|
1114
1034
|
}
|
|
1115
|
-
|
|
1116
1035
|
var customers = (function (actionGroupList, syncActionConfig) {
|
|
1117
1036
|
// actionGroupList contains information about which action groups
|
|
1118
1037
|
// are allowed or ignored
|
|
1038
|
+
|
|
1119
1039
|
// createMapActionGroup returns function 'mapActionGroup' that takes params:
|
|
1120
1040
|
// - action group name
|
|
1121
1041
|
// - callback function that should return a list of actions that correspond
|
|
1122
1042
|
// to the for the action group
|
|
1043
|
+
|
|
1123
1044
|
// this resulting function mapActionGroup will call the callback function
|
|
1124
1045
|
// for allowed action groups and return the return value of the callback
|
|
1125
1046
|
// It will return an empty array for ignored action groups
|
|
@@ -1146,6 +1067,7 @@ var referenceActionsList$1 = [{
|
|
|
1146
1067
|
action: 'setSupplyChannel',
|
|
1147
1068
|
key: 'supplyChannel'
|
|
1148
1069
|
}];
|
|
1070
|
+
|
|
1149
1071
|
/**
|
|
1150
1072
|
* SYNC FUNCTIONS
|
|
1151
1073
|
*/
|
|
@@ -1184,14 +1106,15 @@ function createInventoryMapActions(mapActionGroup, syncActionConfig) {
|
|
|
1184
1106
|
return flatten__default["default"](allActions);
|
|
1185
1107
|
};
|
|
1186
1108
|
}
|
|
1187
|
-
|
|
1188
1109
|
var inventories = (function (actionGroupList, syncActionConfig) {
|
|
1189
1110
|
// actionGroupList contains information about which action groups
|
|
1190
1111
|
// are allowed or ignored
|
|
1112
|
+
|
|
1191
1113
|
// createMapActionGroup returns function 'mapActionGroup' that takes params:
|
|
1192
1114
|
// - action group name
|
|
1193
1115
|
// - callback function that should return a list of actions that correspond
|
|
1194
1116
|
// to the for the action group
|
|
1117
|
+
|
|
1195
1118
|
// this resulting function mapActionGroup will call the callback function
|
|
1196
1119
|
// for allowed action groups and return the return value of the callback
|
|
1197
1120
|
// It will return an empty array for ignored action groups
|
|
@@ -1208,14 +1131,12 @@ function extractMatchingPairs(hashMap, key, before, now) {
|
|
|
1208
1131
|
var newObjPos;
|
|
1209
1132
|
var oldObj;
|
|
1210
1133
|
var newObj;
|
|
1211
|
-
|
|
1212
1134
|
if (hashMap[key]) {
|
|
1213
1135
|
oldObjPos = hashMap[key][0];
|
|
1214
1136
|
newObjPos = hashMap[key][1];
|
|
1215
1137
|
if (before && before[oldObjPos]) oldObj = before[oldObjPos];
|
|
1216
1138
|
if (now && now[newObjPos]) newObj = now[newObjPos];
|
|
1217
1139
|
}
|
|
1218
|
-
|
|
1219
1140
|
return {
|
|
1220
1141
|
oldObj: oldObj,
|
|
1221
1142
|
newObj: newObj
|
|
@@ -1224,7 +1145,6 @@ function extractMatchingPairs(hashMap, key, before, now) {
|
|
|
1224
1145
|
|
|
1225
1146
|
var REGEX_NUMBER$3 = new RegExp(/^\d+$/);
|
|
1226
1147
|
var REGEX_UNDERSCORE_NUMBER$3 = new RegExp(/^_\d+$/);
|
|
1227
|
-
|
|
1228
1148
|
function preProcessCollection() {
|
|
1229
1149
|
var collection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1230
1150
|
var identifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
|
|
@@ -1236,23 +1156,20 @@ function preProcessCollection() {
|
|
|
1236
1156
|
refByIndex: {},
|
|
1237
1157
|
refByIdentifier: {}
|
|
1238
1158
|
});
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1159
|
+
}
|
|
1241
1160
|
|
|
1161
|
+
// creates a hash of a location of an item in collection1 and collection2
|
|
1242
1162
|
function findMatchingPairs(diff) {
|
|
1243
1163
|
var before = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
1244
1164
|
var now = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
1245
1165
|
var identifier = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'id';
|
|
1246
1166
|
var result = {};
|
|
1247
|
-
|
|
1248
1167
|
var _preProcessCollection = preProcessCollection(before, identifier),
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1168
|
+
beforeObjRefByIdentifier = _preProcessCollection.refByIdentifier,
|
|
1169
|
+
beforeObjRefByIndex = _preProcessCollection.refByIndex;
|
|
1252
1170
|
var _preProcessCollection2 = preProcessCollection(now, identifier),
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1171
|
+
nowObjRefByIdentifier = _preProcessCollection2.refByIdentifier,
|
|
1172
|
+
nowObjRefByIndex = _preProcessCollection2.refByIndex;
|
|
1256
1173
|
forEach__default["default"](diff, function (item, key) {
|
|
1257
1174
|
if (REGEX_NUMBER$3.test(key)) {
|
|
1258
1175
|
var matchingIdentifier = nowObjRefByIndex[key];
|
|
@@ -1321,6 +1238,7 @@ var referenceActionsList = [{
|
|
|
1321
1238
|
action: 'transitionState',
|
|
1322
1239
|
key: 'state'
|
|
1323
1240
|
}];
|
|
1241
|
+
|
|
1324
1242
|
/**
|
|
1325
1243
|
* HELPER FUNCTIONS
|
|
1326
1244
|
*/
|
|
@@ -1328,19 +1246,15 @@ var referenceActionsList = [{
|
|
|
1328
1246
|
var getIsAddAction = function getIsAddAction(key, resource) {
|
|
1329
1247
|
return REGEX_NUMBER$2.test(key) && Array.isArray(resource) && resource.length;
|
|
1330
1248
|
};
|
|
1331
|
-
|
|
1332
1249
|
var getIsUpdateAction = function getIsUpdateAction(key, resource) {
|
|
1333
1250
|
return REGEX_NUMBER$2.test(key) && Object.keys(resource).length;
|
|
1334
1251
|
};
|
|
1335
|
-
|
|
1336
1252
|
var getIsRemoveAction = function getIsRemoveAction(key, resource) {
|
|
1337
1253
|
return REGEX_UNDERSCORE_NUMBER$2.test(key) && Number(resource[2]) === 0;
|
|
1338
1254
|
};
|
|
1339
|
-
|
|
1340
1255
|
var getIsItemMovedAction = function getIsItemMovedAction(key, resource) {
|
|
1341
1256
|
return REGEX_UNDERSCORE_NUMBER$2.test(key) && Number(resource[2]) === 3;
|
|
1342
1257
|
};
|
|
1343
|
-
|
|
1344
1258
|
function _buildSkuActions(variantDiff, oldVariant) {
|
|
1345
1259
|
if ({}.hasOwnProperty.call(variantDiff, 'sku')) {
|
|
1346
1260
|
var newValue = getDeltaValue(variantDiff.sku);
|
|
@@ -1351,10 +1265,8 @@ function _buildSkuActions(variantDiff, oldVariant) {
|
|
|
1351
1265
|
sku: newValue || null
|
|
1352
1266
|
};
|
|
1353
1267
|
}
|
|
1354
|
-
|
|
1355
1268
|
return null;
|
|
1356
1269
|
}
|
|
1357
|
-
|
|
1358
1270
|
function _buildKeyActions(variantDiff, oldVariant) {
|
|
1359
1271
|
if ({}.hasOwnProperty.call(variantDiff, 'key')) {
|
|
1360
1272
|
var newValue = getDeltaValue(variantDiff.key);
|
|
@@ -1365,10 +1277,8 @@ function _buildKeyActions(variantDiff, oldVariant) {
|
|
|
1365
1277
|
key: newValue || null
|
|
1366
1278
|
};
|
|
1367
1279
|
}
|
|
1368
|
-
|
|
1369
1280
|
return null;
|
|
1370
1281
|
}
|
|
1371
|
-
|
|
1372
1282
|
function _buildNewSetAttributeAction(id, el, sameForAllAttributeNames) {
|
|
1373
1283
|
var attributeName = el && el.name;
|
|
1374
1284
|
if (!attributeName) return undefined;
|
|
@@ -1378,47 +1288,47 @@ function _buildNewSetAttributeAction(id, el, sameForAllAttributeNames) {
|
|
|
1378
1288
|
name: attributeName,
|
|
1379
1289
|
value: el.value
|
|
1380
1290
|
};
|
|
1381
|
-
|
|
1382
1291
|
if (sameForAllAttributeNames.indexOf(attributeName) !== -1) {
|
|
1383
1292
|
action = _objectSpread2(_objectSpread2({}, action), {}, {
|
|
1384
1293
|
action: 'setAttributeInAllVariants'
|
|
1385
1294
|
});
|
|
1386
1295
|
delete action.variantId;
|
|
1387
1296
|
}
|
|
1388
|
-
|
|
1389
1297
|
return action;
|
|
1390
1298
|
}
|
|
1391
|
-
|
|
1392
1299
|
function _buildSetAttributeAction(diffedValue, oldVariant, attribute, sameForAllAttributeNames) {
|
|
1393
1300
|
if (!attribute) return undefined;
|
|
1394
1301
|
var action = {
|
|
1395
1302
|
action: 'setAttribute',
|
|
1396
1303
|
variantId: oldVariant.id,
|
|
1397
1304
|
name: attribute.name
|
|
1398
|
-
};
|
|
1305
|
+
};
|
|
1399
1306
|
|
|
1307
|
+
// Used as original object for patching long diff text
|
|
1400
1308
|
var oldAttribute = oldVariant.attributes.find(function (a) {
|
|
1401
1309
|
return a.name === attribute.name;
|
|
1402
1310
|
}) || {};
|
|
1403
|
-
|
|
1404
1311
|
if (sameForAllAttributeNames.indexOf(attribute.name) !== -1) {
|
|
1405
1312
|
action = _objectSpread2(_objectSpread2({}, action), {}, {
|
|
1406
1313
|
action: 'setAttributeInAllVariants'
|
|
1407
1314
|
});
|
|
1408
1315
|
delete action.variantId;
|
|
1409
1316
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1317
|
+
if (Array.isArray(diffedValue)) action.value = getDeltaValue(diffedValue, oldAttribute.value);else if (typeof diffedValue === 'string')
|
|
1318
|
+
// LText: value: {en: "", de: ""}
|
|
1412
1319
|
// Enum: value: {key: "foo", label: "Foo"}
|
|
1413
1320
|
// LEnum: value: {key: "foo", label: {en: "Foo", de: "Foo"}}
|
|
1414
1321
|
// Money: value: {centAmount: 123, currencyCode: ""}
|
|
1415
1322
|
// *: value: ""
|
|
1323
|
+
|
|
1416
1324
|
// normal
|
|
1417
|
-
action.value = getDeltaValue(diffedValue, oldAttribute.value);else if (diffedValue.centAmount || diffedValue.currencyCode)
|
|
1325
|
+
action.value = getDeltaValue(diffedValue, oldAttribute.value);else if (diffedValue.centAmount || diffedValue.currencyCode)
|
|
1326
|
+
// Money
|
|
1418
1327
|
action.value = {
|
|
1419
1328
|
centAmount: diffedValue.centAmount ? getDeltaValue(diffedValue.centAmount) : attribute.value.centAmount,
|
|
1420
1329
|
currencyCode: diffedValue.currencyCode ? getDeltaValue(diffedValue.currencyCode) : attribute.value.currencyCode
|
|
1421
|
-
};else if (diffedValue.key)
|
|
1330
|
+
};else if (diffedValue.key)
|
|
1331
|
+
// Enum / LEnum (use only the key)
|
|
1422
1332
|
action.value = getDeltaValue(diffedValue.key);else if (_typeof(diffedValue) === 'object') if ({}.hasOwnProperty.call(diffedValue, '_t') && diffedValue._t === 'a') {
|
|
1423
1333
|
// set-typed attribute
|
|
1424
1334
|
action = _objectSpread2(_objectSpread2({}, action), {}, {
|
|
@@ -1426,6 +1336,7 @@ function _buildSetAttributeAction(diffedValue, oldVariant, attribute, sameForAll
|
|
|
1426
1336
|
});
|
|
1427
1337
|
} else {
|
|
1428
1338
|
// LText
|
|
1339
|
+
|
|
1429
1340
|
var updatedValue = Object.keys(diffedValue).reduce(function (acc, lang) {
|
|
1430
1341
|
var patchedValue = getDeltaValue(diffedValue[lang], acc[lang]);
|
|
1431
1342
|
return Object.assign(acc, _defineProperty({}, lang, patchedValue));
|
|
@@ -1434,18 +1345,16 @@ function _buildSetAttributeAction(diffedValue, oldVariant, attribute, sameForAll
|
|
|
1434
1345
|
}
|
|
1435
1346
|
return action;
|
|
1436
1347
|
}
|
|
1437
|
-
|
|
1438
1348
|
function _buildVariantImagesAction(diffedImages) {
|
|
1439
1349
|
var oldVariant = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1440
1350
|
var newVariant = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1441
|
-
var actions = [];
|
|
1442
|
-
|
|
1351
|
+
var actions = [];
|
|
1352
|
+
// generate a hashMap to be able to reference the right image from both ends
|
|
1443
1353
|
var matchingImagePairs = findMatchingPairs(diffedImages, oldVariant.images, newVariant.images, 'url');
|
|
1444
1354
|
forEach__default["default"](diffedImages, function (image, key) {
|
|
1445
1355
|
var _extractMatchingPairs = extractMatchingPairs(matchingImagePairs, key, oldVariant.images, newVariant.images),
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1356
|
+
oldObj = _extractMatchingPairs.oldObj,
|
|
1357
|
+
newObj = _extractMatchingPairs.newObj;
|
|
1449
1358
|
if (REGEX_NUMBER$2.test(key)) {
|
|
1450
1359
|
// New image
|
|
1451
1360
|
if (Array.isArray(image) && image.length) actions.push({
|
|
@@ -1471,13 +1380,15 @@ function _buildVariantImagesAction(diffedImages) {
|
|
|
1471
1380
|
label: getDeltaValue(image.label)
|
|
1472
1381
|
});
|
|
1473
1382
|
} else if (REGEX_UNDERSCORE_NUMBER$2.test(key)) if (Array.isArray(image) && image.length === 3) {
|
|
1474
|
-
if (Number(image[2]) === 3)
|
|
1383
|
+
if (Number(image[2]) === 3)
|
|
1384
|
+
// image position changed
|
|
1475
1385
|
actions.push({
|
|
1476
1386
|
action: 'moveImageToPosition',
|
|
1477
1387
|
variantId: oldVariant.id,
|
|
1478
1388
|
imageUrl: oldObj.url,
|
|
1479
1389
|
position: Number(image[1])
|
|
1480
|
-
});else if (Number(image[2]) === 0)
|
|
1390
|
+
});else if (Number(image[2]) === 0)
|
|
1391
|
+
// image removed
|
|
1481
1392
|
actions.push({
|
|
1482
1393
|
action: 'removeImage',
|
|
1483
1394
|
variantId: oldVariant.id,
|
|
@@ -1487,26 +1398,24 @@ function _buildVariantImagesAction(diffedImages) {
|
|
|
1487
1398
|
});
|
|
1488
1399
|
return actions;
|
|
1489
1400
|
}
|
|
1490
|
-
|
|
1491
1401
|
function _buildVariantPricesAction(diffedPrices) {
|
|
1492
1402
|
var oldVariant = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1493
1403
|
var newVariant = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1494
1404
|
var enableDiscounted = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1495
1405
|
var addPriceActions = [];
|
|
1496
1406
|
var changePriceActions = [];
|
|
1497
|
-
var removePriceActions = [];
|
|
1407
|
+
var removePriceActions = [];
|
|
1498
1408
|
|
|
1409
|
+
// generate a hashMap to be able to reference the right image from both ends
|
|
1499
1410
|
var matchingPricePairs = findMatchingPairs(diffedPrices, oldVariant.prices, newVariant.prices);
|
|
1500
1411
|
forEach__default["default"](diffedPrices, function (price, key) {
|
|
1501
1412
|
var _extractMatchingPairs2 = extractMatchingPairs(matchingPricePairs, key, oldVariant.prices, newVariant.prices),
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1413
|
+
oldObj = _extractMatchingPairs2.oldObj,
|
|
1414
|
+
newObj = _extractMatchingPairs2.newObj;
|
|
1505
1415
|
if (getIsAddAction(key, price)) {
|
|
1506
1416
|
// Remove read-only fields
|
|
1507
1417
|
var patchedPrice = price.map(function (p) {
|
|
1508
1418
|
var shallowClone = _objectSpread2({}, p);
|
|
1509
|
-
|
|
1510
1419
|
if (enableDiscounted !== true) delete shallowClone.discounted;
|
|
1511
1420
|
return shallowClone;
|
|
1512
1421
|
});
|
|
@@ -1517,18 +1426,14 @@ function _buildVariantPricesAction(diffedPrices) {
|
|
|
1517
1426
|
});
|
|
1518
1427
|
return;
|
|
1519
1428
|
}
|
|
1520
|
-
|
|
1521
1429
|
if (getIsUpdateAction(key, price)) {
|
|
1522
1430
|
// Remove the discounted field and make sure that the price
|
|
1523
1431
|
// still has other values, otherwise simply return
|
|
1524
1432
|
var filteredPrice = _objectSpread2({}, price);
|
|
1525
|
-
|
|
1526
1433
|
if (enableDiscounted !== true) delete filteredPrice.discounted;
|
|
1527
|
-
|
|
1528
1434
|
if (Object.keys(filteredPrice).length) {
|
|
1529
1435
|
// At this point price should have changed, simply pick the new one
|
|
1530
1436
|
var newPrice = _objectSpread2({}, newObj);
|
|
1531
|
-
|
|
1532
1437
|
if (enableDiscounted !== true) delete newPrice.discounted;
|
|
1533
1438
|
changePriceActions.push({
|
|
1534
1439
|
action: 'changePrice',
|
|
@@ -1536,10 +1441,8 @@ function _buildVariantPricesAction(diffedPrices) {
|
|
|
1536
1441
|
price: newPrice
|
|
1537
1442
|
});
|
|
1538
1443
|
}
|
|
1539
|
-
|
|
1540
1444
|
return;
|
|
1541
1445
|
}
|
|
1542
|
-
|
|
1543
1446
|
if (getIsRemoveAction(key, price)) {
|
|
1544
1447
|
// price removed
|
|
1545
1448
|
removePriceActions.push({
|
|
@@ -1550,7 +1453,6 @@ function _buildVariantPricesAction(diffedPrices) {
|
|
|
1550
1453
|
});
|
|
1551
1454
|
return [addPriceActions, changePriceActions, removePriceActions];
|
|
1552
1455
|
}
|
|
1553
|
-
|
|
1554
1456
|
function _buildVariantAttributesActions(attributes, oldVariant, newVariant, sameForAllAttributeNames) {
|
|
1555
1457
|
var actions = [];
|
|
1556
1458
|
if (!attributes) return actions;
|
|
@@ -1559,43 +1461,34 @@ function _buildVariantAttributesActions(attributes, oldVariant, newVariant, same
|
|
|
1559
1461
|
if (Array.isArray(value)) {
|
|
1560
1462
|
var id = oldVariant.id;
|
|
1561
1463
|
var deltaValue = getDeltaValue(value);
|
|
1562
|
-
|
|
1563
1464
|
var setAction = _buildNewSetAttributeAction(id, deltaValue, sameForAllAttributeNames);
|
|
1564
|
-
|
|
1565
1465
|
if (setAction) actions.push(setAction);
|
|
1566
1466
|
} else if (newVariant.attributes) {
|
|
1567
1467
|
var _setAction = _buildSetAttributeAction(value.value, oldVariant, newVariant.attributes[key], sameForAllAttributeNames);
|
|
1568
|
-
|
|
1569
1468
|
if (_setAction) actions.push(_setAction);
|
|
1570
1469
|
}
|
|
1571
1470
|
} else if (REGEX_UNDERSCORE_NUMBER$2.test(key)) if (Array.isArray(value)) {
|
|
1572
1471
|
// Ignore pure array moves!
|
|
1573
1472
|
if (value.length === 3 && value[2] === 3) return;
|
|
1574
1473
|
var _id = oldVariant.id;
|
|
1575
|
-
|
|
1576
1474
|
var _deltaValue = getDeltaValue(value);
|
|
1577
|
-
|
|
1578
|
-
|
|
1475
|
+
if (!_deltaValue) if (value[0] && value[0].name)
|
|
1476
|
+
// unset attribute if
|
|
1579
1477
|
_deltaValue = {
|
|
1580
1478
|
name: value[0].name
|
|
1581
1479
|
};else _deltaValue = undefined;
|
|
1582
|
-
|
|
1583
1480
|
var _setAction2 = _buildNewSetAttributeAction(_id, _deltaValue, sameForAllAttributeNames);
|
|
1584
|
-
|
|
1585
1481
|
if (_setAction2) actions.push(_setAction2);
|
|
1586
1482
|
} else {
|
|
1587
1483
|
var index = key.substring(1);
|
|
1588
|
-
|
|
1589
1484
|
if (newVariant.attributes) {
|
|
1590
1485
|
var _setAction3 = _buildSetAttributeAction(value.value, oldVariant, newVariant.attributes[index], sameForAllAttributeNames);
|
|
1591
|
-
|
|
1592
1486
|
if (_setAction3) actions.push(_setAction3);
|
|
1593
1487
|
}
|
|
1594
1488
|
}
|
|
1595
1489
|
});
|
|
1596
1490
|
return actions;
|
|
1597
1491
|
}
|
|
1598
|
-
|
|
1599
1492
|
function toAssetIdentifier(asset) {
|
|
1600
1493
|
var assetIdentifier = asset.id ? {
|
|
1601
1494
|
assetId: asset.id
|
|
@@ -1604,26 +1497,22 @@ function toAssetIdentifier(asset) {
|
|
|
1604
1497
|
};
|
|
1605
1498
|
return assetIdentifier;
|
|
1606
1499
|
}
|
|
1607
|
-
|
|
1608
1500
|
function toVariantIdentifier(variant) {
|
|
1609
1501
|
var id = variant.id,
|
|
1610
|
-
|
|
1502
|
+
sku = variant.sku;
|
|
1611
1503
|
return id ? {
|
|
1612
1504
|
variantId: id
|
|
1613
1505
|
} : {
|
|
1614
1506
|
sku: sku
|
|
1615
1507
|
};
|
|
1616
1508
|
}
|
|
1617
|
-
|
|
1618
1509
|
function _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant) {
|
|
1619
1510
|
var isAssetOrderChanged = Object.entries(diffAssets).find(function (entry) {
|
|
1620
1511
|
return getIsItemMovedAction(entry[0], entry[1]);
|
|
1621
1512
|
});
|
|
1622
|
-
|
|
1623
1513
|
if (!isAssetOrderChanged) {
|
|
1624
1514
|
return [];
|
|
1625
1515
|
}
|
|
1626
|
-
|
|
1627
1516
|
var assetIdsBefore = oldVariant.assets.map(function (_) {
|
|
1628
1517
|
return _.id;
|
|
1629
1518
|
});
|
|
@@ -1634,24 +1523,21 @@ function _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant)
|
|
|
1634
1523
|
});
|
|
1635
1524
|
var assetIdsToKeep = intersection__default["default"](assetIdsCurrent, assetIdsBefore);
|
|
1636
1525
|
var assetIdsToRemove = without__default["default"].apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
|
|
1637
|
-
|
|
1638
1526
|
var changeAssetOrderAction = _objectSpread2({
|
|
1639
1527
|
action: 'changeAssetOrder',
|
|
1640
1528
|
assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
|
|
1641
1529
|
}, toVariantIdentifier(oldVariant));
|
|
1642
|
-
|
|
1643
1530
|
return [changeAssetOrderAction];
|
|
1644
1531
|
}
|
|
1645
|
-
|
|
1646
1532
|
function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
|
|
1647
|
-
var assetActions = [];
|
|
1533
|
+
var assetActions = [];
|
|
1648
1534
|
|
|
1535
|
+
// generate a hashMap to be able to reference the right asset from both ends
|
|
1649
1536
|
var matchingAssetPairs = findMatchingPairs(diffAssets, oldVariant.assets, newVariant.assets);
|
|
1650
1537
|
forEach__default["default"](diffAssets, function (asset, key) {
|
|
1651
1538
|
var _extractMatchingPairs3 = extractMatchingPairs(matchingAssetPairs, key, oldVariant.assets, newVariant.assets),
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1539
|
+
oldAsset = _extractMatchingPairs3.oldObj,
|
|
1540
|
+
newAsset = _extractMatchingPairs3.newObj;
|
|
1655
1541
|
if (getIsAddAction(key, asset)) {
|
|
1656
1542
|
assetActions.push(_objectSpread2(_objectSpread2({
|
|
1657
1543
|
action: 'addAsset',
|
|
@@ -1661,7 +1547,6 @@ function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
|
|
|
1661
1547
|
}));
|
|
1662
1548
|
return;
|
|
1663
1549
|
}
|
|
1664
|
-
|
|
1665
1550
|
if (getIsUpdateAction(key, asset)) {
|
|
1666
1551
|
// todo add changeAssetOrder
|
|
1667
1552
|
var basicActions = buildBaseAttributesActions({
|
|
@@ -1676,11 +1561,9 @@ function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
|
|
|
1676
1561
|
assetId: oldAsset.id
|
|
1677
1562
|
});
|
|
1678
1563
|
}
|
|
1679
|
-
|
|
1680
1564
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, action), toVariantIdentifier(oldVariant)), toAssetIdentifier(oldAsset));
|
|
1681
1565
|
});
|
|
1682
1566
|
assetActions.push.apply(assetActions, _toConsumableArray(basicActions));
|
|
1683
|
-
|
|
1684
1567
|
if (asset.custom) {
|
|
1685
1568
|
var customActions = actionsMapCustom(asset, newAsset, oldAsset, _objectSpread2(_objectSpread2({
|
|
1686
1569
|
actions: {
|
|
@@ -1690,26 +1573,22 @@ function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
|
|
|
1690
1573
|
}, toVariantIdentifier(oldVariant)), toAssetIdentifier(oldAsset)));
|
|
1691
1574
|
assetActions.push.apply(assetActions, _toConsumableArray(customActions));
|
|
1692
1575
|
}
|
|
1693
|
-
|
|
1694
1576
|
return;
|
|
1695
1577
|
}
|
|
1696
|
-
|
|
1697
1578
|
if (getIsRemoveAction(key, asset)) {
|
|
1698
1579
|
assetActions.push(_objectSpread2(_objectSpread2({
|
|
1699
1580
|
action: 'removeAsset'
|
|
1700
1581
|
}, toAssetIdentifier(oldAsset)), toVariantIdentifier(oldVariant)));
|
|
1701
1582
|
}
|
|
1702
1583
|
});
|
|
1703
|
-
|
|
1704
1584
|
var changedAssetOrderAction = _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant);
|
|
1705
|
-
|
|
1706
1585
|
return [].concat(_toConsumableArray(changedAssetOrderAction), assetActions);
|
|
1707
1586
|
}
|
|
1587
|
+
|
|
1708
1588
|
/**
|
|
1709
1589
|
* SYNC FUNCTIONS
|
|
1710
1590
|
*/
|
|
1711
1591
|
|
|
1712
|
-
|
|
1713
1592
|
function actionsMapBase$h(diff, oldObj, newObj) {
|
|
1714
1593
|
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1715
1594
|
return buildBaseAttributesActions({
|
|
@@ -1764,7 +1643,6 @@ function actionsMapCategories(diff) {
|
|
|
1764
1643
|
var action = {
|
|
1765
1644
|
category: category[0]
|
|
1766
1645
|
};
|
|
1767
|
-
|
|
1768
1646
|
if (category.length === 3) {
|
|
1769
1647
|
// Ignore pure array moves!
|
|
1770
1648
|
if (category[2] !== 3) {
|
|
@@ -1776,13 +1654,14 @@ function actionsMapCategories(diff) {
|
|
|
1776
1654
|
addToCategoryActions.push(action);
|
|
1777
1655
|
}
|
|
1778
1656
|
}
|
|
1779
|
-
});
|
|
1657
|
+
});
|
|
1780
1658
|
|
|
1659
|
+
// Make sure `removeFromCategory` actions come first
|
|
1781
1660
|
return removeFromCategoryActions.concat(addToCategoryActions);
|
|
1782
1661
|
}
|
|
1783
1662
|
function actionsMapCategoryOrderHints(diff) {
|
|
1784
|
-
if (!diff.categoryOrderHints) return [];
|
|
1785
|
-
|
|
1663
|
+
if (!diff.categoryOrderHints) return [];
|
|
1664
|
+
// Ignore this pattern as its means no changes happened [{},0,0]
|
|
1786
1665
|
if (Array.isArray(diff.categoryOrderHints)) return [];
|
|
1787
1666
|
return Object.keys(diff.categoryOrderHints).map(function (categoryId) {
|
|
1788
1667
|
var hintChange = diff.categoryOrderHints[categoryId];
|
|
@@ -1790,9 +1669,13 @@ function actionsMapCategoryOrderHints(diff) {
|
|
|
1790
1669
|
action: 'setCategoryOrderHint',
|
|
1791
1670
|
categoryId: categoryId
|
|
1792
1671
|
};
|
|
1793
|
-
if (hintChange.length === 1)
|
|
1794
|
-
|
|
1795
|
-
action.orderHint = hintChange[
|
|
1672
|
+
if (hintChange.length === 1)
|
|
1673
|
+
// item was added
|
|
1674
|
+
action.orderHint = hintChange[0];else if (hintChange.length === 2 && hintChange[1] !== 0)
|
|
1675
|
+
// item was changed
|
|
1676
|
+
action.orderHint = hintChange[1];
|
|
1677
|
+
|
|
1678
|
+
// else item was removed -> do not set 'orderHint' property
|
|
1796
1679
|
|
|
1797
1680
|
return action;
|
|
1798
1681
|
});
|
|
@@ -1802,12 +1685,10 @@ function actionsMapAssets(diff, oldObj, newObj, variantHashMap) {
|
|
|
1802
1685
|
var variants = diff.variants;
|
|
1803
1686
|
if (variants) forEach__default["default"](variants, function (variant, key) {
|
|
1804
1687
|
var _extractMatchingPairs4 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1688
|
+
oldVariant = _extractMatchingPairs4.oldObj,
|
|
1689
|
+
newVariant = _extractMatchingPairs4.newObj;
|
|
1808
1690
|
if (variant.assets && (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key))) {
|
|
1809
1691
|
var assetActions = _buildVariantAssetsActions(variant.assets, oldVariant, newVariant);
|
|
1810
|
-
|
|
1811
1692
|
allAssetsActions = allAssetsActions.concat(assetActions);
|
|
1812
1693
|
}
|
|
1813
1694
|
});
|
|
@@ -1820,25 +1701,21 @@ function actionsMapAttributes$1(diff, oldObj, newObj) {
|
|
|
1820
1701
|
var variants = diff.variants;
|
|
1821
1702
|
if (variants) forEach__default["default"](variants, function (variant, key) {
|
|
1822
1703
|
var _extractMatchingPairs5 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1704
|
+
oldVariant = _extractMatchingPairs5.oldObj,
|
|
1705
|
+
newVariant = _extractMatchingPairs5.newObj;
|
|
1826
1706
|
if (REGEX_NUMBER$2.test(key) && !Array.isArray(variant)) {
|
|
1827
1707
|
var skuAction = _buildSkuActions(variant, oldVariant);
|
|
1828
|
-
|
|
1829
1708
|
var keyAction = _buildKeyActions(variant, oldVariant);
|
|
1830
|
-
|
|
1831
1709
|
if (skuAction) actions.push(skuAction);
|
|
1832
1710
|
if (keyAction) actions.push(keyAction);
|
|
1833
1711
|
var attributes = variant.attributes;
|
|
1834
|
-
|
|
1835
1712
|
var attrActions = _buildVariantAttributesActions(attributes, oldVariant, newVariant, sameForAllAttributeNames);
|
|
1836
|
-
|
|
1837
1713
|
actions = actions.concat(attrActions);
|
|
1838
1714
|
}
|
|
1839
|
-
});
|
|
1840
|
-
// This is especially necessary for SFA attributes.
|
|
1715
|
+
});
|
|
1841
1716
|
|
|
1717
|
+
// Ensure that an action is unique.
|
|
1718
|
+
// This is especially necessary for SFA attributes.
|
|
1842
1719
|
return uniqWith__default["default"](actions, function (a, b) {
|
|
1843
1720
|
return a.action === b.action && a.name === b.name && a.variantId === b.variantId;
|
|
1844
1721
|
});
|
|
@@ -1848,12 +1725,10 @@ function actionsMapImages(diff, oldObj, newObj, variantHashMap) {
|
|
|
1848
1725
|
var variants = diff.variants;
|
|
1849
1726
|
if (variants) forEach__default["default"](variants, function (variant, key) {
|
|
1850
1727
|
var _extractMatchingPairs6 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1728
|
+
oldVariant = _extractMatchingPairs6.oldObj,
|
|
1729
|
+
newVariant = _extractMatchingPairs6.newObj;
|
|
1854
1730
|
if (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key)) {
|
|
1855
1731
|
var vActions = _buildVariantImagesAction(variant.images, oldVariant, newVariant);
|
|
1856
|
-
|
|
1857
1732
|
actions = actions.concat(vActions);
|
|
1858
1733
|
}
|
|
1859
1734
|
});
|
|
@@ -1866,22 +1741,21 @@ function actionsMapPrices(diff, oldObj, newObj, variantHashMap, enableDiscounted
|
|
|
1866
1741
|
var variants = diff.variants;
|
|
1867
1742
|
if (variants) forEach__default["default"](variants, function (variant, key) {
|
|
1868
1743
|
var _extractMatchingPairs7 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1744
|
+
oldVariant = _extractMatchingPairs7.oldObj,
|
|
1745
|
+
newVariant = _extractMatchingPairs7.newObj;
|
|
1872
1746
|
if (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key)) {
|
|
1873
1747
|
var _buildVariantPricesAc = _buildVariantPricesAction(variant.prices, oldVariant, newVariant, enableDiscounted),
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1748
|
+
_buildVariantPricesAc2 = _slicedToArray(_buildVariantPricesAc, 3),
|
|
1749
|
+
addPriceAction = _buildVariantPricesAc2[0],
|
|
1750
|
+
changePriceAction = _buildVariantPricesAc2[1],
|
|
1751
|
+
removePriceAction = _buildVariantPricesAc2[2];
|
|
1879
1752
|
addPriceActions = addPriceActions.concat(addPriceAction);
|
|
1880
1753
|
changePriceActions = changePriceActions.concat(changePriceAction);
|
|
1881
1754
|
removePriceActions = removePriceActions.concat(removePriceAction);
|
|
1882
1755
|
}
|
|
1883
|
-
});
|
|
1756
|
+
});
|
|
1884
1757
|
|
|
1758
|
+
// price actions need to be in this below order
|
|
1885
1759
|
return changePriceActions.concat(removePriceActions).concat(addPriceActions);
|
|
1886
1760
|
}
|
|
1887
1761
|
function actionsMapPricesCustom(diff, oldObj, newObj, variantHashMap) {
|
|
@@ -1889,16 +1763,14 @@ function actionsMapPricesCustom(diff, oldObj, newObj, variantHashMap) {
|
|
|
1889
1763
|
var variants = diff.variants;
|
|
1890
1764
|
if (variants) forEach__default["default"](variants, function (variant, key) {
|
|
1891
1765
|
var _extractMatchingPairs8 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1766
|
+
oldVariant = _extractMatchingPairs8.oldObj,
|
|
1767
|
+
newVariant = _extractMatchingPairs8.newObj;
|
|
1895
1768
|
if (variant && variant.prices && (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key))) {
|
|
1896
1769
|
var priceHashMap = findMatchingPairs(variant.prices, oldVariant.prices, newVariant.prices);
|
|
1897
1770
|
forEach__default["default"](variant.prices, function (price, index) {
|
|
1898
1771
|
var _extractMatchingPairs9 = extractMatchingPairs(priceHashMap, index, oldVariant.prices, newVariant.prices),
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1772
|
+
oldPrice = _extractMatchingPairs9.oldObj,
|
|
1773
|
+
newPrice = _extractMatchingPairs9.newObj;
|
|
1902
1774
|
if (price.custom && (REGEX_UNDERSCORE_NUMBER$2.test(index) || REGEX_NUMBER$2.test(index))) {
|
|
1903
1775
|
var generatedActions = actionsMapCustom(price, newPrice, oldPrice, {
|
|
1904
1776
|
actions: {
|
|
@@ -1921,15 +1793,14 @@ function actionsMapMasterVariant(oldObj, newObj) {
|
|
|
1921
1793
|
variantId: variantId
|
|
1922
1794
|
};
|
|
1923
1795
|
};
|
|
1924
|
-
|
|
1925
1796
|
var extractMasterVariantId = function extractMasterVariantId(fromObj) {
|
|
1926
1797
|
var variants = Array.isArray(fromObj.variants) ? fromObj.variants : [];
|
|
1927
1798
|
return variants[0] ? variants[0].id : undefined;
|
|
1928
1799
|
};
|
|
1929
|
-
|
|
1930
1800
|
var newMasterVariantId = extractMasterVariantId(newObj);
|
|
1931
|
-
var oldMasterVariantId = extractMasterVariantId(oldObj);
|
|
1801
|
+
var oldMasterVariantId = extractMasterVariantId(oldObj);
|
|
1932
1802
|
|
|
1803
|
+
// Old and new master master variant differ and a new master variant id exists
|
|
1933
1804
|
if (newMasterVariantId && oldMasterVariantId !== newMasterVariantId) return [createChangeMasterVariantAction(newMasterVariantId)];
|
|
1934
1805
|
return [];
|
|
1935
1806
|
}
|
|
@@ -1939,9 +1810,9 @@ function createProductMapActions(mapActionGroup, syncActionConfig) {
|
|
|
1939
1810
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1940
1811
|
var allActions = [];
|
|
1941
1812
|
var sameForAllAttributeNames = options.sameForAllAttributeNames,
|
|
1942
|
-
|
|
1813
|
+
enableDiscounted = options.enableDiscounted;
|
|
1943
1814
|
var publish = newObj.publish,
|
|
1944
|
-
|
|
1815
|
+
staged = newObj.staged;
|
|
1945
1816
|
var variantHashMap = findMatchingPairs(diff.variants, oldObj.variants, newObj.variants);
|
|
1946
1817
|
allActions.push(mapActionGroup('attributes', function () {
|
|
1947
1818
|
return actionsMapAttributes$1(diff, oldObj, newObj, sameForAllAttributeNames || [], variantHashMap);
|
|
@@ -1988,27 +1859,22 @@ function createProductMapActions(mapActionGroup, syncActionConfig) {
|
|
|
1988
1859
|
return flatten__default["default"](allActions);
|
|
1989
1860
|
};
|
|
1990
1861
|
}
|
|
1991
|
-
|
|
1992
1862
|
function moveMasterVariantsIntoVariants(before, now) {
|
|
1993
1863
|
var _copyEmptyArrayProps = copyEmptyArrayProps(before, now),
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1864
|
+
_copyEmptyArrayProps2 = _slicedToArray(_copyEmptyArrayProps, 2),
|
|
1865
|
+
beforeCopy = _copyEmptyArrayProps2[0],
|
|
1866
|
+
nowCopy = _copyEmptyArrayProps2[1];
|
|
1998
1867
|
var move = function move(obj) {
|
|
1999
1868
|
return _objectSpread2(_objectSpread2({}, obj), {}, {
|
|
2000
1869
|
masterVariant: undefined,
|
|
2001
1870
|
variants: [obj.masterVariant].concat(_toConsumableArray(obj.variants || []))
|
|
2002
1871
|
});
|
|
2003
1872
|
};
|
|
2004
|
-
|
|
2005
1873
|
var hasMasterVariant = function hasMasterVariant(obj) {
|
|
2006
1874
|
return obj && obj.masterVariant;
|
|
2007
1875
|
};
|
|
2008
|
-
|
|
2009
1876
|
return [hasMasterVariant(beforeCopy) ? move(beforeCopy) : beforeCopy, hasMasterVariant(nowCopy) ? move(nowCopy) : nowCopy];
|
|
2010
1877
|
}
|
|
2011
|
-
|
|
2012
1878
|
var products = (function (actionGroupList, syncActionConfig) {
|
|
2013
1879
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
2014
1880
|
var doMapActions = createProductMapActions(mapActionGroup, syncActionConfig);
|
|
@@ -2020,15 +1886,12 @@ var products = (function (actionGroupList, syncActionConfig) {
|
|
|
2020
1886
|
|
|
2021
1887
|
var REGEX_NUMBER$1 = new RegExp(/^\d+$/);
|
|
2022
1888
|
var REGEX_UNDERSCORE_NUMBER$1 = new RegExp(/^_\d+$/);
|
|
2023
|
-
|
|
2024
1889
|
var isAddAction = function isAddAction(key, resource) {
|
|
2025
1890
|
return REGEX_NUMBER$1.test(key) && Array.isArray(resource) && resource.length;
|
|
2026
1891
|
};
|
|
2027
|
-
|
|
2028
1892
|
var isRemoveAction = function isRemoveAction(key, resource) {
|
|
2029
1893
|
return REGEX_UNDERSCORE_NUMBER$1.test(key) && Number(resource[2]) === 0;
|
|
2030
1894
|
};
|
|
2031
|
-
|
|
2032
1895
|
var baseActionsList$g = [{
|
|
2033
1896
|
action: 'changeOrderState',
|
|
2034
1897
|
key: 'orderState'
|
|
@@ -2039,6 +1902,7 @@ var baseActionsList$g = [{
|
|
|
2039
1902
|
action: 'changeShipmentState',
|
|
2040
1903
|
key: 'shipmentState'
|
|
2041
1904
|
}];
|
|
1905
|
+
|
|
2042
1906
|
/**
|
|
2043
1907
|
* SYNC FUNCTIONS
|
|
2044
1908
|
*/
|
|
@@ -2065,18 +1929,17 @@ function actionsMapDeliveries(diff, oldObj, newObj) {
|
|
|
2065
1929
|
}));
|
|
2066
1930
|
return handler(deliveriesDiff, oldObj.shippingInfo, newObj.shippingInfo);
|
|
2067
1931
|
}
|
|
2068
|
-
|
|
2069
1932
|
function _buildDeliveryParcelsAction(diffedParcels) {
|
|
2070
1933
|
var oldDelivery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2071
1934
|
var newDelivery = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2072
1935
|
var addParcelActions = [];
|
|
2073
|
-
var removeParcelActions = [];
|
|
1936
|
+
var removeParcelActions = [];
|
|
2074
1937
|
|
|
1938
|
+
// generate a hashMap to be able to reference the right image from both ends
|
|
2075
1939
|
var matchingParcelPairs = findMatchingPairs(diffedParcels, oldDelivery.parcels, newDelivery.parcels);
|
|
2076
1940
|
forEach__default["default"](diffedParcels, function (parcel, key) {
|
|
2077
1941
|
var _extractMatchingPairs = extractMatchingPairs(matchingParcelPairs, key, oldDelivery.parcels, newDelivery.parcels),
|
|
2078
|
-
|
|
2079
|
-
|
|
1942
|
+
oldObj = _extractMatchingPairs.oldObj;
|
|
2080
1943
|
if (isAddAction(key, parcel)) {
|
|
2081
1944
|
addParcelActions.push(_objectSpread2({
|
|
2082
1945
|
action: 'addParcelToDelivery',
|
|
@@ -2084,7 +1947,6 @@ function _buildDeliveryParcelsAction(diffedParcels) {
|
|
|
2084
1947
|
}, getDeltaValue(parcel)));
|
|
2085
1948
|
return;
|
|
2086
1949
|
}
|
|
2087
|
-
|
|
2088
1950
|
if (isRemoveAction(key, parcel)) {
|
|
2089
1951
|
removeParcelActions.push({
|
|
2090
1952
|
action: 'removeParcelFromDelivery',
|
|
@@ -2094,13 +1956,12 @@ function _buildDeliveryParcelsAction(diffedParcels) {
|
|
|
2094
1956
|
});
|
|
2095
1957
|
return [addParcelActions, removeParcelActions];
|
|
2096
1958
|
}
|
|
2097
|
-
|
|
2098
1959
|
function _buildDeliveryItemsAction(diffedItems) {
|
|
2099
1960
|
var newDelivery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2100
|
-
var setDeliveryItemsAction = [];
|
|
1961
|
+
var setDeliveryItemsAction = [];
|
|
1962
|
+
// If there is a diff it means that there were changes (update, adds or removes)
|
|
2101
1963
|
// over the items, which means that `setDeliveryItems` change has happened over
|
|
2102
1964
|
// the delivery
|
|
2103
|
-
|
|
2104
1965
|
if (diffedItems && Object.keys(diffedItems).length > 0) {
|
|
2105
1966
|
setDeliveryItemsAction.push({
|
|
2106
1967
|
action: 'setDeliveryItems',
|
|
@@ -2109,10 +1970,8 @@ function _buildDeliveryItemsAction(diffedItems) {
|
|
|
2109
1970
|
items: newDelivery.items
|
|
2110
1971
|
});
|
|
2111
1972
|
}
|
|
2112
|
-
|
|
2113
1973
|
return [setDeliveryItemsAction];
|
|
2114
1974
|
}
|
|
2115
|
-
|
|
2116
1975
|
function actionsMapParcels(diff, oldObj, newObj, deliveryHashMap) {
|
|
2117
1976
|
var shippingInfo = diff.shippingInfo;
|
|
2118
1977
|
if (!shippingInfo) return [];
|
|
@@ -2122,15 +1981,13 @@ function actionsMapParcels(diff, oldObj, newObj, deliveryHashMap) {
|
|
|
2122
1981
|
var removeParcelActions = [];
|
|
2123
1982
|
if (deliveries) forEach__default["default"](deliveries, function (delivery, key) {
|
|
2124
1983
|
var _extractMatchingPairs2 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
1984
|
+
oldDelivery = _extractMatchingPairs2.oldObj,
|
|
1985
|
+
newDelivery = _extractMatchingPairs2.newObj;
|
|
2128
1986
|
if (REGEX_UNDERSCORE_NUMBER$1.test(key) || REGEX_NUMBER$1.test(key)) {
|
|
2129
1987
|
var _buildDeliveryParcels = _buildDeliveryParcelsAction(delivery.parcels, oldDelivery, newDelivery),
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
1988
|
+
_buildDeliveryParcels2 = _slicedToArray(_buildDeliveryParcels, 2),
|
|
1989
|
+
addParcelAction = _buildDeliveryParcels2[0],
|
|
1990
|
+
removeParcelAction = _buildDeliveryParcels2[1];
|
|
2134
1991
|
addParcelActions = addParcelActions.concat(addParcelAction);
|
|
2135
1992
|
removeParcelActions = removeParcelActions.concat(removeParcelAction);
|
|
2136
1993
|
}
|
|
@@ -2145,42 +2002,34 @@ function actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap) {
|
|
|
2145
2002
|
var setDeliveryItemsActions = [];
|
|
2146
2003
|
forEach__default["default"](deliveries, function (delivery, key) {
|
|
2147
2004
|
var _extractMatchingPairs3 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
2148
|
-
|
|
2149
|
-
|
|
2005
|
+
newDelivery = _extractMatchingPairs3.newObj;
|
|
2150
2006
|
if (REGEX_UNDERSCORE_NUMBER$1.test(key) || REGEX_NUMBER$1.test(key)) {
|
|
2151
2007
|
var _buildDeliveryItemsAc = _buildDeliveryItemsAction(delivery.items, newDelivery),
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2008
|
+
_buildDeliveryItemsAc2 = _slicedToArray(_buildDeliveryItemsAc, 1),
|
|
2009
|
+
setDeliveryItemsAction = _buildDeliveryItemsAc2[0];
|
|
2155
2010
|
setDeliveryItemsActions = setDeliveryItemsActions.concat(setDeliveryItemsAction);
|
|
2156
2011
|
}
|
|
2157
2012
|
});
|
|
2158
2013
|
return setDeliveryItemsActions;
|
|
2159
2014
|
}
|
|
2160
2015
|
function actionsMapReturnsInfo(diff, oldObj, newObj) {
|
|
2161
|
-
var _createBuildArrayActi2;
|
|
2162
|
-
|
|
2163
2016
|
var returnInfoDiff = diff.returnInfo;
|
|
2164
2017
|
if (!returnInfoDiff) return [];
|
|
2165
|
-
var handler = createBuildArrayActions('returnInfo', (
|
|
2018
|
+
var handler = createBuildArrayActions('returnInfo', _defineProperty(_defineProperty({}, ADD_ACTIONS, function (newReturnInfo) {
|
|
2166
2019
|
if (newReturnInfo.items) {
|
|
2167
2020
|
return [_objectSpread2({
|
|
2168
2021
|
action: 'addReturnInfo'
|
|
2169
2022
|
}, newReturnInfo)];
|
|
2170
2023
|
}
|
|
2171
|
-
|
|
2172
2024
|
return [];
|
|
2173
|
-
}),
|
|
2025
|
+
}), CHANGE_ACTIONS, function (oldSReturnInfo, newReturnInfo, key) {
|
|
2174
2026
|
var _returnInfoDiff$key$i = returnInfoDiff[key].items,
|
|
2175
|
-
|
|
2176
|
-
|
|
2027
|
+
items = _returnInfoDiff$key$i === void 0 ? {} : _returnInfoDiff$key$i;
|
|
2177
2028
|
if (Object.keys(items).length === 0) {
|
|
2178
2029
|
return [];
|
|
2179
2030
|
}
|
|
2180
|
-
|
|
2181
2031
|
return Object.keys(items).reduce(function (actions, index) {
|
|
2182
2032
|
var item = newReturnInfo.items[index];
|
|
2183
|
-
|
|
2184
2033
|
if (items[index].shipmentState) {
|
|
2185
2034
|
actions.push({
|
|
2186
2035
|
action: 'setReturnShipmentState',
|
|
@@ -2188,7 +2037,6 @@ function actionsMapReturnsInfo(diff, oldObj, newObj) {
|
|
|
2188
2037
|
shipmentState: item.shipmentState
|
|
2189
2038
|
});
|
|
2190
2039
|
}
|
|
2191
|
-
|
|
2192
2040
|
if (items[index].paymentState) {
|
|
2193
2041
|
actions.push({
|
|
2194
2042
|
action: 'setReturnPaymentState',
|
|
@@ -2196,10 +2044,9 @@ function actionsMapReturnsInfo(diff, oldObj, newObj) {
|
|
|
2196
2044
|
paymentState: item.paymentState
|
|
2197
2045
|
});
|
|
2198
2046
|
}
|
|
2199
|
-
|
|
2200
2047
|
return actions;
|
|
2201
2048
|
}, []);
|
|
2202
|
-
})
|
|
2049
|
+
}));
|
|
2203
2050
|
return handler(diff, oldObj, newObj);
|
|
2204
2051
|
}
|
|
2205
2052
|
|
|
@@ -2207,11 +2054,9 @@ function createOrderMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2207
2054
|
return function doMapActions(diff, newObj, oldObj) {
|
|
2208
2055
|
var allActions = [];
|
|
2209
2056
|
var deliveryHashMap;
|
|
2210
|
-
|
|
2211
2057
|
if (diff.shippingInfo && diff.shippingInfo.deliveries) {
|
|
2212
2058
|
deliveryHashMap = findMatchingPairs(diff.shippingInfo.deliveries, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries);
|
|
2213
2059
|
}
|
|
2214
|
-
|
|
2215
2060
|
allActions.push(mapActionGroup('base', function () {
|
|
2216
2061
|
return actionsMapBase$g(diff, oldObj, newObj, syncActionConfig);
|
|
2217
2062
|
}));
|
|
@@ -2233,14 +2078,15 @@ function createOrderMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2233
2078
|
return flatten__default["default"](allActions);
|
|
2234
2079
|
};
|
|
2235
2080
|
}
|
|
2236
|
-
|
|
2237
2081
|
var orders = (function (actionGroupList, syncActionConfig) {
|
|
2238
2082
|
// actionGroupList contains information about which action groups
|
|
2239
2083
|
// are allowed or ignored
|
|
2084
|
+
|
|
2240
2085
|
// createMapActionGroup returns function 'mapActionGroup' that takes params:
|
|
2241
2086
|
// - action group name
|
|
2242
2087
|
// - callback function that should return a list of actions that correspond
|
|
2243
2088
|
// to the for the action group
|
|
2089
|
+
|
|
2244
2090
|
// this resulting function mapActionGroup will call the callback function
|
|
2245
2091
|
// for allowed action groups and return the return value of the callback
|
|
2246
2092
|
// It will return an empty array for ignored action groups
|
|
@@ -2292,21 +2138,17 @@ function actionsMapBase$f(diff, oldObj, newObj) {
|
|
|
2292
2138
|
}
|
|
2293
2139
|
|
|
2294
2140
|
var validityActions = ['setValidFrom', 'setValidUntil'];
|
|
2295
|
-
|
|
2296
2141
|
var isValidityActions = function isValidityActions(actionName) {
|
|
2297
2142
|
return validityActions.includes(actionName);
|
|
2298
2143
|
};
|
|
2299
|
-
|
|
2300
2144
|
function combineValidityActions() {
|
|
2301
2145
|
var actions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
2302
|
-
|
|
2303
2146
|
var _actions$filter = actions.filter(function (item) {
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2147
|
+
return isValidityActions(item.action);
|
|
2148
|
+
}),
|
|
2149
|
+
_actions$filter2 = _slicedToArray(_actions$filter, 2),
|
|
2150
|
+
setValidFromAction = _actions$filter2[0],
|
|
2151
|
+
setValidUntilAction = _actions$filter2[1];
|
|
2310
2152
|
if (setValidFromAction && setValidUntilAction) {
|
|
2311
2153
|
return [].concat(_toConsumableArray(actions.filter(function (item) {
|
|
2312
2154
|
return !isValidityActions(item.action);
|
|
@@ -2316,7 +2158,6 @@ function combineValidityActions() {
|
|
|
2316
2158
|
validUntil: setValidUntilAction.validUntil
|
|
2317
2159
|
}]);
|
|
2318
2160
|
}
|
|
2319
|
-
|
|
2320
2161
|
return actions;
|
|
2321
2162
|
}
|
|
2322
2163
|
|
|
@@ -2329,7 +2170,6 @@ function createProductDiscountsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2329
2170
|
return combineValidityActions(flatten__default["default"](allActions));
|
|
2330
2171
|
};
|
|
2331
2172
|
}
|
|
2332
|
-
|
|
2333
2173
|
var productDiscounts = (function (actionGroupList) {
|
|
2334
2174
|
var syncActionConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2335
2175
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
@@ -2397,15 +2237,16 @@ function createDiscountCodesMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2397
2237
|
return combineValidityActions(flatten__default["default"](allActions));
|
|
2398
2238
|
};
|
|
2399
2239
|
}
|
|
2400
|
-
|
|
2401
2240
|
var discountCodes = (function (actionGroupList) {
|
|
2402
2241
|
var syncActionConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2403
2242
|
// actionGroupList contains information about which action groups
|
|
2404
2243
|
// are allowed or ignored
|
|
2244
|
+
|
|
2405
2245
|
// createMapActionGroup returns function 'mapActionGroup' that takes params:
|
|
2406
2246
|
// - action group name
|
|
2407
2247
|
// - callback function that should return a list of actions that correspond
|
|
2408
2248
|
// to the for the action group
|
|
2249
|
+
|
|
2409
2250
|
// this resulting function mapActionGroup will call the callback function
|
|
2410
2251
|
// for allowed action groups and return the return value of the callback
|
|
2411
2252
|
// It will return an empty array for ignored action groups
|
|
@@ -2447,7 +2288,6 @@ function createCustomerGroupMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2447
2288
|
return flatten__default["default"](allActions);
|
|
2448
2289
|
};
|
|
2449
2290
|
}
|
|
2450
|
-
|
|
2451
2291
|
var customerGroup = (function (actionGroupList) {
|
|
2452
2292
|
var syncActionConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2453
2293
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
@@ -2518,7 +2358,6 @@ function createCartDiscountsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2518
2358
|
return combineValidityActions(flatten__default["default"](allActions));
|
|
2519
2359
|
};
|
|
2520
2360
|
}
|
|
2521
|
-
|
|
2522
2361
|
var cartDiscounts = (function (actionGroupList) {
|
|
2523
2362
|
var syncActionConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2524
2363
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
@@ -2550,25 +2389,23 @@ function actionsMapBase$b(diff, oldObj, newObj) {
|
|
|
2550
2389
|
});
|
|
2551
2390
|
}
|
|
2552
2391
|
function actionsMapRates(diff, oldObj, newObj) {
|
|
2553
|
-
var
|
|
2554
|
-
|
|
2555
|
-
var handler = createBuildArrayActions('rates', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newObject) {
|
|
2392
|
+
var handler = createBuildArrayActions('rates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newObject) {
|
|
2556
2393
|
return {
|
|
2557
2394
|
action: 'addTaxRate',
|
|
2558
2395
|
taxRate: newObject
|
|
2559
2396
|
};
|
|
2560
|
-
}),
|
|
2397
|
+
}), REMOVE_ACTIONS, function (objectToRemove) {
|
|
2561
2398
|
return {
|
|
2562
2399
|
action: 'removeTaxRate',
|
|
2563
2400
|
taxRateId: objectToRemove.id
|
|
2564
2401
|
};
|
|
2565
|
-
}),
|
|
2402
|
+
}), CHANGE_ACTIONS, function (oldObject, updatedObject) {
|
|
2566
2403
|
return {
|
|
2567
2404
|
action: 'replaceTaxRate',
|
|
2568
2405
|
taxRateId: oldObject.id === updatedObject.id ? oldObject.id : updatedObject.id,
|
|
2569
2406
|
taxRate: updatedObject
|
|
2570
2407
|
};
|
|
2571
|
-
})
|
|
2408
|
+
}));
|
|
2572
2409
|
return handler(diff, oldObj, newObj);
|
|
2573
2410
|
}
|
|
2574
2411
|
|
|
@@ -2584,14 +2421,15 @@ function createTaxCategoriesMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2584
2421
|
return flatten__default["default"](allActions);
|
|
2585
2422
|
};
|
|
2586
2423
|
}
|
|
2587
|
-
|
|
2588
2424
|
var taxCategories = (function (actionGroupList, syncActionConfig) {
|
|
2589
2425
|
// config contains information about which action groups
|
|
2590
2426
|
// are allowed or ignored
|
|
2427
|
+
|
|
2591
2428
|
// createMapActionGroup returns function 'mapActionGroup' that takes params:
|
|
2592
2429
|
// - action group name
|
|
2593
2430
|
// - callback function that should return a list of actions that correspond
|
|
2594
2431
|
// to the for the action group
|
|
2432
|
+
|
|
2595
2433
|
// this resulting function mapActionGroup will call the callback function
|
|
2596
2434
|
// for allowed action groups and return the return value of the callback
|
|
2597
2435
|
// It will return an empty array for ignored action groups
|
|
@@ -2613,13 +2451,11 @@ var baseActionsList$a = [{
|
|
|
2613
2451
|
action: 'setKey',
|
|
2614
2452
|
key: 'key'
|
|
2615
2453
|
}];
|
|
2616
|
-
|
|
2617
2454
|
var hasLocation = function hasLocation(locations, otherLocation) {
|
|
2618
2455
|
return locations.some(function (location) {
|
|
2619
2456
|
return location.country === otherLocation.country;
|
|
2620
2457
|
});
|
|
2621
2458
|
};
|
|
2622
|
-
|
|
2623
2459
|
function actionsMapBase$a(diff, oldObj, newObj) {
|
|
2624
2460
|
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2625
2461
|
return buildBaseAttributesActions({
|
|
@@ -2631,36 +2467,37 @@ function actionsMapBase$a(diff, oldObj, newObj) {
|
|
|
2631
2467
|
});
|
|
2632
2468
|
}
|
|
2633
2469
|
function actionsMapLocations(diff, oldObj, newObj) {
|
|
2634
|
-
var
|
|
2635
|
-
|
|
2636
|
-
var handler = createBuildArrayActions('locations', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newLocation) {
|
|
2470
|
+
var handler = createBuildArrayActions('locations', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newLocation) {
|
|
2637
2471
|
return {
|
|
2638
2472
|
action: 'addLocation',
|
|
2639
2473
|
location: newLocation
|
|
2640
2474
|
};
|
|
2641
|
-
}),
|
|
2642
|
-
return (
|
|
2475
|
+
}), REMOVE_ACTIONS, function (oldLocation) {
|
|
2476
|
+
return (
|
|
2477
|
+
// We only add the action if the location is not included in the new object.
|
|
2643
2478
|
!hasLocation(newObj.locations, oldLocation) ? {
|
|
2644
2479
|
action: 'removeLocation',
|
|
2645
2480
|
location: oldLocation
|
|
2646
2481
|
} : null
|
|
2647
2482
|
);
|
|
2648
|
-
}),
|
|
2649
|
-
var result = [];
|
|
2650
|
-
// included in the new object
|
|
2483
|
+
}), CHANGE_ACTIONS, function (oldLocation, newLocation) {
|
|
2484
|
+
var result = [];
|
|
2651
2485
|
|
|
2486
|
+
// We only remove the location in case that the oldLocation is not
|
|
2487
|
+
// included in the new object
|
|
2652
2488
|
if (!hasLocation(newObj.locations, oldLocation)) result.push({
|
|
2653
2489
|
action: 'removeLocation',
|
|
2654
2490
|
location: oldLocation
|
|
2655
|
-
});
|
|
2656
|
-
// included in the old object
|
|
2491
|
+
});
|
|
2657
2492
|
|
|
2493
|
+
// We only add the location in case that the newLocation was not
|
|
2494
|
+
// included in the old object
|
|
2658
2495
|
if (!hasLocation(oldObj.locations, newLocation)) result.push({
|
|
2659
2496
|
action: 'addLocation',
|
|
2660
2497
|
location: newLocation
|
|
2661
2498
|
});
|
|
2662
2499
|
return result;
|
|
2663
|
-
})
|
|
2500
|
+
}));
|
|
2664
2501
|
return handler(diff, oldObj, newObj);
|
|
2665
2502
|
}
|
|
2666
2503
|
|
|
@@ -2676,14 +2513,15 @@ function createZonesMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2676
2513
|
return flatten__default["default"](allActions);
|
|
2677
2514
|
};
|
|
2678
2515
|
}
|
|
2679
|
-
|
|
2680
2516
|
var zones = (function (actionGroupList, syncActionConfig) {
|
|
2681
2517
|
// config contains information about which action groups
|
|
2682
2518
|
// are allowed or ignored
|
|
2519
|
+
|
|
2683
2520
|
// createMapActionGroup returns function 'mapActionGroup' that takes params:
|
|
2684
2521
|
// - action group name
|
|
2685
2522
|
// - callback function that should return a list of actions that correspond
|
|
2686
2523
|
// to the for the action group
|
|
2524
|
+
|
|
2687
2525
|
// this resulting function mapActionGroup will call the callback function
|
|
2688
2526
|
// for allowed action groups and return the return value of the callback
|
|
2689
2527
|
// It will return an empty array for ignored action groups
|
|
@@ -2719,6 +2557,9 @@ var baseActionsList$9 = [{
|
|
|
2719
2557
|
}, {
|
|
2720
2558
|
action: 'changeTaxCategory',
|
|
2721
2559
|
key: 'taxCategory'
|
|
2560
|
+
}, {
|
|
2561
|
+
action: 'changeActive',
|
|
2562
|
+
key: 'active'
|
|
2722
2563
|
}];
|
|
2723
2564
|
function actionsMapBase$9(diff, oldObj, newObj) {
|
|
2724
2565
|
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
@@ -2730,7 +2571,6 @@ function actionsMapBase$9(diff, oldObj, newObj) {
|
|
|
2730
2571
|
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
2731
2572
|
});
|
|
2732
2573
|
}
|
|
2733
|
-
|
|
2734
2574
|
var addShippingRates = function addShippingRates(newZoneRate) {
|
|
2735
2575
|
return newZoneRate.shippingRates ? newZoneRate.shippingRates.map(function (shippingRate) {
|
|
2736
2576
|
return {
|
|
@@ -2740,23 +2580,20 @@ var addShippingRates = function addShippingRates(newZoneRate) {
|
|
|
2740
2580
|
};
|
|
2741
2581
|
}) : [];
|
|
2742
2582
|
};
|
|
2743
|
-
|
|
2744
2583
|
function actionsMapZoneRatesShippingRates(diff, oldObj, newObj) {
|
|
2745
|
-
var
|
|
2746
|
-
|
|
2747
|
-
var handler = createBuildArrayActions('shippingRates', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newShippingRate) {
|
|
2584
|
+
var handler = createBuildArrayActions('shippingRates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newShippingRate) {
|
|
2748
2585
|
return {
|
|
2749
2586
|
action: 'addShippingRate',
|
|
2750
2587
|
zone: newObj.zone,
|
|
2751
2588
|
shippingRate: newShippingRate
|
|
2752
2589
|
};
|
|
2753
|
-
}),
|
|
2590
|
+
}), REMOVE_ACTIONS, function (oldShippingRate) {
|
|
2754
2591
|
return {
|
|
2755
2592
|
action: 'removeShippingRate',
|
|
2756
2593
|
zone: oldObj.zone,
|
|
2757
2594
|
shippingRate: oldShippingRate
|
|
2758
2595
|
};
|
|
2759
|
-
}),
|
|
2596
|
+
}), CHANGE_ACTIONS, function (oldShippingRate, newShippingRate) {
|
|
2760
2597
|
return [{
|
|
2761
2598
|
action: 'removeShippingRate',
|
|
2762
2599
|
zone: oldObj.zone,
|
|
@@ -2766,24 +2603,21 @@ function actionsMapZoneRatesShippingRates(diff, oldObj, newObj) {
|
|
|
2766
2603
|
zone: newObj.zone,
|
|
2767
2604
|
shippingRate: newShippingRate
|
|
2768
2605
|
}];
|
|
2769
|
-
})
|
|
2606
|
+
}));
|
|
2770
2607
|
return handler(diff, oldObj, newObj);
|
|
2771
2608
|
}
|
|
2772
|
-
|
|
2773
2609
|
function actionsMapZoneRates(diff, oldObj, newObj) {
|
|
2774
|
-
var
|
|
2775
|
-
|
|
2776
|
-
var handler = createBuildArrayActions('zoneRates', (_createBuildArrayActi2 = {}, _defineProperty(_createBuildArrayActi2, ADD_ACTIONS, function (newZoneRate) {
|
|
2610
|
+
var handler = createBuildArrayActions('zoneRates', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newZoneRate) {
|
|
2777
2611
|
return [{
|
|
2778
2612
|
action: 'addZone',
|
|
2779
2613
|
zone: newZoneRate.zone
|
|
2780
2614
|
}].concat(_toConsumableArray(addShippingRates(newZoneRate)));
|
|
2781
|
-
}),
|
|
2615
|
+
}), REMOVE_ACTIONS, function (oldZoneRate) {
|
|
2782
2616
|
return {
|
|
2783
2617
|
action: 'removeZone',
|
|
2784
2618
|
zone: oldZoneRate.zone
|
|
2785
2619
|
};
|
|
2786
|
-
}),
|
|
2620
|
+
}), CHANGE_ACTIONS, function (oldZoneRate, newZoneRate) {
|
|
2787
2621
|
var hasZoneActions = false;
|
|
2788
2622
|
var shippingRateActions = Object.keys(diff.zoneRates).reduce(function (actions, key) {
|
|
2789
2623
|
if (diff.zoneRates[key].zone) hasZoneActions = true;
|
|
@@ -2797,7 +2631,7 @@ function actionsMapZoneRates(diff, oldObj, newObj) {
|
|
|
2797
2631
|
action: 'addZone',
|
|
2798
2632
|
zone: newZoneRate.zone
|
|
2799
2633
|
}]) : shippingRateActions);
|
|
2800
|
-
})
|
|
2634
|
+
}));
|
|
2801
2635
|
return handler(diff, oldObj, newObj);
|
|
2802
2636
|
}
|
|
2803
2637
|
|
|
@@ -2816,14 +2650,15 @@ function createShippingMethodsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2816
2650
|
return flatten__default["default"](allActions);
|
|
2817
2651
|
};
|
|
2818
2652
|
}
|
|
2819
|
-
|
|
2820
2653
|
var shippingMethods = (function (actionGroupList, syncActionConfig) {
|
|
2821
2654
|
// actionGroupList contains information about which action groups
|
|
2822
2655
|
// are allowed or ignored
|
|
2656
|
+
|
|
2823
2657
|
// createMapActionGroup returns function 'mapActionGroup' that takes params:
|
|
2824
2658
|
// - action group name
|
|
2825
2659
|
// - callback function that should return a list of actions that correspond
|
|
2826
2660
|
// to the for the action group
|
|
2661
|
+
|
|
2827
2662
|
// this resulting function mapActionGroup will call the callback function
|
|
2828
2663
|
// for allowed action groups and return the return value of the callback
|
|
2829
2664
|
// It will return an empty array for ignored action groups
|
|
@@ -2844,7 +2679,6 @@ var keys = Object.keys;
|
|
|
2844
2679
|
* @param b the value to test
|
|
2845
2680
|
* @returns are the values equal by the SameValueZero principle
|
|
2846
2681
|
*/
|
|
2847
|
-
|
|
2848
2682
|
function sameValueZeroEqual(a, b) {
|
|
2849
2683
|
return a === b || a !== a && b !== b;
|
|
2850
2684
|
}
|
|
@@ -2854,8 +2688,6 @@ function sameValueZeroEqual(a, b) {
|
|
|
2854
2688
|
* @param value the value to test
|
|
2855
2689
|
* @returns is the value a plain object
|
|
2856
2690
|
*/
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
2691
|
function isPlainObject(value) {
|
|
2860
2692
|
return value.constructor === Object || value.constructor == null;
|
|
2861
2693
|
}
|
|
@@ -2865,8 +2697,6 @@ function isPlainObject(value) {
|
|
|
2865
2697
|
* @param value the value to test
|
|
2866
2698
|
* @returns is the value promise-like
|
|
2867
2699
|
*/
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
2700
|
function isPromiseLike(value) {
|
|
2871
2701
|
return !!value && typeof value.then === 'function';
|
|
2872
2702
|
}
|
|
@@ -2876,8 +2706,6 @@ function isPromiseLike(value) {
|
|
|
2876
2706
|
* @param value the value to test
|
|
2877
2707
|
* @returns is the value a react element
|
|
2878
2708
|
*/
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
2709
|
function isReactElement(value) {
|
|
2882
2710
|
return !!(value && value.$$typeof);
|
|
2883
2711
|
}
|
|
@@ -2887,8 +2715,6 @@ function isReactElement(value) {
|
|
|
2887
2715
|
*
|
|
2888
2716
|
* @returns the new cache object
|
|
2889
2717
|
*/
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
2718
|
function getNewCacheFallback() {
|
|
2893
2719
|
var values = [];
|
|
2894
2720
|
return {
|
|
@@ -2905,15 +2731,12 @@ function getNewCacheFallback() {
|
|
|
2905
2731
|
*
|
|
2906
2732
|
* @returns the new cache object
|
|
2907
2733
|
*/
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
2734
|
var getNewCache = function (canUseWeakMap) {
|
|
2911
2735
|
if (canUseWeakMap) {
|
|
2912
2736
|
return function _getNewCache() {
|
|
2913
2737
|
return new WeakSet();
|
|
2914
2738
|
};
|
|
2915
2739
|
}
|
|
2916
|
-
|
|
2917
2740
|
return getNewCacheFallback;
|
|
2918
2741
|
}(HAS_WEAKSET_SUPPORT);
|
|
2919
2742
|
/**
|
|
@@ -2922,37 +2745,28 @@ var getNewCache = function (canUseWeakMap) {
|
|
|
2922
2745
|
* @param [isEqual] the isEqual comparator to use instead of isDeepEqual
|
|
2923
2746
|
* @returns the method to create the `isEqual` function
|
|
2924
2747
|
*/
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
2748
|
function createCircularEqualCreator(isEqual) {
|
|
2928
2749
|
return function createCircularEqual(comparator) {
|
|
2929
2750
|
var _comparator = isEqual || comparator;
|
|
2930
|
-
|
|
2931
2751
|
return function circularEqual(a, b, cache) {
|
|
2932
2752
|
if (cache === void 0) {
|
|
2933
2753
|
cache = getNewCache();
|
|
2934
2754
|
}
|
|
2935
|
-
|
|
2936
2755
|
var isCacheableA = !!a && _typeof(a) === 'object';
|
|
2937
2756
|
var isCacheableB = !!b && _typeof(b) === 'object';
|
|
2938
|
-
|
|
2939
2757
|
if (isCacheableA || isCacheableB) {
|
|
2940
2758
|
var hasA = isCacheableA && cache.has(a);
|
|
2941
2759
|
var hasB = isCacheableB && cache.has(b);
|
|
2942
|
-
|
|
2943
2760
|
if (hasA || hasB) {
|
|
2944
2761
|
return hasA && hasB;
|
|
2945
2762
|
}
|
|
2946
|
-
|
|
2947
2763
|
if (isCacheableA) {
|
|
2948
2764
|
cache.add(a);
|
|
2949
2765
|
}
|
|
2950
|
-
|
|
2951
2766
|
if (isCacheableB) {
|
|
2952
2767
|
cache.add(b);
|
|
2953
2768
|
}
|
|
2954
2769
|
}
|
|
2955
|
-
|
|
2956
2770
|
return _comparator(a, b, cache);
|
|
2957
2771
|
};
|
|
2958
2772
|
};
|
|
@@ -2966,21 +2780,16 @@ function createCircularEqualCreator(isEqual) {
|
|
|
2966
2780
|
* @param meta the meta object to pass through
|
|
2967
2781
|
* @returns are the arrays equal
|
|
2968
2782
|
*/
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
2783
|
function areArraysEqual(a, b, isEqual, meta) {
|
|
2972
2784
|
var index = a.length;
|
|
2973
|
-
|
|
2974
2785
|
if (b.length !== index) {
|
|
2975
2786
|
return false;
|
|
2976
2787
|
}
|
|
2977
|
-
|
|
2978
2788
|
while (index-- > 0) {
|
|
2979
2789
|
if (!isEqual(a[index], b[index], meta)) {
|
|
2980
2790
|
return false;
|
|
2981
2791
|
}
|
|
2982
2792
|
}
|
|
2983
|
-
|
|
2984
2793
|
return true;
|
|
2985
2794
|
}
|
|
2986
2795
|
/**
|
|
@@ -2992,11 +2801,8 @@ function areArraysEqual(a, b, isEqual, meta) {
|
|
|
2992
2801
|
* @param meta the meta map to pass through
|
|
2993
2802
|
* @returns are the maps equal
|
|
2994
2803
|
*/
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
2804
|
function areMapsEqual(a, b, isEqual, meta) {
|
|
2998
2805
|
var isValueEqual = a.size === b.size;
|
|
2999
|
-
|
|
3000
2806
|
if (isValueEqual && a.size) {
|
|
3001
2807
|
var matchedIndices_1 = {};
|
|
3002
2808
|
a.forEach(function (aValue, aKey) {
|
|
@@ -3006,22 +2812,18 @@ function areMapsEqual(a, b, isEqual, meta) {
|
|
|
3006
2812
|
b.forEach(function (bValue, bKey) {
|
|
3007
2813
|
if (!hasMatch_1 && !matchedIndices_1[matchIndex_1]) {
|
|
3008
2814
|
hasMatch_1 = isEqual(aKey, bKey, meta) && isEqual(aValue, bValue, meta);
|
|
3009
|
-
|
|
3010
2815
|
if (hasMatch_1) {
|
|
3011
2816
|
matchedIndices_1[matchIndex_1] = true;
|
|
3012
2817
|
}
|
|
3013
2818
|
}
|
|
3014
|
-
|
|
3015
2819
|
matchIndex_1++;
|
|
3016
2820
|
});
|
|
3017
2821
|
isValueEqual = hasMatch_1;
|
|
3018
2822
|
}
|
|
3019
2823
|
});
|
|
3020
2824
|
}
|
|
3021
|
-
|
|
3022
2825
|
return isValueEqual;
|
|
3023
2826
|
}
|
|
3024
|
-
|
|
3025
2827
|
var OWNER = '_owner';
|
|
3026
2828
|
var hasOwnProperty = Function.prototype.bind.call(Function.prototype.call, Object.prototype.hasOwnProperty);
|
|
3027
2829
|
/**
|
|
@@ -3033,36 +2835,28 @@ var hasOwnProperty = Function.prototype.bind.call(Function.prototype.call, Objec
|
|
|
3033
2835
|
* @param meta the meta object to pass through
|
|
3034
2836
|
* @returns are the objects equal
|
|
3035
2837
|
*/
|
|
3036
|
-
|
|
3037
2838
|
function areObjectsEqual(a, b, isEqual, meta) {
|
|
3038
2839
|
var keysA = keys(a);
|
|
3039
2840
|
var index = keysA.length;
|
|
3040
|
-
|
|
3041
2841
|
if (keys(b).length !== index) {
|
|
3042
2842
|
return false;
|
|
3043
2843
|
}
|
|
3044
|
-
|
|
3045
2844
|
if (index) {
|
|
3046
2845
|
var key = void 0;
|
|
3047
|
-
|
|
3048
2846
|
while (index-- > 0) {
|
|
3049
2847
|
key = keysA[index];
|
|
3050
|
-
|
|
3051
2848
|
if (key === OWNER) {
|
|
3052
2849
|
var reactElementA = isReactElement(a);
|
|
3053
2850
|
var reactElementB = isReactElement(b);
|
|
3054
|
-
|
|
3055
2851
|
if ((reactElementA || reactElementB) && reactElementA !== reactElementB) {
|
|
3056
2852
|
return false;
|
|
3057
2853
|
}
|
|
3058
2854
|
}
|
|
3059
|
-
|
|
3060
2855
|
if (!hasOwnProperty(b, key) || !isEqual(a[key], b[key], meta)) {
|
|
3061
2856
|
return false;
|
|
3062
2857
|
}
|
|
3063
2858
|
}
|
|
3064
2859
|
}
|
|
3065
|
-
|
|
3066
2860
|
return true;
|
|
3067
2861
|
}
|
|
3068
2862
|
/**
|
|
@@ -3072,8 +2866,6 @@ function areObjectsEqual(a, b, isEqual, meta) {
|
|
|
3072
2866
|
* @param b the regExp to test agains
|
|
3073
2867
|
* @returns are the regExps equal
|
|
3074
2868
|
*/
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
2869
|
function areRegExpsEqual(a, b) {
|
|
3078
2870
|
return a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.unicode === b.unicode && a.sticky === b.sticky && a.lastIndex === b.lastIndex;
|
|
3079
2871
|
}
|
|
@@ -3086,11 +2878,8 @@ function areRegExpsEqual(a, b) {
|
|
|
3086
2878
|
* @param meta the meta set to pass through
|
|
3087
2879
|
* @returns are the sets equal
|
|
3088
2880
|
*/
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
2881
|
function areSetsEqual(a, b, isEqual, meta) {
|
|
3092
2882
|
var isValueEqual = a.size === b.size;
|
|
3093
|
-
|
|
3094
2883
|
if (isValueEqual && a.size) {
|
|
3095
2884
|
var matchedIndices_2 = {};
|
|
3096
2885
|
a.forEach(function (aValue) {
|
|
@@ -3100,31 +2889,24 @@ function areSetsEqual(a, b, isEqual, meta) {
|
|
|
3100
2889
|
b.forEach(function (bValue) {
|
|
3101
2890
|
if (!hasMatch_2 && !matchedIndices_2[matchIndex_2]) {
|
|
3102
2891
|
hasMatch_2 = isEqual(aValue, bValue, meta);
|
|
3103
|
-
|
|
3104
2892
|
if (hasMatch_2) {
|
|
3105
2893
|
matchedIndices_2[matchIndex_2] = true;
|
|
3106
2894
|
}
|
|
3107
2895
|
}
|
|
3108
|
-
|
|
3109
2896
|
matchIndex_2++;
|
|
3110
2897
|
});
|
|
3111
2898
|
isValueEqual = hasMatch_2;
|
|
3112
2899
|
}
|
|
3113
2900
|
});
|
|
3114
2901
|
}
|
|
3115
|
-
|
|
3116
2902
|
return isValueEqual;
|
|
3117
2903
|
}
|
|
3118
|
-
|
|
3119
2904
|
var HAS_MAP_SUPPORT = typeof Map === 'function';
|
|
3120
2905
|
var HAS_SET_SUPPORT = typeof Set === 'function';
|
|
3121
|
-
|
|
3122
2906
|
function createComparator(createIsEqual) {
|
|
3123
|
-
var isEqual =
|
|
3124
|
-
/* eslint-disable no-use-before-define */
|
|
2907
|
+
var isEqual = /* eslint-disable no-use-before-define */
|
|
3125
2908
|
typeof createIsEqual === 'function' ? createIsEqual(comparator) : comparator;
|
|
3126
2909
|
/* eslint-enable */
|
|
3127
|
-
|
|
3128
2910
|
/**
|
|
3129
2911
|
* compare the value of the two objects and return true if they are equivalent in values
|
|
3130
2912
|
*
|
|
@@ -3133,69 +2915,52 @@ function createComparator(createIsEqual) {
|
|
|
3133
2915
|
* @param [meta] an optional meta object that is passed through to all equality test calls
|
|
3134
2916
|
* @returns are a and b equivalent in value
|
|
3135
2917
|
*/
|
|
3136
|
-
|
|
3137
2918
|
function comparator(a, b, meta) {
|
|
3138
2919
|
if (a === b) {
|
|
3139
2920
|
return true;
|
|
3140
2921
|
}
|
|
3141
|
-
|
|
3142
2922
|
if (a && b && _typeof(a) === 'object' && _typeof(b) === 'object') {
|
|
3143
2923
|
if (isPlainObject(a) && isPlainObject(b)) {
|
|
3144
2924
|
return areObjectsEqual(a, b, isEqual, meta);
|
|
3145
2925
|
}
|
|
3146
|
-
|
|
3147
2926
|
var aShape = Array.isArray(a);
|
|
3148
2927
|
var bShape = Array.isArray(b);
|
|
3149
|
-
|
|
3150
2928
|
if (aShape || bShape) {
|
|
3151
2929
|
return aShape === bShape && areArraysEqual(a, b, isEqual, meta);
|
|
3152
2930
|
}
|
|
3153
|
-
|
|
3154
2931
|
aShape = a instanceof Date;
|
|
3155
2932
|
bShape = b instanceof Date;
|
|
3156
|
-
|
|
3157
2933
|
if (aShape || bShape) {
|
|
3158
2934
|
return aShape === bShape && sameValueZeroEqual(a.getTime(), b.getTime());
|
|
3159
2935
|
}
|
|
3160
|
-
|
|
3161
2936
|
aShape = a instanceof RegExp;
|
|
3162
2937
|
bShape = b instanceof RegExp;
|
|
3163
|
-
|
|
3164
2938
|
if (aShape || bShape) {
|
|
3165
2939
|
return aShape === bShape && areRegExpsEqual(a, b);
|
|
3166
2940
|
}
|
|
3167
|
-
|
|
3168
2941
|
if (isPromiseLike(a) || isPromiseLike(b)) {
|
|
3169
2942
|
return a === b;
|
|
3170
2943
|
}
|
|
3171
|
-
|
|
3172
2944
|
if (HAS_MAP_SUPPORT) {
|
|
3173
2945
|
aShape = a instanceof Map;
|
|
3174
2946
|
bShape = b instanceof Map;
|
|
3175
|
-
|
|
3176
2947
|
if (aShape || bShape) {
|
|
3177
2948
|
return aShape === bShape && areMapsEqual(a, b, isEqual, meta);
|
|
3178
2949
|
}
|
|
3179
2950
|
}
|
|
3180
|
-
|
|
3181
2951
|
if (HAS_SET_SUPPORT) {
|
|
3182
2952
|
aShape = a instanceof Set;
|
|
3183
2953
|
bShape = b instanceof Set;
|
|
3184
|
-
|
|
3185
2954
|
if (aShape || bShape) {
|
|
3186
2955
|
return aShape === bShape && areSetsEqual(a, b, isEqual, meta);
|
|
3187
2956
|
}
|
|
3188
2957
|
}
|
|
3189
|
-
|
|
3190
2958
|
return areObjectsEqual(a, b, isEqual, meta);
|
|
3191
2959
|
}
|
|
3192
|
-
|
|
3193
2960
|
return a !== a && b !== b;
|
|
3194
2961
|
}
|
|
3195
|
-
|
|
3196
2962
|
return comparator;
|
|
3197
2963
|
}
|
|
3198
|
-
|
|
3199
2964
|
var deepEqual = createComparator();
|
|
3200
2965
|
createComparator(function () {
|
|
3201
2966
|
return sameValueZeroEqual;
|
|
@@ -3226,21 +2991,20 @@ function actionsMapBase$8(diff, previous, next) {
|
|
|
3226
2991
|
newObj: next,
|
|
3227
2992
|
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
3228
2993
|
});
|
|
3229
|
-
}
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
// this is nearly similar to `buildBaseAttributesActions`, however with a significant difference.
|
|
3230
2997
|
// `buildBasAttributesActions` generates update-actions with help of `diff`,
|
|
3231
2998
|
// which is an object consisting of flags which indicates different operations.
|
|
3232
2999
|
// `generateBaseFieldsUpdateActions` only generate based on `previous` and `next`.
|
|
3233
|
-
|
|
3234
3000
|
var generateBaseFieldsUpdateActions = function generateBaseFieldsUpdateActions(previous, next, actionDefinition) {
|
|
3235
3001
|
var isEmpty = createIsEmptyValue([undefined, null, '']);
|
|
3236
3002
|
return Object.entries(actionDefinition).reduce(function (nextUpdateActions, _ref) {
|
|
3237
3003
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3004
|
+
field = _ref2[0],
|
|
3005
|
+
actionFieldDefinition = _ref2[1];
|
|
3241
3006
|
if (isEmpty(previous[field]) && isEmpty(next[field])) return nextUpdateActions;
|
|
3242
3007
|
if (!isEmpty(previous[field]) && isEmpty(next[field])) return [].concat(_toConsumableArray(nextUpdateActions), [actionFieldDefinition]);
|
|
3243
|
-
|
|
3244
3008
|
if (!deepEqual(previous[field], next[field])) {
|
|
3245
3009
|
switch (field) {
|
|
3246
3010
|
// BEWARE that this is generates update-action only for key of enum attribute value,
|
|
@@ -3248,7 +3012,8 @@ var generateBaseFieldsUpdateActions = function generateBaseFieldsUpdateActions(p
|
|
|
3248
3012
|
// `generateBaseFieldsUpdateActions`, we need to extract the following logic so we could
|
|
3249
3013
|
// cover both entity types.
|
|
3250
3014
|
case 'key':
|
|
3251
|
-
return [].concat(_toConsumableArray(nextUpdateActions), [
|
|
3015
|
+
return [].concat(_toConsumableArray(nextUpdateActions), [
|
|
3016
|
+
// Another option is to have explicit name of `field` e.g `enumKey`, which we could use to
|
|
3252
3017
|
// generate appropriate update-action for respective entity type.
|
|
3253
3018
|
// An outline of this on the top of my head:
|
|
3254
3019
|
// ```js
|
|
@@ -3278,7 +3043,6 @@ var generateBaseFieldsUpdateActions = function generateBaseFieldsUpdateActions(p
|
|
|
3278
3043
|
newKey: next[field]
|
|
3279
3044
|
}]);
|
|
3280
3045
|
// attribute
|
|
3281
|
-
|
|
3282
3046
|
case 'attributeConstraint':
|
|
3283
3047
|
case 'inputHint':
|
|
3284
3048
|
return [].concat(_toConsumableArray(nextUpdateActions), [{
|
|
@@ -3286,7 +3050,6 @@ var generateBaseFieldsUpdateActions = function generateBaseFieldsUpdateActions(p
|
|
|
3286
3050
|
attributeName: actionFieldDefinition.attributeName,
|
|
3287
3051
|
newValue: next[field]
|
|
3288
3052
|
}]);
|
|
3289
|
-
|
|
3290
3053
|
default:
|
|
3291
3054
|
return [].concat(_toConsumableArray(nextUpdateActions), [_defineProperty({
|
|
3292
3055
|
action: actionFieldDefinition.action,
|
|
@@ -3294,11 +3057,9 @@ var generateBaseFieldsUpdateActions = function generateBaseFieldsUpdateActions(p
|
|
|
3294
3057
|
}, field, next[field])]);
|
|
3295
3058
|
}
|
|
3296
3059
|
}
|
|
3297
|
-
|
|
3298
3060
|
return nextUpdateActions;
|
|
3299
3061
|
}, []);
|
|
3300
3062
|
};
|
|
3301
|
-
|
|
3302
3063
|
var generateUpdateActionsForAttributeDefinitions = function generateUpdateActionsForAttributeDefinitions() {
|
|
3303
3064
|
var attributeDefinitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3304
3065
|
var removedAttributeDefinitions = attributeDefinitions.filter(function (attributeDefinition) {
|
|
@@ -3345,7 +3106,6 @@ var generateUpdateActionsForAttributeDefinitions = function generateUpdateAction
|
|
|
3345
3106
|
};
|
|
3346
3107
|
})));
|
|
3347
3108
|
};
|
|
3348
|
-
|
|
3349
3109
|
var generateUpdateActionsForAttributeEnumValues = function generateUpdateActionsForAttributeEnumValues() {
|
|
3350
3110
|
var attributeEnumValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3351
3111
|
var removedAttributeEnumValues = attributeEnumValues.filter(function (attributeEnumValue) {
|
|
@@ -3373,7 +3133,6 @@ var generateUpdateActionsForAttributeEnumValues = function generateUpdateActions
|
|
|
3373
3133
|
attributeName: updatedAttributeEnumValue.hint.attributeName
|
|
3374
3134
|
}
|
|
3375
3135
|
});
|
|
3376
|
-
|
|
3377
3136
|
if (!deepEqual(updatedAttributeEnumValue.previous.label, updatedAttributeEnumValue.next.label)) {
|
|
3378
3137
|
if (updatedAttributeEnumValue.hint.isLocalized) {
|
|
3379
3138
|
return [].concat(_toConsumableArray(updateActions), [{
|
|
@@ -3382,14 +3141,12 @@ var generateUpdateActionsForAttributeEnumValues = function generateUpdateActions
|
|
|
3382
3141
|
newValue: updatedAttributeEnumValue.next
|
|
3383
3142
|
}]);
|
|
3384
3143
|
}
|
|
3385
|
-
|
|
3386
3144
|
return [].concat(_toConsumableArray(updateActions), [{
|
|
3387
3145
|
action: 'changePlainEnumValueLabel',
|
|
3388
3146
|
attributeName: updatedAttributeEnumValue.hint.attributeName,
|
|
3389
3147
|
newValue: updatedAttributeEnumValue.next
|
|
3390
3148
|
}]);
|
|
3391
3149
|
}
|
|
3392
|
-
|
|
3393
3150
|
return updateActions;
|
|
3394
3151
|
}))), _toConsumableArray(addedAttributeEnumValues.map(function (addedAttributeEnumValue) {
|
|
3395
3152
|
return {
|
|
@@ -3399,7 +3156,6 @@ var generateUpdateActionsForAttributeEnumValues = function generateUpdateActions
|
|
|
3399
3156
|
};
|
|
3400
3157
|
})));
|
|
3401
3158
|
};
|
|
3402
|
-
|
|
3403
3159
|
var generateChangeAttributeOrderAction = function generateChangeAttributeOrderAction() {
|
|
3404
3160
|
var attrsOld = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3405
3161
|
var attrsNew = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -3417,9 +3173,10 @@ var generateChangeAttributeOrderAction = function generateChangeAttributeOrderAc
|
|
|
3417
3173
|
return action.action === 'addAttributeDefinition';
|
|
3418
3174
|
}).map(function (action) {
|
|
3419
3175
|
return action.attribute.name;
|
|
3420
|
-
});
|
|
3421
|
-
// calculate how the productType will look like after adding/removing attributes
|
|
3176
|
+
});
|
|
3422
3177
|
|
|
3178
|
+
// changeAttributeOrder action will be sent to CTP API as the last action so we have to
|
|
3179
|
+
// calculate how the productType will look like after adding/removing attributes
|
|
3423
3180
|
var patchedOldAttributesOrder = attrsOld.map(function (attribute) {
|
|
3424
3181
|
return attribute.name;
|
|
3425
3182
|
}).filter(function (name) {
|
|
@@ -3431,7 +3188,6 @@ var generateChangeAttributeOrderAction = function generateChangeAttributeOrderAc
|
|
|
3431
3188
|
};
|
|
3432
3189
|
return null;
|
|
3433
3190
|
};
|
|
3434
|
-
|
|
3435
3191
|
var actionsMapForHints = function actionsMapForHints() {
|
|
3436
3192
|
var nestedValuesChanges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3437
3193
|
var ptOld = arguments.length > 1 ? arguments[1] : undefined;
|
|
@@ -3444,14 +3200,14 @@ var actionsMapForHints = function actionsMapForHints() {
|
|
|
3444
3200
|
|
|
3445
3201
|
function createProductTypeMapActions(mapActionGroup, syncActionConfig) {
|
|
3446
3202
|
return function doMapActions(diff, next, previous, options) {
|
|
3447
|
-
return flatten__default["default"]([
|
|
3203
|
+
return flatten__default["default"]([
|
|
3204
|
+
// we support only base fields for the product type,
|
|
3448
3205
|
// for attributes, applying hints would be recommended
|
|
3449
3206
|
mapActionGroup('base', function () {
|
|
3450
3207
|
return actionsMapBase$8(diff, previous, next, syncActionConfig);
|
|
3451
3208
|
}), actionsMapForHints(options.nestedValuesChanges, previous, next)]);
|
|
3452
3209
|
};
|
|
3453
3210
|
}
|
|
3454
|
-
|
|
3455
3211
|
var productTypes = (function (actionGroupList, syncActionConfig) {
|
|
3456
3212
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
3457
3213
|
var doMapActions = createProductTypeMapActions(mapActionGroup, syncActionConfig);
|
|
@@ -3494,26 +3250,24 @@ function actionsMapBase$7(diff, oldObj, newObj) {
|
|
|
3494
3250
|
});
|
|
3495
3251
|
}
|
|
3496
3252
|
function actionsMapRoles(diff, oldObj, newObj) {
|
|
3497
|
-
var
|
|
3498
|
-
|
|
3499
|
-
var buildArrayActions = createBuildArrayActions('roles', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newRole) {
|
|
3253
|
+
var buildArrayActions = createBuildArrayActions('roles', _defineProperty(_defineProperty({}, ADD_ACTIONS, function (newRole) {
|
|
3500
3254
|
return {
|
|
3501
3255
|
action: 'addRoles',
|
|
3502
3256
|
roles: newRole
|
|
3503
3257
|
};
|
|
3504
|
-
}),
|
|
3258
|
+
}), REMOVE_ACTIONS, function (oldRole) {
|
|
3505
3259
|
return {
|
|
3506
3260
|
action: 'removeRoles',
|
|
3507
3261
|
roles: oldRole
|
|
3508
3262
|
};
|
|
3509
|
-
})
|
|
3263
|
+
}));
|
|
3510
3264
|
return buildArrayActions(diff, oldObj, newObj);
|
|
3511
3265
|
}
|
|
3512
3266
|
|
|
3267
|
+
// This function groups `addRoles` and `removeRoles` actions to one array
|
|
3513
3268
|
function groupRoleActions(_ref) {
|
|
3514
3269
|
var _ref2 = _slicedToArray(_ref, 1),
|
|
3515
|
-
|
|
3516
|
-
|
|
3270
|
+
actions = _ref2[0];
|
|
3517
3271
|
var addActionRoles = [];
|
|
3518
3272
|
var removeActionRoles = [];
|
|
3519
3273
|
actions.forEach(function (action) {
|
|
@@ -3530,7 +3284,6 @@ function groupRoleActions(_ref) {
|
|
|
3530
3284
|
return action.roles.length;
|
|
3531
3285
|
});
|
|
3532
3286
|
}
|
|
3533
|
-
|
|
3534
3287
|
function createStatesMapActions(mapActionGroup, syncActionConfig) {
|
|
3535
3288
|
return function doMapActions(diff, newObj, oldObj) {
|
|
3536
3289
|
var baseActions = [];
|
|
@@ -3544,7 +3297,6 @@ function createStatesMapActions(mapActionGroup, syncActionConfig) {
|
|
|
3544
3297
|
return flatten__default["default"]([].concat(baseActions, _toConsumableArray(groupRoleActions(roleActions))));
|
|
3545
3298
|
};
|
|
3546
3299
|
}
|
|
3547
|
-
|
|
3548
3300
|
var states = (function (actionGroupList, syncActionConfig) {
|
|
3549
3301
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
3550
3302
|
var doMapActions = createStatesMapActions(mapActionGroup, syncActionConfig);
|
|
@@ -3596,7 +3348,6 @@ function createChannelsMapActions$1(mapActionGroup, syncActionConfig) {
|
|
|
3596
3348
|
return flatten__default["default"](allActions);
|
|
3597
3349
|
};
|
|
3598
3350
|
}
|
|
3599
|
-
|
|
3600
3351
|
var channels = (function (actionGroupList) {
|
|
3601
3352
|
var syncActionConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3602
3353
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
@@ -3609,15 +3360,12 @@ var channels = (function (actionGroupList) {
|
|
|
3609
3360
|
|
|
3610
3361
|
var REGEX_NUMBER = new RegExp(/^\d+$/);
|
|
3611
3362
|
var REGEX_UNDERSCORE_NUMBER = new RegExp(/^_\d+$/);
|
|
3612
|
-
|
|
3613
3363
|
var getIsChangedOperation = function getIsChangedOperation(key) {
|
|
3614
3364
|
return REGEX_NUMBER.test(key);
|
|
3615
3365
|
};
|
|
3616
|
-
|
|
3617
3366
|
var getIsRemovedOperation = function getIsRemovedOperation(key) {
|
|
3618
3367
|
return REGEX_UNDERSCORE_NUMBER.test(key);
|
|
3619
3368
|
};
|
|
3620
|
-
|
|
3621
3369
|
var baseActionsList$5 = [{
|
|
3622
3370
|
action: 'changeKey',
|
|
3623
3371
|
key: 'key'
|
|
@@ -3638,38 +3386,35 @@ function actionsMapBase$5(diff, oldObj, newObj) {
|
|
|
3638
3386
|
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
3639
3387
|
});
|
|
3640
3388
|
}
|
|
3641
|
-
|
|
3642
3389
|
function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next) {
|
|
3643
|
-
var _createBuildArrayActi;
|
|
3644
|
-
|
|
3645
3390
|
var addEnumActionName = attributeType === 'Enum' ? 'addEnumValue' : 'addLocalizedEnumValue';
|
|
3646
3391
|
var changeEnumValueLabelActionName = attributeType === 'Enum' ? 'changeEnumValueLabel' : 'changeLocalizedEnumValueLabel';
|
|
3647
3392
|
var changeEnumOrderActionName = attributeType === 'Enum' ? 'changeEnumValueOrder' : 'changeLocalizedEnumValueOrder';
|
|
3648
|
-
var buildArrayActions = createBuildArrayActions('values', (
|
|
3393
|
+
var buildArrayActions = createBuildArrayActions('values', _defineProperty(_defineProperty({}, ADD_ACTIONS, function (newEnum) {
|
|
3649
3394
|
return {
|
|
3650
3395
|
fieldName: fieldName,
|
|
3651
3396
|
action: addEnumActionName,
|
|
3652
3397
|
value: newEnum
|
|
3653
3398
|
};
|
|
3654
|
-
}),
|
|
3399
|
+
}), CHANGE_ACTIONS, function (oldEnum, newEnum) {
|
|
3655
3400
|
var oldEnumInNext = next.values.find(function (nextEnum) {
|
|
3656
3401
|
return nextEnum.key === oldEnum.key;
|
|
3657
|
-
});
|
|
3402
|
+
});
|
|
3403
|
+
|
|
3404
|
+
// These `changeActions` would impose a nested structure among
|
|
3658
3405
|
// the accumulated `updateActions` generated by `buildArrayActions`
|
|
3659
3406
|
// In the end; we have to flatten the structure before we pass it back
|
|
3660
3407
|
// to the client.
|
|
3661
|
-
|
|
3662
3408
|
var changeActions = [];
|
|
3663
|
-
|
|
3664
3409
|
if (oldEnumInNext) {
|
|
3665
3410
|
// If the enum value is changed, we need to change the order first
|
|
3666
|
-
var isKeyChanged = oldEnum.key !== newEnum.key;
|
|
3411
|
+
var isKeyChanged = oldEnum.key !== newEnum.key;
|
|
3667
3412
|
|
|
3413
|
+
// check if the label is changed
|
|
3668
3414
|
var foundPreviousEnum = previous.values.find(function (previousEnum) {
|
|
3669
3415
|
return previousEnum.key === newEnum.key;
|
|
3670
3416
|
});
|
|
3671
3417
|
var isLabelEqual = isEqual__default["default"](foundPreviousEnum.label, newEnum.label);
|
|
3672
|
-
|
|
3673
3418
|
if (isKeyChanged) {
|
|
3674
3419
|
// these actions is then flatten in the end
|
|
3675
3420
|
changeActions.push({
|
|
@@ -3678,7 +3423,6 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
|
|
|
3678
3423
|
value: newEnum
|
|
3679
3424
|
});
|
|
3680
3425
|
}
|
|
3681
|
-
|
|
3682
3426
|
if (!isLabelEqual) {
|
|
3683
3427
|
changeActions.push({
|
|
3684
3428
|
fieldName: fieldName,
|
|
@@ -3693,12 +3437,11 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
|
|
|
3693
3437
|
value: newEnum
|
|
3694
3438
|
});
|
|
3695
3439
|
}
|
|
3696
|
-
|
|
3697
3440
|
return changeActions;
|
|
3698
|
-
})
|
|
3699
|
-
var actions = [];
|
|
3441
|
+
}));
|
|
3442
|
+
var actions = [];
|
|
3443
|
+
// following lists are necessary to ensure that when we change the
|
|
3700
3444
|
// order of enumValues, we generate one updateAction instead of one at a time.
|
|
3701
|
-
|
|
3702
3445
|
var newEnumValuesOrder = [];
|
|
3703
3446
|
flatten__default["default"](buildArrayActions(attributeDiff, previous, next)).forEach(function (updateAction) {
|
|
3704
3447
|
if (updateAction.action === changeEnumOrderActionName) {
|
|
@@ -3713,18 +3456,14 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
|
|
|
3713
3456
|
keys: newEnumValuesOrder
|
|
3714
3457
|
}] : []));
|
|
3715
3458
|
}
|
|
3716
|
-
|
|
3717
3459
|
function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPaths) {
|
|
3718
3460
|
var actions = [];
|
|
3719
3461
|
forEach__default["default"](fieldDefinitionsDiff, function (diffValue, diffKey) {
|
|
3720
3462
|
var extractedPairs = extractMatchingPairs(diffPaths, diffKey, previous, next);
|
|
3721
|
-
|
|
3722
3463
|
if (getIsChangedOperation(diffKey)) {
|
|
3723
3464
|
var _diffValue$type;
|
|
3724
|
-
|
|
3725
3465
|
if (Array.isArray(diffValue)) {
|
|
3726
3466
|
var deltaValue = getDeltaValue(diffValue);
|
|
3727
|
-
|
|
3728
3467
|
if (deltaValue.name) {
|
|
3729
3468
|
actions.push({
|
|
3730
3469
|
action: 'addFieldDefinition',
|
|
@@ -3757,7 +3496,6 @@ function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPa
|
|
|
3757
3496
|
});
|
|
3758
3497
|
} else {
|
|
3759
3498
|
var _deltaValue = getDeltaValue(diffValue);
|
|
3760
|
-
|
|
3761
3499
|
if (_deltaValue === undefined && diffValue[0].name) actions.push({
|
|
3762
3500
|
action: 'removeFieldDefinition',
|
|
3763
3501
|
fieldName: diffValue[0].name
|
|
@@ -3765,11 +3503,12 @@ function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPa
|
|
|
3765
3503
|
}
|
|
3766
3504
|
}
|
|
3767
3505
|
}
|
|
3768
|
-
});
|
|
3506
|
+
});
|
|
3507
|
+
|
|
3508
|
+
// Make sure to execute removeActions before creating new ones
|
|
3769
3509
|
// in order to prevent any eventual removal of `addAction`.
|
|
3770
3510
|
// List of `removeActions` can be found here
|
|
3771
3511
|
// https://docs.commercetools.com/http-api-projects-types.html#change-key
|
|
3772
|
-
|
|
3773
3512
|
var sortedActions = sortBy__default["default"](actions, function (action) {
|
|
3774
3513
|
return action.action !== 'removeFieldDefinition';
|
|
3775
3514
|
});
|
|
@@ -3787,7 +3526,6 @@ function createTypeMapActions(mapActionGroup, syncActionConfig) {
|
|
|
3787
3526
|
return flatten__default["default"](allActions);
|
|
3788
3527
|
};
|
|
3789
3528
|
}
|
|
3790
|
-
|
|
3791
3529
|
var types = (function (actionGroupList, syncActionConfig) {
|
|
3792
3530
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
3793
3531
|
var doMapActions = createTypeMapActions(mapActionGroup, syncActionConfig);
|
|
@@ -3815,6 +3553,15 @@ var baseActionsList$4 = [{
|
|
|
3815
3553
|
}, {
|
|
3816
3554
|
action: 'setShippingRateInputType',
|
|
3817
3555
|
key: 'shippingRateInputType'
|
|
3556
|
+
}, {
|
|
3557
|
+
action: 'changeMyBusinessUnitStatusOnCreation',
|
|
3558
|
+
key: 'myBusinessUnitStatusOnCreation'
|
|
3559
|
+
}, {
|
|
3560
|
+
action: 'setMyBusinessUnitAssociateRoleOnCreation',
|
|
3561
|
+
key: 'myBusinessUnitAssociateRoleOnCreation'
|
|
3562
|
+
}, {
|
|
3563
|
+
action: 'changeCustomerSearchStatus',
|
|
3564
|
+
key: 'customerSearchStatus'
|
|
3818
3565
|
}];
|
|
3819
3566
|
function actionsMapBase$4(diff, oldObj, newObj) {
|
|
3820
3567
|
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
@@ -3836,7 +3583,6 @@ function createChannelsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
3836
3583
|
return flatten__default["default"](allActions);
|
|
3837
3584
|
};
|
|
3838
3585
|
}
|
|
3839
|
-
|
|
3840
3586
|
var projects = (function (actionGroupList) {
|
|
3841
3587
|
var syncActionConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3842
3588
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
@@ -3881,7 +3627,6 @@ function createStoresMapActions(mapActionGroup) {
|
|
|
3881
3627
|
return flatten__default["default"](allActions);
|
|
3882
3628
|
};
|
|
3883
3629
|
}
|
|
3884
|
-
|
|
3885
3630
|
var stores = (function (actionGroupList) {
|
|
3886
3631
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
3887
3632
|
var doMapActions = createStoresMapActions(mapActionGroup);
|
|
@@ -3920,7 +3665,6 @@ function createProductSelectionsMapActions(mapActionGroup) {
|
|
|
3920
3665
|
return flatten__default["default"](allActions);
|
|
3921
3666
|
};
|
|
3922
3667
|
}
|
|
3923
|
-
|
|
3924
3668
|
var productSelections = (function (actionGroupList) {
|
|
3925
3669
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
3926
3670
|
var doMapActions = createProductSelectionsMapActions(mapActionGroup);
|
|
@@ -3937,7 +3681,8 @@ var baseActionsList$1 = [{
|
|
|
3937
3681
|
}, {
|
|
3938
3682
|
action: 'setDiscountedPrice',
|
|
3939
3683
|
key: 'discounted'
|
|
3940
|
-
},
|
|
3684
|
+
},
|
|
3685
|
+
// TODO: Later add more accurate actions `addPriceTier`, `removePriceTier`
|
|
3941
3686
|
{
|
|
3942
3687
|
action: 'setPriceTiers',
|
|
3943
3688
|
key: 'tiers'
|
|
@@ -3976,7 +3721,6 @@ function createPriceMapActions(mapActionGroup, syncActionConfig) {
|
|
|
3976
3721
|
return combineValidityActions([].concat(_toConsumableArray(baseActions), _toConsumableArray(customActions)));
|
|
3977
3722
|
};
|
|
3978
3723
|
}
|
|
3979
|
-
|
|
3980
3724
|
var prices = (function (actionGroupList, syncActionConfig) {
|
|
3981
3725
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
3982
3726
|
var doMapActions = createPriceMapActions(mapActionGroup, syncActionConfig);
|
|
@@ -3991,7 +3735,6 @@ var hasAttribute = function hasAttribute(attributes, newValue) {
|
|
|
3991
3735
|
return attribute.key === newValue.key;
|
|
3992
3736
|
});
|
|
3993
3737
|
};
|
|
3994
|
-
|
|
3995
3738
|
var baseActionsList = [{
|
|
3996
3739
|
action: 'changeName',
|
|
3997
3740
|
key: 'name'
|
|
@@ -4013,35 +3756,34 @@ function actionsMapBase(diff, oldObj, newObj) {
|
|
|
4013
3756
|
});
|
|
4014
3757
|
}
|
|
4015
3758
|
function actionsMapAttributes(diff, oldObj, newObj) {
|
|
4016
|
-
var
|
|
4017
|
-
|
|
4018
|
-
var handler = createBuildArrayActions('attributes', (_createBuildArrayActi = {}, _defineProperty(_createBuildArrayActi, ADD_ACTIONS, function (newAttribute) {
|
|
3759
|
+
var handler = createBuildArrayActions('attributes', _defineProperty(_defineProperty(_defineProperty({}, ADD_ACTIONS, function (newAttribute) {
|
|
4019
3760
|
return {
|
|
4020
3761
|
action: 'addAttribute',
|
|
4021
3762
|
attribute: newAttribute
|
|
4022
3763
|
};
|
|
4023
|
-
}),
|
|
3764
|
+
}), REMOVE_ACTIONS, function (oldAttribute) {
|
|
4024
3765
|
// We only add the action if the attribute is not included in the new object.
|
|
4025
3766
|
return !hasAttribute(newObj.attributes, oldAttribute) ? {
|
|
4026
3767
|
action: 'removeAttribute',
|
|
4027
3768
|
attribute: oldAttribute
|
|
4028
3769
|
} : null;
|
|
4029
|
-
}),
|
|
4030
|
-
var result = [];
|
|
3770
|
+
}), CHANGE_ACTIONS, function (oldAttribute, newAttribute) {
|
|
3771
|
+
var result = [];
|
|
3772
|
+
// We only remove the attribute in case that the oldAttribute is not
|
|
4031
3773
|
// included in the new object
|
|
4032
|
-
|
|
4033
3774
|
if (!hasAttribute(newObj.attributes, oldAttribute)) result.push({
|
|
4034
3775
|
action: 'removeAttribute',
|
|
4035
3776
|
attribute: oldAttribute
|
|
4036
|
-
});
|
|
4037
|
-
// included in the old object
|
|
3777
|
+
});
|
|
4038
3778
|
|
|
3779
|
+
// We only add the attribute in case that the newAttribute was not
|
|
3780
|
+
// included in the old object
|
|
4039
3781
|
if (!hasAttribute(oldObj.attributes, newAttribute)) result.push({
|
|
4040
3782
|
action: 'addAttribute',
|
|
4041
3783
|
attribute: newAttribute
|
|
4042
3784
|
});
|
|
4043
3785
|
return result;
|
|
4044
|
-
})
|
|
3786
|
+
}));
|
|
4045
3787
|
return handler(diff, oldObj, newObj);
|
|
4046
3788
|
}
|
|
4047
3789
|
|
|
@@ -4057,7 +3799,6 @@ function createAttributeGroupsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
4057
3799
|
return flatten__default["default"](allActions);
|
|
4058
3800
|
};
|
|
4059
3801
|
}
|
|
4060
|
-
|
|
4061
3802
|
var attributeGroups = (function (actionGroupList, syncActionConfig) {
|
|
4062
3803
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
4063
3804
|
var doMapActions = createAttributeGroupsMapActions(mapActionGroup, syncActionConfig);
|