@commercetools/sync-actions 6.1.1 → 7.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true,
5
+ })
6
+ exports.default = createMapActionGroup
7
+ // Array of action groups which need to be whitelisted or blacklisted.
8
+ // Example:
9
+ // [
10
+ // { type: 'base', group: 'black' },
11
+ // { type: 'prices', group: 'white' },
12
+ // { type: 'variants', group: 'black' },
13
+ // ]
14
+ function createMapActionGroup() {
15
+ var actionGroups =
16
+ arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
17
+
18
+ return function mapActionGroup(type, fn) {
19
+ if (!Object.keys(actionGroups).length) return fn()
20
+
21
+ var found = actionGroups.find(function(c) {
22
+ return c.type === type
23
+ })
24
+ if (!found) return []
25
+
26
+ if (found.group === 'black') return []
27
+ if (found.group === 'white') return fn()
28
+
29
+ throw new Error(
30
+ "Action group '" +
31
+ found.group +
32
+ "' not supported. Please use black or white."
33
+ )
34
+ }
35
+ }
@@ -0,0 +1,93 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true,
5
+ })
6
+
7
+ var _typeof =
8
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
9
+ ? function(obj) {
10
+ return typeof obj
11
+ }
12
+ : function(obj) {
13
+ return obj &&
14
+ typeof Symbol === 'function' &&
15
+ obj.constructor === Symbol &&
16
+ obj !== Symbol.prototype
17
+ ? 'symbol'
18
+ : typeof obj
19
+ } // Requiring directily from `jsondiffpatch` entry point will cause warnings
20
+ // while bundling with webpack because of dynamic requires.
21
+ // To get around this issue, simply require the `Diffpatcher` directly.
22
+ // https://github.com/benjamine/jsondiffpatch/issues/76#issuecomment-270207970
23
+
24
+ exports.objectHash = objectHash
25
+ exports.diff = diff
26
+ exports.patch = patch
27
+ exports.getDeltaValue = getDeltaValue
28
+
29
+ var _diffpatcher = require('jsondiffpatch/src/diffpatcher')
30
+
31
+ var diffpatcher = new _diffpatcher.DiffPatcher({
32
+ objectHash: objectHash,
33
+ arrays: {
34
+ // detect items moved inside the array
35
+ detectMove: true,
36
+
37
+ // value of items moved is not included in deltas
38
+ includeValueOnMove: false,
39
+ },
40
+ textDiff: {
41
+ // If the value to diff has a bigger length,
42
+ // a text diffing algorithm is used
43
+ // See https://github.com/benjamine/jsondiffpatch/
44
+ // blob/master/docs/deltas.md#text-diffs
45
+ minLength: 300,
46
+ },
47
+ })
48
+
49
+ function objectHash(obj, index) {
50
+ var objIndex = '$$index:' + index
51
+ return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) ===
52
+ 'object' && obj !== null
53
+ ? obj.id || obj.name || obj.url || objIndex
54
+ : objIndex
55
+ }
56
+
57
+ function diff(oldObj, newObj) {
58
+ return diffpatcher.diff(oldObj, newObj)
59
+ }
60
+
61
+ function patch(obj, delta) {
62
+ return diffpatcher.patch(obj, delta)
63
+ }
64
+
65
+ function getDeltaValue(arr, originalObject) {
66
+ if (!Array.isArray(arr))
67
+ throw new Error('Expected array to extract delta value')
68
+
69
+ if (arr.length === 1) return arr[0] // new
70
+
71
+ if (arr.length === 2) return arr[1] // update
72
+
73
+ if (arr.length === 3 && arr[2] === 0) return undefined // delete
74
+
75
+ if (arr.length === 3 && arr[2] === 2) {
76
+ // text diff
77
+ if (!originalObject)
78
+ throw new Error(
79
+ 'Cannot apply patch to long text diff. Missing original object.'
80
+ )
81
+ // try to apply patch to given object based on delta value
82
+ return patch(originalObject, arr)
83
+ }
84
+
85
+ if (arr.length === 3 && arr[2] === 3)
86
+ // array move
87
+ throw new Error(
88
+ 'Detected an array move, it should not happen as ' +
89
+ '`includeValueOnMove` should be set to false'
90
+ )
91
+
92
+ throw new Error('Got unsupported number ' + arr[2] + ' in delta value')
93
+ }
@@ -0,0 +1,67 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true,
5
+ })
6
+ exports.default = findMatchingPairs
7
+
8
+ var _lodash = require('lodash.foreach')
9
+
10
+ var _lodash2 = _interopRequireDefault(_lodash)
11
+
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : { default: obj }
14
+ }
15
+
16
+ var REGEX_NUMBER = new RegExp(/^\d+$/)
17
+ var REGEX_UNDERSCORE_NUMBER = new RegExp(/^_\d+$/)
18
+
19
+ function preProcessCollection() {
20
+ var collection =
21
+ arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
22
+ var identifier =
23
+ arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id'
24
+
25
+ return collection.reduce(
26
+ function(acc, currentValue, currentIndex) {
27
+ acc.refByIndex[String(currentIndex)] = currentValue[identifier]
28
+ acc.refByIdentifier[currentValue[identifier]] = String(currentIndex)
29
+ return acc
30
+ },
31
+ {
32
+ refByIndex: {},
33
+ refByIdentifier: {},
34
+ }
35
+ )
36
+ }
37
+
38
+ // creates a hash of a location of an item in collection1 and collection2
39
+ function findMatchingPairs(diff) {
40
+ var before =
41
+ arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []
42
+ var now =
43
+ arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []
44
+ var identifier =
45
+ arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'id'
46
+
47
+ var result = {}
48
+
49
+ var _preProcessCollection = preProcessCollection(before, identifier),
50
+ beforeObjRefByIdentifier = _preProcessCollection.refByIdentifier,
51
+ beforeObjRefByIndex = _preProcessCollection.refByIndex
52
+
53
+ var _preProcessCollection2 = preProcessCollection(now, identifier),
54
+ nowObjRefByIdentifier = _preProcessCollection2.refByIdentifier,
55
+ nowObjRefByIndex = _preProcessCollection2.refByIndex
56
+ ;(0, _lodash2.default)(diff, function(item, key) {
57
+ if (REGEX_NUMBER.test(key)) {
58
+ var matchingIdentifier = nowObjRefByIndex[key]
59
+ result[key] = [beforeObjRefByIdentifier[matchingIdentifier], key]
60
+ } else if (REGEX_UNDERSCORE_NUMBER.test(key)) {
61
+ var index = key.substring(1)
62
+ var _matchingIdentifier = beforeObjRefByIndex[index]
63
+ result[key] = [index, nowObjRefByIdentifier[_matchingIdentifier]]
64
+ }
65
+ })
66
+ return result
67
+ }
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
- "private": false,
3
2
  "publishConfig": {
4
3
  "access": "public"
5
4
  },
