@commercetools/sync-actions 8.1.0 → 8.2.1
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 +14 -0
- package/dist/commercetools-sync-actions.cjs.js +147 -3
- package/dist/commercetools-sync-actions.esm.js +152 -3
- package/dist/commercetools-sync-actions.umd.js +1 -1
- package/dist/commercetools-sync-actions.umd.min.js +1 -1
- package/dist/declarations/index.d.ts +1 -0
- package/dist/declarations/standalone-variants/standalone-variant-actions.d.ts +47 -0
- package/dist/declarations/standalone-variants/standalone-variants.d.ts +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @commercetools/sync-actions
|
|
2
2
|
|
|
3
|
+
## 8.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#49](https://github.com/commercetools/typescript-dev-utilities/pull/49) [`41a6524`](https://github.com/commercetools/typescript-dev-utilities/commit/41a65244b2affccd304c739216fa8754d37128b2) Thanks [@kafis](https://github.com/kafis)! - fix addAsset action generation for product-tailoring when more than one asset is added to a previously undefined asset array
|
|
8
|
+
|
|
9
|
+
## 8.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#46](https://github.com/commercetools/typescript-dev-utilities/pull/46) [`ba9a9a1`](https://github.com/commercetools/typescript-dev-utilities/commit/ba9a9a1f4fb8a63c7eeaeb4c523d2cbe19b7e539) Thanks [@ddouglasz](https://github.com/ddouglasz)! - Add support for standalone variants actions
|
|
14
|
+
|
|
15
|
+
- [#48](https://github.com/commercetools/typescript-dev-utilities/pull/48) [`94a83b1`](https://github.com/commercetools/typescript-dev-utilities/commit/94a83b1783467c7a2c53026744cdf96be22e1b3c) Thanks [@kafis](https://github.com/kafis)! - When an `addAsset` action for product-tailoring's variant is generated, the position property is omitted when the source product-tailoring's variant did not include an asset array.
|
|
16
|
+
|
|
3
17
|
## 8.1.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -40129,6 +40129,7 @@ __export(index_exports, {
|
|
|
40129
40129
|
createSyncRecurringOrders: () => recurring_orders_default,
|
|
40130
40130
|
createSyncShippingMethods: () => shipping_methods_default,
|
|
40131
40131
|
createSyncStandalonePrices: () => prices_default,
|
|
40132
|
+
createSyncStandaloneVariants: () => createSyncStandaloneVariants,
|
|
40132
40133
|
createSyncStates: () => states_default,
|
|
40133
40134
|
createSyncStores: () => stores_default,
|
|
40134
40135
|
createSyncSubscriptions: () => subscriptions_default,
|
|
@@ -43770,6 +43771,12 @@ function _buildVariantChangeAssetOrderAction2(diffAssets, oldVariant, newVariant
|
|
|
43770
43771
|
];
|
|
43771
43772
|
}
|
|
43772
43773
|
function _buildVariantAssetsActions2(diffAssets, oldVariant, newVariant) {
|
|
43774
|
+
if (Array.isArray(diffAssets) && diffAssets.length === 1 && Array.isArray(diffAssets[0])) {
|
|
43775
|
+
return diffAssets[0].map((asset) => __spreadValues({
|
|
43776
|
+
action: "addAsset",
|
|
43777
|
+
asset
|
|
43778
|
+
}, toVariantIdentifier2(newVariant)));
|
|
43779
|
+
}
|
|
43773
43780
|
const assetActions = [];
|
|
43774
43781
|
const matchingAssetPairs = findMatchingPairs(
|
|
43775
43782
|
diffAssets,
|
|
@@ -43784,12 +43791,14 @@ function _buildVariantAssetsActions2(diffAssets, oldVariant, newVariant) {
|
|
|
43784
43791
|
newVariant.assets
|
|
43785
43792
|
);
|
|
43786
43793
|
if (getIsAddAction(key, asset)) {
|
|
43787
|
-
|
|
43794
|
+
const action = __spreadValues({
|
|
43788
43795
|
action: "addAsset",
|
|
43789
43796
|
asset: getDeltaValue(asset)
|
|
43790
|
-
}, toVariantIdentifier2(newVariant))
|
|
43797
|
+
}, toVariantIdentifier2(newVariant));
|
|
43798
|
+
const actionWithPosition = __spreadProps(__spreadValues({}, action), {
|
|
43791
43799
|
position: Number(key)
|
|
43792
|
-
})
|
|
43800
|
+
});
|
|
43801
|
+
assetActions.push(oldVariant.assets ? actionWithPosition : action);
|
|
43793
43802
|
return;
|
|
43794
43803
|
}
|
|
43795
43804
|
if (getIsUpdateAction(key, asset)) {
|
|
@@ -44495,6 +44504,140 @@ var subscriptions_default = (actionGroupList, syncActionConfig = {}) => {
|
|
|
44495
44504
|
return { buildActions };
|
|
44496
44505
|
};
|
|
44497
44506
|
|
|
44507
|
+
// src/standalone-variants/standalone-variant-actions.ts
|
|
44508
|
+
function convertAttributeToUpdateActionShape(attribute) {
|
|
44509
|
+
const { name, value } = attribute;
|
|
44510
|
+
return __spreadValues({
|
|
44511
|
+
name
|
|
44512
|
+
}, typeof value !== "undefined" ? {
|
|
44513
|
+
value: JSON.stringify(value)
|
|
44514
|
+
} : {});
|
|
44515
|
+
}
|
|
44516
|
+
function _buildStagedAction(actionName, payload, config = {}) {
|
|
44517
|
+
const action = __spreadValues({
|
|
44518
|
+
action: actionName
|
|
44519
|
+
}, payload);
|
|
44520
|
+
if (config.staged !== false) {
|
|
44521
|
+
action.staged = true;
|
|
44522
|
+
}
|
|
44523
|
+
return action;
|
|
44524
|
+
}
|
|
44525
|
+
function _buildKeyAction(variantDiff, oldVariant) {
|
|
44526
|
+
if ({}.hasOwnProperty.call(variantDiff, "key")) {
|
|
44527
|
+
const newValue = getDeltaValue(
|
|
44528
|
+
variantDiff.key
|
|
44529
|
+
);
|
|
44530
|
+
if (!newValue && !oldVariant.key) return null;
|
|
44531
|
+
return {
|
|
44532
|
+
action: "setKey",
|
|
44533
|
+
key: newValue || void 0
|
|
44534
|
+
};
|
|
44535
|
+
}
|
|
44536
|
+
return null;
|
|
44537
|
+
}
|
|
44538
|
+
function _buildSkuAction(variantDiff, oldVariant, config = {}) {
|
|
44539
|
+
if ({}.hasOwnProperty.call(variantDiff, "sku")) {
|
|
44540
|
+
const newValue = getDeltaValue(
|
|
44541
|
+
variantDiff.sku
|
|
44542
|
+
);
|
|
44543
|
+
if (!newValue && !oldVariant.sku) return null;
|
|
44544
|
+
return _buildStagedAction("setSku", { sku: newValue || void 0 }, config);
|
|
44545
|
+
}
|
|
44546
|
+
return null;
|
|
44547
|
+
}
|
|
44548
|
+
function _buildPublishAction(oldVariant, newVariant) {
|
|
44549
|
+
if (oldVariant.published !== true && newVariant.published === true) {
|
|
44550
|
+
return { action: "publish" };
|
|
44551
|
+
}
|
|
44552
|
+
if (oldVariant.published === true && newVariant.published !== true) {
|
|
44553
|
+
return { action: "unpublish" };
|
|
44554
|
+
}
|
|
44555
|
+
return null;
|
|
44556
|
+
}
|
|
44557
|
+
function actionsMapBase27(diff2, oldVariant, newVariant, config = {}) {
|
|
44558
|
+
const actions = [];
|
|
44559
|
+
if (!oldVariant || !diff2) {
|
|
44560
|
+
return actions;
|
|
44561
|
+
}
|
|
44562
|
+
const keyAction = _buildKeyAction(diff2, oldVariant);
|
|
44563
|
+
if (keyAction) {
|
|
44564
|
+
actions.push(keyAction);
|
|
44565
|
+
}
|
|
44566
|
+
const skuAction = _buildSkuAction(diff2, oldVariant, config);
|
|
44567
|
+
if (skuAction) {
|
|
44568
|
+
actions.push(skuAction);
|
|
44569
|
+
}
|
|
44570
|
+
const publishAction = _buildPublishAction(oldVariant, newVariant);
|
|
44571
|
+
if (publishAction) {
|
|
44572
|
+
actions.push(publishAction);
|
|
44573
|
+
}
|
|
44574
|
+
return actions;
|
|
44575
|
+
}
|
|
44576
|
+
function actionsMapAttributes3(diff2, _oldVariant, newVariant, config = {}) {
|
|
44577
|
+
if (!(diff2 == null ? void 0 : diff2.attributes)) {
|
|
44578
|
+
return [];
|
|
44579
|
+
}
|
|
44580
|
+
const attributes = (newVariant.attributes || []).map(
|
|
44581
|
+
convertAttributeToUpdateActionShape
|
|
44582
|
+
);
|
|
44583
|
+
return [_buildStagedAction("setAttributes", { attributes }, config)];
|
|
44584
|
+
}
|
|
44585
|
+
function actionsMapImages3(diff2, _oldVariant, newVariant, config = {}) {
|
|
44586
|
+
if (!(diff2 == null ? void 0 : diff2.images)) {
|
|
44587
|
+
return [];
|
|
44588
|
+
}
|
|
44589
|
+
const images = newVariant.images || [];
|
|
44590
|
+
return [_buildStagedAction("setImages", { images }, config)];
|
|
44591
|
+
}
|
|
44592
|
+
function actionsMapAssets4(diff2, _oldVariant, newVariant, config = {}) {
|
|
44593
|
+
if (!(diff2 == null ? void 0 : diff2.assets)) {
|
|
44594
|
+
return [];
|
|
44595
|
+
}
|
|
44596
|
+
const assets = newVariant.assets || [];
|
|
44597
|
+
return [_buildStagedAction("setAssets", { assets }, config)];
|
|
44598
|
+
}
|
|
44599
|
+
|
|
44600
|
+
// src/standalone-variants/standalone-variants.ts
|
|
44601
|
+
function createStandaloneVariantsMapActions(mapActionGroup, syncActionConfig) {
|
|
44602
|
+
return function doMapActions(diff2, newObj, oldObj) {
|
|
44603
|
+
const allActions = [];
|
|
44604
|
+
allActions.push(
|
|
44605
|
+
...mapActionGroup(
|
|
44606
|
+
"base",
|
|
44607
|
+
() => actionsMapBase27(diff2, oldObj, newObj, syncActionConfig)
|
|
44608
|
+
)
|
|
44609
|
+
);
|
|
44610
|
+
allActions.push(
|
|
44611
|
+
...mapActionGroup(
|
|
44612
|
+
"attributes",
|
|
44613
|
+
() => actionsMapAttributes3(diff2, oldObj, newObj, syncActionConfig)
|
|
44614
|
+
)
|
|
44615
|
+
);
|
|
44616
|
+
allActions.push(
|
|
44617
|
+
...mapActionGroup(
|
|
44618
|
+
"images",
|
|
44619
|
+
() => actionsMapImages3(diff2, oldObj, newObj, syncActionConfig)
|
|
44620
|
+
)
|
|
44621
|
+
);
|
|
44622
|
+
allActions.push(
|
|
44623
|
+
...mapActionGroup(
|
|
44624
|
+
"assets",
|
|
44625
|
+
() => actionsMapAssets4(diff2, oldObj, newObj, syncActionConfig)
|
|
44626
|
+
)
|
|
44627
|
+
);
|
|
44628
|
+
return allActions;
|
|
44629
|
+
};
|
|
44630
|
+
}
|
|
44631
|
+
function createSyncStandaloneVariants(actionGroupList, syncActionConfig = {}) {
|
|
44632
|
+
const mapActionGroup = createMapActionGroup(actionGroupList);
|
|
44633
|
+
const doMapActions = createStandaloneVariantsMapActions(
|
|
44634
|
+
mapActionGroup,
|
|
44635
|
+
syncActionConfig
|
|
44636
|
+
);
|
|
44637
|
+
const buildActions = createBuildActions(diff, doMapActions);
|
|
44638
|
+
return { buildActions };
|
|
44639
|
+
}
|
|
44640
|
+
|
|
44498
44641
|
// src/utils/types.ts
|
|
44499
44642
|
var types_exports = {};
|
|
44500
44643
|
__reExport(types_exports, __toESM(require_commercetools_platform_sdk_cjs()));
|
|
@@ -44523,6 +44666,7 @@ __reExport(index_exports, types_exports, module.exports);
|
|
|
44523
44666
|
createSyncRecurringOrders,
|
|
44524
44667
|
createSyncShippingMethods,
|
|
44525
44668
|
createSyncStandalonePrices,
|
|
44669
|
+
createSyncStandaloneVariants,
|
|
44526
44670
|
createSyncStates,
|
|
44527
44671
|
createSyncStores,
|
|
44528
44672
|
createSyncSubscriptions,
|
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
createSyncRecurringOrders: () => recurring_orders_default,
|
|
40
40
|
createSyncShippingMethods: () => shipping_methods_default,
|
|
41
41
|
createSyncStandalonePrices: () => prices_default,
|
|
42
|
+
createSyncStandaloneVariants: () => createSyncStandaloneVariants,
|
|
42
43
|
createSyncStates: () => states_default,
|
|
43
44
|
createSyncStores: () => stores_default,
|
|
44
45
|
createSyncSubscriptions: () => subscriptions_default,
|
|
@@ -3700,6 +3701,13 @@ function _buildVariantChangeAssetOrderAction2(diffAssets, oldVariant, newVariant
|
|
|
3700
3701
|
];
|
|
3701
3702
|
}
|
|
3702
3703
|
function _buildVariantAssetsActions2(diffAssets, oldVariant, newVariant) {
|
|
3704
|
+
if (Array.isArray(diffAssets) && diffAssets.length === 1 && Array.isArray(diffAssets[0])) {
|
|
3705
|
+
return diffAssets[0].map((asset) => ({
|
|
3706
|
+
action: "addAsset",
|
|
3707
|
+
asset,
|
|
3708
|
+
...toVariantIdentifier2(newVariant)
|
|
3709
|
+
}));
|
|
3710
|
+
}
|
|
3703
3711
|
const assetActions = [];
|
|
3704
3712
|
const matchingAssetPairs = findMatchingPairs(
|
|
3705
3713
|
diffAssets,
|
|
@@ -3714,12 +3722,16 @@ function _buildVariantAssetsActions2(diffAssets, oldVariant, newVariant) {
|
|
|
3714
3722
|
newVariant.assets
|
|
3715
3723
|
);
|
|
3716
3724
|
if (getIsAddAction(key, asset)) {
|
|
3717
|
-
|
|
3725
|
+
const action = {
|
|
3718
3726
|
action: "addAsset",
|
|
3719
3727
|
asset: getDeltaValue(asset),
|
|
3720
|
-
...toVariantIdentifier2(newVariant)
|
|
3728
|
+
...toVariantIdentifier2(newVariant)
|
|
3729
|
+
};
|
|
3730
|
+
const actionWithPosition = {
|
|
3731
|
+
...action,
|
|
3721
3732
|
position: Number(key)
|
|
3722
|
-
}
|
|
3733
|
+
};
|
|
3734
|
+
assetActions.push(oldVariant.assets ? actionWithPosition : action);
|
|
3723
3735
|
return;
|
|
3724
3736
|
}
|
|
3725
3737
|
if (getIsUpdateAction(key, asset)) {
|
|
@@ -4439,6 +4451,142 @@ var subscriptions_default = (actionGroupList, syncActionConfig = {}) => {
|
|
|
4439
4451
|
return { buildActions };
|
|
4440
4452
|
};
|
|
4441
4453
|
|
|
4454
|
+
// src/standalone-variants/standalone-variant-actions.ts
|
|
4455
|
+
function convertAttributeToUpdateActionShape(attribute) {
|
|
4456
|
+
const { name, value } = attribute;
|
|
4457
|
+
return {
|
|
4458
|
+
name,
|
|
4459
|
+
...typeof value !== "undefined" ? {
|
|
4460
|
+
value: JSON.stringify(value)
|
|
4461
|
+
} : {}
|
|
4462
|
+
};
|
|
4463
|
+
}
|
|
4464
|
+
function _buildStagedAction(actionName, payload, config = {}) {
|
|
4465
|
+
const action = {
|
|
4466
|
+
action: actionName,
|
|
4467
|
+
...payload
|
|
4468
|
+
};
|
|
4469
|
+
if (config.staged !== false) {
|
|
4470
|
+
action.staged = true;
|
|
4471
|
+
}
|
|
4472
|
+
return action;
|
|
4473
|
+
}
|
|
4474
|
+
function _buildKeyAction(variantDiff, oldVariant) {
|
|
4475
|
+
if ({}.hasOwnProperty.call(variantDiff, "key")) {
|
|
4476
|
+
const newValue = getDeltaValue(
|
|
4477
|
+
variantDiff.key
|
|
4478
|
+
);
|
|
4479
|
+
if (!newValue && !oldVariant.key) return null;
|
|
4480
|
+
return {
|
|
4481
|
+
action: "setKey",
|
|
4482
|
+
key: newValue || void 0
|
|
4483
|
+
};
|
|
4484
|
+
}
|
|
4485
|
+
return null;
|
|
4486
|
+
}
|
|
4487
|
+
function _buildSkuAction(variantDiff, oldVariant, config = {}) {
|
|
4488
|
+
if ({}.hasOwnProperty.call(variantDiff, "sku")) {
|
|
4489
|
+
const newValue = getDeltaValue(
|
|
4490
|
+
variantDiff.sku
|
|
4491
|
+
);
|
|
4492
|
+
if (!newValue && !oldVariant.sku) return null;
|
|
4493
|
+
return _buildStagedAction("setSku", { sku: newValue || void 0 }, config);
|
|
4494
|
+
}
|
|
4495
|
+
return null;
|
|
4496
|
+
}
|
|
4497
|
+
function _buildPublishAction(oldVariant, newVariant) {
|
|
4498
|
+
if (oldVariant.published !== true && newVariant.published === true) {
|
|
4499
|
+
return { action: "publish" };
|
|
4500
|
+
}
|
|
4501
|
+
if (oldVariant.published === true && newVariant.published !== true) {
|
|
4502
|
+
return { action: "unpublish" };
|
|
4503
|
+
}
|
|
4504
|
+
return null;
|
|
4505
|
+
}
|
|
4506
|
+
function actionsMapBase27(diff2, oldVariant, newVariant, config = {}) {
|
|
4507
|
+
const actions = [];
|
|
4508
|
+
if (!oldVariant || !diff2) {
|
|
4509
|
+
return actions;
|
|
4510
|
+
}
|
|
4511
|
+
const keyAction = _buildKeyAction(diff2, oldVariant);
|
|
4512
|
+
if (keyAction) {
|
|
4513
|
+
actions.push(keyAction);
|
|
4514
|
+
}
|
|
4515
|
+
const skuAction = _buildSkuAction(diff2, oldVariant, config);
|
|
4516
|
+
if (skuAction) {
|
|
4517
|
+
actions.push(skuAction);
|
|
4518
|
+
}
|
|
4519
|
+
const publishAction = _buildPublishAction(oldVariant, newVariant);
|
|
4520
|
+
if (publishAction) {
|
|
4521
|
+
actions.push(publishAction);
|
|
4522
|
+
}
|
|
4523
|
+
return actions;
|
|
4524
|
+
}
|
|
4525
|
+
function actionsMapAttributes3(diff2, _oldVariant, newVariant, config = {}) {
|
|
4526
|
+
if (!diff2?.attributes) {
|
|
4527
|
+
return [];
|
|
4528
|
+
}
|
|
4529
|
+
const attributes = (newVariant.attributes || []).map(
|
|
4530
|
+
convertAttributeToUpdateActionShape
|
|
4531
|
+
);
|
|
4532
|
+
return [_buildStagedAction("setAttributes", { attributes }, config)];
|
|
4533
|
+
}
|
|
4534
|
+
function actionsMapImages3(diff2, _oldVariant, newVariant, config = {}) {
|
|
4535
|
+
if (!diff2?.images) {
|
|
4536
|
+
return [];
|
|
4537
|
+
}
|
|
4538
|
+
const images = newVariant.images || [];
|
|
4539
|
+
return [_buildStagedAction("setImages", { images }, config)];
|
|
4540
|
+
}
|
|
4541
|
+
function actionsMapAssets4(diff2, _oldVariant, newVariant, config = {}) {
|
|
4542
|
+
if (!diff2?.assets) {
|
|
4543
|
+
return [];
|
|
4544
|
+
}
|
|
4545
|
+
const assets = newVariant.assets || [];
|
|
4546
|
+
return [_buildStagedAction("setAssets", { assets }, config)];
|
|
4547
|
+
}
|
|
4548
|
+
|
|
4549
|
+
// src/standalone-variants/standalone-variants.ts
|
|
4550
|
+
function createStandaloneVariantsMapActions(mapActionGroup, syncActionConfig) {
|
|
4551
|
+
return function doMapActions(diff2, newObj, oldObj) {
|
|
4552
|
+
const allActions = [];
|
|
4553
|
+
allActions.push(
|
|
4554
|
+
...mapActionGroup(
|
|
4555
|
+
"base",
|
|
4556
|
+
() => actionsMapBase27(diff2, oldObj, newObj, syncActionConfig)
|
|
4557
|
+
)
|
|
4558
|
+
);
|
|
4559
|
+
allActions.push(
|
|
4560
|
+
...mapActionGroup(
|
|
4561
|
+
"attributes",
|
|
4562
|
+
() => actionsMapAttributes3(diff2, oldObj, newObj, syncActionConfig)
|
|
4563
|
+
)
|
|
4564
|
+
);
|
|
4565
|
+
allActions.push(
|
|
4566
|
+
...mapActionGroup(
|
|
4567
|
+
"images",
|
|
4568
|
+
() => actionsMapImages3(diff2, oldObj, newObj, syncActionConfig)
|
|
4569
|
+
)
|
|
4570
|
+
);
|
|
4571
|
+
allActions.push(
|
|
4572
|
+
...mapActionGroup(
|
|
4573
|
+
"assets",
|
|
4574
|
+
() => actionsMapAssets4(diff2, oldObj, newObj, syncActionConfig)
|
|
4575
|
+
)
|
|
4576
|
+
);
|
|
4577
|
+
return allActions;
|
|
4578
|
+
};
|
|
4579
|
+
}
|
|
4580
|
+
function createSyncStandaloneVariants(actionGroupList, syncActionConfig = {}) {
|
|
4581
|
+
const mapActionGroup = createMapActionGroup(actionGroupList);
|
|
4582
|
+
const doMapActions = createStandaloneVariantsMapActions(
|
|
4583
|
+
mapActionGroup,
|
|
4584
|
+
syncActionConfig
|
|
4585
|
+
);
|
|
4586
|
+
const buildActions = createBuildActions(diff, doMapActions);
|
|
4587
|
+
return { buildActions };
|
|
4588
|
+
}
|
|
4589
|
+
|
|
4442
4590
|
// src/utils/types.ts
|
|
4443
4591
|
var types_exports = {};
|
|
4444
4592
|
__reExport(types_exports, platform_sdk_star);
|
|
@@ -4467,6 +4615,7 @@ export {
|
|
|
4467
4615
|
recurring_orders_default as createSyncRecurringOrders,
|
|
4468
4616
|
shipping_methods_default as createSyncShippingMethods,
|
|
4469
4617
|
prices_default as createSyncStandalonePrices,
|
|
4618
|
+
createSyncStandaloneVariants,
|
|
4470
4619
|
states_default as createSyncStates,
|
|
4471
4620
|
stores_default as createSyncStores,
|
|
4472
4621
|
subscriptions_default as createSyncSubscriptions,
|