@commercetools/sync-actions 8.0.1 → 8.1.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.
@@ -32,6 +32,7 @@ __export(index_exports, {
32
32
  createSyncOrders: () => orders_default,
33
33
  createSyncProductDiscounts: () => product_discounts_default,
34
34
  createSyncProductSelections: () => product_selections_default,
35
+ createSyncProductTailoring: () => product_tailoring_default,
35
36
  createSyncProductTypes: () => product_types_default,
36
37
  createSyncProducts: () => products_default,
37
38
  createSyncProjects: () => projects_default,
@@ -967,9 +968,15 @@ function findMatchingPairs(diff2, before = [], now = [], identifier = "id") {
967
968
  return result;
968
969
  }
969
970
 
970
- // src/products/product-actions.ts
971
+ // src/utils/array-actions-utils.ts
971
972
  var REGEX_NUMBER3 = new RegExp(/^\d+$/);
972
973
  var REGEX_UNDERSCORE_NUMBER3 = new RegExp(/^_\d+$/);
974
+ var getIsAddAction = (key, resource) => REGEX_NUMBER3.test(key) && Array.isArray(resource) && resource.length;
975
+ var getIsUpdateAction = (key, resource) => REGEX_NUMBER3.test(key) && Object.keys(resource).length;
976
+ var getIsRemoveAction = (key, resource) => REGEX_UNDERSCORE_NUMBER3.test(key) && Number(resource[2]) === 0;
977
+ var getIsItemMovedAction = (key, resource) => REGEX_UNDERSCORE_NUMBER3.test(key) && Number(resource[2]) === 3;
978
+
979
+ // src/products/product-actions.ts
973
980
  var baseActionsList4 = [
974
981
  { action: "changeName", key: "name" },
975
982
  { action: "changeSlug", key: "slug" },
@@ -994,10 +1001,6 @@ var referenceActionsList4 = [
994
1001
  { action: "setTaxCategory", key: "taxCategory" },
995
1002
  { action: "transitionState", key: "state" }
996
1003
  ];
997
- var getIsAddAction = (key, resource) => REGEX_NUMBER3.test(key) && Array.isArray(resource) && resource.length;
998
- var getIsUpdateAction = (key, resource) => REGEX_NUMBER3.test(key) && Object.keys(resource).length;
999
- var getIsRemoveAction = (key, resource) => REGEX_UNDERSCORE_NUMBER3.test(key) && Number(resource[2]) === 0;
1000
- var getIsItemMovedAction = (key, resource) => REGEX_UNDERSCORE_NUMBER3.test(key) && Number(resource[2]) === 3;
1001
1004
  function _buildSkuActions(variantDiff, oldVariant) {
1002
1005
  if ({}.hasOwnProperty.call(variantDiff, "sku")) {
1003
1006
  const newValue = getDeltaValue(variantDiff.sku);
@@ -3495,170 +3498,764 @@ var product_selections_default = (actionGroupList) => {
3495
3498
  return { buildActions };
3496
3499
  };
3497
3500
 
3498
- // src/prices/prices-actions.ts
3501
+ // src/product-tailoring/product-tailoring-actions.ts
3502
+ import forEach5 from "lodash.foreach";
3503
+ import uniqWith2 from "lodash.uniqwith";
3504
+ import intersection2 from "lodash.intersection";
3505
+ import without2 from "lodash.without";
3499
3506
  var baseActionsList21 = [
3500
- { action: "changeValue", key: "value" },
3501
- { action: "setDiscountedPrice", key: "discounted" },
3502
- // TODO: Later add more accurate actions `addPriceTier`, `removePriceTier`
3503
- { action: "setPriceTiers", key: "tiers" },
3504
- { action: "setKey", key: "key" },
3505
- { action: "setValidFrom", key: "validFrom" },
3506
- { action: "setValidUntil", key: "validUntil" },
3507
- { action: "changeActive", key: "active" }
3507
+ { action: "setName", key: "name" },
3508
+ { action: "setSlug", key: "slug" },
3509
+ { action: "setDescription", key: "description" }
3508
3510
  ];
3509
- function actionsMapBase21(diff2, oldObj, newObj, config = {}) {
3510
- return buildBaseAttributesActions({
3511
- actions: baseActionsList21,
3512
- diff: diff2,
3513
- oldObj,
3514
- newObj,
3515
- shouldOmitEmptyString: config.shouldOmitEmptyString,
3516
- shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3517
- shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3518
- });
3511
+ var metaActionsList3 = [
3512
+ { action: "setMetaTitle", key: "metaTitle" },
3513
+ { action: "setMetaDescription", key: "metaDescription" },
3514
+ { action: "setMetaKeywords", key: "metaKeywords" }
3515
+ ];
3516
+ var baseAssetActionsList2 = [
3517
+ { action: "setAssetKey", key: "key", actionKey: "assetKey" },
3518
+ { action: "changeAssetName", key: "name" },
3519
+ { action: "setAssetDescription", key: "description" },
3520
+ { action: "setAssetTags", key: "tags" },
3521
+ { action: "setAssetSources", key: "sources" }
3522
+ ];
3523
+ function _buildAttributeValue2(diffedValue, oldAttributeValue, newAttributeValue) {
3524
+ let value;
3525
+ if (Array.isArray(diffedValue))
3526
+ value = getDeltaValue(diffedValue, oldAttributeValue);
3527
+ else if (typeof diffedValue === "string")
3528
+ value = getDeltaValue(diffedValue, oldAttributeValue);
3529
+ else if (diffedValue.centAmount || diffedValue.currencyCode)
3530
+ value = {
3531
+ centAmount: diffedValue.centAmount ? getDeltaValue(diffedValue.centAmount) : newAttributeValue.centAmount,
3532
+ currencyCode: diffedValue.currencyCode ? getDeltaValue(diffedValue.currencyCode) : newAttributeValue.currencyCode
3533
+ };
3534
+ else if (diffedValue.key) value = getDeltaValue(diffedValue.key);
3535
+ else if (typeof diffedValue === "object")
3536
+ if ({}.hasOwnProperty.call(diffedValue, "_t") && diffedValue._t === "a") {
3537
+ value = newAttributeValue;
3538
+ } else {
3539
+ const updatedValue = Object.keys(diffedValue).reduce(
3540
+ (acc, lang) => {
3541
+ const patchedValue = getDeltaValue(
3542
+ diffedValue[lang],
3543
+ acc[lang]
3544
+ );
3545
+ return Object.assign(acc, { [lang]: patchedValue });
3546
+ },
3547
+ { ...oldAttributeValue }
3548
+ );
3549
+ value = updatedValue;
3550
+ }
3551
+ return value;
3519
3552
  }
3520
-
3521
- // src/prices/prices.ts
3522
- function createPriceMapActions(mapActionGroup, syncActionConfig) {
3523
- return function doMapActions(diff2, newObj, oldObj) {
3524
- const baseActions = mapActionGroup(
3525
- "base",
3526
- () => actionsMapBase21(diff2, oldObj, newObj, syncActionConfig)
3527
- );
3528
- const customActions = mapActionGroup(
3529
- "custom",
3530
- () => actionsMapCustom(diff2, newObj, oldObj)
3531
- );
3532
- return combineValidityActions([...baseActions, ...customActions]);
3553
+ function _buildNewSetAttributeAction2(variantId, attr, sameForAllAttributeNames) {
3554
+ const attributeName = attr && attr.name;
3555
+ if (!attributeName) return void 0;
3556
+ let action = {
3557
+ action: "setAttribute",
3558
+ variantId,
3559
+ name: attributeName,
3560
+ value: attr.value
3533
3561
  };
3562
+ if (sameForAllAttributeNames.indexOf(attributeName) !== -1) {
3563
+ action = { ...action, action: "setAttributeInAllVariants" };
3564
+ delete action.variantId;
3565
+ }
3566
+ return action;
3534
3567
  }
3535
- var prices_default = (actionGroupList, syncActionConfig) => {
3536
- const mapActionGroup = createMapActionGroup(actionGroupList);
3537
- const doMapActions = createPriceMapActions(mapActionGroup, syncActionConfig);
3538
- const buildActions = createBuildActions(
3539
- diff,
3540
- doMapActions
3568
+ function _buildSetAttributeAction2(diffedValue, oldVariant, attribute, sameForAllAttributeNames) {
3569
+ if (!attribute || !diffedValue) return void 0;
3570
+ let action = {
3571
+ action: "setAttribute",
3572
+ variantId: oldVariant.id,
3573
+ name: attribute.name,
3574
+ value: null
3575
+ };
3576
+ const oldAttribute = (oldVariant.attributes || []).find(
3577
+ (a) => a.name === attribute.name
3541
3578
  );
3542
- return { buildActions };
3543
- };
3544
-
3545
- // src/attribute-groups/attribute-groups-actions.ts
3546
- var hasAttribute = (attributes, newValue) => attributes.some((attribute) => attribute.key === newValue.key);
3547
- var baseActionsList22 = [
3548
- { action: "changeName", key: "name" },
3549
- { action: "setKey", key: "key" },
3550
- { action: "setDescription", key: "description" }
3551
- ];
3552
- function actionsMapBase22(diff2, oldObj, newObj, config = {}) {
3553
- return buildBaseAttributesActions({
3554
- actions: baseActionsList22,
3555
- diff: diff2,
3556
- oldObj,
3557
- newObj,
3558
- shouldOmitEmptyString: config.shouldOmitEmptyString,
3559
- shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3560
- shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3561
- });
3562
- }
3563
- function actionsMapAttributes2(diff2, oldObj, newObj) {
3564
- const handler = createBuildArrayActions("attributes", {
3565
- [ADD_ACTIONS]: (newAttribute) => ({
3566
- action: "addAttribute",
3567
- attribute: newAttribute
3568
- }),
3569
- [REMOVE_ACTIONS]: (oldAttribute) => {
3570
- return !hasAttribute(newObj.attributes, oldAttribute) ? {
3571
- action: "removeAttribute",
3572
- attribute: oldAttribute
3573
- } : null;
3574
- },
3575
- [CHANGE_ACTIONS]: (oldAttribute, newAttribute) => {
3576
- const result = [];
3577
- if (!hasAttribute(newObj.attributes, oldAttribute))
3578
- result.push({
3579
- action: "removeAttribute",
3580
- attribute: oldAttribute
3581
- });
3582
- if (!hasAttribute(oldObj.attributes, newAttribute))
3583
- result.push({
3584
- action: "addAttribute",
3585
- attribute: newAttribute
3586
- });
3587
- return result;
3588
- }
3589
- });
3590
- return handler(diff2, oldObj, newObj);
3579
+ if (sameForAllAttributeNames.indexOf(attribute.name) !== -1) {
3580
+ action = { ...action, action: "setAttributeInAllVariants" };
3581
+ delete action.variantId;
3582
+ }
3583
+ action.value = _buildAttributeValue2(
3584
+ diffedValue,
3585
+ oldAttribute?.value,
3586
+ attribute.value
3587
+ );
3588
+ return action;
3591
3589
  }
3592
-
3593
- // src/attribute-groups/attribute-groups.ts
3594
- function createAttributeGroupsMapActions(mapActionGroup, syncActionConfig) {
3595
- return function doMapActions(diff2, newObj, oldObj) {
3596
- const allActions = [];
3597
- allActions.push(
3598
- mapActionGroup(
3599
- "base",
3600
- () => actionsMapBase22(diff2, oldObj, newObj, syncActionConfig)
3601
- )
3602
- );
3603
- allActions.push(
3604
- mapActionGroup(
3605
- "attributes",
3606
- () => actionsMapAttributes2(
3607
- diff2,
3608
- oldObj,
3609
- newObj
3610
- )
3611
- ).flat()
3612
- );
3613
- return allActions.flat();
3590
+ function _buildNewSetProductAttributeAction2(attr) {
3591
+ const attributeName = attr && attr.name;
3592
+ if (!attributeName) return void 0;
3593
+ return {
3594
+ action: "setProductAttribute",
3595
+ name: attributeName,
3596
+ value: attr.value
3614
3597
  };
3615
3598
  }
3616
- var attribute_groups_default = (actionGroupList, syncActionConfig) => {
3617
- const mapActionGroup = createMapActionGroup(actionGroupList);
3618
- const doMapActions = createAttributeGroupsMapActions(
3619
- mapActionGroup,
3620
- syncActionConfig
3599
+ function _buildSetProductAttributeAction2(diffedValue, oldProductData, newAttribute) {
3600
+ if (!newAttribute || !diffedValue) return void 0;
3601
+ const action = {
3602
+ action: "setProductAttribute",
3603
+ name: newAttribute.name,
3604
+ value: null
3605
+ };
3606
+ const oldAttribute = (oldProductData.attributes || []).find(
3607
+ (a) => a.name === newAttribute.name
3608
+ ) || {};
3609
+ action.value = _buildAttributeValue2(
3610
+ diffedValue,
3611
+ oldAttribute.value,
3612
+ newAttribute.value
3621
3613
  );
3622
- const buildActions = createBuildActions(
3623
- diff,
3624
- doMapActions
3614
+ return action;
3615
+ }
3616
+ function _buildVariantImagesAction2(diffedImages, oldVariant = {}, newVariant = {}) {
3617
+ const actions = [];
3618
+ const matchingImagePairs = findMatchingPairs(
3619
+ diffedImages,
3620
+ oldVariant.images,
3621
+ newVariant.images,
3622
+ "url"
3625
3623
  );
3626
- return { buildActions };
3627
- };
3628
-
3629
- // src/api-extensions/api-extensions-actions.ts
3630
- var baseActionsList23 = [
3631
- { action: "setKey", key: "key" },
3632
- { action: "changeTriggers", key: "triggers" },
3633
- { action: "setTimeoutInMs", key: "timeoutInMs" },
3634
- { action: "changeDestination", key: "destination" }
3635
- ];
3636
- var actionsMapBase23 = (diff2, oldObj, newObj, config) => {
3637
- return buildBaseAttributesActions({
3638
- actions: baseActionsList23,
3639
- diff: diff2,
3640
- oldObj,
3641
- newObj,
3642
- shouldOmitEmptyString: config?.shouldOmitEmptyString
3643
- });
3644
- };
3645
-
3646
- // src/api-extensions/api-extensions.ts
3647
- var createApiExtensionsMapActions = (mapActionGroup, syncActionConfig) => {
3648
- return function doMapActions(diff2, newObj, oldObj) {
3649
- const allActions = [];
3650
- allActions.push(
3651
- mapActionGroup(
3652
- "base",
3653
- () => actionsMapBase23(diff2, oldObj, newObj, syncActionConfig)
3654
- )
3624
+ forEach5(diffedImages, (image, key) => {
3625
+ const { oldObj, newObj } = extractMatchingPairs(
3626
+ matchingImagePairs,
3627
+ key,
3628
+ oldVariant.images,
3629
+ newVariant.images
3655
3630
  );
3656
- return allActions.flat();
3657
- };
3658
- };
3659
- var api_extensions_default = (actionGroupList, syncActionConfig) => {
3660
- const mapActionGroup = createMapActionGroup(actionGroupList);
3661
- const doMapActions = createApiExtensionsMapActions(
3631
+ if (REGEX_NUMBER3.test(key)) {
3632
+ if (Array.isArray(image) && image.length)
3633
+ actions.push({
3634
+ action: "addExternalImage",
3635
+ variantId: oldVariant.id,
3636
+ image: getDeltaValue(image)
3637
+ });
3638
+ else if (typeof image === "object") {
3639
+ if ({}.hasOwnProperty.call(image, "url") && image.url.length === 2) {
3640
+ actions.push({
3641
+ action: "removeImage",
3642
+ variantId: oldVariant.id,
3643
+ imageUrl: oldObj.url
3644
+ });
3645
+ actions.push({
3646
+ action: "addExternalImage",
3647
+ variantId: oldVariant.id,
3648
+ image: newObj
3649
+ });
3650
+ } else if ({}.hasOwnProperty.call(image, "label") && (image.label.length === 1 || image.label.length === 2))
3651
+ actions.push({
3652
+ action: "setImageLabel",
3653
+ variantId: oldVariant.id,
3654
+ imageUrl: oldObj.url,
3655
+ label: getDeltaValue(image.label)
3656
+ });
3657
+ }
3658
+ } else if (REGEX_UNDERSCORE_NUMBER3.test(key)) {
3659
+ if (Array.isArray(image) && image.length === 3) {
3660
+ if (Number(image[2]) === 3)
3661
+ actions.push({
3662
+ action: "moveImageToPosition",
3663
+ variantId: oldVariant.id,
3664
+ imageUrl: oldObj.url,
3665
+ position: Number(image[1])
3666
+ });
3667
+ else if (Number(image[2]) === 0)
3668
+ actions.push({
3669
+ action: "removeImage",
3670
+ variantId: oldVariant.id,
3671
+ imageUrl: oldObj.url
3672
+ });
3673
+ }
3674
+ }
3675
+ });
3676
+ return actions;
3677
+ }
3678
+ function toAssetIdentifier3(asset) {
3679
+ return asset.id ? { assetId: asset.id } : { assetKey: asset.key };
3680
+ }
3681
+ function toVariantIdentifier2(variant) {
3682
+ const { id, sku } = variant;
3683
+ return id ? { variantId: id } : { sku };
3684
+ }
3685
+ function _buildVariantChangeAssetOrderAction2(diffAssets, oldVariant, newVariant) {
3686
+ const isAssetOrderChanged = Object.entries(diffAssets).find(
3687
+ (entry) => getIsItemMovedAction(entry[0], entry[1])
3688
+ );
3689
+ if (!isAssetOrderChanged) return [];
3690
+ const assetIdsBefore = (oldVariant.assets || []).map((_) => _.id);
3691
+ const assetIdsCurrent = (newVariant.assets || []).map((_) => _.id).filter((_) => _ !== void 0);
3692
+ const assetIdsToKeep = intersection2(assetIdsCurrent, assetIdsBefore);
3693
+ const assetIdsToRemove = without2(assetIdsBefore, ...assetIdsToKeep);
3694
+ return [
3695
+ {
3696
+ action: "changeAssetOrder",
3697
+ assetOrder: assetIdsToKeep.concat(assetIdsToRemove),
3698
+ ...toVariantIdentifier2(oldVariant)
3699
+ }
3700
+ ];
3701
+ }
3702
+ function _buildVariantAssetsActions2(diffAssets, oldVariant, newVariant) {
3703
+ const assetActions = [];
3704
+ const matchingAssetPairs = findMatchingPairs(
3705
+ diffAssets,
3706
+ oldVariant.assets,
3707
+ newVariant.assets
3708
+ );
3709
+ forEach5(diffAssets, (asset, key) => {
3710
+ const { oldObj: oldAsset, newObj: newAsset } = extractMatchingPairs(
3711
+ matchingAssetPairs,
3712
+ key,
3713
+ oldVariant.assets,
3714
+ newVariant.assets
3715
+ );
3716
+ if (getIsAddAction(key, asset)) {
3717
+ assetActions.push({
3718
+ action: "addAsset",
3719
+ asset: getDeltaValue(asset),
3720
+ ...toVariantIdentifier2(newVariant),
3721
+ position: Number(key)
3722
+ });
3723
+ return;
3724
+ }
3725
+ if (getIsUpdateAction(key, asset)) {
3726
+ const basicActions = buildBaseAttributesActions({
3727
+ actions: baseAssetActionsList2,
3728
+ diff: asset,
3729
+ oldObj: oldAsset,
3730
+ newObj: newAsset
3731
+ }).map((action) => {
3732
+ if (action.action === "setAssetKey") {
3733
+ return {
3734
+ ...action,
3735
+ ...toVariantIdentifier2(oldVariant),
3736
+ assetId: oldAsset.id
3737
+ };
3738
+ }
3739
+ return {
3740
+ ...action,
3741
+ ...toVariantIdentifier2(oldVariant),
3742
+ ...toAssetIdentifier3(oldAsset)
3743
+ };
3744
+ });
3745
+ assetActions.push(...basicActions);
3746
+ if (asset.custom) {
3747
+ const customActions = actionsMapCustom(asset, newAsset, oldAsset, {
3748
+ actions: {
3749
+ setCustomType: "setAssetCustomType",
3750
+ setCustomField: "setAssetCustomField"
3751
+ },
3752
+ ...toVariantIdentifier2(oldVariant),
3753
+ ...toAssetIdentifier3(oldAsset)
3754
+ });
3755
+ assetActions.push(...customActions);
3756
+ }
3757
+ return;
3758
+ }
3759
+ if (getIsRemoveAction(key, asset)) {
3760
+ assetActions.push({
3761
+ action: "removeAsset",
3762
+ ...toAssetIdentifier3(oldAsset),
3763
+ ...toVariantIdentifier2(oldVariant)
3764
+ });
3765
+ }
3766
+ });
3767
+ const changedAssetOrderAction = _buildVariantChangeAssetOrderAction2(
3768
+ diffAssets,
3769
+ oldVariant,
3770
+ newVariant
3771
+ );
3772
+ return [...changedAssetOrderAction, ...assetActions];
3773
+ }
3774
+ function _buildVariantAttributesActions2(attributes, oldVariant, newVariant, sameForAllAttributeNames) {
3775
+ const actions = [];
3776
+ if (!attributes) return actions;
3777
+ forEach5(attributes, (value, key) => {
3778
+ if (REGEX_NUMBER3.test(key)) {
3779
+ if (Array.isArray(value)) {
3780
+ const { id } = oldVariant;
3781
+ const deltaValue = getDeltaValue(value);
3782
+ const setAction = _buildNewSetAttributeAction2(
3783
+ id,
3784
+ deltaValue,
3785
+ sameForAllAttributeNames
3786
+ );
3787
+ if (setAction) actions.push(setAction);
3788
+ } else if (newVariant.attributes) {
3789
+ const setAction = _buildSetAttributeAction2(
3790
+ value.value,
3791
+ oldVariant,
3792
+ newVariant.attributes[key],
3793
+ sameForAllAttributeNames
3794
+ );
3795
+ if (setAction) actions.push(setAction);
3796
+ }
3797
+ } else if (REGEX_UNDERSCORE_NUMBER3.test(key))
3798
+ if (Array.isArray(value)) {
3799
+ if (value.length === 3 && value[2] === 3) return;
3800
+ const { id } = oldVariant;
3801
+ let deltaValue = getDeltaValue(value);
3802
+ if (!deltaValue)
3803
+ if (value[0] && value[0].name) deltaValue = { name: value[0].name };
3804
+ else deltaValue = void 0;
3805
+ const setAction = _buildNewSetAttributeAction2(
3806
+ id,
3807
+ deltaValue,
3808
+ sameForAllAttributeNames
3809
+ );
3810
+ if (setAction) actions.push(setAction);
3811
+ } else {
3812
+ const index = key.substring(1);
3813
+ if (newVariant.attributes) {
3814
+ const setAction = _buildSetAttributeAction2(
3815
+ value.value,
3816
+ oldVariant,
3817
+ newVariant.attributes[index],
3818
+ sameForAllAttributeNames
3819
+ );
3820
+ if (setAction) actions.push(setAction);
3821
+ }
3822
+ }
3823
+ });
3824
+ return actions;
3825
+ }
3826
+ function _buildProductAttributesActions2(diffedAttributes, oldProductData, newProductData) {
3827
+ const actions = [];
3828
+ if (!diffedAttributes) return actions;
3829
+ forEach5(diffedAttributes, (value, key) => {
3830
+ if (REGEX_NUMBER3.test(key)) {
3831
+ if (Array.isArray(value)) {
3832
+ const setAction = _buildNewSetProductAttributeAction2(
3833
+ getDeltaValue(value)
3834
+ );
3835
+ if (setAction) actions.push(setAction);
3836
+ } else if (newProductData.attributes) {
3837
+ const setAction = _buildSetProductAttributeAction2(
3838
+ value["value"],
3839
+ oldProductData,
3840
+ newProductData.attributes[key]
3841
+ );
3842
+ if (setAction) actions.push(setAction);
3843
+ }
3844
+ } else if (REGEX_UNDERSCORE_NUMBER3.test(key)) {
3845
+ if (Array.isArray(value)) {
3846
+ if (value.length === 3 && value[2] === 3) return;
3847
+ let deltaValue = getDeltaValue(value);
3848
+ if (!deltaValue)
3849
+ if (value[0] && value[0].name) deltaValue = { name: value[0].name };
3850
+ else deltaValue = void 0;
3851
+ const setAction = _buildNewSetProductAttributeAction2(
3852
+ deltaValue
3853
+ );
3854
+ if (setAction) actions.push(setAction);
3855
+ } else {
3856
+ const index = key.substring(1);
3857
+ if (newProductData.attributes) {
3858
+ const setAction = _buildSetProductAttributeAction2(
3859
+ value["value"],
3860
+ oldProductData,
3861
+ newProductData.attributes[index]
3862
+ );
3863
+ if (setAction) actions.push(setAction);
3864
+ }
3865
+ }
3866
+ }
3867
+ });
3868
+ return actions;
3869
+ }
3870
+ function actionsMapBase21(diff2, oldObj, newObj, config = {}) {
3871
+ return buildBaseAttributesActions({
3872
+ actions: baseActionsList21,
3873
+ diff: diff2,
3874
+ oldObj,
3875
+ newObj,
3876
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3877
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
3878
+ });
3879
+ }
3880
+ function actionsMapMeta3(diff2, oldObj, newObj, config = {}) {
3881
+ return buildBaseAttributesActions({
3882
+ actions: metaActionsList3,
3883
+ diff: diff2,
3884
+ oldObj,
3885
+ newObj,
3886
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3887
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
3888
+ });
3889
+ }
3890
+ function actionsMapAddVariants2(diff2, oldObj, newObj) {
3891
+ const handler = createBuildArrayActions("variants", {
3892
+ [ADD_ACTIONS]: (newObject) => ({
3893
+ ...newObject,
3894
+ action: "addVariant"
3895
+ })
3896
+ });
3897
+ return handler(diff2, oldObj, newObj);
3898
+ }
3899
+ function actionsMapRemoveVariants2(diff2, oldObj, newObj) {
3900
+ const handler = createBuildArrayActions("variants", {
3901
+ [REMOVE_ACTIONS]: ({ id, sku }) => ({
3902
+ action: "removeVariant",
3903
+ ...id ? { id } : { sku }
3904
+ })
3905
+ });
3906
+ return handler(diff2, oldObj, newObj);
3907
+ }
3908
+ function actionsMapImages2(diff2, oldObj, newObj, variantHashMap) {
3909
+ let actions = [];
3910
+ const { variants } = diff2;
3911
+ if (variants)
3912
+ forEach5(variants, (variant, key) => {
3913
+ const { oldObj: oldVariant, newObj: newVariant } = extractMatchingPairs(
3914
+ variantHashMap,
3915
+ key,
3916
+ oldObj.variants,
3917
+ newObj.variants
3918
+ );
3919
+ if (REGEX_UNDERSCORE_NUMBER3.test(key) || REGEX_NUMBER3.test(key)) {
3920
+ const vActions = _buildVariantImagesAction2(
3921
+ variant.images,
3922
+ oldVariant,
3923
+ newVariant
3924
+ );
3925
+ actions = actions.concat(vActions);
3926
+ }
3927
+ });
3928
+ return actions;
3929
+ }
3930
+ function actionsMapAssets3(diff2, oldObj, newObj, variantHashMap) {
3931
+ let allAssetsActions = [];
3932
+ const { variants } = diff2;
3933
+ if (variants)
3934
+ forEach5(variants, (variant, key) => {
3935
+ const { oldObj: oldVariant, newObj: newVariant } = extractMatchingPairs(
3936
+ variantHashMap,
3937
+ key,
3938
+ oldObj.variants,
3939
+ newObj.variants
3940
+ );
3941
+ if (variant.assets && (REGEX_UNDERSCORE_NUMBER3.test(key) || REGEX_NUMBER3.test(key))) {
3942
+ const assetActions = _buildVariantAssetsActions2(
3943
+ variant.assets,
3944
+ oldVariant,
3945
+ newVariant
3946
+ );
3947
+ allAssetsActions = allAssetsActions.concat(assetActions);
3948
+ }
3949
+ });
3950
+ return allAssetsActions;
3951
+ }
3952
+ function actionsMapProductAttributes2(diff2, oldObj, newObj) {
3953
+ return _buildProductAttributesActions2(diff2.attributes, oldObj, newObj);
3954
+ }
3955
+ function actionsMapVariantAttributes(diff2, oldObj, newObj, sameForAllAttributeNames = [], variantHashMap) {
3956
+ let actions = [];
3957
+ const { variants } = diff2;
3958
+ if (variants)
3959
+ forEach5(variants, (variant, key) => {
3960
+ const { oldObj: oldVariant, newObj: newVariant } = extractMatchingPairs(
3961
+ variantHashMap,
3962
+ key,
3963
+ oldObj.variants,
3964
+ newObj.variants
3965
+ );
3966
+ if (REGEX_NUMBER3.test(key) && !Array.isArray(variant)) {
3967
+ const { attributes } = variant;
3968
+ const attrActions = _buildVariantAttributesActions2(
3969
+ attributes,
3970
+ oldVariant,
3971
+ newVariant,
3972
+ sameForAllAttributeNames
3973
+ );
3974
+ actions = actions.concat(attrActions);
3975
+ }
3976
+ });
3977
+ return uniqWith2(
3978
+ actions,
3979
+ (a, b) => a.action === b.action && a.name === b.name && a.variantId === b.variantId
3980
+ );
3981
+ }
3982
+
3983
+ // src/product-tailoring/product-tailoring.ts
3984
+ function createProductTailoringMapActions(mapActionGroup, syncActionConfig) {
3985
+ return function doMapActions(diff2, newObj, oldObj, options = {}) {
3986
+ const allActions = [];
3987
+ const { publish, staged } = newObj;
3988
+ const variantHashMap = findMatchingPairs(
3989
+ diff2.variants,
3990
+ oldObj.variants,
3991
+ newObj.variants
3992
+ );
3993
+ const config = { ...syncActionConfig, ...options };
3994
+ allActions.push(
3995
+ mapActionGroup(
3996
+ "base",
3997
+ () => actionsMapBase21(diff2, oldObj, newObj, config)
3998
+ )
3999
+ );
4000
+ allActions.push(
4001
+ mapActionGroup(
4002
+ "meta",
4003
+ () => actionsMapMeta3(diff2, oldObj, newObj, config)
4004
+ )
4005
+ );
4006
+ allActions.push(
4007
+ mapActionGroup(
4008
+ "variants",
4009
+ () => actionsMapAddVariants2(diff2, oldObj, newObj)
4010
+ )
4011
+ );
4012
+ allActions.push(
4013
+ mapActionGroup(
4014
+ "variants",
4015
+ () => actionsMapRemoveVariants2(diff2, oldObj, newObj)
4016
+ )
4017
+ );
4018
+ allActions.push(
4019
+ mapActionGroup(
4020
+ "images",
4021
+ () => actionsMapImages2(
4022
+ diff2,
4023
+ oldObj,
4024
+ newObj,
4025
+ variantHashMap
4026
+ )
4027
+ )
4028
+ );
4029
+ allActions.push(
4030
+ mapActionGroup(
4031
+ "assets",
4032
+ () => actionsMapAssets3(
4033
+ diff2,
4034
+ oldObj,
4035
+ newObj,
4036
+ variantHashMap
4037
+ )
4038
+ )
4039
+ );
4040
+ allActions.push(
4041
+ mapActionGroup(
4042
+ "attributes",
4043
+ () => actionsMapProductAttributes2(
4044
+ diff2,
4045
+ oldObj,
4046
+ newObj
4047
+ )
4048
+ )
4049
+ );
4050
+ allActions.push(
4051
+ mapActionGroup(
4052
+ "attributes",
4053
+ () => actionsMapVariantAttributes(
4054
+ diff2,
4055
+ oldObj,
4056
+ newObj,
4057
+ options.sameForAllAttributeNames || [],
4058
+ variantHashMap
4059
+ )
4060
+ )
4061
+ );
4062
+ if (publish === true || staged === false)
4063
+ return allActions.flat().map((action) => ({
4064
+ ...action,
4065
+ staged: false
4066
+ }));
4067
+ return allActions.flat();
4068
+ };
4069
+ }
4070
+ function prepareVariantsForDiff(before, now) {
4071
+ const [beforeCopy, nowCopy] = copyEmptyArrayProps(
4072
+ before,
4073
+ now
4074
+ );
4075
+ const ensureVariants = (obj) => ({
4076
+ ...obj,
4077
+ variants: obj?.variants || []
4078
+ });
4079
+ return [ensureVariants(beforeCopy), ensureVariants(nowCopy)];
4080
+ }
4081
+ var product_tailoring_default = (actionGroupList, syncActionConfig) => {
4082
+ const mapActionGroup = createMapActionGroup(actionGroupList);
4083
+ const doMapActions = createProductTailoringMapActions(
4084
+ mapActionGroup,
4085
+ syncActionConfig
4086
+ );
4087
+ const buildActions = createBuildActions(
4088
+ diff,
4089
+ doMapActions,
4090
+ prepareVariantsForDiff
4091
+ );
4092
+ return { buildActions };
4093
+ };
4094
+
4095
+ // src/prices/prices-actions.ts
4096
+ var baseActionsList22 = [
4097
+ { action: "changeValue", key: "value" },
4098
+ { action: "setDiscountedPrice", key: "discounted" },
4099
+ // TODO: Later add more accurate actions `addPriceTier`, `removePriceTier`
4100
+ { action: "setPriceTiers", key: "tiers" },
4101
+ { action: "setKey", key: "key" },
4102
+ { action: "setValidFrom", key: "validFrom" },
4103
+ { action: "setValidUntil", key: "validUntil" },
4104
+ { action: "changeActive", key: "active" }
4105
+ ];
4106
+ function actionsMapBase22(diff2, oldObj, newObj, config = {}) {
4107
+ return buildBaseAttributesActions({
4108
+ actions: baseActionsList22,
4109
+ diff: diff2,
4110
+ oldObj,
4111
+ newObj,
4112
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4113
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
4114
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4115
+ });
4116
+ }
4117
+
4118
+ // src/prices/prices.ts
4119
+ function createPriceMapActions(mapActionGroup, syncActionConfig) {
4120
+ return function doMapActions(diff2, newObj, oldObj) {
4121
+ const baseActions = mapActionGroup(
4122
+ "base",
4123
+ () => actionsMapBase22(diff2, oldObj, newObj, syncActionConfig)
4124
+ );
4125
+ const customActions = mapActionGroup(
4126
+ "custom",
4127
+ () => actionsMapCustom(diff2, newObj, oldObj)
4128
+ );
4129
+ return combineValidityActions([...baseActions, ...customActions]);
4130
+ };
4131
+ }
4132
+ var prices_default = (actionGroupList, syncActionConfig) => {
4133
+ const mapActionGroup = createMapActionGroup(actionGroupList);
4134
+ const doMapActions = createPriceMapActions(mapActionGroup, syncActionConfig);
4135
+ const buildActions = createBuildActions(
4136
+ diff,
4137
+ doMapActions
4138
+ );
4139
+ return { buildActions };
4140
+ };
4141
+
4142
+ // src/attribute-groups/attribute-groups-actions.ts
4143
+ var hasAttribute = (attributes, newValue) => attributes.some((attribute) => attribute.key === newValue.key);
4144
+ var baseActionsList23 = [
4145
+ { action: "changeName", key: "name" },
4146
+ { action: "setKey", key: "key" },
4147
+ { action: "setDescription", key: "description" }
4148
+ ];
4149
+ function actionsMapBase23(diff2, oldObj, newObj, config = {}) {
4150
+ return buildBaseAttributesActions({
4151
+ actions: baseActionsList23,
4152
+ diff: diff2,
4153
+ oldObj,
4154
+ newObj,
4155
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
4156
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
4157
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4158
+ });
4159
+ }
4160
+ function actionsMapAttributes2(diff2, oldObj, newObj) {
4161
+ const handler = createBuildArrayActions("attributes", {
4162
+ [ADD_ACTIONS]: (newAttribute) => ({
4163
+ action: "addAttribute",
4164
+ attribute: newAttribute
4165
+ }),
4166
+ [REMOVE_ACTIONS]: (oldAttribute) => {
4167
+ return !hasAttribute(newObj.attributes, oldAttribute) ? {
4168
+ action: "removeAttribute",
4169
+ attribute: oldAttribute
4170
+ } : null;
4171
+ },
4172
+ [CHANGE_ACTIONS]: (oldAttribute, newAttribute) => {
4173
+ const result = [];
4174
+ if (!hasAttribute(newObj.attributes, oldAttribute))
4175
+ result.push({
4176
+ action: "removeAttribute",
4177
+ attribute: oldAttribute
4178
+ });
4179
+ if (!hasAttribute(oldObj.attributes, newAttribute))
4180
+ result.push({
4181
+ action: "addAttribute",
4182
+ attribute: newAttribute
4183
+ });
4184
+ return result;
4185
+ }
4186
+ });
4187
+ return handler(diff2, oldObj, newObj);
4188
+ }
4189
+
4190
+ // src/attribute-groups/attribute-groups.ts
4191
+ function createAttributeGroupsMapActions(mapActionGroup, syncActionConfig) {
4192
+ return function doMapActions(diff2, newObj, oldObj) {
4193
+ const allActions = [];
4194
+ allActions.push(
4195
+ mapActionGroup(
4196
+ "base",
4197
+ () => actionsMapBase23(diff2, oldObj, newObj, syncActionConfig)
4198
+ )
4199
+ );
4200
+ allActions.push(
4201
+ mapActionGroup(
4202
+ "attributes",
4203
+ () => actionsMapAttributes2(
4204
+ diff2,
4205
+ oldObj,
4206
+ newObj
4207
+ )
4208
+ ).flat()
4209
+ );
4210
+ return allActions.flat();
4211
+ };
4212
+ }
4213
+ var attribute_groups_default = (actionGroupList, syncActionConfig) => {
4214
+ const mapActionGroup = createMapActionGroup(actionGroupList);
4215
+ const doMapActions = createAttributeGroupsMapActions(
4216
+ mapActionGroup,
4217
+ syncActionConfig
4218
+ );
4219
+ const buildActions = createBuildActions(
4220
+ diff,
4221
+ doMapActions
4222
+ );
4223
+ return { buildActions };
4224
+ };
4225
+
4226
+ // src/api-extensions/api-extensions-actions.ts
4227
+ var baseActionsList24 = [
4228
+ { action: "setKey", key: "key" },
4229
+ { action: "changeTriggers", key: "triggers" },
4230
+ { action: "setTimeoutInMs", key: "timeoutInMs" },
4231
+ { action: "changeDestination", key: "destination" }
4232
+ ];
4233
+ var actionsMapBase24 = (diff2, oldObj, newObj, config) => {
4234
+ return buildBaseAttributesActions({
4235
+ actions: baseActionsList24,
4236
+ diff: diff2,
4237
+ oldObj,
4238
+ newObj,
4239
+ shouldOmitEmptyString: config?.shouldOmitEmptyString
4240
+ });
4241
+ };
4242
+
4243
+ // src/api-extensions/api-extensions.ts
4244
+ var createApiExtensionsMapActions = (mapActionGroup, syncActionConfig) => {
4245
+ return function doMapActions(diff2, newObj, oldObj) {
4246
+ const allActions = [];
4247
+ allActions.push(
4248
+ mapActionGroup(
4249
+ "base",
4250
+ () => actionsMapBase24(diff2, oldObj, newObj, syncActionConfig)
4251
+ )
4252
+ );
4253
+ return allActions.flat();
4254
+ };
4255
+ };
4256
+ var api_extensions_default = (actionGroupList, syncActionConfig) => {
4257
+ const mapActionGroup = createMapActionGroup(actionGroupList);
4258
+ const doMapActions = createApiExtensionsMapActions(
3662
4259
  mapActionGroup,
3663
4260
  syncActionConfig
3664
4261
  );
@@ -3667,7 +4264,7 @@ var api_extensions_default = (actionGroupList, syncActionConfig) => {
3667
4264
  };
3668
4265
 
3669
4266
  // src/business-units/business-units-actions.ts
3670
- var baseActionsList24 = [
4267
+ var baseActionsList25 = [
3671
4268
  {
3672
4269
  action: "setStores",
3673
4270
  key: "stores"
@@ -3703,9 +4300,9 @@ var actionsMapAssociates = (diff2, oldObj, newObj) => {
3703
4300
  });
3704
4301
  return handler(diff2, oldObj, newObj);
3705
4302
  };
3706
- var actionsMapBase24 = (diff2, oldObj, newObj, config) => {
4303
+ var actionsMapBase25 = (diff2, oldObj, newObj, config) => {
3707
4304
  return buildBaseAttributesActions({
3708
- actions: baseActionsList24,
4305
+ actions: baseActionsList25,
3709
4306
  diff: diff2,
3710
4307
  oldObj,
3711
4308
  newObj,
@@ -3720,7 +4317,7 @@ var createCustomerMapActions2 = (mapActionGroup, syncActionConfig) => {
3720
4317
  allActions.push(
3721
4318
  mapActionGroup(
3722
4319
  "base",
3723
- () => actionsMapBase24(
4320
+ () => actionsMapBase25(
3724
4321
  diff2,
3725
4322
  oldObj,
3726
4323
  newObj,
@@ -3795,15 +4392,15 @@ var business_units_default = (actionGroupList, syncActionConfig) => {
3795
4392
  };
3796
4393
 
3797
4394
  // src/subscriptions/subscriptions-actions.ts
3798
- var baseActionsList25 = [
4395
+ var baseActionsList26 = [
3799
4396
  { action: "setKey", key: "key" },
3800
4397
  { action: "setMessages", key: "messages" },
3801
4398
  { action: "setChanges", key: "changes" },
3802
4399
  { action: "changeDestination", key: "destination" }
3803
4400
  ];
3804
- var actionsMapBase25 = (diff2, oldObj, newObj, config) => {
4401
+ var actionsMapBase26 = (diff2, oldObj, newObj, config) => {
3805
4402
  return buildBaseAttributesActions({
3806
- actions: baseActionsList25,
4403
+ actions: baseActionsList26,
3807
4404
  diff: diff2,
3808
4405
  oldObj,
3809
4406
  newObj,
@@ -3818,7 +4415,7 @@ var createSubscriptionsMapActions = (mapActionGroup, syncActionConfig) => {
3818
4415
  allActions.push(
3819
4416
  mapActionGroup(
3820
4417
  "base",
3821
- () => actionsMapBase25(
4418
+ () => actionsMapBase26(
3822
4419
  diff2,
3823
4420
  oldObj,
3824
4421
  newObj,
@@ -3863,6 +4460,7 @@ export {
3863
4460
  orders_default as createSyncOrders,
3864
4461
  product_discounts_default as createSyncProductDiscounts,
3865
4462
  product_selections_default as createSyncProductSelections,
4463
+ product_tailoring_default as createSyncProductTailoring,
3866
4464
  product_types_default as createSyncProductTypes,
3867
4465
  products_default as createSyncProducts,
3868
4466
  projects_default as createSyncProjects,