6
5
  "engines": {
7
- "node": ">=14"
6
+ "node": ">=18"
8
7
  },
9
8
  "name": "@commercetools/sync-actions",
10
- "version": "6.1.1",
9
+ "version": "7.0.0-rc.2",
11
10
  "description": "Build API update actions for the commercetools platform.",
12
11
  "keywords": [
13
12
  "commercetools",
@@ -36,15 +35,15 @@
36
35
  },
37
36
  "dependencies": {
38
37
  "fast-equals": "^2.0.0",
39
- "jsondiffpatch": "0.4.0",
38
+ "jsondiffpatch": "0.6.0",
40
39
  "lodash.flatten": "^4.4.0",
41
40
  "lodash.foreach": "^4.5.0",
41
+ "lodash.intersection": "^4.4.0",
42
42
  "lodash.isequal": "^4.5.0",
43
43
  "lodash.isnil": "^4.0.0",
44
44
  "lodash.shuffle": "^4.2.0",
45
45
  "lodash.sortby": "^4.7.0",
46
46
  "lodash.uniqwith": "^4.5.0",
47
- "lodash.intersection": "^4.4.0",
48
47
  "lodash.without": "^4.4.0"
49
48
  }
50
49
  }
package/CHANGELOG.md DELETED
@@ -1,211 +0,0 @@
1
- # @commercetools/sync-actions
2
-
3
- ## 6.1.1
4
-
5
- ### Patch Changes
6
-
7
- - [#1927](https://github.com/commercetools/nodejs/pull/1927) [`a4705c19`](https://github.com/commercetools/nodejs/commit/a4705c19af234cccde74cb52bfff912bf380c6ba) Thanks [@CarlosCortizasCT](https://github.com/CarlosCortizasCT)! - We found an issue in the way the `jsondiffpatch` was used that made this package not usable in a browser environment.
8
-
9
- In this version we adjust the way that package is imported and we pin a transitive dependency (`chalk`) to fix the error.
10
-
11
- ## 6.1.0
12
-
13
- ### Minor Changes
14
-
15
- - [#1921](https://github.com/commercetools/nodejs/pull/1921) [`c9d23e86`](https://github.com/commercetools/nodejs/commit/c9d23e86a6013aafb6a3c296121e1c5995d9eab6) Thanks [@kafis](https://github.com/kafis)! - Introducing configuration to control the behaviour regarding generation of UpdateActions in respect to unsetting fields
16
-
17
- ## 6.0.0
18
-
19
- ### Major Changes
20
-
21
- - [#1919](https://github.com/commercetools/nodejs/pull/1919) [`1c867e02`](https://github.com/commercetools/nodejs/commit/1c867e02285f5030d5ef7aebef46ea27e5e8521b) Thanks [@CarlosCortizasCT](https://github.com/CarlosCortizasCT)! - Update the way we import the `jsondiffpath` dependency to use `import` instead of `require`.
22
-
23
- ## 5.19.2
24
-
25
- ### Patch Changes
26
-
27
- - [#1914](https://github.com/commercetools/nodejs/pull/1914) [`6e1195ed`](https://github.com/commercetools/nodejs/commit/6e1195ed05cc3338eac94e47f439f10b7b0e6e75) Thanks [@antoniolodias](https://github.com/antoniolodias)! - fix: filter out unchanged taxrates from changed list
28
-
29
- ## 5.19.1
30
-
31
- ### Patch Changes
32
-
33
- - [#1912](https://github.com/commercetools/nodejs/pull/1912) [`06866537`](https://github.com/commercetools/nodejs/commit/06866537feb04eaf26521d43b654cbc2920bab0d) Thanks [@markus-azer](https://github.com/markus-azer)! - Fix product action groups category order hints
34
-
35
- ## 5.19.0
36
-
37
- ### Minor Changes
38
-
39
- - [#1908](https://github.com/commercetools/nodejs/pull/1908) [`df373a1a`](https://github.com/commercetools/nodejs/commit/df373a1adbcaa2340b0af0656fd0dbab055329f8) Thanks [@ChristianMoll](https://github.com/ChristianMoll)! - Fix action keys for changeMyBusinessUnitStatusOnCreation, setMyBusinessUnitAssociateRoleOnCreation and changeCustomerSearchStatus
40
-
41
- ## 5.18.0
42
-
43
- ### Minor Changes
44
-
45
- - [#1903](https://github.com/commercetools/nodejs/pull/1903) [`164f1ce7`](https://github.com/commercetools/nodejs/commit/164f1ce7526bb15a16f531572518cbb6ddd61098) Thanks [@ChristianMoll](https://github.com/ChristianMoll)! - Add sync actions changeMyBusinessUnitStatusOnCreation, setMyBusinessUnitAssociateRoleOnCreation and changeCustomerSearchStatus
46
-
47
- ## 5.17.0
48
-
49
- ### Minor Changes
50
-
51
- - [#1897](https://github.com/commercetools/nodejs/pull/1897) [`940dd70b`](https://github.com/commercetools/nodejs/commit/940dd70ba53c51e0fb74849aadb688db6add764d) Thanks [@antoniolodias](https://github.com/antoniolodias)! - add changeActive to shipping methods base actions
52
-
53
- ## 5.16.0
54
-
55
- ### Minor Changes
56
-
57
- - [#1892](https://github.com/commercetools/nodejs/pull/1892) [`fb03b746`](https://github.com/commercetools/nodejs/commit/fb03b7463a990934d2b11fd17b784af104431cc4) Thanks [@ragafus](https://github.com/ragafus)! - Add support for DiscountCodes `setKey` action.
58
-
59
- ## 5.15.0
60
-
61
- ### Minor Changes
62
-
63
- - [#1885](https://github.com/commercetools/nodejs/pull/1885) [`d6cb2740`](https://github.com/commercetools/nodejs/commit/d6cb27401279cb42a49366f32802f8ca8c7f01a3) Thanks [@kafis](https://github.com/kafis)! - Add support for 'changeAssetOrder' in (ProductVariants)[https://docs.commercetools.com/api/projects/products#change-asset-order].
64
-
65
- ## 5.14.0
66
-
67
- ### Minor Changes
68
-
69
- - [#1876](https://github.com/commercetools/nodejs/pull/1876) [`27f0d2b6`](https://github.com/commercetools/nodejs/commit/27f0d2b66fefbe082b6a27e7fa940b09e7e6088c) Thanks [@jaikumar-tj](https://github.com/jaikumar-tj)! - Add support for attribute groups `changeName`, `setKey`, `setDescription`, `addAttribute` and `removeAttribute` actions.
70
-
71
- ## 5.13.0
72
-
73
- ### Minor Changes
74
-
75
- - [#1874](https://github.com/commercetools/nodejs/pull/1874) [`69f4501d`](https://github.com/commercetools/nodejs/commit/69f4501dc5401ab2b44f4d3096a978094e402c9f) Thanks [@taylor-knapp](https://github.com/taylor-knapp)! - Handle long text values performantly
76
-
77
- ## 5.12.2
78
-
79
- ### Patch Changes
80
-
81
- - [#1871](https://github.com/commercetools/nodejs/pull/1871) [`4f8ea39b`](https://github.com/commercetools/nodejs/commit/4f8ea39b66ddd5014ac8f923ed980584bd96290c) Thanks [@ARRIOLALEO](https://github.com/ARRIOLALEO)! - rollback setPriceTiers name change
82
-
83
- ## 5.12.1
84
-
85
- ### Patch Changes
86
-
87
- - [#1869](https://github.com/commercetools/nodejs/pull/1869) [`7285a9fb`](https://github.com/commercetools/nodejs/commit/7285a9fbcbcfca6a9460e36ba7b58bb30f34fac6) Thanks [@ARRIOLALEO](https://github.com/ARRIOLALEO)! - Add support for StandalonePrice `setPriceTier`
88
-
89
- ## 5.12.0
90
-
91
- ### Minor Changes
92
-
93
- - [#1863](https://github.com/commercetools/nodejs/pull/1863) [`7ed7a663`](https://github.com/commercetools/nodejs/commit/7ed7a663c1cb3aa87bfb4b4c2c008949a66a62e0) Thanks [@ragafus](https://github.com/ragafus)! - Add support for StandalonePrice `setKey`, `setValidFrom`, `setValidUntil`, `setValidFromAndUntil` and `changeActive` actions.
94
-
95
- ## 5.11.0
96
-
97
- ### Minor Changes
98
-
99
- - [#1864](https://github.com/commercetools/nodejs/pull/1864) [`91f6b617`](https://github.com/commercetools/nodejs/commit/91f6b61794e7d66766097965e452e14c85e40f14) Thanks [@ARRIOLALEO](https://github.com/ARRIOLALEO)! - Add support for StandalonePrice `setPriceTiers`
100
-
101
- ## 5.10.0
102
-
103
- ### Minor Changes
104
-
105
- - [#1856](https://github.com/commercetools/nodejs/pull/1856) [`9a3e3711`](https://github.com/commercetools/nodejs/commit/9a3e3711bf6594deafb5d54a9ce9e32450f9c4d6) Thanks [@qmateub](https://github.com/qmateub)! - orders sync-actions: support action on delivery items `setDeliveryItems`
106
-
107
- ## 5.9.0
108
-
109
- ### Minor Changes
110
-
111
- - [#1853](https://github.com/commercetools/nodejs/pull/1853) [`4bb8f979`](https://github.com/commercetools/nodejs/commit/4bb8f979c317bbce1654ca0f1abc9b4717fdda0b) Thanks [@markus-azer](https://github.com/markus-azer)! - types sync-actions: support the following actions `changeInputHint`, `changeEnumValueLabel`, `changeLocalizedEnumValueLabel`.
112
-
113
- ## 5.8.0
114
-
115
- ### Minor Changes
116
-
117
- - [#1852](https://github.com/commercetools/nodejs/pull/1852) [`94a376c8`](https://github.com/commercetools/nodejs/commit/94a376c89525b7cee58b710154ddf7cb146cd16c) Thanks [@markus-azer](https://github.com/markus-azer)! - types sync-actions: fix action structure for changeFieldDefinitionOrder
118
- fix internal type sync error by adding optional chaining
119
-
120
- ## 5.7.0
121
-
122
- ### Minor Changes
123
-
124
- - [#1850](https://github.com/commercetools/nodejs/pull/1850) [`330cd9a9`](https://github.com/commercetools/nodejs/commit/330cd9a9b4fca045d479d2d220d2a2a2b966b1f4) Thanks [@markus-azer](https://github.com/markus-azer)! - types sync-actions: fix action structure for changeLocalizedEnumValueOrder, changeEnumValueOrder
125
-
126
- ## 5.6.0
127
-
128
- ### Minor Changes
129
-
130
- - [#1844](https://github.com/commercetools/nodejs/pull/1844) [`23f0529b`](https://github.com/commercetools/nodejs/commit/23f0529bbf359a11500dbf87bdc9e59cb759c89a) Thanks [@markus-azer](https://github.com/markus-azer)! - Add localizedName action to shipping methods
131
-
132
- ## 5.5.0
133
-
134
- ### Minor Changes
135
-
136
- - [#1841](https://github.com/commercetools/nodejs/pull/1841) [`b90c7238`](https://github.com/commercetools/nodejs/commit/b90c7238f0d3d892e1066fd2883cff062b099e66) Thanks [@Rombelirk](https://github.com/Rombelirk)! - Add Custom Fields to Shipping Methods.
137
-
138
- ## 5.4.1
139
-
140
- ### Patch Changes
141
-
142
- - [#1839](https://github.com/commercetools/nodejs/pull/1839) [`d6cadcbc`](https://github.com/commercetools/nodejs/commit/d6cadcbc4b850fa6f438b65c3b63b294a32a58ee) Thanks [@tdeekens](https://github.com/tdeekens)! - Fix failing to sync froozen arrays for prices
143
-
144
- ## 5.4.0
145
-
146
- ### Minor Changes
147
-
148
- - [#1836](https://github.com/commercetools/nodejs/pull/1836) [`ad34d030`](https://github.com/commercetools/nodejs/commit/ad34d03041e7e6b8284da6224dc968fde537a85a) Thanks [@nicolasnieto92](https://github.com/nicolasnieto92)! - Add setAuthenticationMode sync action
149
-
150
- ## 5.3.1
151
-
152
- ### Patch Changes
153
-
154
- - [#1818](https://github.com/commercetools/nodejs/pull/1818) [`856929e3`](https://github.com/commercetools/nodejs/commit/856929e3bc176021a9b52e1ff9c888e51c83cccd) Thanks [@qmateub](https://github.com/qmateub)! - fix(sync-actions/orders): adjust diff calculation of returnInfo items
155
-
156
- ## 5.3.0
157
-
158
- ### Minor Changes
159
-
160
- - [#1820](https://github.com/commercetools/nodejs/pull/1820) [`c3964026`](https://github.com/commercetools/nodejs/commit/c3964026b401cb1c8ae8b581a3fcc4ea692ed3b4) Thanks [@danrleyt](https://github.com/danrleyt)! - Adding support to quote requests and staged quotes
161
-
162
- ## 5.2.0
163
-
164
- ### Minor Changes
165
-
166
- - [`cad54c42`](https://github.com/commercetools/nodejs/commit/cad54c421e18464ae03fb283a30f2ba2f3f6e46a) Thanks [@qmateub](https://github.com/qmateub)! - feat(sync-actions): improve performance for large arrays comparisons"
167
-
168
- ## 5.1.0
169
-
170
- ### Minor Changes
171
-
172
- - [#1803](https://github.com/commercetools/nodejs/pull/1803) [`823985ae`](https://github.com/commercetools/nodejs/commit/823985ae67465673c26f296b68681f255230d571) Thanks [@nicolasnieto92](https://github.com/nicolasnieto92)! - Add createSyncStandalonePrices export to index for supporting prices sync actions
173
-
174
- ## 5.0.0
175
-
176
- ### Major Changes
177
-
178
- - [#1775](https://github.com/commercetools/nodejs/pull/1775) [`35669f30`](https://github.com/commercetools/nodejs/commit/35669f30dbc4b24d59ec3df3f38417b1f2a77837) Thanks [@ajimae](https://github.com/ajimae)! - Drop support for Node `v10` and `v12`. Supported versions now are `v14`, `v16` and `v18`.
179
-
180
- ## 4.13.0
181
-
182
- ### Minor Changes
183
-
184
- - [#1798](https://github.com/commercetools/nodejs/pull/1798) [`850325d0`](https://github.com/commercetools/nodejs/commit/850325d08603764787c387b2341e4009d0c4f788) Thanks [@markus-azer](https://github.com/markus-azer)! - support standalone prices
185
-
186
- ## 4.12.0
187
-
188
- ### Minor Changes
189
-
190
- - [#1796](https://github.com/commercetools/nodejs/pull/1796) [`7aaf91cd`](https://github.com/commercetools/nodejs/commit/7aaf91cdecb7c844943369fc137a5356becdba36) Thanks [@VineetKumarKushwaha](https://github.com/VineetKumarKushwaha)! - Fix custom types sync actions to detect addEnumValue action correctly
191
-
192
- ## 4.11.0
193
-
194
- ### Minor Changes
195
-
196
- - [#1788](https://github.com/commercetools/nodejs/pull/1788) [`f1acfb67`](https://github.com/commercetools/nodejs/commit/f1acfb67708d8253f551481fd65097add48c6686) Thanks [@nicolasnieto92](https://github.com/nicolasnieto92)! - Add setPriceMode sync action for commercetools-importer project
197
-
198
- ## 4.10.1
199
-
200
- ### Patch Changes
201
-
202
- - [#1770](https://github.com/commercetools/nodejs/pull/1770) [`381d1e1f`](https://github.com/commercetools/nodejs/commit/381d1e1f07cc2705962973e3a48934bf7884e309) Thanks [@mohib0306](https://github.com/mohib0306)! - Fix product selection's name update action. `setName` => `changeName`
203
- Expose `createSyncProductSelections` from `sync-actions` package
204
-
205
- ## 4.10.0
206
-
207
- ### Minor Changes
208
-
209
- - [#1767](https://github.com/commercetools/nodejs/pull/1767) [`1aef3423`](https://github.com/commercetools/nodejs/commit/1aef3423e96da7f5df20fd5f66ec29146cacee83) Thanks [@mohib0306](https://github.com/mohib0306)! - feat(sync-actions/product-selections): add sync action support for product selections
210
-
211
- As product selections are available via the API, the sync-actions package is updated to support generating update actions for product selections.