@labdigital/commercetools-mock 0.10.1 → 0.12.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/dist/index.js CHANGED
@@ -1035,13 +1035,13 @@ var ProjectService = class {
1035
1035
  if (!project) {
1036
1036
  return response.status(404).send({});
1037
1037
  }
1038
- this.repository.processUpdateActions(
1038
+ const updatedResource = this.repository.processUpdateActions(
1039
1039
  getRepositoryContext(request),
1040
1040
  project,
1041
1041
  updateRequest.version,
1042
1042
  updateRequest.actions
1043
1043
  );
1044
- return response.status(200).send({});
1044
+ return response.status(200).send(updatedResource);
1045
1045
  }
1046
1046
  };
1047
1047
 
@@ -2670,6 +2670,123 @@ var ProductRepository = class extends AbstractResourceRepository {
2670
2670
  setKey: (context, resource, { key }) => {
2671
2671
  resource.key = key;
2672
2672
  return resource;
2673
+ },
2674
+ addExternalImage: (context, resource, { variantId, sku, image, staged }) => {
2675
+ const addImg = (data) => {
2676
+ const { variant, isMasterVariant, variantIndex } = getVariant(
2677
+ data,
2678
+ variantId,
2679
+ sku
2680
+ );
2681
+ if (!variant) {
2682
+ throw new Error(
2683
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
2684
+ );
2685
+ }
2686
+ if (!variant.images) {
2687
+ variant.images = [];
2688
+ } else {
2689
+ const existingImage = variant.images.find((x) => x.url === image.url);
2690
+ if (existingImage) {
2691
+ throw new Error(
2692
+ `Cannot add image '${image.url}' because product '${resource.id}' already has that image.`
2693
+ );
2694
+ }
2695
+ }
2696
+ variant.images.push(image);
2697
+ if (isMasterVariant) {
2698
+ data.masterVariant = variant;
2699
+ } else {
2700
+ data.variants[variantIndex] = variant;
2701
+ }
2702
+ };
2703
+ const onlyStaged = staged !== void 0 ? staged : true;
2704
+ addImg(resource.masterData.staged);
2705
+ if (!onlyStaged) {
2706
+ addImg(resource.masterData.current);
2707
+ }
2708
+ checkForStagedChanges(resource);
2709
+ return resource;
2710
+ },
2711
+ removeImage: (context, resource, { variantId, sku, imageUrl, staged }) => {
2712
+ const removeImg = (data) => {
2713
+ const { variant, isMasterVariant, variantIndex } = getVariant(
2714
+ data,
2715
+ variantId,
2716
+ sku
2717
+ );
2718
+ if (!variant) {
2719
+ throw new Error(
2720
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
2721
+ );
2722
+ }
2723
+ const variantImages = variant.images ?? [];
2724
+ const existingImage = variantImages.find((x) => x.url === imageUrl);
2725
+ if (!existingImage) {
2726
+ throw new Error(
2727
+ `Cannot remove image '${imageUrl}' because product '${resource.id}' does not have that image.`
2728
+ );
2729
+ }
2730
+ variant.images = variantImages.filter((image) => image.url !== imageUrl);
2731
+ if (isMasterVariant) {
2732
+ data.masterVariant = variant;
2733
+ } else {
2734
+ data.variants[variantIndex] = variant;
2735
+ }
2736
+ };
2737
+ const onlyStaged = staged !== void 0 ? staged : true;
2738
+ removeImg(resource.masterData.staged);
2739
+ if (!onlyStaged) {
2740
+ removeImg(resource.masterData.current);
2741
+ }
2742
+ checkForStagedChanges(resource);
2743
+ return resource;
2744
+ },
2745
+ moveImageToPosition: (context, resource, {
2746
+ variantId,
2747
+ sku,
2748
+ imageUrl,
2749
+ position,
2750
+ staged
2751
+ }) => {
2752
+ const moveImg = (data) => {
2753
+ const { variant, isMasterVariant, variantIndex } = getVariant(
2754
+ data,
2755
+ variantId,
2756
+ sku
2757
+ );
2758
+ if (!variant) {
2759
+ throw new Error(
2760
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
2761
+ );
2762
+ }
2763
+ const variantImages = variant.images ?? [];
2764
+ const existingImage = variantImages.find((x) => x.url === imageUrl);
2765
+ if (!existingImage) {
2766
+ throw new Error(
2767
+ `Cannot move image '${imageUrl}' because product '${resource.id}' does not have that image.`
2768
+ );
2769
+ }
2770
+ if (position >= variantImages.length) {
2771
+ throw new Error(
2772
+ `Invalid position given. Position in images where the image should be moved. Must be between 0 and the total number of images minus 1.`
2773
+ );
2774
+ }
2775
+ variant.images = variantImages.filter((image) => image.url !== imageUrl);
2776
+ variant.images.splice(position, 0, existingImage);
2777
+ if (isMasterVariant) {
2778
+ data.masterVariant = variant;
2779
+ } else {
2780
+ data.variants[variantIndex] = variant;
2781
+ }
2782
+ };
2783
+ const onlyStaged = staged !== void 0 ? staged : true;
2784
+ moveImg(resource.masterData.staged);
2785
+ if (!onlyStaged) {
2786
+ moveImg(resource.masterData.current);
2787
+ }
2788
+ checkForStagedChanges(resource);
2789
+ return resource;
2673
2790
  }
2674
2791
  };
2675
2792
  }
@@ -3519,6 +3636,7 @@ var ProjectRepository = class extends AbstractRepository {
3519
3636
  },
3520
3637
  changeMessagesConfiguration: (context, resource, { messagesConfiguration }) => {
3521
3638
  resource.messages.enabled = messagesConfiguration.enabled;
3639
+ resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
3522
3640
  },
3523
3641
  changeProductSearchIndexingEnabled: (context, resource, { enabled }) => {
3524
3642
  var _a;
@@ -3838,6 +3956,9 @@ var StateRepository = class extends AbstractResourceRepository {
3838
3956
  changeKey: (context, resource, { key }) => {
3839
3957
  resource.key = key;
3840
3958
  },
3959
+ changeInitial: (context, resource, { initial }) => {
3960
+ resource.initial = initial;
3961
+ },
3841
3962
  setDescription: (context, resource, { description }) => {
3842
3963
  resource.description = description;
3843
3964
  },