@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.mjs CHANGED
@@ -1002,13 +1002,13 @@ var ProjectService = class {
1002
1002
  if (!project) {
1003
1003
  return response.status(404).send({});
1004
1004
  }
1005
- this.repository.processUpdateActions(
1005
+ const updatedResource = this.repository.processUpdateActions(
1006
1006
  getRepositoryContext(request),
1007
1007
  project,
1008
1008
  updateRequest.version,
1009
1009
  updateRequest.actions
1010
1010
  );
1011
- return response.status(200).send({});
1011
+ return response.status(200).send(updatedResource);
1012
1012
  }
1013
1013
  };
1014
1014
 
@@ -2637,6 +2637,123 @@ var ProductRepository = class extends AbstractResourceRepository {
2637
2637
  setKey: (context, resource, { key }) => {
2638
2638
  resource.key = key;
2639
2639
  return resource;
2640
+ },
2641
+ addExternalImage: (context, resource, { variantId, sku, image, staged }) => {
2642
+ const addImg = (data) => {
2643
+ const { variant, isMasterVariant, variantIndex } = getVariant(
2644
+ data,
2645
+ variantId,
2646
+ sku
2647
+ );
2648
+ if (!variant) {
2649
+ throw new Error(
2650
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
2651
+ );
2652
+ }
2653
+ if (!variant.images) {
2654
+ variant.images = [];
2655
+ } else {
2656
+ const existingImage = variant.images.find((x) => x.url === image.url);
2657
+ if (existingImage) {
2658
+ throw new Error(
2659
+ `Cannot add image '${image.url}' because product '${resource.id}' already has that image.`
2660
+ );
2661
+ }
2662
+ }
2663
+ variant.images.push(image);
2664
+ if (isMasterVariant) {
2665
+ data.masterVariant = variant;
2666
+ } else {
2667
+ data.variants[variantIndex] = variant;
2668
+ }
2669
+ };
2670
+ const onlyStaged = staged !== void 0 ? staged : true;
2671
+ addImg(resource.masterData.staged);
2672
+ if (!onlyStaged) {
2673
+ addImg(resource.masterData.current);
2674
+ }
2675
+ checkForStagedChanges(resource);
2676
+ return resource;
2677
+ },
2678
+ removeImage: (context, resource, { variantId, sku, imageUrl, staged }) => {
2679
+ const removeImg = (data) => {
2680
+ const { variant, isMasterVariant, variantIndex } = getVariant(
2681
+ data,
2682
+ variantId,
2683
+ sku
2684
+ );
2685
+ if (!variant) {
2686
+ throw new Error(
2687
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
2688
+ );
2689
+ }
2690
+ const variantImages = variant.images ?? [];
2691
+ const existingImage = variantImages.find((x) => x.url === imageUrl);
2692
+ if (!existingImage) {
2693
+ throw new Error(
2694
+ `Cannot remove image '${imageUrl}' because product '${resource.id}' does not have that image.`
2695
+ );
2696
+ }
2697
+ variant.images = variantImages.filter((image) => image.url !== imageUrl);
2698
+ if (isMasterVariant) {
2699
+ data.masterVariant = variant;
2700
+ } else {
2701
+ data.variants[variantIndex] = variant;
2702
+ }
2703
+ };
2704
+ const onlyStaged = staged !== void 0 ? staged : true;
2705
+ removeImg(resource.masterData.staged);
2706
+ if (!onlyStaged) {
2707
+ removeImg(resource.masterData.current);
2708
+ }
2709
+ checkForStagedChanges(resource);
2710
+ return resource;
2711
+ },
2712
+ moveImageToPosition: (context, resource, {
2713
+ variantId,
2714
+ sku,
2715
+ imageUrl,
2716
+ position,
2717
+ staged
2718
+ }) => {
2719
+ const moveImg = (data) => {
2720
+ const { variant, isMasterVariant, variantIndex } = getVariant(
2721
+ data,
2722
+ variantId,
2723
+ sku
2724
+ );
2725
+ if (!variant) {
2726
+ throw new Error(
2727
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
2728
+ );
2729
+ }
2730
+ const variantImages = variant.images ?? [];
2731
+ const existingImage = variantImages.find((x) => x.url === imageUrl);
2732
+ if (!existingImage) {
2733
+ throw new Error(
2734
+ `Cannot move image '${imageUrl}' because product '${resource.id}' does not have that image.`
2735
+ );
2736
+ }
2737
+ if (position >= variantImages.length) {
2738
+ throw new Error(
2739
+ `Invalid position given. Position in images where the image should be moved. Must be between 0 and the total number of images minus 1.`
2740
+ );
2741
+ }
2742
+ variant.images = variantImages.filter((image) => image.url !== imageUrl);
2743
+ variant.images.splice(position, 0, existingImage);
2744
+ if (isMasterVariant) {
2745
+ data.masterVariant = variant;
2746
+ } else {
2747
+ data.variants[variantIndex] = variant;
2748
+ }
2749
+ };
2750
+ const onlyStaged = staged !== void 0 ? staged : true;
2751
+ moveImg(resource.masterData.staged);
2752
+ if (!onlyStaged) {
2753
+ moveImg(resource.masterData.current);
2754
+ }
2755
+ checkForStagedChanges(resource);
2756
+ return resource;
2640
2757
  }
2641
2758
  };
2642
2759
  }
@@ -3486,6 +3603,7 @@ var ProjectRepository = class extends AbstractRepository {
3486
3603
  },
3487
3604
  changeMessagesConfiguration: (context, resource, { messagesConfiguration }) => {
3488
3605
  resource.messages.enabled = messagesConfiguration.enabled;
3606
+ resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
3489
3607
  },
3490
3608
  changeProductSearchIndexingEnabled: (context, resource, { enabled }) => {
3491
3609
  var _a;
@@ -3805,6 +3923,9 @@ var StateRepository = class extends AbstractResourceRepository {
3805
3923
  changeKey: (context, resource, { key }) => {
3806
3924
  resource.key = key;
3807
3925
  },
3926
+ changeInitial: (context, resource, { initial }) => {
3927
+ resource.initial = initial;
3928
+ },
3808
3929
  setDescription: (context, resource, { description }) => {
3809
3930
  resource.description = description;
3810
3931
  },