@shopware/composables 1.11.1 → 1.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.
Files changed (99) hide show
  1. package/README.md +12 -11
  2. package/dist/index.d.mts +26 -1
  3. package/dist/index.d.ts +26 -1
  4. package/dist/index.mjs +125 -75
  5. package/package.json +11 -12
  6. package/src/cms/useCmsElementConfig.test.ts +1 -0
  7. package/src/cms/useCmsElementConfig.ts +1 -0
  8. package/src/cms/useCmsElementImage.test.ts +1 -0
  9. package/src/cms/useCmsElementImage.ts +2 -0
  10. package/src/cms/useCmsElementProductBox.test.ts +1 -0
  11. package/src/cms/useCmsElementProductBox.ts +2 -0
  12. package/src/createShopwareContext.test.ts +1 -0
  13. package/src/createShopwareContext.ts +8 -0
  14. package/src/devtools/plugin.ts +13 -13
  15. package/src/helpers/ContextError.spec.ts +1 -0
  16. package/src/index.test.ts +2 -0
  17. package/src/index.ts +1 -0
  18. package/src/types/cmsElementTypes.ts +1 -0
  19. package/src/useAddToCart/useAddToCart.test.ts +1 -0
  20. package/src/useAddToCart/useAddToCart.ts +1 -0
  21. package/src/useAddress/useAddress.test.ts +2 -0
  22. package/src/useAddress/useAddress.ts +1 -0
  23. package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +1 -0
  24. package/src/useBreadcrumbs/useBreadcrumbs.test.ts +2 -0
  25. package/src/useBreadcrumbs/useBreadcrumbs.ts +1 -0
  26. package/src/useCart/useCart.test.ts +2 -0
  27. package/src/useCart/useCart.ts +1 -0
  28. package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +1 -0
  29. package/src/useCartItem/useCartItem.test.ts +2 -0
  30. package/src/useCartItem/useCartItem.ts +1 -0
  31. package/src/useCartNotification/useCartNotification.test.ts +2 -0
  32. package/src/useCategory/useCategory.test.ts +2 -0
  33. package/src/useCategory/useCategory.ts +2 -0
  34. package/src/useCategorySearch/useCategorySearch.test.ts +29 -0
  35. package/src/useCategorySearch/useCategorySearch.ts +15 -7
  36. package/src/useCheckout/useCheckout.test.ts +1 -0
  37. package/src/useCheckout/useCheckout.ts +1 -0
  38. package/src/useCmsBlock/useCmsBlock.test.ts +2 -0
  39. package/src/useCmsMeta/useCmsMeta.test.ts +2 -0
  40. package/src/useCmsMeta/useCmsMeta.ts +1 -0
  41. package/src/useCmsSection/useCmsSection.test.ts +2 -0
  42. package/src/useCmsTranslations/useCmsTranslations.test.ts +2 -0
  43. package/src/useCountries/useCountries.test.ts +19 -0
  44. package/src/useCountries/useCountries.ts +14 -7
  45. package/src/useCustomerOrders/useCustomerOrders.test.ts +1 -0
  46. package/src/useCustomerOrders/useCustomerOrders.ts +1 -0
  47. package/src/useCustomerPassword/useCustomerPassword.test.ts +1 -0
  48. package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +1 -0
  49. package/src/useInternationalization/useInternationalization.test.ts +14 -1
  50. package/src/useInternationalization/useInternationalization.ts +5 -3
  51. package/src/useLandingSearch/useLandingSearch.test.ts +1 -0
  52. package/src/useLandingSearch/useLandingSearch.ts +1 -0
  53. package/src/useListing/useListing.test.ts +2 -0
  54. package/src/useListing/useListing.ts +3 -2
  55. package/src/useLocalWishlist/useLocalWishlist.test.ts +1 -0
  56. package/src/useNavigation/useNavigation.test.ts +24 -1
  57. package/src/useNavigation/useNavigation.ts +36 -14
  58. package/src/useNavigationContext/useNavigationContext.test.ts +1 -0
  59. package/src/useNavigationContext/useNavigationContext.ts +1 -0
  60. package/src/useNavigationSearch/useNavigationSearch.test.ts +30 -0
  61. package/src/useNavigationSearch/useNavigationSearch.ts +19 -12
  62. package/src/useNewsletter/useNewsletter.test.ts +1 -0
  63. package/src/useNewsletter/useNewsletter.ts +1 -0
  64. package/src/useNotifications/useNotifications.test.ts +1 -0
  65. package/src/useOrderDetails/useOrderDetails.test.ts +1 -0
  66. package/src/useOrderDetails/useOrderDetails.ts +1 -0
  67. package/src/useOrderPayment/useOrderPayment.test.ts +2 -0
  68. package/src/useOrderPayment/useOrderPayment.ts +1 -0
  69. package/src/usePrice/usePrice.test.ts +2 -0
  70. package/src/usePrice/usePrice.ts +1 -0
  71. package/src/useProduct/useProduct.test.ts +2 -0
  72. package/src/useProduct/useProduct.ts +2 -0
  73. package/src/useProductAssociations/useProductAssociations.spec.ts +48 -0
  74. package/src/useProductAssociations/useProductAssociations.ts +7 -3
  75. package/src/useProductConfigurator/useProductConfigurator.spec.ts +24 -0
  76. package/src/useProductConfigurator/useProductConfigurator.ts +20 -13
  77. package/src/useProductPrice/useProductPrice.test.ts +2 -0
  78. package/src/useProductPrice/useProductPrice.ts +1 -0
  79. package/src/useProductReviews/useProductReviews.test.ts +1 -0
  80. package/src/useProductReviews/useProductReviews.ts +1 -0
  81. package/src/useProductSearch/useProductSearch.test.ts +24 -1
  82. package/src/useProductSearch/useProductSearch.ts +24 -11
  83. package/src/useProductSearchSuggest/useProductSearchSuggest.test.ts +1 -0
  84. package/src/useProductSearchSuggest/useProductSearchSuggest.ts +1 -0
  85. package/src/useProductWishlist/useProductWishlist.test.ts +2 -0
  86. package/src/useProductWishlist/useProductWishlist.ts +1 -0
  87. package/src/useSalutations/useSalutations.spec.ts +15 -0
  88. package/src/useSalutations/useSalutations.ts +5 -2
  89. package/src/useSessionContext/useSessionContext.test.ts +18 -0
  90. package/src/useSessionContext/useSessionContext.ts +10 -0
  91. package/src/useShopwareContext/useShopwareContext.test.ts +1 -0
  92. package/src/useShopwareContext/useShopwareContext.ts +13 -0
  93. package/src/useSyncWishlist/useSyncWishlist.test.ts +1 -0
  94. package/src/useSyncWishlist/useSyncWishlist.ts +1 -0
  95. package/src/useUrlResolver/useUrlResolver.test.ts +1 -0
  96. package/src/useUser/useUser.test.ts +35 -2
  97. package/src/useUser/useUser.ts +34 -25
  98. package/src/useWishlist/useWishlist.test.ts +2 -0
  99. package/src/useWishlist/useWishlist.ts +1 -0
