@commercetools/sync-actions 8.0.0 → 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.
@@ -5953,7 +5953,7 @@ var require_lodash3 = __commonJS({
5953
5953
  var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto;
5954
5954
  return value === proto;
5955
5955
  }
5956
- function forEach5(collection, iteratee) {
5956
+ function forEach6(collection, iteratee) {
5957
5957
  var func = isArray(collection) ? arrayEach : baseEach;
5958
5958
  return func(collection, typeof iteratee == "function" ? iteratee : identity);
5959
5959
  }
@@ -5987,7 +5987,7 @@ var require_lodash3 = __commonJS({
5987
5987
  function identity(value) {
5988
5988
  return value;
5989
5989
  }
5990
- module2.exports = forEach5;
5990
+ module2.exports = forEach6;
5991
5991
  }
5992
5992
  });
5993
5993
 
@@ -6299,7 +6299,7 @@ var require_lodash4 = __commonJS({
6299
6299
  }
6300
6300
  return "";
6301
6301
  }
6302
- function uniqWith2(array, comparator) {
6302
+ function uniqWith3(array, comparator) {
6303
6303
  return array && array.length ? baseUniq(array, void 0, comparator) : [];
6304
6304
  }
6305
6305
  function eq(value, other) {
@@ -6315,7 +6315,7 @@ var require_lodash4 = __commonJS({
6315
6315
  }
6316
6316
  function noop() {
6317
6317
  }
6318
- module2.exports = uniqWith2;
6318
+ module2.exports = uniqWith3;
6319
6319
  }
6320
6320
  });
6321
6321
 
@@ -6653,7 +6653,7 @@ var require_lodash5 = __commonJS({
6653
6653
  }
6654
6654
  return "";
6655
6655
  }
6656
- var intersection2 = baseRest(function(arrays) {
6656
+ var intersection3 = baseRest(function(arrays) {
6657
6657
  var mapped = arrayMap(arrays, castArrayLikeObject);
6658
6658
  return mapped.length && mapped[0] === arrays[0] ? baseIntersection(mapped) : [];
6659
6659
  });
@@ -6680,7 +6680,7 @@ var require_lodash5 = __commonJS({
6680
6680
  function isObjectLike(value) {
6681
6681
  return !!value && typeof value == "object";
6682
6682
  }
6683
- module2.exports = intersection2;
6683
+ module2.exports = intersection3;
6684
6684
  }
6685
6685
  });
6686
6686
 
@@ -7017,7 +7017,7 @@ var require_lodash6 = __commonJS({
7017
7017
  }
7018
7018
  return "";
7019
7019
  }
7020
- var without2 = baseRest(function(array, values) {
7020
+ var without3 = baseRest(function(array, values) {
7021
7021
  return isArrayLikeObject(array) ? baseDifference(array, values) : [];
7022
7022
  });
7023
7023
  function eq(value, other) {
@@ -7043,7 +7043,7 @@ var require_lodash6 = __commonJS({
7043
7043
  function isObjectLike(value) {
7044
7044
  return !!value && typeof value == "object";
7045
7045
  }
7046
- module2.exports = without2;
7046
+ module2.exports = without3;
7047
7047
  }
7048
7048
  });
7049
7049
 
@@ -40122,6 +40122,7 @@ __export(index_exports, {
40122
40122
  createSyncOrders: () => orders_default,
40123
40123
  createSyncProductDiscounts: () => product_discounts_default,
40124
40124
  createSyncProductSelections: () => product_selections_default,
40125
+ createSyncProductTailoring: () => product_tailoring_default,
40125
40126
  createSyncProductTypes: () => product_types_default,
40126
40127
  createSyncProducts: () => products_default,
40127
40128
  createSyncProjects: () => projects_default,
@@ -41055,9 +41056,15 @@ function findMatchingPairs(diff2, before = [], now = [], identifier = "id") {
41055
41056
  return result;
41056
41057
  }
41057
41058
 
41058
- // src/products/product-actions.ts
41059
+ // src/utils/array-actions-utils.ts
41059
41060
  var REGEX_NUMBER3 = new RegExp(/^\d+$/);
41060
41061
  var REGEX_UNDERSCORE_NUMBER3 = new RegExp(/^_\d+$/);
41062
+ var getIsAddAction = (key, resource) => REGEX_NUMBER3.test(key) && Array.isArray(resource) && resource.length;
41063
+ var getIsUpdateAction = (key, resource) => REGEX_NUMBER3.test(key) && Object.keys(resource).length;
41064
+ var getIsRemoveAction = (key, resource) => REGEX_UNDERSCORE_NUMBER3.test(key) && Number(resource[2]) === 0;
41065
+ var getIsItemMovedAction = (key, resource) => REGEX_UNDERSCORE_NUMBER3.test(key) && Number(resource[2]) === 3;
41066
+
41067
+ // src/products/product-actions.ts
41061
41068
  var baseActionsList4 = [
41062
41069
  { action: "changeName", key: "name" },
41063
41070
  { action: "changeSlug", key: "slug" },
@@ -41082,10 +41089,6 @@ var referenceActionsList4 = [
41082
41089
  { action: "setTaxCategory", key: "taxCategory" },
41083
41090
  { action: "transitionState", key: "state" }
41084
41091
  ];
41085
- var getIsAddAction = (key, resource) => REGEX_NUMBER3.test(key) && Array.isArray(resource) && resource.length;
41086
- var getIsUpdateAction = (key, resource) => REGEX_NUMBER3.test(key) && Object.keys(resource).length;
41087
- var getIsRemoveAction = (key, resource) => REGEX_UNDERSCORE_NUMBER3.test(key) && Number(resource[2]) === 0;
41088
- var getIsItemMovedAction = (key, resource) => REGEX_UNDERSCORE_NUMBER3.test(key) && Number(resource[2]) === 3;
41089
41092
  function _buildSkuActions(variantDiff, oldVariant) {
41090
41093
  if ({}.hasOwnProperty.call(variantDiff, "sku")) {
41091
41094
  const newValue = getDeltaValue(variantDiff.sku);
@@ -43566,8 +43569,587 @@ var product_selections_default = (actionGroupList) => {
43566
43569
  return { buildActions };
43567
43570
  };
43568
43571
 
43569
- // src/prices/prices-actions.ts
43572
+ // src/product-tailoring/product-tailoring-actions.ts
43573
+ var import_lodash14 = __toESM(require_lodash3());
43574
+ var import_lodash15 = __toESM(require_lodash4());
43575
+ var import_lodash16 = __toESM(require_lodash5());
43576
+ var import_lodash17 = __toESM(require_lodash6());
43570
43577
  var baseActionsList21 = [
43578
+ { action: "setName", key: "name" },
43579
+ { action: "setSlug", key: "slug" },
43580
+ { action: "setDescription", key: "description" }
43581
+ ];
43582
+ var metaActionsList3 = [
43583
+ { action: "setMetaTitle", key: "metaTitle" },
43584
+ { action: "setMetaDescription", key: "metaDescription" },
43585
+ { action: "setMetaKeywords", key: "metaKeywords" }
43586
+ ];
43587
+ var baseAssetActionsList2 = [
43588
+ { action: "setAssetKey", key: "key", actionKey: "assetKey" },
43589
+ { action: "changeAssetName", key: "name" },
43590
+ { action: "setAssetDescription", key: "description" },
43591
+ { action: "setAssetTags", key: "tags" },
43592
+ { action: "setAssetSources", key: "sources" }
43593
+ ];
43594
+ function _buildAttributeValue2(diffedValue, oldAttributeValue, newAttributeValue) {
43595
+ let value;
43596
+ if (Array.isArray(diffedValue))
43597
+ value = getDeltaValue(diffedValue, oldAttributeValue);
43598
+ else if (typeof diffedValue === "string")
43599
+ value = getDeltaValue(diffedValue, oldAttributeValue);
43600
+ else if (diffedValue.centAmount || diffedValue.currencyCode)
43601
+ value = {
43602
+ centAmount: diffedValue.centAmount ? getDeltaValue(diffedValue.centAmount) : newAttributeValue.centAmount,
43603
+ currencyCode: diffedValue.currencyCode ? getDeltaValue(diffedValue.currencyCode) : newAttributeValue.currencyCode
43604
+ };
43605
+ else if (diffedValue.key) value = getDeltaValue(diffedValue.key);
43606
+ else if (typeof diffedValue === "object")
43607
+ if ({}.hasOwnProperty.call(diffedValue, "_t") && diffedValue._t === "a") {
43608
+ value = newAttributeValue;
43609
+ } else {
43610
+ const updatedValue = Object.keys(diffedValue).reduce(
43611
+ (acc, lang) => {
43612
+ const patchedValue = getDeltaValue(
43613
+ diffedValue[lang],
43614
+ acc[lang]
43615
+ );
43616
+ return Object.assign(acc, { [lang]: patchedValue });
43617
+ },
43618
+ __spreadValues({}, oldAttributeValue)
43619
+ );
43620
+ value = updatedValue;
43621
+ }
43622
+ return value;
43623
+ }
43624
+ function _buildNewSetAttributeAction2(variantId, attr, sameForAllAttributeNames) {
43625
+ const attributeName = attr && attr.name;
43626
+ if (!attributeName) return void 0;
43627
+ let action = {
43628
+ action: "setAttribute",
43629
+ variantId,
43630
+ name: attributeName,
43631
+ value: attr.value
43632
+ };
43633
+ if (sameForAllAttributeNames.indexOf(attributeName) !== -1) {
43634
+ action = __spreadProps(__spreadValues({}, action), { action: "setAttributeInAllVariants" });
43635
+ delete action.variantId;
43636
+ }
43637
+ return action;
43638
+ }
43639
+ function _buildSetAttributeAction2(diffedValue, oldVariant, attribute, sameForAllAttributeNames) {
43640
+ if (!attribute || !diffedValue) return void 0;
43641
+ let action = {
43642
+ action: "setAttribute",
43643
+ variantId: oldVariant.id,
43644
+ name: attribute.name,
43645
+ value: null
43646
+ };
43647
+ const oldAttribute = (oldVariant.attributes || []).find(
43648
+ (a) => a.name === attribute.name
43649
+ );
43650
+ if (sameForAllAttributeNames.indexOf(attribute.name) !== -1) {
43651
+ action = __spreadProps(__spreadValues({}, action), { action: "setAttributeInAllVariants" });
43652
+ delete action.variantId;
43653
+ }
43654
+ action.value = _buildAttributeValue2(
43655
+ diffedValue,
43656
+ oldAttribute == null ? void 0 : oldAttribute.value,
43657
+ attribute.value
43658
+ );
43659
+ return action;
43660
+ }
43661
+ function _buildNewSetProductAttributeAction2(attr) {
43662
+ const attributeName = attr && attr.name;
43663
+ if (!attributeName) return void 0;
43664
+ return {
43665
+ action: "setProductAttribute",
43666
+ name: attributeName,
43667
+ value: attr.value
43668
+ };
43669
+ }
43670
+ function _buildSetProductAttributeAction2(diffedValue, oldProductData, newAttribute) {
43671
+ if (!newAttribute || !diffedValue) return void 0;
43672
+ const action = {
43673
+ action: "setProductAttribute",
43674
+ name: newAttribute.name,
43675
+ value: null
43676
+ };
43677
+ const oldAttribute = (oldProductData.attributes || []).find(
43678
+ (a) => a.name === newAttribute.name
43679
+ ) || {};
43680
+ action.value = _buildAttributeValue2(
43681
+ diffedValue,
43682
+ oldAttribute.value,
43683
+ newAttribute.value
43684
+ );
43685
+ return action;
43686
+ }
43687
+ function _buildVariantImagesAction2(diffedImages, oldVariant = {}, newVariant = {}) {
43688
+ const actions = [];
43689
+ const matchingImagePairs = findMatchingPairs(
43690
+ diffedImages,
43691
+ oldVariant.images,
43692
+ newVariant.images,
43693
+ "url"
43694
+ );
43695
+ (0, import_lodash14.default)(diffedImages, (image, key) => {
43696
+ const { oldObj, newObj } = extractMatchingPairs(
43697
+ matchingImagePairs,
43698
+ key,
43699
+ oldVariant.images,
43700
+ newVariant.images
43701
+ );
43702
+ if (REGEX_NUMBER3.test(key)) {
43703
+ if (Array.isArray(image) && image.length)
43704
+ actions.push({
43705
+ action: "addExternalImage",
43706
+ variantId: oldVariant.id,
43707
+ image: getDeltaValue(image)
43708
+ });
43709
+ else if (typeof image === "object") {
43710
+ if ({}.hasOwnProperty.call(image, "url") && image.url.length === 2) {
43711
+ actions.push({
43712
+ action: "removeImage",
43713
+ variantId: oldVariant.id,
43714
+ imageUrl: oldObj.url
43715
+ });
43716
+ actions.push({
43717
+ action: "addExternalImage",
43718
+ variantId: oldVariant.id,
43719
+ image: newObj
43720
+ });
43721
+ } else if ({}.hasOwnProperty.call(image, "label") && (image.label.length === 1 || image.label.length === 2))
43722
+ actions.push({
43723
+ action: "setImageLabel",
43724
+ variantId: oldVariant.id,
43725
+ imageUrl: oldObj.url,
43726
+ label: getDeltaValue(image.label)
43727
+ });
43728
+ }
43729
+ } else if (REGEX_UNDERSCORE_NUMBER3.test(key)) {
43730
+ if (Array.isArray(image) && image.length === 3) {
43731
+ if (Number(image[2]) === 3)
43732
+ actions.push({
43733
+ action: "moveImageToPosition",
43734
+ variantId: oldVariant.id,
43735
+ imageUrl: oldObj.url,
43736
+ position: Number(image[1])
43737
+ });
43738
+ else if (Number(image[2]) === 0)
43739
+ actions.push({
43740
+ action: "removeImage",
43741
+ variantId: oldVariant.id,
43742
+ imageUrl: oldObj.url
43743
+ });
43744
+ }
43745
+ }
43746
+ });
43747
+ return actions;
43748
+ }
43749
+ function toAssetIdentifier3(asset) {
43750
+ return asset.id ? { assetId: asset.id } : { assetKey: asset.key };
43751
+ }
43752
+ function toVariantIdentifier2(variant) {
43753
+ const { id, sku } = variant;
43754
+ return id ? { variantId: id } : { sku };
43755
+ }
43756
+ function _buildVariantChangeAssetOrderAction2(diffAssets, oldVariant, newVariant) {
43757
+ const isAssetOrderChanged = Object.entries(diffAssets).find(
43758
+ (entry) => getIsItemMovedAction(entry[0], entry[1])
43759
+ );
43760
+ if (!isAssetOrderChanged) return [];
43761
+ const assetIdsBefore = (oldVariant.assets || []).map((_) => _.id);
43762
+ const assetIdsCurrent = (newVariant.assets || []).map((_) => _.id).filter((_) => _ !== void 0);
43763
+ const assetIdsToKeep = (0, import_lodash16.default)(assetIdsCurrent, assetIdsBefore);
43764
+ const assetIdsToRemove = (0, import_lodash17.default)(assetIdsBefore, ...assetIdsToKeep);
43765
+ return [
43766
+ __spreadValues({
43767
+ action: "changeAssetOrder",
43768
+ assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
43769
+ }, toVariantIdentifier2(oldVariant))
43770
+ ];
43771
+ }
43772
+ function _buildVariantAssetsActions2(diffAssets, oldVariant, newVariant) {
43773
+ const assetActions = [];
43774
+ const matchingAssetPairs = findMatchingPairs(
43775
+ diffAssets,
43776
+ oldVariant.assets,
43777
+ newVariant.assets
43778
+ );
43779
+ (0, import_lodash14.default)(diffAssets, (asset, key) => {
43780
+ const { oldObj: oldAsset, newObj: newAsset } = extractMatchingPairs(
43781
+ matchingAssetPairs,
43782
+ key,
43783
+ oldVariant.assets,
43784
+ newVariant.assets
43785
+ );
43786
+ if (getIsAddAction(key, asset)) {
43787
+ assetActions.push(__spreadProps(__spreadValues({
43788
+ action: "addAsset",
43789
+ asset: getDeltaValue(asset)
43790
+ }, toVariantIdentifier2(newVariant)), {
43791
+ position: Number(key)
43792
+ }));
43793
+ return;
43794
+ }
43795
+ if (getIsUpdateAction(key, asset)) {
43796
+ const basicActions = buildBaseAttributesActions({
43797
+ actions: baseAssetActionsList2,
43798
+ diff: asset,
43799
+ oldObj: oldAsset,
43800
+ newObj: newAsset
43801
+ }).map((action) => {
43802
+ if (action.action === "setAssetKey") {
43803
+ return __spreadProps(__spreadValues(__spreadValues({}, action), toVariantIdentifier2(oldVariant)), {
43804
+ assetId: oldAsset.id
43805
+ });
43806
+ }
43807
+ return __spreadValues(__spreadValues(__spreadValues({}, action), toVariantIdentifier2(oldVariant)), toAssetIdentifier3(oldAsset));
43808
+ });
43809
+ assetActions.push(...basicActions);
43810
+ if (asset.custom) {
43811
+ const customActions = actionsMapCustom(asset, newAsset, oldAsset, __spreadValues(__spreadValues({
43812
+ actions: {
43813
+ setCustomType: "setAssetCustomType",
43814
+ setCustomField: "setAssetCustomField"
43815
+ }
43816
+ }, toVariantIdentifier2(oldVariant)), toAssetIdentifier3(oldAsset)));
43817
+ assetActions.push(...customActions);
43818
+ }
43819
+ return;
43820
+ }
43821
+ if (getIsRemoveAction(key, asset)) {
43822
+ assetActions.push(__spreadValues(__spreadValues({
43823
+ action: "removeAsset"
43824
+ }, toAssetIdentifier3(oldAsset)), toVariantIdentifier2(oldVariant)));
43825
+ }
43826
+ });
43827
+ const changedAssetOrderAction = _buildVariantChangeAssetOrderAction2(
43828
+ diffAssets,
43829
+ oldVariant,
43830
+ newVariant
43831
+ );
43832
+ return [...changedAssetOrderAction, ...assetActions];
43833
+ }
43834
+ function _buildVariantAttributesActions2(attributes, oldVariant, newVariant, sameForAllAttributeNames) {
43835
+ const actions = [];
43836
+ if (!attributes) return actions;
43837
+ (0, import_lodash14.default)(attributes, (value, key) => {
43838
+ if (REGEX_NUMBER3.test(key)) {
43839
+ if (Array.isArray(value)) {
43840
+ const { id } = oldVariant;
43841
+ const deltaValue = getDeltaValue(value);
43842
+ const setAction = _buildNewSetAttributeAction2(
43843
+ id,
43844
+ deltaValue,
43845
+ sameForAllAttributeNames
43846
+ );
43847
+ if (setAction) actions.push(setAction);
43848
+ } else if (newVariant.attributes) {
43849
+ const setAction = _buildSetAttributeAction2(
43850
+ value.value,
43851
+ oldVariant,
43852
+ newVariant.attributes[key],
43853
+ sameForAllAttributeNames
43854
+ );
43855
+ if (setAction) actions.push(setAction);
43856
+ }
43857
+ } else if (REGEX_UNDERSCORE_NUMBER3.test(key))
43858
+ if (Array.isArray(value)) {
43859
+ if (value.length === 3 && value[2] === 3) return;
43860
+ const { id } = oldVariant;
43861
+ let deltaValue = getDeltaValue(value);
43862
+ if (!deltaValue)
43863
+ if (value[0] && value[0].name) deltaValue = { name: value[0].name };
43864
+ else deltaValue = void 0;
43865
+ const setAction = _buildNewSetAttributeAction2(
43866
+ id,
43867
+ deltaValue,
43868
+ sameForAllAttributeNames
43869
+ );
43870
+ if (setAction) actions.push(setAction);
43871
+ } else {
43872
+ const index = key.substring(1);
43873
+ if (newVariant.attributes) {
43874
+ const setAction = _buildSetAttributeAction2(
43875
+ value.value,
43876
+ oldVariant,
43877
+ newVariant.attributes[index],
43878
+ sameForAllAttributeNames
43879
+ );
43880
+ if (setAction) actions.push(setAction);
43881
+ }
43882
+ }
43883
+ });
43884
+ return actions;
43885
+ }
43886
+ function _buildProductAttributesActions2(diffedAttributes, oldProductData, newProductData) {
43887
+ const actions = [];
43888
+ if (!diffedAttributes) return actions;
43889
+ (0, import_lodash14.default)(diffedAttributes, (value, key) => {
43890
+ if (REGEX_NUMBER3.test(key)) {
43891
+ if (Array.isArray(value)) {
43892
+ const setAction = _buildNewSetProductAttributeAction2(
43893
+ getDeltaValue(value)
43894
+ );
43895
+ if (setAction) actions.push(setAction);
43896
+ } else if (newProductData.attributes) {
43897
+ const setAction = _buildSetProductAttributeAction2(
43898
+ value["value"],
43899
+ oldProductData,
43900
+ newProductData.attributes[key]
43901
+ );
43902
+ if (setAction) actions.push(setAction);
43903
+ }
43904
+ } else if (REGEX_UNDERSCORE_NUMBER3.test(key)) {
43905
+ if (Array.isArray(value)) {
43906
+ if (value.length === 3 && value[2] === 3) return;
43907
+ let deltaValue = getDeltaValue(value);
43908
+ if (!deltaValue)
43909
+ if (value[0] && value[0].name) deltaValue = { name: value[0].name };
43910
+ else deltaValue = void 0;
43911
+ const setAction = _buildNewSetProductAttributeAction2(
43912
+ deltaValue
43913
+ );
43914
+ if (setAction) actions.push(setAction);
43915
+ } else {
43916
+ const index = key.substring(1);
43917
+ if (newProductData.attributes) {
43918
+ const setAction = _buildSetProductAttributeAction2(
43919
+ value["value"],
43920
+ oldProductData,
43921
+ newProductData.attributes[index]
43922
+ );
43923
+ if (setAction) actions.push(setAction);
43924
+ }
43925
+ }
43926
+ }
43927
+ });
43928
+ return actions;
43929
+ }
43930
+ function actionsMapBase21(diff2, oldObj, newObj, config = {}) {
43931
+ return buildBaseAttributesActions({
43932
+ actions: baseActionsList21,
43933
+ diff: diff2,
43934
+ oldObj,
43935
+ newObj,
43936
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
43937
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
43938
+ });
43939
+ }
43940
+ function actionsMapMeta3(diff2, oldObj, newObj, config = {}) {
43941
+ return buildBaseAttributesActions({
43942
+ actions: metaActionsList3,
43943
+ diff: diff2,
43944
+ oldObj,
43945
+ newObj,
43946
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
43947
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
43948
+ });
43949
+ }
43950
+ function actionsMapAddVariants2(diff2, oldObj, newObj) {
43951
+ const handler = createBuildArrayActions("variants", {
43952
+ [ADD_ACTIONS]: (newObject) => __spreadProps(__spreadValues({}, newObject), {
43953
+ action: "addVariant"
43954
+ })
43955
+ });
43956
+ return handler(diff2, oldObj, newObj);
43957
+ }
43958
+ function actionsMapRemoveVariants2(diff2, oldObj, newObj) {
43959
+ const handler = createBuildArrayActions("variants", {
43960
+ [REMOVE_ACTIONS]: ({ id, sku }) => __spreadValues({
43961
+ action: "removeVariant"
43962
+ }, id ? { id } : { sku })
43963
+ });
43964
+ return handler(diff2, oldObj, newObj);
43965
+ }
43966
+ function actionsMapImages2(diff2, oldObj, newObj, variantHashMap) {
43967
+ let actions = [];
43968
+ const { variants } = diff2;
43969
+ if (variants)
43970
+ (0, import_lodash14.default)(variants, (variant, key) => {
43971
+ const { oldObj: oldVariant, newObj: newVariant } = extractMatchingPairs(
43972
+ variantHashMap,
43973
+ key,
43974
+ oldObj.variants,
43975
+ newObj.variants
43976
+ );
43977
+ if (REGEX_UNDERSCORE_NUMBER3.test(key) || REGEX_NUMBER3.test(key)) {
43978
+ const vActions = _buildVariantImagesAction2(
43979
+ variant.images,
43980
+ oldVariant,
43981
+ newVariant
43982
+ );
43983
+ actions = actions.concat(vActions);
43984
+ }
43985
+ });
43986
+ return actions;
43987
+ }
43988
+ function actionsMapAssets3(diff2, oldObj, newObj, variantHashMap) {
43989
+ let allAssetsActions = [];
43990
+ const { variants } = diff2;
43991
+ if (variants)
43992
+ (0, import_lodash14.default)(variants, (variant, key) => {
43993
+ const { oldObj: oldVariant, newObj: newVariant } = extractMatchingPairs(
43994
+ variantHashMap,
43995
+ key,
43996
+ oldObj.variants,
43997
+ newObj.variants
43998
+ );
43999
+ if (variant.assets && (REGEX_UNDERSCORE_NUMBER3.test(key) || REGEX_NUMBER3.test(key))) {
44000
+ const assetActions = _buildVariantAssetsActions2(
44001
+ variant.assets,
44002
+ oldVariant,
44003
+ newVariant
44004
+ );
44005
+ allAssetsActions = allAssetsActions.concat(assetActions);
44006
+ }
44007
+ });
44008
+ return allAssetsActions;
44009
+ }
44010
+ function actionsMapProductAttributes2(diff2, oldObj, newObj) {
44011
+ return _buildProductAttributesActions2(diff2.attributes, oldObj, newObj);
44012
+ }
44013
+ function actionsMapVariantAttributes(diff2, oldObj, newObj, sameForAllAttributeNames = [], variantHashMap) {
44014
+ let actions = [];
44015
+ const { variants } = diff2;
44016
+ if (variants)
44017
+ (0, import_lodash14.default)(variants, (variant, key) => {
44018
+ const { oldObj: oldVariant, newObj: newVariant } = extractMatchingPairs(
44019
+ variantHashMap,
44020
+ key,
44021
+ oldObj.variants,
44022
+ newObj.variants
44023
+ );
44024
+ if (REGEX_NUMBER3.test(key) && !Array.isArray(variant)) {
44025
+ const { attributes } = variant;
44026
+ const attrActions = _buildVariantAttributesActions2(
44027
+ attributes,
44028
+ oldVariant,
44029
+ newVariant,
44030
+ sameForAllAttributeNames
44031
+ );
44032
+ actions = actions.concat(attrActions);
44033
+ }
44034
+ });
44035
+ return (0, import_lodash15.default)(
44036
+ actions,
44037
+ (a, b) => a.action === b.action && a.name === b.name && a.variantId === b.variantId
44038
+ );
44039
+ }
44040
+
44041
+ // src/product-tailoring/product-tailoring.ts
44042
+ function createProductTailoringMapActions(mapActionGroup, syncActionConfig) {
44043
+ return function doMapActions(diff2, newObj, oldObj, options = {}) {
44044
+ const allActions = [];
44045
+ const { publish, staged } = newObj;
44046
+ const variantHashMap = findMatchingPairs(
44047
+ diff2.variants,
44048
+ oldObj.variants,
44049
+ newObj.variants
44050
+ );
44051
+ const config = __spreadValues(__spreadValues({}, syncActionConfig), options);
44052
+ allActions.push(
44053
+ mapActionGroup(
44054
+ "base",
44055
+ () => actionsMapBase21(diff2, oldObj, newObj, config)
44056
+ )
44057
+ );
44058
+ allActions.push(
44059
+ mapActionGroup(
44060
+ "meta",
44061
+ () => actionsMapMeta3(diff2, oldObj, newObj, config)
44062
+ )
44063
+ );
44064
+ allActions.push(
44065
+ mapActionGroup(
44066
+ "variants",
44067
+ () => actionsMapAddVariants2(diff2, oldObj, newObj)
44068
+ )
44069
+ );
44070
+ allActions.push(
44071
+ mapActionGroup(
44072
+ "variants",
44073
+ () => actionsMapRemoveVariants2(diff2, oldObj, newObj)
44074
+ )
44075
+ );
44076
+ allActions.push(
44077
+ mapActionGroup(
44078
+ "images",
44079
+ () => actionsMapImages2(
44080
+ diff2,
44081
+ oldObj,
44082
+ newObj,
44083
+ variantHashMap
44084
+ )
44085
+ )
44086
+ );
44087
+ allActions.push(
44088
+ mapActionGroup(
44089
+ "assets",
44090
+ () => actionsMapAssets3(
44091
+ diff2,
44092
+ oldObj,
44093
+ newObj,
44094
+ variantHashMap
44095
+ )
44096
+ )
44097
+ );
44098
+ allActions.push(
44099
+ mapActionGroup(
44100
+ "attributes",
44101
+ () => actionsMapProductAttributes2(
44102
+ diff2,
44103
+ oldObj,
44104
+ newObj
44105
+ )
44106
+ )
44107
+ );
44108
+ allActions.push(
44109
+ mapActionGroup(
44110
+ "attributes",
44111
+ () => actionsMapVariantAttributes(
44112
+ diff2,
44113
+ oldObj,
44114
+ newObj,
44115
+ options.sameForAllAttributeNames || [],
44116
+ variantHashMap
44117
+ )
44118
+ )
44119
+ );
44120
+ if (publish === true || staged === false)
44121
+ return allActions.flat().map((action) => __spreadProps(__spreadValues({}, action), {
44122
+ staged: false
44123
+ }));
44124
+ return allActions.flat();
44125
+ };
44126
+ }
44127
+ function prepareVariantsForDiff(before, now) {
44128
+ const [beforeCopy, nowCopy] = copyEmptyArrayProps(
44129
+ before,
44130
+ now
44131
+ );
44132
+ const ensureVariants = (obj) => __spreadProps(__spreadValues({}, obj), {
44133
+ variants: (obj == null ? void 0 : obj.variants) || []
44134
+ });
44135
+ return [ensureVariants(beforeCopy), ensureVariants(nowCopy)];
44136
+ }
44137
+ var product_tailoring_default = (actionGroupList, syncActionConfig) => {
44138
+ const mapActionGroup = createMapActionGroup(actionGroupList);
44139
+ const doMapActions = createProductTailoringMapActions(
44140
+ mapActionGroup,
44141
+ syncActionConfig
44142
+ );
44143
+ const buildActions = createBuildActions(
44144
+ diff,
44145
+ doMapActions,
44146
+ prepareVariantsForDiff
44147
+ );
44148
+ return { buildActions };
44149
+ };
44150
+
44151
+ // src/prices/prices-actions.ts
44152
+ var baseActionsList22 = [
43571
44153
  { action: "changeValue", key: "value" },
43572
44154
  { action: "setDiscountedPrice", key: "discounted" },
43573
44155
  // TODO: Later add more accurate actions `addPriceTier`, `removePriceTier`
@@ -43577,9 +44159,9 @@ var baseActionsList21 = [
43577
44159
  { action: "setValidUntil", key: "validUntil" },
43578
44160
  { action: "changeActive", key: "active" }
43579
44161
  ];
43580
- function actionsMapBase21(diff2, oldObj, newObj, config = {}) {
44162
+ function actionsMapBase22(diff2, oldObj, newObj, config = {}) {
43581
44163
  return buildBaseAttributesActions({
43582
- actions: baseActionsList21,
44164
+ actions: baseActionsList22,
43583
44165
  diff: diff2,
43584
44166
  oldObj,
43585
44167
  newObj,
@@ -43594,7 +44176,7 @@ function createPriceMapActions(mapActionGroup, syncActionConfig) {
43594
44176
  return function doMapActions(diff2, newObj, oldObj) {
43595
44177
  const baseActions = mapActionGroup(
43596
44178
  "base",
43597
- () => actionsMapBase21(diff2, oldObj, newObj, syncActionConfig)
44179
+ () => actionsMapBase22(diff2, oldObj, newObj, syncActionConfig)
43598
44180
  );
43599
44181
  const customActions = mapActionGroup(
43600
44182
  "custom",
@@ -43615,14 +44197,14 @@ var prices_default = (actionGroupList, syncActionConfig) => {
43615
44197
 
43616
44198
  // src/attribute-groups/attribute-groups-actions.ts
43617
44199
  var hasAttribute = (attributes, newValue) => attributes.some((attribute) => attribute.key === newValue.key);
43618
- var baseActionsList22 = [
44200
+ var baseActionsList23 = [
43619
44201
  { action: "changeName", key: "name" },
43620
44202
  { action: "setKey", key: "key" },
43621
44203
  { action: "setDescription", key: "description" }
43622
44204
  ];
43623
- function actionsMapBase22(diff2, oldObj, newObj, config = {}) {
44205
+ function actionsMapBase23(diff2, oldObj, newObj, config = {}) {
43624
44206
  return buildBaseAttributesActions({
43625
- actions: baseActionsList22,
44207
+ actions: baseActionsList23,
43626
44208
  diff: diff2,
43627
44209
  oldObj,
43628
44210
  newObj,
@@ -43668,7 +44250,7 @@ function createAttributeGroupsMapActions(mapActionGroup, syncActionConfig) {
43668
44250
  allActions.push(
43669
44251
  mapActionGroup(
43670
44252
  "base",
43671
- () => actionsMapBase22(diff2, oldObj, newObj, syncActionConfig)
44253
+ () => actionsMapBase23(diff2, oldObj, newObj, syncActionConfig)
43672
44254
  )
43673
44255
  );
43674
44256
  allActions.push(
@@ -43698,15 +44280,15 @@ var attribute_groups_default = (actionGroupList, syncActionConfig) => {
43698
44280
  };
43699
44281
 
43700
44282
  // src/api-extensions/api-extensions-actions.ts
43701
- var baseActionsList23 = [
44283
+ var baseActionsList24 = [
43702
44284
  { action: "setKey", key: "key" },
43703
44285
  { action: "changeTriggers", key: "triggers" },
43704
44286
  { action: "setTimeoutInMs", key: "timeoutInMs" },
43705
44287
  { action: "changeDestination", key: "destination" }
43706
44288
  ];
43707
- var actionsMapBase23 = (diff2, oldObj, newObj, config) => {
44289
+ var actionsMapBase24 = (diff2, oldObj, newObj, config) => {
43708
44290
  return buildBaseAttributesActions({
43709
- actions: baseActionsList23,
44291
+ actions: baseActionsList24,
43710
44292
  diff: diff2,
43711
44293
  oldObj,
43712
44294
  newObj,
@@ -43721,7 +44303,7 @@ var createApiExtensionsMapActions = (mapActionGroup, syncActionConfig) => {
43721
44303
  allActions.push(
43722
44304
  mapActionGroup(
43723
44305
  "base",
43724
- () => actionsMapBase23(diff2, oldObj, newObj, syncActionConfig)
44306
+ () => actionsMapBase24(diff2, oldObj, newObj, syncActionConfig)
43725
44307
  )
43726
44308
  );
43727
44309
  return allActions.flat();
@@ -43738,7 +44320,7 @@ var api_extensions_default = (actionGroupList, syncActionConfig) => {
43738
44320
  };
43739
44321
 
43740
44322
  // src/business-units/business-units-actions.ts
43741
- var baseActionsList24 = [
44323
+ var baseActionsList25 = [
43742
44324
  {
43743
44325
  action: "setStores",
43744
44326
  key: "stores"
@@ -43774,9 +44356,9 @@ var actionsMapAssociates = (diff2, oldObj, newObj) => {
43774
44356
  });
43775
44357
  return handler(diff2, oldObj, newObj);
43776
44358
  };
43777
- var actionsMapBase24 = (diff2, oldObj, newObj, config) => {
44359
+ var actionsMapBase25 = (diff2, oldObj, newObj, config) => {
43778
44360
  return buildBaseAttributesActions({
43779
- actions: baseActionsList24,
44361
+ actions: baseActionsList25,
43780
44362
  diff: diff2,
43781
44363
  oldObj,
43782
44364
  newObj,
@@ -43791,7 +44373,7 @@ var createCustomerMapActions2 = (mapActionGroup, syncActionConfig) => {
43791
44373
  allActions.push(
43792
44374
  mapActionGroup(
43793
44375
  "base",
43794
- () => actionsMapBase24(
44376
+ () => actionsMapBase25(
43795
44377
  diff2,
43796
44378
  oldObj,
43797
44379
  newObj,
@@ -43866,15 +44448,15 @@ var business_units_default = (actionGroupList, syncActionConfig) => {
43866
44448
  };
43867
44449
 
43868
44450
  // src/subscriptions/subscriptions-actions.ts
43869
- var baseActionsList25 = [
44451
+ var baseActionsList26 = [
43870
44452
  { action: "setKey", key: "key" },
43871
44453
  { action: "setMessages", key: "messages" },
43872
44454
  { action: "setChanges", key: "changes" },
43873
44455
  { action: "changeDestination", key: "destination" }
43874
44456
  ];
43875
- var actionsMapBase25 = (diff2, oldObj, newObj, config) => {
44457
+ var actionsMapBase26 = (diff2, oldObj, newObj, config) => {
43876
44458
  return buildBaseAttributesActions({
43877
- actions: baseActionsList25,
44459
+ actions: baseActionsList26,
43878
44460
  diff: diff2,
43879
44461
  oldObj,
43880
44462
  newObj,
@@ -43889,7 +44471,7 @@ var createSubscriptionsMapActions = (mapActionGroup, syncActionConfig) => {
43889
44471
  allActions.push(
43890
44472
  mapActionGroup(
43891
44473
  "base",
43892
- () => actionsMapBase25(
44474
+ () => actionsMapBase26(
43893
44475
  diff2,
43894
44476
  oldObj,
43895
44477
  newObj,
@@ -43934,6 +44516,7 @@ __reExport(index_exports, types_exports, module.exports);
43934
44516
  createSyncOrders,
43935
44517
  createSyncProductDiscounts,
43936
44518
  createSyncProductSelections,
44519
+ createSyncProductTailoring,
43937
44520
  createSyncProductTypes,
43938
44521
  createSyncProducts,
43939
44522
  createSyncProjects,