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