@shopware/composables 1.9.0 → 1.10.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.
Files changed (34) hide show
  1. package/README.md +30 -6
  2. package/dist/index.d.mts +99 -29
  3. package/dist/index.d.ts +99 -29
  4. package/dist/index.mjs +104 -59
  5. package/package.json +10 -10
  6. package/src/cms/cmsAssociations.ts +5 -1
  7. package/src/cms/useCmsElementConfig.ts +1 -1
  8. package/src/types/cmsBlockTypes.ts +2 -0
  9. package/src/types/cmsElementTypes.ts +25 -19
  10. package/src/useCart/useCart.test.ts +12 -0
  11. package/src/useCart/useCart.ts +17 -0
  12. package/src/useCountries/useCountries.test.ts +41 -0
  13. package/src/useCountries/useCountries.ts +16 -0
  14. package/src/useCustomerOrders/useCustomerOrders.ts +1 -1
  15. package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +19 -21
  16. package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.ts +23 -30
  17. package/src/useLandingSearch/useLandingSearch.test.ts +1 -1
  18. package/src/useLandingSearch/useLandingSearch.ts +1 -1
  19. package/src/useListing/useListing.test.ts +73 -0
  20. package/src/useListing/useListing.ts +10 -3
  21. package/src/useNavigationSearch/useNavigationSearch.test.ts +21 -0
  22. package/src/useNavigationSearch/useNavigationSearch.ts +6 -3
  23. package/src/useNewsletter/useNewsletter.ts +13 -0
  24. package/src/useOrderDetails/useOrderDetails.ts +5 -11
  25. package/src/useOrderPayment/useOrderPayment.ts +1 -0
  26. package/src/usePrice/usePrice.test.ts +3 -3
  27. package/src/useProductWishlist/useProductWishlist.ts +2 -2
  28. package/src/useSessionContext/useSessionContext.ts +1 -1
  29. package/src/useSyncWishlist/useSyncWishlist.test.ts +34 -17
  30. package/src/useSyncWishlist/useSyncWishlist.ts +27 -8
  31. package/src/useUser/useUser.test.ts +126 -3
  32. package/src/useUser/useUser.ts +6 -1
  33. package/src/useWishlist/useWishlist.test.ts +9 -0
  34. package/src/useWishlist/useWishlist.ts +22 -6
package/dist/index.mjs CHANGED
@@ -292,6 +292,17 @@ function useCartFunction() {
292
292
  setCartErrors(data);
293
293
  return data;
294
294
  }
