@commercetools/sync-actions 8.1.0 → 8.2.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 +8 -0
- package/dist/commercetools-sync-actions.cjs.js +141 -3
- package/dist/commercetools-sync-actions.esm.js +145 -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,13 @@
|
|
|
1
1
|
# @commercetools/sync-actions
|
|
2
2
|
|
|
3
|
+
## 8.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
9
|
+
- [#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.
|
|
10
|
+
|
|
3
11
|
## 8.1.0
|
|
4
12
|
|
|
5
13
|
### 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,
|
|
@@ -43784,12 +43785,14 @@ function _buildVariantAssetsActions2(diffAssets, oldVariant, newVariant) {
|
|
|
43784
43785
|
newVariant.assets
|
|
43785
43786
|
);
|
|
43786
43787
|
if (getIsAddAction(key, asset)) {
|
|
43787
|
-
|
|
43788
|
+
const action = __spreadValues({
|
|
43788
43789
|
action: "addAsset",
|
|
43789
43790
|
asset: getDeltaValue(asset)
|
|
43790
|
-
}, toVariantIdentifier2(newVariant))
|
|
43791
|
+
}, toVariantIdentifier2(newVariant));
|
|
43792
|
+
const actionWithPosition = __spreadProps(__spreadValues({}, action), {
|
|
43791
43793
|
position: Number(key)
|
|
43792
|
-
})
|
|
43794
|
+
});
|
|
43795
|
+
assetActions.push(oldVariant.assets ? actionWithPosition : action);
|
|
43793
43796
|
return;
|
|
43794
43797
|
}
|
|
43795
43798
|
if (getIsUpdateAction(key, asset)) {
|
|
@@ -44495,6 +44498,140 @@ var subscriptions_default = (actionGroupList, syncActionConfig = {}) => {
|
|
|
44495
44498
|
return { buildActions };
|
|
44496
44499
|
};
|
|
44497
44500
|
|
|
44501
|
+
// src/standalone-variants/standalone-variant-actions.ts
|
|
44502
|
+
function convertAttributeToUpdateActionShape(attribute) {
|
|
44503
|
+
const { name, value } = attribute;
|
|
44504
|
+
return __spreadValues({
|
|
44505
|
+
name
|
|
44506
|
+
}, typeof value !== "undefined" ? {
|
|
44507
|
+
value: JSON.stringify(value)
|
|
44508
|
+
} : {});
|
|
44509
|
+
}
|
|
44510
|
+
function _buildStagedAction(actionName, payload, config = {}) {
|
|
44511
|
+
const action = __spreadValues({
|
|
44512
|
+
action: actionName
|
|
44513
|
+
}, payload);
|
|
44514
|
+
if (config.staged !== false) {
|
|
44515
|
+
action.staged = true;
|
|
44516
|
+
}
|
|
44517
|
+
return action;
|
|
44518
|
+
}
|
|
44519
|
+
function _buildKeyAction(variantDiff, oldVariant) {
|
|
44520
|
+
if ({}.hasOwnProperty.call(variantDiff, "key")) {
|
|
44521
|
+
const newValue = getDeltaValue(
|
|
44522
|
+
variantDiff.key
|
|
44523
|
+
);
|
|
44524
|
+
if (!newValue && !oldVariant.key) return null;
|
|
44525
|
+
return {
|
|
44526
|
+
action: "setKey",
|
|
44527
|
+
key: newValue || void 0
|
|
44528
|
+
};
|
|
44529
|
+
}
|
|
44530
|
+
return null;
|
|
44531
|
+
}
|
|
44532
|
+
function _buildSkuAction(variantDiff, oldVariant, config = {}) {
|
|
44533
|
+
if ({}.hasOwnProperty.call(variantDiff, "sku")) {
|
|
44534
|
+
const newValue = getDeltaValue(
|
|
44535
|
+
variantDiff.sku
|
|
44536
|
+
);
|
|
44537
|
+
if (!newValue && !oldVariant.sku) return null;
|
|
44538
|
+
return _buildStagedAction("setSku", { sku: newValue || void 0 }, config);
|
|
44539
|
+
}
|
|
44540
|
+
return null;
|
|
44541
|
+
}
|
|
44542
|
+
function _buildPublishAction(oldVariant, newVariant) {
|
|
44543
|
+
if (oldVariant.published !== true && newVariant.published === true) {
|
|
44544
|
+
return { action: "publish" };
|
|
44545
|
+
}
|
|
44546
|
+
if (oldVariant.published === true && newVariant.published !== true) {
|
|
44547
|
+
return { action: "unpublish" };
|
|
44548
|
+
}
|
|
44549
|
+
return null;
|
|
44550
|
+
}
|
|
44551
|
+
function actionsMapBase27(diff2, oldVariant, newVariant, config = {}) {
|
|
44552
|
+
const actions = [];
|
|
44553
|
+
if (!oldVariant || !diff2) {
|
|
44554
|
+
return actions;
|
|
44555
|
+
}
|
|
44556
|
+
const keyAction = _buildKeyAction(diff2, oldVariant);
|
|
44557
|
+
if (keyAction) {
|
|
44558
|
+
actions.push(keyAction);
|
|
44559
|
+
}
|
|
44560
|
+
const skuAction = _buildSkuAction(diff2, oldVariant, config);
|
|
44561
|
+
if (skuAction) {
|
|
44562
|
+
actions.push(skuAction);
|
|
44563
|
+
}
|
|
44564
|
+
const publishAction = _buildPublishAction(oldVariant, newVariant);
|
|
44565
|
+
if (publishAction) {
|
|
44566
|
+
actions.push(publishAction);
|
|
44567
|
+
}
|
|
44568
|
+
return actions;
|
|
44569
|
+
}
|
|
44570
|
+
function actionsMapAttributes3(diff2, _oldVariant, newVariant, config = {}) {
|
|
44571
|
+
if (!(diff2 == null ? void 0 : diff2.attributes)) {
|
|
44572
|
+
return [];
|
|
44573
|
+
}
|
|
44574
|
+
const attributes = (newVariant.attributes || []).map(
|
|
44575
|
+
convertAttributeToUpdateActionShape
|
|
44576
|
+
);
|
|
44577
|
+
return [_buildStagedAction("setAttributes", { attributes }, config)];
|
|
44578
|
+
}
|
|
44579
|
+
function actionsMapImages3(diff2, _oldVariant, newVariant, config = {}) {
|
|
44580
|
+
if (!(diff2 == null ? void 0 : diff2.images)) {
|
|
44581
|
+
return [];
|
|
44582
|
+
}
|
|
44583
|
+
const images = newVariant.images || [];
|
|
44584
|
+
return [_buildStagedAction("setImages", { images }, config)];
|
|
44585
|
+
}
|
|
44586
|
+
function actionsMapAssets4(diff2, _oldVariant, newVariant, config = {}) {
|
|
44587
|
+
if (!(diff2 == null ? void 0 : diff2.assets)) {
|
|
44588
|
+
return [];
|
|
44589
|
+
}
|
|
44590
|
+
const assets = newVariant.assets || [];
|
|
44591
|
+
return [_buildStagedAction("setAssets", { assets }, config)];
|
|
44592
|
+
}
|
|
44593
|
+
|
|
44594
|
+
// src/standalone-variants/standalone-variants.ts
|
|
44595
|
+
function createStandaloneVariantsMapActions(mapActionGroup, syncActionConfig) {
|
|
44596
|
+
return function doMapActions(diff2, newObj, oldObj) {
|
|
44597
|
+
const allActions = [];
|
|
44598
|
+
allActions.push(
|
|
44599
|
+
...mapActionGroup(
|
|
44600
|
+
"base",
|
|
44601
|
+
() => actionsMapBase27(diff2, oldObj, newObj, syncActionConfig)
|
|
44602
|
+
)
|
|
44603
|
+
);
|
|
44604
|
+
allActions.push(
|
|
44605
|
+
...mapActionGroup(
|
|
44606
|
+
"attributes",
|
|
44607
|
+
() => actionsMapAttributes3(diff2, oldObj, newObj, syncActionConfig)
|
|
44608
|
+
)
|
|
44609
|
+
);
|
|
44610
|
+
allActions.push(
|
|
44611
|
+
...mapActionGroup(
|
|
44612
|
+
"images",
|
|
44613
|
+
() => actionsMapImages3(diff2, oldObj, newObj, syncActionConfig)
|
|
44614
|
+
)
|
|
44615
|
+
);
|
|
44616
|
+
allActions.push(
|
|
44617
|
+
...mapActionGroup(
|
|
44618
|
+
"assets",
|
|
44619
|
+
() => actionsMapAssets4(diff2, oldObj, newObj, syncActionConfig)
|
|
44620
|
+
)
|
|
44621
|
+
);
|
|
44622
|
+
return allActions;
|
|
44623
|
+
};
|
|
44624
|
+
}
|
|
44625
|
+
function createSyncStandaloneVariants(actionGroupList, syncActionConfig = {}) {
|
|
44626
|
+
const mapActionGroup = createMapActionGroup(actionGroupList);
|
|
44627
|
+
const doMapActions = createStandaloneVariantsMapActions(
|
|
44628
|
+
mapActionGroup,
|
|
44629
|
+
syncActionConfig
|
|
44630
|
+
);
|
|
44631
|
+
const buildActions = createBuildActions(diff, doMapActions);
|
|
44632
|
+
return { buildActions };
|
|
44633
|
+
}
|
|
44634
|
+
|
|
44498
44635
|
// src/utils/types.ts
|
|
44499
44636
|
var types_exports = {};
|
|
44500
44637
|
__reExport(types_exports, __toESM(require_commercetools_platform_sdk_cjs()));
|
|
@@ -44523,6 +44660,7 @@ __reExport(index_exports, types_exports, module.exports);
|
|
|
44523
44660
|
createSyncRecurringOrders,
|
|
44524
44661
|
createSyncShippingMethods,
|
|
44525
44662
|
createSyncStandalonePrices,
|
|
44663
|
+
createSyncStandaloneVariants,
|
|
44526
44664
|
createSyncStates,
|
|
44527
44665
|
createSyncStores,
|
|
44528
44666
|
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,
|
|
@@ -3714,12 +3715,16 @@ function _buildVariantAssetsActions2(diffAssets, oldVariant, newVariant) {
|
|
|
3714
3715
|
newVariant.assets
|
|
3715
3716
|
);
|
|
3716
3717
|
if (getIsAddAction(key, asset)) {
|
|
3717
|
-
|
|
3718
|
+
const action = {
|
|
3718
3719
|
action: "addAsset",
|
|
3719
3720
|
asset: getDeltaValue(asset),
|
|
3720
|
-
...toVariantIdentifier2(newVariant)
|
|
3721
|
+
...toVariantIdentifier2(newVariant)
|
|
3722
|
+
};
|
|
3723
|
+
const actionWithPosition = {
|
|
3724
|
+
...action,
|
|
3721
3725
|
position: Number(key)
|
|
3722
|
-
}
|
|
3726
|
+
};
|
|
3727
|
+
assetActions.push(oldVariant.assets ? actionWithPosition : action);
|
|
3723
3728
|
return;
|
|
3724
3729
|
}
|
|
3725
3730
|
if (getIsUpdateAction(key, asset)) {
|
|
@@ -4439,6 +4444,142 @@ var subscriptions_default = (actionGroupList, syncActionConfig = {}) => {
|
|
|
4439
4444
|
return { buildActions };
|
|
4440
4445
|
};
|
|
4441
4446
|
|
|
4447
|
+
// src/standalone-variants/standalone-variant-actions.ts
|
|
4448
|
+
function convertAttributeToUpdateActionShape(attribute) {
|
|
4449
|
+
const { name, value } = attribute;
|
|
4450
|
+
return {
|
|
4451
|
+
name,
|
|
4452
|
+
...typeof value !== "undefined" ? {
|
|
4453
|
+
value: JSON.stringify(value)
|
|
4454
|
+
} : {}
|
|
4455
|
+
};
|
|
4456
|
+
}
|
|
4457
|
+
function _buildStagedAction(actionName, payload, config = {}) {
|
|
4458
|
+
const action = {
|
|
4459
|
+
action: actionName,
|
|
4460
|
+
...payload
|
|
4461
|
+
};
|
|
4462
|
+
if (config.staged !== false) {
|
|
4463
|
+
action.staged = true;
|
|
4464
|
+
}
|
|
4465
|
+
return action;
|
|
4466
|
+
}
|
|
4467
|
+
function _buildKeyAction(variantDiff, oldVariant) {
|
|
4468
|
+
if ({}.hasOwnProperty.call(variantDiff, "key")) {
|
|
4469
|
+
const newValue = getDeltaValue(
|
|
4470
|
+
variantDiff.key
|
|
4471
|
+
);
|
|
4472
|
+
if (!newValue && !oldVariant.key) return null;
|
|
4473
|
+
return {
|
|
4474
|
+
action: "setKey",
|
|
4475
|
+
key: newValue || void 0
|
|
4476
|
+
};
|
|
4477
|
+
}
|
|
4478
|
+
return null;
|
|
4479
|
+
}
|
|
4480
|
+
function _buildSkuAction(variantDiff, oldVariant, config = {}) {
|
|
4481
|
+
if ({}.hasOwnProperty.call(variantDiff, "sku")) {
|
|
4482
|
+
const newValue = getDeltaValue(
|
|
4483
|
+
variantDiff.sku
|
|
4484
|
+
);
|
|
4485
|
+
if (!newValue && !oldVariant.sku) return null;
|
|
4486
|
+
return _buildStagedAction("setSku", { sku: newValue || void 0 }, config);
|
|
4487
|
+
}
|
|
4488
|
+
return null;
|
|
4489
|
+
}
|
|
4490
|
+
function _buildPublishAction(oldVariant, newVariant) {
|
|
4491
|
+
if (oldVariant.published !== true && newVariant.published === true) {
|
|
4492
|
+
return { action: "publish" };
|
|
4493
|
+
}
|
|
4494
|
+
if (oldVariant.published === true && newVariant.published !== true) {
|
|
4495
|
+
return { action: "unpublish" };
|
|
4496
|
+
}
|
|
4497
|
+
return null;
|
|
4498
|
+
}
|
|
4499
|
+
function actionsMapBase27(diff2, oldVariant, newVariant, config = {}) {
|
|
4500
|
+
const actions = [];
|
|
4501
|
+
if (!oldVariant || !diff2) {
|
|
4502
|
+
return actions;
|
|
4503
|
+
}
|
|
4504
|
+
const keyAction = _buildKeyAction(diff2, oldVariant);
|
|
4505
|
+
if (keyAction) {
|
|
4506
|
+
actions.push(keyAction);
|
|
4507
|
+
}
|
|
4508
|
+
const skuAction = _buildSkuAction(diff2, oldVariant, config);
|
|
4509
|
+
if (skuAction) {
|
|
4510
|
+
actions.push(skuAction);
|
|
4511
|
+
}
|
|
4512
|
+
const publishAction = _buildPublishAction(oldVariant, newVariant);
|
|
4513
|
+
if (publishAction) {
|
|
4514
|
+
actions.push(publishAction);
|
|
4515
|
+
}
|
|
4516
|
+
return actions;
|
|
4517
|
+
}
|
|
4518
|
+
function actionsMapAttributes3(diff2, _oldVariant, newVariant, config = {}) {
|
|
4519
|
+
if (!diff2?.attributes) {
|
|
4520
|
+
return [];
|
|
4521
|
+
}
|
|
4522
|
+
const attributes = (newVariant.attributes || []).map(
|
|
4523
|
+
convertAttributeToUpdateActionShape
|
|
4524
|
+
);
|
|
4525
|
+
return [_buildStagedAction("setAttributes", { attributes }, config)];
|
|
4526
|
+
}
|
|
4527
|
+
function actionsMapImages3(diff2, _oldVariant, newVariant, config = {}) {
|
|
4528
|
+
if (!diff2?.images) {
|
|
4529
|
+
return [];
|
|
4530
|
+
}
|
|
4531
|
+
const images = newVariant.images || [];
|
|
4532
|
+
return [_buildStagedAction("setImages", { images }, config)];
|
|
4533
|
+
}
|
|
4534
|
+
function actionsMapAssets4(diff2, _oldVariant, newVariant, config = {}) {
|
|
4535
|
+
if (!diff2?.assets) {
|
|
4536
|
+
return [];
|
|
4537
|
+
}
|
|
4538
|
+
const assets = newVariant.assets || [];
|
|
4539
|
+
return [_buildStagedAction("setAssets", { assets }, config)];
|
|
4540
|
+
}
|
|
4541
|
+
|
|
4542
|
+
// src/standalone-variants/standalone-variants.ts
|
|
4543
|
+
function createStandaloneVariantsMapActions(mapActionGroup, syncActionConfig) {
|
|
4544
|
+
return function doMapActions(diff2, newObj, oldObj) {
|
|
4545
|
+
const allActions = [];
|
|
4546
|
+
allActions.push(
|
|
4547
|
+
...mapActionGroup(
|
|
4548
|
+
"base",
|
|
4549
|
+
() => actionsMapBase27(diff2, oldObj, newObj, syncActionConfig)
|
|
4550
|
+
)
|
|
4551
|
+
);
|
|
4552
|
+
allActions.push(
|
|
4553
|
+
...mapActionGroup(
|
|
4554
|
+
"attributes",
|
|
4555
|
+
() => actionsMapAttributes3(diff2, oldObj, newObj, syncActionConfig)
|
|
4556
|
+
)
|
|
4557
|
+
);
|
|
4558
|
+
allActions.push(
|
|
4559
|
+
...mapActionGroup(
|
|
4560
|
+
"images",
|
|
4561
|
+
() => actionsMapImages3(diff2, oldObj, newObj, syncActionConfig)
|
|
4562
|
+
)
|
|
4563
|
+
);
|
|
4564
|
+
allActions.push(
|
|
4565
|
+
...mapActionGroup(
|
|
4566
|
+
"assets",
|
|
4567
|
+
() => actionsMapAssets4(diff2, oldObj, newObj, syncActionConfig)
|
|
4568
|
+
)
|
|
4569
|
+
);
|
|
4570
|
+
return allActions;
|
|
4571
|
+
};
|
|
4572
|
+
}
|
|
4573
|
+
function createSyncStandaloneVariants(actionGroupList, syncActionConfig = {}) {
|
|
4574
|
+
const mapActionGroup = createMapActionGroup(actionGroupList);
|
|
4575
|
+
const doMapActions = createStandaloneVariantsMapActions(
|
|
4576
|
+
mapActionGroup,
|
|
4577
|
+
syncActionConfig
|
|
4578
|
+
);
|
|
4579
|
+
const buildActions = createBuildActions(diff, doMapActions);
|
|
4580
|
+
return { buildActions };
|
|
4581
|
+
}
|
|
4582
|
+
|
|
4442
4583
|
// src/utils/types.ts
|
|
4443
4584
|
var types_exports = {};
|
|
4444
4585
|
__reExport(types_exports, platform_sdk_star);
|
|
@@ -4467,6 +4608,7 @@ export {
|
|
|
4467
4608
|
recurring_orders_default as createSyncRecurringOrders,
|
|
4468
4609
|
shipping_methods_default as createSyncShippingMethods,
|
|
4469
4610
|
prices_default as createSyncStandalonePrices,
|
|
4611
|
+
createSyncStandaloneVariants,
|
|
4470
4612
|
states_default as createSyncStates,
|
|
4471
4613
|
stores_default as createSyncStores,
|
|
4472
4614
|
subscriptions_default as createSyncSubscriptions,
|