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