295
+ async function removeItemById(id) {
296
+ const { data } = await apiClient.invoke(
297
+ "removeLineItem post /checkout/cart/line-item/delete",
298
+ {
299
+ body: { ids: [id] }
300
+ }
301
+ );
302
+ _storeCart.value = data;
303
+ setCartErrors(data);
304
+ return data;
305
+ }
295
306
  async function changeProductQuantity(params) {
296
307
  const { data } = await apiClient.invoke(
297
308
  "updateLineItem patch /checkout/cart/line-item",
@@ -388,6 +399,7 @@ function useCartFunction() {
388
399
  count,
389
400
  refreshCart,
390
401
  removeItem,
402
+ removeItemById,
391
403
  totalPrice,
392
404
  shippingTotal,
393
405
  subtotal,
@@ -475,7 +487,11 @@ function useCategory(category) {
475
487
 
476
488
  const cmsAssociations = {
477
489
  associations: {
478
- media: {},
490
+ media: {
491
+ associations: {
492
+ media: {}
493
+ }
494
+ },
479
495
  cmsPage: {
480
496
  associations: {
481
497
  sections: {
@@ -696,6 +712,12 @@ function useCountries() {
696
712
  const getCountries = computed(() => {
697
713
  return _sharedCountries.value ?? [];
698
714
  });
715
+ const getCountriesOptions = computed(() => {
716
+ return _sharedCountries.value?.map((element) => ({
717
+ label: element.translated.name,
718
+ value: element.id
719
+ })) ?? [];
720
+ });
699
721
  const mountedCallback = async () => {
700
722
  if (!_sharedCountries.value) {
701
723
  await fetchCountries();
@@ -711,7 +733,8 @@ function useCountries() {
711
733
  mountedCallback,
712
734
  fetchCountries,
713
735
  getStatesForCountry,
714
- getCountries
736
+ getCountries,
737
+ getCountriesOptions
715
738
  };
716
739
  }
717
740
 
@@ -779,31 +802,29 @@ function useCustomerPassword() {
779
802
 
780
803
  function useDefaultOrderAssociations() {
781
804
  const orderAssociations = {
782
- associations: {
783
- stateMachineState: {},
784
- lineItems: {
785
- associations: {
786
- cover: {},
787
- downloads: {
788
- associations: {
789
- media: {}
790
- }
805
+ stateMachineState: {},
806
+ lineItems: {
807
+ associations: {
808
+ cover: {},
809
+ downloads: {
810
+ associations: {
811
+ media: {}
791
812
  }
792
813
  }
793
- },
794
- addresses: {},
795
- deliveries: {
796
- associations: {
797
- shippingMethod: {},
798
- shippingOrderAddress: {},
799
- stateMachineState: {}
800
- }
801
- },
802
- transactions: {
803
- associations: {
804
- paymentMethod: {},
805
- stateMachineState: {}
806
- }
814
+ }
815
+ },
816
+ addresses: {},
817
+ deliveries: {
818
+ associations: {
819
+ shippingMethod: {},
820
+ shippingOrderAddress: {},
821
+ stateMachineState: {}
822
+ }
823
+ },
824
+ transactions: {
825
+ associations: {
826
+ paymentMethod: {},
827
+ stateMachineState: {}
807
828
  }
808
829
  }
809
830
  };
@@ -873,7 +894,7 @@ function useInternationalization(pathResolver) {
873
894
  function useLandingSearch() {
874
895
  const { apiClient } = useShopwareContext();
875
896
  const search = async (navigationId, options) => {
876
- const associations = options?.withCmsAssociations ? cmsAssociations : {};
897
+ const associations = options?.withCmsAssociations ? cmsAssociations.associations : {};
877
898
  const result = await apiClient.invoke(
878
899
  "readLandingPage post /landing-page/{landingPageId}",
879
900
  {
@@ -953,13 +974,17 @@ function useListing(params) {
953
974
  return createListingComposable({
954
975
  listingKey: listingType,
955
976
  searchMethod,
956
- searchDefaults: params?.defaultSearchCriteria || {}
977
+ searchDefaults: params?.defaultSearchCriteria || {},
957
978
  //getDefaults(),
979
+ initialListing: params?.initialListing
958
980
  });
959
981
  }
960
982
  const [_createCategoryListingContext, _categoryListingContext] = createInjectionState(
961
- () => {
962
- return useListing({ listingType: "categoryListing" });
983
+ (initialListing) => {
984
+ return useListing({
985
+ listingType: "categoryListing",
986
+ initialListing
987
+ });
963
988
  },
964
989
  {
965
990
  injectionKey: "categoryListing"
@@ -981,17 +1006,18 @@ const useProductSearchListing = createSharedComposable(
981
1006
  function createListingComposable({
982
1007
  searchMethod,
983
1008
  searchDefaults,
984
- listingKey
1009
+ listingKey,
1010
+ initialListing
985
1011
  }) {
986
1012
  const loading = ref(false);
987
1013
  const loadingMore = ref(false);
988
- const _storeInitialListing = inject(`useListingInitial-${listingKey}`, ref(null));
1014
+ const _storeInitialListing = inject(`useListingInitial-${listingKey}`, ref(initialListing ?? null));
989
1015
  provide(`useListingInitial-${listingKey}`, _storeInitialListing);
990
1016
  const _storeAppliedListing = inject(`useListingApplied-${listingKey}`, ref(null));
991
1017
  provide(`useListingApplied-${listingKey}`, _storeAppliedListing);
992
1018
  const getInitialListing = computed(() => _storeInitialListing.value);
993
- const setInitialListing = async (initialListing) => {
994
- _storeInitialListing.value = initialListing;
1019
+ const setInitialListing = async (initialListing2) => {
1020
+ _storeInitialListing.value = initialListing2;
995
1021
  _storeAppliedListing.value = null;
996
1022
  };
997
1023
  const initSearch = async (criteria) => {
@@ -1290,7 +1316,7 @@ function useNavigationSearch() {
1290
1316
  };
1291
1317
  }
1292
1318
  const isTechnicalUrl = path.startsWith("/navigation/") || path.startsWith("/detail/") || path.startsWith("/landingPage/");
1293
- const normalizedPath = isTechnicalUrl ? path : path.substring(1);
1319
+ const normalizedPath = isTechnicalUrl ? path.endsWith("/") ? path.slice(0, -1) : path : path.substring(1);
1294
1320
  const seoResult = await apiClient.invoke("readSeoUrl post /seo-url", {
1295
1321
  body: {
1296
1322
  filter: [
@@ -1310,6 +1336,8 @@ function useNavigationSearch() {
1310
1336
  }
1311
1337
 
1312
1338
  function useNewsletter() {
1339
+ const SUBSRIBE_KEY = "subscribe";
1340
+ const UNSUBSCRIBE_KEY = "unsubscribe";
1313
1341
  const { apiClient } = useShopwareContext();
1314
1342
  const { getStorefrontUrl } = useInternationalization();
1315
1343
  const newsletterStatus = ref("undefined");
@@ -1352,7 +1380,9 @@ function useNewsletter() {
1352
1380
  isNewsletterSubscriber,
1353
1381
  getNewsletterStatus,
1354
1382
  newsletterStatus,
1355
- confirmationNeeded
1383
+ confirmationNeeded,
1384
+ SUBSRIBE_KEY,
1385
+ UNSUBSCRIBE_KEY
1356
1386
  };
1357
1387
  }
1358
1388
 
@@ -1446,14 +1476,8 @@ function useOrderDetails(orderId, associations) {
1446
1476
  associations ? associations : {}
1447
1477
  );
1448
1478
  const params = {
1449
- filter: [
1450
- {
1451
- type: "equals",
1452
- field: "id",
1453
- value: orderId
1454
- }
1455
- ],
1456
- associations: mergedAssociations.associations,
1479
+ ids: [orderId],
1480
+ associations: mergedAssociations,
1457
1481
  checkPromotion: true
1458
1482
  };
1459
1483
  const orderDetailsResponse = await apiClient.invoke(
@@ -1578,7 +1602,10 @@ function useOrderPayment(order) {
1578
1602
  const paymentUrl = ref();
1579
1603
  const state = computed(() => activeTransaction.value?.stateMachineState);
1580
1604
  const isAsynchronous = computed(
1581
- () => activeTransaction.value?.paymentMethod?.asynchronous && activeTransaction.value?.paymentMethod?.afterOrderEnabled
1605
+ () => (
1606
+ // @ts-expect-error TODO: [MAJOR] Removed since 6.7
1607
+ activeTransaction.value?.paymentMethod?.asynchronous && activeTransaction.value?.paymentMethod?.afterOrderEnabled
1608
+ )
1582
1609
  );
1583
1610
  async function handlePayment(finishUrl, errorUrl) {
1584
1611
  if (!order.value) {
@@ -2164,8 +2191,11 @@ function useShopwareContext() {
2164
2191
  }
2165
2192
 
2166
2193
  const _wishlistItems = ref([]);
2194
+ const _wishlistProducts = ref([]);
2167
2195
  const _currentPage = ref(1);
2196
+ const _limit = ref(15);
2168
2197
  const totalWishlistItemsCount = ref(0);
2198
+ const isLoading = ref(false);
2169
2199
  function useSyncWishlist() {
2170
2200
  const { apiClient } = useShopwareContext();
2171
2201
  async function addToWishlistSync(id) {
@@ -2193,13 +2223,15 @@ function useSyncWishlist() {
2193
2223
  _wishlistItems.value = [
2194
2224
  ...response.data.products.elements.map((element) => element.id)
2195
2225
  ];
2226
+ _wishlistProducts.value = response.data.products.elements;
2196
2227
  totalWishlistItemsCount.value = response.data.products.total ?? 0;
2197
2228
  _currentPage.value = response.data.products.page ?? 1;
2198
- } catch (e) {
2199
- if (e instanceof ApiClientError) {
2200
- if (e.status !== 404) console.error(e);
2201
- _wishlistItems.value = [];
2202
- }
2229
+ _limit.value = response.data.products.limit ?? 15;
2230
+ } catch (error) {
2231
+ console.error("[useSyncWishlist][getWishlistProducts][error]:", error);
2232
+ _wishlistItems.value = [];
2233
+ _wishlistProducts.value = [];
2234
+ totalWishlistItemsCount.value = 0;
2203
2235
  }
2204
2236
  }
2205
2237
  async function mergeWishlistProducts(productIds) {
@@ -2213,14 +2245,19 @@ function useSyncWishlist() {
2213
2245
  const items = computed(() => _wishlistItems.value);
2214
2246
  const count = computed(() => totalWishlistItemsCount.value);
2215
2247
  const currentPage = computed(() => _currentPage.value);
2248
+ const products = computed(() => _wishlistProducts.value);
2249
+ const limit = computed(() => _limit.value);
2216
2250
  return {
2217
2251
  getWishlistProducts,
2218
2252
  addToWishlistSync,
2219
2253
  removeFromWishlistSync,
2220
2254
  mergeWishlistProducts,
2255
+ products,
2221
2256
  items,
2222
2257
  count,
2223
- currentPage
2258
+ currentPage,
2259
+ isLoading,
2260
+ limit
2224
2261
  };
2225
2262
  }
2226
2263
 
@@ -2256,7 +2293,8 @@ function useUser() {
2256
2293
  const { getStorefrontUrl } = useInternationalization();
2257
2294
  const { refreshCart } = useCart();
2258
2295
  const userDefaultPaymentMethod = computed(
2259
- () => user.value?.defaultPaymentMethod?.translated || null
2296
+ () => user.value?.lastPaymentMethod?.translated || // @ts-expect-error TODO: [MAJOR] Removed since 6.7
2297
+ user.value?.defaultPaymentMethod?.translated || null
2260
2298
  );
2261
2299
  const userDefaultBillingAddress = computed(
2262
2300
  () => user.value?.defaultBillingAddress || null
@@ -2359,6 +2397,7 @@ function useUser() {
2359
2397
  }
2360
2398
  async function setDefaultPaymentMethod(paymentMethodId) {
2361
2399
  await apiClient.invoke(
2400
+ // @ts-expect-error TODO: [MAJOR] Removed since 6.7
2362
2401
  "changePaymentMethod post /account/change-payment-method/{paymentMethodId}",
2363
2402
  {
2364
2403
  pathParams: { paymentMethodId }
@@ -2418,19 +2457,23 @@ function useWishlist() {
2418
2457
  mergeWishlistProducts: mergeWishlistProductsSync,
2419
2458
  removeFromWishlistSync,
2420
2459
  count: countSync,
2421
- currentPage
2460
+ currentPage,
2461
+ products,
2462
+ limit: limitSync
2422
2463
  } = useSyncWishlist();
2423
2464
  const limit = ref(15);
2424
2465
  const getWishlistProducts = async (query) => {
2425
- const wishlistQuery = {};
2466
+ let wishlistQuery = {
2467
+ limit: limit.value
2468
+ };
2426
2469
  if (query) {
2427
- defu(wishlistQuery, query);
2428
- }
2429
- if (query?.limit) {
2430
- limit.value = query.limit;
2470
+ wishlistQuery = defu(query, wishlistQuery);
2471
+ if (query.limit) {
2472
+ limit.value = query.limit;
2473
+ }
2431
2474
  }
2432
2475
  if (canSyncWishlist.value) {
2433
- await getWishlistProductsSync(query);
2476
+ await getWishlistProductsSync(wishlistQuery);
2434
2477
  } else {
2435
2478
  getWishlistProductsLocal();
2436
2479
  }
@@ -2468,7 +2511,9 @@ function useWishlist() {
2468
2511
  currentPage,
2469
2512
  totalPagesCount,
2470
2513
  count,
2471
- canSyncWishlist
2514
+ canSyncWishlist,
2515
+ products,
2516
+ limit: limitSync
2472
2517
  };
2473
2518
  }
2474
2519
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware/composables",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Shopware Frontends composables for Vue",
5
5
  "author": "Shopware",
6
6
  "repository": {
@@ -51,22 +51,22 @@
51
51
  "types"
52
52
  ],
53
53
  "dependencies": {
54
- "@vueuse/core": "13.1.0",
54
+ "@vueuse/core": "14.0.0",
55
55
  "defu": "6.1.4",
56
56
  "scule": "1.3.0",
57
- "@shopware/helpers": "1.4.0",
58
- "@shopware/api-client": "1.3.0"
57
+ "@shopware/helpers": "1.6.0",
58
+ "@shopware/api-client": "1.4.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@biomejs/biome": "1.8.3",
62
- "@nuxt/kit": "3.16.2",
63
- "@vitest/coverage-v8": "3.1.1",
62
+ "@nuxt/kit": "4.2.1",
63
+ "@vitest/coverage-v8": "3.2.4",
64
64
  "@vue/test-utils": "2.4.6",
65
- "happy-dom": "17.4.4",
66
- "typescript": "5.8.3",
65
+ "happy-dom": "20.0.10",
66
+ "typescript": "5.9.3",
67
67
  "unbuild": "2.0.0",
68
- "vitest": "3.1.1",
69
- "vue": "3.5.13",
68
+ "vitest": "3.2.4",
69
+ "vue": "3.5.24",
70
70
  "tsconfig": "0.0.0"
71
71
  },
72
72
  "scripts": {
@@ -1,6 +1,10 @@
1
1
  export const cmsAssociations = {
2
2
  associations: {
3
- media: {},
3
+ media: {
4
+ associations: {
5
+ media: {},
6
+ },
7
+ },
4
8
  cmsPage: {
5
9
  associations: {
6
10
  sections: {
@@ -7,7 +7,7 @@ import type { ElementConfig } from "../types";
7
7
  * @category CMS (Shopping Experiences)
8
8
  */
9
9
  export function useCmsElementConfig<
10
- T extends Schemas["CmsSlot"] & {
10
+ T extends Omit<Schemas["CmsSlot"], "config"> & {
11
11
  config: T["config"] extends {
12
12
  [key in infer X extends keyof T["config"]]: ElementConfig<unknown>;
13
13
  }
@@ -79,3 +79,5 @@ export type CmsBlockCrossSelling = BlockType<"content">;
79
79
 
80
80
  export type CmsBlockForm = BlockType<"content">;
81
81
  export type CmsBlockHtml = BlockType<"content">;
82
+
83
+ export type CmsBlockImageGalleryBig = BlockType<"imageGallery">;
@@ -31,7 +31,7 @@ type ElementFieldConfig = {
31
31
  };
32
32
 
33
33
  // Text
34
- export type CmsElementText = Schemas["CmsSlot"] & {
34
+ export type CmsElementText = Omit<Schemas["CmsSlot"], "config"> & {
35
35
  type: "text" | typeof String;
36
36
  slot: typeof String;
37
37
  config: TextElementConfig;
@@ -46,7 +46,7 @@ export type CmsElementText = Schemas["CmsSlot"] & {
46
46
  };
47
47
 
48
48
  // HTML
49
- export type CmsElementHtml = Schemas["CmsSlot"] & {
49
+ export type CmsElementHtml = Omit<Schemas["CmsSlot"], "config"> & {
50
50
  type: "html";
51
51
  data: {
52
52
  content: string;
@@ -68,7 +68,7 @@ type ImageElementConfig = {
68
68
  horizontalAlign: ElementConfig<VerticalAlign>;
69
69
  };
70
70
 
71
- export type CmsElementImage = Schemas["CmsSlot"] & {
71
+ export type CmsElementImage = Omit<Schemas["CmsSlot"], "config"> & {
72
72
  type: "image";
73
73
  config: ImageElementConfig;
74
74
  data: {
@@ -102,7 +102,7 @@ type ImageSliderElementConfig = ImageElementConfig &
102
102
  >;
103
103
  };
104
104
 
105
- export type CmsElementImageSlider = Schemas["CmsSlot"] & {
105
+ export type CmsElementImageSlider = Omit<Schemas["CmsSlot"], "config"> & {
106
106
  type: "image-slider";
107
107
  config: ImageSliderElementConfig;
108
108
  data: {
@@ -128,7 +128,7 @@ type ImageGalleryElementConfig = ImageSliderElementConfig & {
128
128
  zoom: ElementConfig<boolean>;
129
129
  };
130
130
 
131
- export type CmsElementImageGallery = Schemas["CmsSlot"] & {
131
+ export type CmsElementImageGallery = Omit<Schemas["CmsSlot"], "config"> & {
132
132
  type: "image-gallery";
133
133
  config: ImageGalleryElementConfig;
134
134
  data: {
@@ -159,9 +159,9 @@ type YouTubeVideoElementConfig = {
159
159
  previewMedia: ElementConfig<string>;
160
160
  showControls: ElementConfig<boolean>;
161
161
  needsConfirmation: ElementConfig<boolean>;
162
- advancePrivacyMode: ElementConfig<boolean>;
162
+ advancedPrivacyMode: ElementConfig<boolean>;
163
163
  };
164
- export type CmsElementYoutubeVideo = Schemas["CmsSlot"] & {
164
+ export type CmsElementYoutubeVideo = Omit<Schemas["CmsSlot"], "config"> & {
165
165
  type: "youtube-video";
166
166
  config: YouTubeVideoElementConfig;
167
167
  data: {
@@ -189,7 +189,7 @@ type VimeoVideoElementConfig = {
189
189
  needsConfirmation: ElementConfig<boolean>;
190
190
  };
191
191
 
192
- export type CmsElementVimeoVideo = Schemas["CmsSlot"] & {
192
+ export type CmsElementVimeoVideo = Omit<Schemas["CmsSlot"], "config"> & {
193
193
  type: "vimeo-video";
194
194
  config: VimeoVideoElementConfig;
195
195
  data: {
@@ -208,7 +208,7 @@ type ProductBoxElementConfig = {
208
208
  product: ElementConfig<string>;
209
209
  };
210
210
 
211
- export type CmsElementProductBox = Schemas["CmsSlot"] & {
211
+ export type CmsElementProductBox = Omit<Schemas["CmsSlot"], "config"> & {
212
212
  type: "product-box";
213
213
  config: ProductBoxElementConfig;
214
214
  data: {
@@ -234,7 +234,7 @@ type ProductSliderElementConfig = {
234
234
  productStreamSorting: ElementConfig<string>;
235
235
  };
236
236
 
237
- export type CmsElementProductSlider = Schemas["CmsSlot"] & {
237
+ export type CmsElementProductSlider = Omit<Schemas["CmsSlot"], "config"> & {
238
238
  type: "product-slider";
239
239
  config: ProductSliderElementConfig;
240
240
  data: {
@@ -256,7 +256,7 @@ type CmsSidebarFilterElementConfig = {
256
256
  verticalAlign: ElementConfig<VerticalAlign>;
257
257
  };
258
258
 
259
- export type CmsElementSidebarFilter = Schemas["CmsSlot"] & {
259
+ export type CmsElementSidebarFilter = Omit<Schemas["CmsSlot"], "config"> & {
260
260
  type: "sidebar-filter";
261
261
  config: CmsSidebarFilterElementConfig;
262
262
  };
@@ -273,7 +273,7 @@ type CmsProductListingElementConfig = {
273
273
  propertyWhitelist: ElementConfig<string[]>;
274
274
  };
275
275
 
276
- export type CmsElementProductListing = Schemas["CmsSlot"] & {
276
+ export type CmsElementProductListing = Omit<Schemas["CmsSlot"], "config"> & {
277
277
  type: "product-listing";
278
278
  config: CmsProductListingElementConfig;
279
279
  data: {
@@ -286,7 +286,10 @@ export type CmsElementProductListing = Schemas["CmsSlot"] & {
286
286
 
287
287
  type CategoryNavigationElementConfig = unknown;
288
288
 
289
- export type CmsElementCategoryNavigation = Schemas["CmsSlot"] & {
289
+ export type CmsElementCategoryNavigation = Omit<
290
+ Schemas["CmsSlot"],
291
+ "config"
292
+ > & {
290
293
  type: "category-navigation";
291
294
  config: CategoryNavigationElementConfig;
292
295
  };
@@ -296,7 +299,10 @@ type ProductDescriptionReviewsElementConfig = {
296
299
  alignment: ElementConfig<VerticalAlign>;
297
300
  };
298
301
 
299
- export type CmsElementProductDescriptionReviews = Schemas["CmsSlot"] & {
302
+ export type CmsElementProductDescriptionReviews = Omit<
303
+ Schemas["CmsSlot"],
304
+ "config"
305
+ > & {
300
306
  type: "product-description-reviews";
301
307
  config: ProductDescriptionReviewsElementConfig;
302
308
  data: {
@@ -314,7 +320,7 @@ export type CmsElementProductDescriptionReviews = Schemas["CmsSlot"] & {
314
320
 
315
321
  type BuyBoxElementConfig = ProductDescriptionReviewsElementConfig;
316
322
  // buy box has the same interface in data as product description reviews! unify later
317
- export type CmsElementBuyBox = Schemas["CmsSlot"] & {
323
+ export type CmsElementBuyBox = Omit<Schemas["CmsSlot"], "config"> & {
318
324
  type: "buy-box";
319
325
  config: BuyBoxElementConfig;
320
326
  data: {
@@ -337,7 +343,7 @@ type CrossSellingElementConfig = {
337
343
  displayMode: ElementConfig<DisplayMode>;
338
344
  };
339
345
 
340
- export type CmsElementCrossSelling = Schemas["CmsSlot"] & {
346
+ export type CmsElementCrossSelling = Omit<Schemas["CmsSlot"], "config"> & {
341
347
  type: "cross-selling";
342
348
  config: CrossSellingElementConfig;
343
349
  data: {
@@ -356,14 +362,14 @@ type FormElementConfig = {
356
362
  defaultMailReceiver: ElementConfig<boolean>;
357
363
  };
358
364
 
359
- export type CmsElementForm = Schemas["CmsSlot"] & {
365
+ export type CmsElementForm = Omit<Schemas["CmsSlot"], "config"> & {
360
366
  type: "form";
361
367
  config: FormElementConfig;
362
368
  data: Schemas["Salutation"][];
363
369
  };
364
370
 
365
371
  // Product Name
366
- export type CmsElementProductName = Schemas["CmsSlot"] & {
372
+ export type CmsElementProductName = Omit<Schemas["CmsSlot"], "config"> & {
367
373
  type: "product-name";
368
374
  config: TextElementConfig;
369
375
  fieldConfig: ElementFieldConfig[];
@@ -377,7 +383,7 @@ export type CmsElementProductName = Schemas["CmsSlot"] & {
377
383
  };
378
384
 
379
385
  // Manufacturer Logo
380
- export type CmsElementManufacturerLogo = Schemas["CmsSlot"] & {
386
+ export type CmsElementManufacturerLogo = Omit<Schemas["CmsSlot"], "config"> & {
381
387
  type: "manufacturer-logo";
382
388
  config: ImageElementConfig;
383
389
  data: {
@@ -144,6 +144,18 @@ describe("useCart", () => {
144
144
  );
145
145
  });
146
146
 
147
+ it("remove item by id", async () => {
148
+ await vm.removeItemById("01893ed931d571718e8138e7df7d68d1");
149
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
150
+ expect.stringContaining("removeLineItem"),
151
+ expect.objectContaining({
152
+ body: {
153
+ ids: ["01893ed931d571718e8138e7df7d68d1"],
154
+ },
155
+ }),
156
+ );
157
+ });
158
+
147
159
  it("submitPromotionCode", async () => {
148
160
  injections.apiClient.invoke.mockResolvedValue({
149
161
  data: {
@@ -60,6 +60,10 @@ export type UseCartReturn = {
60
60
  * Removes the provided LineItem from the cart
61
61
  */
62
62
  removeItem(lineItem: Schemas["LineItem"]): Promise<Schemas["Cart"]>;
63
+ /**
64
+ * Removes the item with the provided id from the cart
65
+ */
66
+ removeItemById(id: string): Promise<Schemas["Cart"]>;
63
67
  /**
64
68
  * The total price of the cart (including calculated costs like shipping)
65
69
  */
@@ -168,6 +172,18 @@ export function useCartFunction(): UseCartReturn {
168
172
  return data;
169
173
  }
170
174
 
175
+ async function removeItemById(id: string) {
176
+ const { data } = await apiClient.invoke(
177
+ "removeLineItem post /checkout/cart/line-item/delete",
178
+ {
179
+ body: { ids: [id] },
180
+ },
181
+ );
182
+ _storeCart.value = data;
183
+ setCartErrors(data);
184
+ return data;
185
+ }
186
+
171
187
  async function changeProductQuantity(params: {
172
188
  id: string;
173
189
  quantity: number;
@@ -301,6 +317,7 @@ export function useCartFunction(): UseCartReturn {
301
317
  count,
302
318
  refreshCart,
303
319
  removeItem,
320
+ removeItemById,
304
321
  totalPrice,
305
322
  shippingTotal,
306
323
  subtotal,
@@ -61,4 +61,45 @@ describe("useCountries", () => {
61
61
 
62
62
  expect(vm.getCountries).toStrictEqual([]);
63
63
  });
64
+
65
+ it("useCountries flow - getCountriesOptions", async () => {
66
+ const { vm } = await useSetup(useCountries, {
67
+ apiClient: {
68
+ invoke: vi.fn().mockResolvedValue({
69
+ data: CountryMock,
70
+ }),
71
+ },
72
+ });
73
+
74
+ await vm.fetchCountries();
75
+
76
+ expect(vm.getCountriesOptions).toStrictEqual([
77
+ {
78
+ value: "16bb0446bf094f5d8bebf450652abafc",
79
+ label: "Sweden",
80
+ },
81
+ {
82
+ value: "184eb596425f4d56aa9ed8af9c3dc8d1",
83
+ label: "Ireland",
84
+ },
85
+ {
86
+ value: "20513996f80f4d00b5ebedc51a2deae2",
87
+ label: "Australia",
88
+ },
89
+ ]);
90
+ });
91
+
92
+ it("useCountries flow - getCountriesOptions - empty array", async () => {
93
+ const { vm } = await useSetup(useCountries, {
94
+ apiClient: {
95
+ invoke: vi.fn().mockResolvedValue({
96
+ data: {
97
+ elements: null,
98
+ },
99
+ }),
100
+ },
101
+ });
102
+
103
+ expect(vm.getCountriesOptions).toStrictEqual([]);
104
+ });
64
105
  });