@@ -14,6 +14,13 @@ export function createShopwareContext(
14
14
  devStorefrontUrl?: string | null;
15
15
  enableDevtools?: boolean;
16
16
  browserLocale?: string;
17
+ /**
18
+ * Opt in to reading data via cacheable GET Store API routes instead of
19
+ * POST. Surfaced on the Shopware context as `cacheableReads`.
20
+ *
21
+ * @default false
22
+ */
23
+ cacheableReads?: boolean;
17
24
  },
18
25
  ) {
19
26
  const scope: EffectScope = effectScope(true);
@@ -36,6 +43,7 @@ export function createShopwareContext(
36
43
  devStorefrontUrl: options.devStorefrontUrl,
37
44
  state,
38
45
  browserLocale: options.browserLocale || "en-US",
46
+ cacheableReads: options.cacheableReads ?? false,
39
47
  });
40
48
 
41
49
  if (options?.enableDevtools && typeof window !== "undefined") {
@@ -10,13 +10,13 @@ export const shopwareSymbol = Symbol("shopware") as InjectionKey<string>;
10
10
  /* istanbul ignore next */
11
11
  export function registerShopwareDevtools(
12
12
  app: App,
13
- // biome-ignore lint: not used plugin for now, ignoring type errors
13
+ // TODO: Improve devtools typing.
14
14
  shopwarePluginInstance: any,
15
15
  ) {
16
- // biome-ignore lint: not used plugin for now, ignoring type errors
16
+ // TODO: Improve devtools typing.
17
17
  let devtoolsApi: any;
18
18
  let trackId = 0;
19
- // biome-ignore lint: not used plugin for now, ignoring type errors
19
+ // TODO: Improve devtools typing.
20
20
  let currentSharedState: any = null;
21
21
 
22
22
  setupDevtoolsPlugin(
@@ -26,7 +26,7 @@ export function registerShopwareDevtools(
26
26
  logo: "https://shopware.com/media/unknown/2d/80/8c/shopware_signet_blue.svg",
27
27
  packageName: "shopware-frontends",
28
28
  homepage: "shopware.com",
29
- // biome-ignore lint: not used plugin for now, ignoring type errors
29
+ // TODO: Improve devtools typing.
30
30
  app: app as any,
31
31
  enableEarlyProxy: true,
32
32
  },
@@ -68,12 +68,12 @@ export function registerShopwareDevtools(
68
68
  }
69
69
  });
70
70
 
71
- // biome-ignore lint: not used plugin for now, ignoring type errors
71
+ // TODO: Improve devtools typing.
72
72
  function displayState(state: any) {
73
73
  if (!state) return null;
74
- // biome-ignore lint: not used plugin for now, ignoring type errors
74
+ // TODO: Improve devtools typing.
75
75
  const res: any = {};
76
- // biome-ignore lint/complexity/noForEach: ignore for now
76
+ // TODO: Keep iteration behavior while devtools typing is improved.
77
77
  Object.keys(state).forEach((refKey) => {
78
78
  res[refKey] = unref(currentSharedState[refKey]);
79
79
  });
@@ -116,12 +116,12 @@ export function registerShopwareDevtools(
116
116
  );
117
117
 
118
118
  const devtools = {
119
- // biome-ignore lint: not used plugin for now, ignoring type errors
119
+ // TODO: Improve devtools typing.
120
120
  trackEvent: (label: string, params: any) => {
121
121
  const groupId = `track${trackId++}`;
122
122
 
123
123
  // Start
124
- // biome-ignore lint: not used plugin for now, ignoring type errors
124
+ // TODO: Improve devtools typing.
125
125
  const log = (label: string, params: any) => {
126
126
  devtoolsApi.addTimelineEvent({
127
127
  layerId: TIMELINE_EVENT_LAYER_ID,
@@ -143,7 +143,7 @@ export function registerShopwareDevtools(
143
143
  log,
144
144
  };
145
145
  },
146
- // biome-ignore lint: not used plugin for now, ignoring type errors
146
+ // TODO: Improve devtools typing.
147
147
  log: (label: string, params: any) => {
148
148
  devtoolsApi.addTimelineEvent({
149
149
  layerId: TIMELINE_EVENT_LAYER_ID,
@@ -157,7 +157,7 @@ export function registerShopwareDevtools(
157
157
  },
158
158
  });
159
159
  },
160
- // biome-ignore lint: not used plugin for now, ignoring type errors
160
+ // TODO: Improve devtools typing.
161
161
  warning: (label: string, params: any) => {
162
162
  devtoolsApi.addTimelineEvent({
163
163
  layerId: TIMELINE_EVENT_LAYER_ID,
@@ -172,7 +172,7 @@ export function registerShopwareDevtools(
172
172
  },
173
173
  });
174
174
  },
175
- // biome-ignore lint: not used plugin for now, ignoring type errors
175
+ // TODO: Improve devtools typing.
176
176
  error: (label: string, params: any) => {
177
177
  devtoolsApi.addTimelineEvent({
178
178
  layerId: TIMELINE_EVENT_LAYER_ID,
@@ -188,7 +188,7 @@ export function registerShopwareDevtools(
188
188
  });
189
189
  },
190
190
  _internal: {
191
- // biome-ignore lint: not used plugin for now, ignoring type errors
191
+ // TODO: Improve devtools typing.
192
192
  updateSharedState: (state: any) => {
193
193
  currentSharedState = state;
194
194
  devtoolsApi.sendInspectorState(INSPECTOR_ID);
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import ContextError from "./ContextError";
3
4
 
4
5
  describe("contextError", () => {
package/src/index.test.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
  import * as vue from "vue";
3
+
3
4
  import type { Schemas } from "#shopware";
5
+
4
6
  import { getDefaultApiParams, resolveCmsComponent } from "./index";
5
7
  import CmsPage from "./mocks/CmsPage";
6
8
 
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { pascalCase } from "scule";
2
2
  import { resolveComponent } from "vue";
3
+
3
4
  import type { Schemas } from "#shopware";
4
5
 
5
6
  /**
@@ -1,4 +1,5 @@
1
1
  import type { CSSProperties } from "vue";
2
+
2
3
  import type { Schemas } from "#shopware";
3
4
 
4
5
  export type SourceType = "static" | "mapped";
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
  import { ref } from "vue";
3
+
3
4
  import { useSetup } from "../_test";
4
5
  import ProductMocked from "../mocks/Product";
5
6
  import { useAddToCart } from "./useAddToCart";
@@ -1,5 +1,6 @@
1
1
  import { computed, ref, unref } from "vue";
2
2
  import type { ComputedRef, Ref } from "vue";
3
+
3
4
  import { useCart } from "#imports";
4
5
  import type { Schemas } from "#shopware";
5
6
  export type UseAddToCartReturn = {
@@ -1,7 +1,9 @@
1
1
  import { ApiClientError } from "@shopware/api-client";
2
2
  import type { FetchResponse } from "ofetch";
3
3
  import { describe, expect, it, vi } from "vitest";
4
+
4
5
  import type { Schemas } from "#shopware";
6
+
5
7
  import { useSetup } from "../_test";
6
8
  import { useAddress } from "./useAddress";
7
9
 
@@ -2,6 +2,7 @@ import { ApiClientError } from "@shopware/api-client";
2
2
  import type { ApiError } from "@shopware/api-client";
3
3
  import { computed, inject, provide, ref } from "vue";
4
4
  import type { ComputedRef, Ref } from "vue";
5
+
5
6
  import { useShopwareContext } from "#imports";
6
7
  import type { Schemas } from "#shopware";
7
8
 
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import { useSetup } from "../_test";
3
4
  import { useB2bQuoteManagement } from "./useB2bQuoteManagement";
4
5
  /**
@@ -1,5 +1,7 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import { useBreadcrumbs } from "./useBreadcrumbs";
5
7
 
@@ -1,5 +1,6 @@
1
1
  import { computed } from "vue";
2
2
  import type { ComputedRef } from "vue";
3
+
3
4
  import { useContext } from "#imports";
4
5
  import type { Schemas, operations } from "#shopware";
5
6
 
@@ -1,5 +1,7 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
2
3
  import type { Schemas, operations } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import Cart from "../mocks/Cart";
5
7
  import { useCart } from "./useCart";
@@ -1,6 +1,7 @@
1
1
  import { createSharedComposable } from "@vueuse/core";
2
2
  import { computed } from "vue";
3
3
  import type { ComputedRef } from "vue";
4
+
4
5
  import { useContext, useShopwareContext } from "#imports";
5
6
  import type { Schemas, operations } from "#shopware";
6
7
 
@@ -1,5 +1,6 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
2
  import { ref } from "vue";
3
+
3
4
  import { useCart, useCartErrorParamsResolver } from "#imports";
4
5
 
5
6
  vi.mock("../useCart/useCart.ts");
@@ -1,7 +1,9 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
2
  import { ref } from "vue";
3
3
  import type { Ref } from "vue";
4
+
4
5
  import type { Schemas } from "#shopware";
6
+
5
7
  import { useSetup } from "../_test";
6
8
  import Cart from "../mocks/Cart";
7
9
  import { useCartItem } from "./useCartItem";
@@ -1,6 +1,7 @@
1
1
  import { getMainImageUrl } from "@shopware/helpers";
2
2
  import { computed } from "vue";
3
3
  import type { ComputedRef, Ref } from "vue";
4
+
4
5
  import { useCart } from "#imports";
5
6
  import type { Schemas } from "#shopware";
6
7
 
@@ -1,5 +1,7 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
2
3
  import { useCart, useCartNotification } from "#imports";
4
+
3
5
  import { useSetup } from "../_test";
4
6
 
5
7
  const pushErrorSpy = vi.fn();
@@ -1,6 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { ref } from "vue";
3
+
3
4
  import type { Schemas } from "#shopware";
5
+
4
6
  import { useSetup } from "../_test";
5
7
  import { useCategory } from "./useCategory";
6
8
 
@@ -1,7 +1,9 @@
1
1
  import { computed } from "vue";
2
2
  import type { ComputedRef, Ref } from "vue";
3
+
3
4
  import { useContext } from "#imports";
4
5
  import type { Schemas } from "#shopware";
6
+
5
7
  import ContextError from "../helpers/ContextError";
6
8
 
7
9
  export type UseCategoryReturn = {
@@ -1,4 +1,6 @@
1
+ import { encodeForQuery } from "@shopware/api-client/helpers";
1
2
  import { describe, expect, it } from "vitest";
3
+
2
4
  import { useSetup } from "../_test";
3
5
  import { cmsAssociations } from "../cms/cmsAssociations";
4
6
  import { useCategorySearch } from "./useCategorySearch";
@@ -95,4 +97,31 @@ describe("useCategorySearch", () => {
95
97
  }),
96
98
  );
97
99
  });
100
+
101
+ it("advancedSearch uses the cacheable GET variant when cacheableReads is enabled", () => {
102
+ const { vm, injections } = useSetup(useCategorySearch, {
103
+ shopware: { cacheableReads: true },
104
+ });
105
+ injections.apiClient.invoke.mockResolvedValue({
106
+ data: {},
107
+ });
108
+
109
+ vm.advancedSearch({
110
+ query: {
111
+ limit: 10,
112
+ },
113
+ });
114
+
115
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
116
+ expect.stringContaining("readCategoryListGet get"),
117
+ expect.objectContaining({
118
+ query: {
119
+ _criteria: encodeForQuery({
120
+ associations: {},
121
+ limit: 10,
122
+ }),
123
+ },
124
+ }),
125
+ );
126
+ });
98
127
  });
@@ -1,5 +1,8 @@
1
+ import { encodeForQuery } from "@shopware/api-client/helpers";
2
+
1
3
  import { useShopwareContext } from "#imports";
2
4
  import type { Schemas } from "#shopware";
5
+
3
6
  import { cmsAssociations } from "../cms/cmsAssociations";
4
7
 
5
8
  export type UseCategorySearchReturn = {
@@ -30,7 +33,7 @@ export type UseCategorySearchReturn = {
30
33
  * @category Navigation & Routing
31
34
  */
32
35
  export function useCategorySearch(): UseCategorySearchReturn {
33
- const { apiClient } = useShopwareContext();
36
+ const { apiClient, cacheableReads } = useShopwareContext();
34
37
 
35
38
  async function search(
36
39
  categoryId: string,
@@ -65,12 +68,17 @@ export function useCategorySearch(): UseCategorySearchReturn {
65
68
  const associations = options?.withCmsAssociations
66
69
  ? cmsAssociations.associations
67
70
  : {};
68
- const result = await apiClient.invoke("readCategoryList post /category", {
69
- body: {
70
- associations,
71
- ...options?.query,
72
- },
73
- });
71
+ const criteria = {
72
+ associations,
73
+ ...options?.query,
74
+ };
75
+ const result = cacheableReads
76
+ ? await apiClient.invoke("readCategoryListGet get /category", {
77
+ query: { _criteria: encodeForQuery(criteria) },
78
+ })
79
+ : await apiClient.invoke("readCategoryList post /category", {
80
+ body: criteria,
81
+ });
74
82
  return result.data.elements ?? [];
75
83
  }
76
84
 
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
  import { ref } from "vue";
3
+
3
4
  import { useSetup } from "../_test";
4
5
  import { useCheckout } from "./useCheckout";
5
6
 
@@ -1,6 +1,7 @@
1
1
  import { defu } from "defu";
2
2
  import { computed, inject, provide, ref } from "vue";
3
3
  import type { ComputedRef } from "vue";
4
+
4
5
  import { useSessionContext, useShopwareContext } from "#imports";
5
6
  import type { Schemas, operations } from "#shopware";
6
7
 
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import { useCmsBlock } from "./useCmsBlock";
5
7
 
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import LandingPageMock from "../mocks/LandingPage";
5
7
  import { useCmsMeta } from "./useCmsMeta";
@@ -1,6 +1,7 @@
1
1
  import { getTranslatedProperty } from "@shopware/helpers";
2
2
  import { computed } from "vue";
3
3
  import type { ComputedRef } from "vue";
4
+
4
5
  import type { Schemas } from "#shopware";
5
6
 
6
7
  export type UseCmsMetaReturn = {
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import CmsPage from "../mocks/CmsPage";
5
7
  import { useCmsSection } from "./useCmsSection";
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import { useCmsTranslations } from "#imports";
4
+
3
5
  import { useSetup } from "../_test";
4
6
 
5
7
  describe("useCmsTranslations", () => {
@@ -1,5 +1,7 @@
1
+ import { encodeForQuery } from "@shopware/api-client/helpers";
1
2
  import { describe, expect, it, vi } from "vitest";
2
3
  import { ref } from "vue";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import CountryMock from "../mocks/Country";
5
7
  import { useCountries } from "./useCountries";
@@ -104,6 +106,23 @@ describe("useCountries", () => {
104
106
  expect(vm.getCountriesOptions).toStrictEqual([]);
105
107
  });
106
108
 
109
+ it("uses the cacheable GET variant when cacheableReads is enabled", async () => {
110
+ const { vm, injections } = await useSetup(useCountries, {
111
+ shopware: { cacheableReads: true },
112
+ apiClient: {
113
+ invoke: vi.fn().mockResolvedValue({ data: CountryMock }),
114
+ },
115
+ } as Parameters<typeof useSetup>[1]);
116
+ await vm.fetchCountries();
117
+
118
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
119
+ expect.stringContaining("readCountryGet get"),
120
+ expect.objectContaining({
121
+ query: { _criteria: encodeForQuery({ associations: { states: {} } }) },
122
+ }),
123
+ );
124
+ });
125
+
107
126
  it("should not fetch when swCountries already populated", async () => {
108
127
  const preloadedCountries = ref(CountryMock.elements);
109
128
  const { vm, injections } = await useSetup(useCountries, {
@@ -1,5 +1,7 @@
1
+ import { encodeForQuery } from "@shopware/api-client/helpers";
1
2
  import { computed, inject, onMounted, provide, ref } from "vue";
2
3
  import type { ComputedRef } from "vue";
4
+
3
5
  import { useShopwareContext } from "#imports";
4
6
  import type { Schemas, operations } from "#shopware";
5
7
 
@@ -24,19 +26,24 @@ export type UseCountriesReturn = {
24
26
  * @category Context & Language
25
27
  */
26
28
  export function useCountries(): UseCountriesReturn {
27
- const { apiClient } = useShopwareContext();
29
+ const { apiClient, cacheableReads } = useShopwareContext();
28
30
 
29
31
  const _sharedCountries = inject("swCountries", ref());
30
32
  provide("swCountries", _sharedCountries);
31
33
 
32
34
  async function fetchCountries() {
33
- const result = await apiClient.invoke("readCountry post /country", {
34
- body: {
35
- associations: {
36
- states: {},
37
- },
35
+ const criteria = {
36
+ associations: {
37
+ states: {},
38
38
  },
39
- });
39
+ };
40
+ const result = cacheableReads
41
+ ? await apiClient.invoke("readCountryGet get /country", {
42
+ query: { _criteria: encodeForQuery(criteria) },
43
+ })
44
+ : await apiClient.invoke("readCountry post /country", {
45
+ body: criteria,
46
+ });
40
47
  _sharedCountries.value = result.data.elements;
41
48
  return result.data;
42
49
  }
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import { useSetup } from "../_test";
3
4
  import { useCustomerOrders } from "./useCustomerOrders";
4
5
 
@@ -1,5 +1,6 @@
1
1
  import { computed, ref } from "vue";
2
2
  import type { ComputedRef, Ref } from "vue";
3
+
3
4
  import { useShopwareContext } from "#imports";
4
5
  import type { Schemas, operations } from "#shopware";
5
6
 
@@ -1,6 +1,7 @@
1
1
  import { ApiClientError } from "@shopware/api-client";
2
2
  import type { FetchResponse } from "ofetch";
3
3
  import { describe, expect, it, vi } from "vitest";
4
+
4
5
  import { useSetup } from "../_test";
5
6
  import { useCustomerPassword } from "./useCustomerPassword";
6
7
 
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import { useSetup } from "../_test";
3
4
  import { useDefaultOrderAssociations } from "./useDefaultOrderAssociations";
4
5
 
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import { useInternationalization } from "./useInternationalization";
5
7
  import type { RouteObject } from "./useInternationalization";
@@ -28,7 +30,18 @@ describe("useInternationalization", () => {
28
30
  injections.apiClient.invoke.mockResolvedValue({ data: {} });
29
31
  vm.getAvailableLanguages();
30
32
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
31
- expect.stringContaining("readLanguages"),
33
+ expect.stringContaining("readLanguages post"),
34
+ );
35
+ });
36
+
37
+ it("getAvailableLanguages uses the cacheable GET variant when cacheableReads is enabled", async () => {
38
+ const { vm, injections } = useSetup(useInternationalization, {
39
+ shopware: { cacheableReads: true },
40
+ } as Parameters<typeof useSetup>[1]);
41
+ injections.apiClient.invoke.mockResolvedValue({ data: {} });
42
+ await vm.getAvailableLanguages();
43
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
44
+ "readLanguagesGet get /language",
32
45
  );
33
46
  });
34
47
 
@@ -1,5 +1,6 @@
1
1
  import { urlIsAbsolute } from "@shopware/helpers";
2
2
  import type { Ref } from "vue";
3
+
3
4
  import { useContext, useShopwareContext } from "#imports";
4
5
  import type { Schemas, operations } from "#shopware";
5
6
 
@@ -80,8 +81,7 @@ export type RouteObject = {
80
81
  export function useInternationalization(
81
82
  pathResolver?: (path: string) => string,
82
83
  ): UseInternationalizationReturn {
83
- const { devStorefrontUrl } = useShopwareContext();
84
- const { apiClient } = useShopwareContext();
84
+ const { devStorefrontUrl, apiClient, cacheableReads } = useShopwareContext();
85
85
 
86
86
  const _storeLanguages = useContext<Schemas["Language"][]>("swLanguages");
87
87
  const _storeCurrentLanguage = useContext<string>(
@@ -94,7 +94,9 @@ export function useInternationalization(
94
94
  }
95
95
 
96
96
  async function getAvailableLanguages() {
97
- const { data } = await apiClient.invoke("readLanguages post /language");
97
+ const { data } = cacheableReads
98
+ ? await apiClient.invoke("readLanguagesGet get /language")
99
+ : await apiClient.invoke("readLanguages post /language");
98
100
  _storeLanguages.value = data.elements;
99
101
  return data;
100
102
  }
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import { useSetup } from "../_test";
3
4
  import { cmsAssociations } from "../cms/cmsAssociations";
4
5
  import LandingPageMock from "../mocks/LandingPage";
@@ -1,5 +1,6 @@
1
1
  import { useShopwareContext } from "#imports";
2
2
  import type { Schemas, operations } from "#shopware";
3
+
3
4
  import { cmsAssociations } from "../cms/cmsAssociations";
4
5
 
5
6
  export type UseLandingSearchReturn = {
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import ContextError from "../helpers/ContextError";
5
7
  import searchMock from "../mocks/Search";
@@ -2,6 +2,7 @@ import { getListingFilters } from "@shopware/helpers";
2
2
  import { createInjectionState, createSharedComposable } from "@vueuse/core";
3
3
  import { computed, inject, provide, ref } from "vue";
4
4
  import type { ComputedRef, Ref } from "vue";
5
+
5
6
  import { useCategory, useShopwareContext } from "#imports";
6
7
  import type { Schemas, operations } from "#shopware";
7
8
 
@@ -37,8 +38,8 @@ function merge<T extends { [key in keyof T]: unknown }>(
37
38
  export type ListingType = "productSearchListing" | "categoryListing";
38
39
 
39
40
  export type ShortcutFilterParam<
40
- T extends
41
- keyof Schemas["ProductListingCriteria"] = keyof Schemas["ProductListingCriteria"],
41
+ T extends keyof Schemas["ProductListingCriteria"] =
42
+ keyof Schemas["ProductListingCriteria"],
42
43
  > = {
43
44
  code: T;
44
45
  value: Schemas["ProductListingCriteria"][T];
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
+
2
3
  import { useSetup } from "../_test";
3
4
  import { useLocalWishlist } from "./useLocalWishlist";
4
5