@shopware/composables 1.10.0 → 1.11.1

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 (46) hide show
  1. package/README.md +11 -30
  2. package/dist/index.d.mts +26 -9
  3. package/dist/index.d.ts +26 -9
  4. package/dist/index.mjs +37 -23
  5. package/package.json +16 -14
  6. package/src/cms/useCmsElementConfig.test.ts +8 -0
  7. package/src/cms/useCmsElementConfig.ts +3 -0
  8. package/src/cms/useCmsElementImage.test.ts +23 -0
  9. package/src/cms/useCmsElementProductBox.test.ts +21 -0
  10. package/src/devtools/plugin.ts +1 -2
  11. package/src/mocks/Configurator.ts +36 -36
  12. package/src/useAddToCart/useAddToCart.test.ts +18 -1
  13. package/src/useAddress/useAddress.test.ts +41 -2
  14. package/src/useAddress/useAddress.ts +1 -1
  15. package/src/useCart/useCart.test.ts +30 -0
  16. package/src/useCartNotification/useCartNotification.test.ts +30 -0
  17. package/src/useCheckout/useCheckout.test.ts +43 -1
  18. package/src/useCmsMeta/useCmsMeta.test.ts +26 -0
  19. package/src/useCountries/useCountries.test.ts +14 -0
  20. package/src/useLocalWishlist/useLocalWishlist.test.ts +44 -5
  21. package/src/useLocalWishlist/useLocalWishlist.ts +3 -2
  22. package/src/useNavigationContext/useNavigationContext.test.ts +25 -24
  23. package/src/useNavigationSearch/useNavigationSearch.test.ts +95 -2
  24. package/src/useNavigationSearch/useNavigationSearch.ts +18 -8
  25. package/src/useNewsletter/useNewsletter.test.ts +20 -1
  26. package/src/useNewsletter/useNewsletter.ts +7 -4
  27. package/src/useOrderDetails/useOrderDetails.test.ts +92 -3
  28. package/src/useOrderDetails/useOrderDetails.ts +7 -3
  29. package/src/useOrderPayment/useOrderPayment.test.ts +55 -1
  30. package/src/usePrice/usePrice.test.ts +10 -0
  31. package/src/usePrice/usePrice.ts +2 -7
  32. package/src/useProduct/useProduct.test.ts +14 -1
  33. package/src/useProductAssociations/useProductAssociations.spec.ts +1 -0
  34. package/src/useProductConfigurator/useProductConfigurator.spec.ts +38 -0
  35. package/src/useProductConfigurator/useProductConfigurator.ts +1 -1
  36. package/src/useProductPrice/useProductPrice.test.ts +7 -7
  37. package/src/useProductPrice/useProductPrice.ts +12 -4
  38. package/src/useProductReviews/useProductReviews.test.ts +15 -3
  39. package/src/useSalutations/useSalutations.spec.ts +13 -0
  40. package/src/useSessionContext/useSessionContext.test.ts +122 -4
  41. package/src/useSessionContext/useSessionContext.ts +13 -1
  42. package/src/useSyncWishlist/useSyncWishlist.test.ts +60 -8
  43. package/src/useUrlResolver/useUrlResolver.test.ts +6 -12
  44. package/src/useUrlResolver/useUrlResolver.ts +4 -6
  45. package/src/useUser/useUser.test.ts +107 -15
  46. package/src/useWishlist/useWishlist.test.ts +124 -26
@@ -22,7 +22,7 @@ describe("useProductPrice", () => {
22
22
  expect(vm.referencePrice).toStrictEqual(
23
23
  mockedProduct.calculatedPrice?.referencePrice,
24
24
  );
25
- expect(vm.isListPrice).toBe(false);
25
+ expect(vm.hasListPrice).toBe(false);
26
26
  expect(vm.regulationPrice).toBe(80);
27
27
  });
28
28
 
@@ -60,10 +60,10 @@ describe("useProductPrice", () => {
60
60
  ),
61
61
  );
62
62
  expect(vm.displayFrom).toBe(false);
63
- expect(vm.isListPrice).toBe(false);
63
+ expect(vm.hasListPrice).toBe(false);
64
64
  });
65
65
 
66
- it("isListPrice should be false with more than one calculatedPrices value", () => {
66
+ it("hasListPrice should be false with more than one calculatedPrices value", () => {
67
67
  const { vm } = useSetup(() =>
68
68
  useProductPrice(
69
69
  ref(
@@ -85,10 +85,10 @@ describe("useProductPrice", () => {
85
85
  ),
86
86
  );
87
87
  expect(vm.displayFrom).toBe(true);
88
- expect(vm.isListPrice).toBe(false);
88
+ expect(vm.hasListPrice).toBe(false);
89
89
  });
90
90
 
91
- it("isListPrice should be true with one calculatedPrices value", () => {
91
+ it("hasListPrice should be true with one calculatedPrices value", () => {
92
92
  const { vm } = useSetup(() =>
93
93
  useProductPrice(
94
94
  ref({
@@ -103,7 +103,7 @@ describe("useProductPrice", () => {
103
103
  ),
104
104
  );
105
105
  expect(vm.displayFrom).toBe(false);
106
- expect(vm.isListPrice).toBe(true);
106
+ expect(vm.hasListPrice).toBe(true);
107
107
  });
108
108
 
109
109
  it("displayFrom - second variant", async () => {
@@ -121,6 +121,6 @@ describe("useProductPrice", () => {
121
121
  ),
122
122
  );
123
123
  expect(vm.displayFrom).toBe(false);
124
- expect(vm.isListPrice).toBe(false);
124
+ expect(vm.hasListPrice).toBe(false);
125
125
  });
126
126
  });
@@ -18,7 +18,7 @@ export type UseProductPriceReturn = {
18
18
  */
19
19
  unitPrice: ComputedRef<number | undefined>;
20
20
  /**
21
- * Can be used if isListPrice is set to true
21
+ * Can be used if hasListPrice is set to true
22
22
  */
23
23
  referencePrice: ComputedRef<
24
24
  Schemas["CalculatedPrice"]["referencePrice"] | undefined
@@ -36,7 +36,13 @@ export type UseProductPriceReturn = {
36
36
  */
37
37
  tierPrices: ComputedRef<TierPrice[]>;
38
38
  /**
39
- * determines whether a discount price is set
39
+ * Whether the product currently has a list price reduction / discount
40
+ * (e.g. for strikethrough / discount display, typically based on `listPrice.percentage`).
41
+ */
42
+ hasListPrice: ComputedRef<boolean>;
43
+ /**
44
+ * Whether the product currently has a list price reduction / discount.
45
+ * @deprecated Use `hasListPrice` instead. Will be removed in a future version.
40
46
  */
41
47
  isListPrice: ComputedRef<boolean>;
42
48
  /**
@@ -107,7 +113,7 @@ export function useProductPrice(
107
113
  () => _price.value,
108
114
  );
109
115
 
110
- const isListPrice: ComputedRef<boolean> = computed(() => {
116
+ const hasListPrice: ComputedRef<boolean> = computed(() => {
111
117
  return !!_price.value?.listPrice?.percentage;
112
118
  });
113
119
 
@@ -125,7 +131,9 @@ export function useProductPrice(
125
131
  displayFrom,
126
132
  tierPrices,
127
133
  referencePrice,
128
- isListPrice,
134
+ hasListPrice,
135
+ /** @deprecated Use hasListPrice instead */
136
+ isListPrice: hasListPrice,
129
137
  regulationPrice,
130
138
  };
131
139
  }
@@ -6,19 +6,31 @@ import { useProductReviews } from "./useProductReviews";
6
6
 
7
7
  describe("useProductReviews", () => {
8
8
  it("load product reviews", async () => {
9
- const { vm, injections } = await useSetup(() =>
9
+ const { vm, injections } = useSetup(() =>
10
10
  useProductReviews(ref(ProductMock)),
11
11
  );
12
- injections.apiClient.invoke.mockResolvedValue({ data: {} });
12
+ injections.apiClient.invoke.mockResolvedValue({
13
+ data: { elements: [{ id: "1", content: "Great!" }] },
14
+ });
13
15
  await vm.loadProductReviews();
14
16
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
15
17
  expect.stringContaining("readProductReviews"),
16
18
  expect.objectContaining({}),
17
19
  );
20
+ expect(vm.productReviews).toEqual([{ id: "1", content: "Great!" }]);
21
+ });
22
+
23
+ it("load product reviews with empty elements", async () => {
24
+ const { vm, injections } = useSetup(() =>
25
+ useProductReviews(ref(ProductMock)),
26
+ );
27
+ injections.apiClient.invoke.mockResolvedValue({ data: {} });
28
+ await vm.loadProductReviews();
29
+ expect(vm.productReviews).toEqual([]);
18
30
  });
19
31
 
20
32
  it("add product review", async () => {
21
- const { vm, injections } = await useSetup(() =>
33
+ const { vm, injections } = useSetup(() =>
22
34
  useProductReviews(ref(ProductMock)),
23
35
  );
24
36
 
@@ -1,5 +1,6 @@
1
1
  import { flushPromises } from "@vue/test-utils";
2
2
  import { describe, expect, it, vi } from "vitest";
3
+ import { ref } from "vue";
3
4
  import { useSetup } from "../_test";
4
5
  import Salutations from "../mocks/Salutations";
5
6
  import { useSalutations } from "./useSalutations";
@@ -34,4 +35,16 @@ describe("useSalutations", () => {
34
35
 
35
36
  expect(vm.getSalutations).toStrictEqual([]);
36
37
  });
38
+
39
+ it("should not fetch when swSalutations already populated", async () => {
40
+ const preloadedSalutations = ref(Salutations);
41
+ const { vm, injections } = useSetup(useSalutations, {
42
+ apiClient: { invoke: vi.fn() },
43
+ swSalutations: preloadedSalutations,
44
+ } as Parameters<typeof useSetup>[1]);
45
+ await flushPromises();
46
+
47
+ expect(injections.apiClient.invoke).not.toHaveBeenCalled();
48
+ expect(vm.getSalutations).toStrictEqual(Salutations);
49
+ });
37
50
  });
@@ -70,7 +70,7 @@ describe("useSessionContext", () => {
70
70
  it("setShippingMethod", async () => {
71
71
  const { vm, injections } = useSetup(() => useSessionContext());
72
72
  injections.apiClient.invoke.mockResolvedValue({ data: {} });
73
- vm.setShippingMethod({ id: "test" });
73
+ await vm.setShippingMethod({ id: "test" });
74
74
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
75
75
  expect.stringContaining("updateContext"),
76
76
  expect.objectContaining({
@@ -90,10 +90,19 @@ describe("useSessionContext", () => {
90
90
  );
91
91
  });
92
92
 
93
+ it("setShippingMethod - error without id", async () => {
94
+ const { vm } = useSetup(() => useSessionContext());
95
+ await expect(
96
+ vm.setShippingMethod({} as { id: string }),
97
+ ).rejects.toThrowError(
98
+ "You need to provide shipping method id in order to set shipping method.",
99
+ );
100
+ });
101
+
93
102
  it("setPaymentMethod", async () => {
94
103
  const { vm, injections } = useSetup(() => useSessionContext());
95
104
  injections.apiClient.invoke.mockResolvedValue({ data: {} });
96
- vm.setPaymentMethod({ id: "test" });
105
+ await vm.setPaymentMethod({ id: "test" });
97
106
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
98
107
  expect.stringContaining("updateContext"),
99
108
  expect.objectContaining({
@@ -113,6 +122,15 @@ describe("useSessionContext", () => {
113
122
  );
114
123
  });
115
124
 
125
+ it("setPaymentMethod - error without id", async () => {
126
+ const { vm } = useSetup(() => useSessionContext());
127
+ await expect(
128
+ vm.setPaymentMethod({} as { id: string }),
129
+ ).rejects.toThrowError(
130
+ "You need to provide payment method id in order to set payment method.",
131
+ );
132
+ });
133
+
116
134
  it("setCurrency", async () => {
117
135
  const { vm, injections } = useSetup(() => useSessionContext());
118
136
  injections.apiClient.invoke.mockResolvedValue({ data: {} });
@@ -134,10 +152,19 @@ describe("useSessionContext", () => {
134
152
  expect(consoleErrorSpy).toHaveBeenCalled();
135
153
  });
136
154
 
155
+ it("setCurrency - undefined id", async () => {
156
+ const { vm, injections } = useSetup(() => useSessionContext());
157
+ await vm.setCurrency({ id: undefined } as unknown as { id: string });
158
+ expect(consoleErrorSpy).toHaveBeenCalled();
159
+ expect(injections.apiClient.invoke).not.toHaveBeenCalledWith(
160
+ expect.stringContaining("updateContext"),
161
+ );
162
+ });
163
+
137
164
  it("setActiveShippingAddress", async () => {
138
165
  const { vm, injections } = useSetup(() => useSessionContext());
139
166
  injections.apiClient.invoke.mockResolvedValue({ data: {} });
140
- vm.setActiveShippingAddress({ id: "test" });
167
+ await vm.setActiveShippingAddress({ id: "test" });
141
168
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
142
169
  expect.stringContaining("updateContext"),
143
170
  expect.objectContaining({
@@ -156,10 +183,17 @@ describe("useSessionContext", () => {
156
183
  );
157
184
  });
158
185
 
186
+ it("setActiveShippingAddress - error without id", async () => {
187
+ const { vm } = useSetup(() => useSessionContext());
188
+ await expect(vm.setActiveShippingAddress({})).rejects.toThrowError(
189
+ "You need to provide address id in order to set the address.",
190
+ );
191
+ });
192
+
159
193
  it("setActiveBillingAddress", async () => {
160
194
  const { vm, injections } = useSetup(() => useSessionContext());
161
195
  injections.apiClient.invoke.mockResolvedValue({ data: {} });
162
- vm.setActiveBillingAddress({ id: "test" });
196
+ await vm.setActiveBillingAddress({ id: "test" });
163
197
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
164
198
  expect.stringContaining("updateContext"),
165
199
  expect.objectContaining({
@@ -178,6 +212,13 @@ describe("useSessionContext", () => {
178
212
  );
179
213
  });
180
214
 
215
+ it("setActiveBillingAddress - error without id", async () => {
216
+ const { vm } = useSetup(() => useSessionContext());
217
+ await expect(vm.setActiveBillingAddress({})).rejects.toThrowError(
218
+ "You need to provide address id in order to set the address.",
219
+ );
220
+ });
221
+
181
222
  it("setContext", () => {
182
223
  const { vm } = useSetup(() => useSessionContext());
183
224
  vm.setContext({
@@ -218,4 +259,81 @@ describe("useSessionContext", () => {
218
259
  city: "test",
219
260
  });
220
261
  });
262
+
263
+ it("countryId, salesChannelCountryId, languageId, languageIdChain, taxState", () => {
264
+ const { vm } = useSetup(() => useSessionContext());
265
+ vm.setContext({
266
+ shippingLocation: {
267
+ country: { id: "country-1" },
268
+ },
269
+ salesChannel: { countryId: "sales-country-1", languageId: "lang-1" },
270
+ context: { languageIdChain: ["chain-1"], taxState: "net" },
271
+ } as unknown as Schemas["SalesChannelContext"]);
272
+
273
+ expect(vm.countryId).toBe("country-1");
274
+ expect(vm.salesChannelCountryId).toBe("sales-country-1");
275
+ expect(vm.languageId).toBe("lang-1");
276
+ expect(vm.languageIdChain).toBe("chain-1");
277
+ expect(vm.taxState).toBe("net");
278
+ });
279
+
280
+ it("languageIdChain - empty when no chain", () => {
281
+ const { vm } = useSetup(() => useSessionContext());
282
+ vm.setContext({
283
+ context: {},
284
+ } as unknown as Schemas["SalesChannelContext"]);
285
+
286
+ expect(vm.languageIdChain).toBe("");
287
+ });
288
+
289
+ it("setLanguage - undefined id", () => {
290
+ const { vm, injections } = useSetup(() => useSessionContext());
291
+ vm.setLanguage({ id: undefined } as unknown as { id: string });
292
+ expect(injections.apiClient.invoke).not.toHaveBeenCalledWith(
293
+ expect.stringContaining("updateContext"),
294
+ );
295
+ });
296
+
297
+ it("selectedShippingMethod, selectedPaymentMethod, currency, activeBillingAddress, userFromContext", () => {
298
+ const { vm } = useSetup(() => useSessionContext());
299
+
300
+ expect(vm.selectedShippingMethod).toBeNull();
301
+ expect(vm.selectedPaymentMethod).toBeNull();
302
+ expect(vm.currency).toBeNull();
303
+ expect(vm.activeBillingAddress).toBeNull();
304
+ expect(vm.userFromContext).toBeUndefined();
305
+
306
+ vm.setContext({
307
+ shippingMethod: { id: "ship-1", name: "Standard" },
308
+ paymentMethod: { id: "pay-1", name: "Invoice" },
309
+ currency: { id: "curr-1", isoCode: "EUR" },
310
+ customer: {
311
+ activeBillingAddress: { city: "Berlin" },
312
+ id: "cust-1",
313
+ },
314
+ } as unknown as Schemas["SalesChannelContext"]);
315
+
316
+ expect(vm.selectedShippingMethod).toStrictEqual({
317
+ id: "ship-1",
318
+ name: "Standard",
319
+ });
320
+ expect(vm.selectedPaymentMethod).toStrictEqual({
321
+ id: "pay-1",
322
+ name: "Invoice",
323
+ });
324
+ expect(vm.currency).toStrictEqual({ id: "curr-1", isoCode: "EUR" });
325
+ expect(vm.activeBillingAddress).toStrictEqual({ city: "Berlin" });
326
+ expect(vm.userFromContext).toStrictEqual({
327
+ activeBillingAddress: { city: "Berlin" },
328
+ id: "cust-1",
329
+ });
330
+ });
331
+
332
+ it("useSessionContext with initial context", () => {
333
+ const initialContext = {
334
+ shippingLocation: { country: { id: "initial-country" } },
335
+ } as unknown as Schemas["SalesChannelContext"];
336
+ const { vm } = useSetup(() => useSessionContext(initialContext));
337
+ expect(vm.countryId).toBe("initial-country");
338
+ });
221
339
  });
@@ -86,13 +86,23 @@ export type UseSessionContextReturn = {
86
86
  */
87
87
  salesChannelCountryId: ComputedRef<string | undefined>;
88
88
  /**
89
- * current language id
89
+ * @deprecated use salesChannelLanguageId instead
90
+ * sales channel language id
90
91
  */
91
92
  languageId: ComputedRef<string | undefined>;
92
93
  /**
94
+ * sales channel language code
95
+ */
96
+ salesChannelLanguageId: ComputedRef<string | undefined>;
97
+ /**
98
+ * @deprecated use currentLanguageId instead
93
99
  * current language id chain
94
100
  */
95
101
  languageIdChain: ComputedRef<string>;
102
+ /**
103
+ * current language code
104
+ */
105
+ currentLanguageId: ComputedRef<string | undefined>;
96
106
  /**
97
107
  * current context's customer object
98
108
  */
@@ -275,6 +285,8 @@ export function useSessionContext(
275
285
  setLanguage,
276
286
  languageId,
277
287
  languageIdChain,
288
+ salesChannelLanguageId: languageId,
289
+ currentLanguageId: languageIdChain,
278
290
  setCountry,
279
291
  setContext,
280
292
  };
@@ -14,20 +14,29 @@ describe("useSyncWishlist", () => {
14
14
  describe("methods", () => {
15
15
  describe("addToWishlist", () => {
16
16
  it("should add product to the wishlist", async () => {
17
- const { vm } = useSetup(() => useSyncWishlist());
17
+ const { vm, injections } = useSetup(() => useSyncWishlist());
18
+ injections.apiClient.invoke.mockResolvedValue({});
19
+
20
+ await vm.addToWishlistSync("some-id");
18
21
 
19
- await expect(vm.addToWishlistSync("some-id")).resolves.toBe(undefined);
22
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
23
+ "addProductOnWishlist post /customer/wishlist/add/{productId}",
24
+ { pathParams: { productId: "some-id" } },
25
+ );
20
26
  });
21
27
  });
22
28
 
23
29
  describe("removeFromWishlist", () => {
24
- it("should remove product from the wishlist", () => {
25
- const { vm } = useSetup(() => useSyncWishlist());
30
+ it("should remove product from the wishlist", async () => {
31
+ const { vm, injections } = useSetup(() => useSyncWishlist());
32
+ injections.apiClient.invoke.mockResolvedValue({});
33
+
34
+ await vm.removeFromWishlistSync("some-id");
26
35
 
27
- vm.getWishlistProducts();
28
- vm.removeFromWishlistSync("some-id");
29
- // Mocked value
30
- expect(vm.count).toBe(vm.count);
36
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
37
+ "deleteProductOnWishlist delete /customer/wishlist/delete/{productId}",
38
+ { pathParams: { productId: "some-id" } },
39
+ );
31
40
  });
32
41
  });
33
42
 
@@ -84,6 +93,49 @@ describe("useSyncWishlist", () => {
84
93
  );
85
94
  expect(vm.count).toBe(9);
86
95
  expect(vm.items.length).toBe(1);
96
+ expect(vm.products).toStrictEqual([{ id: "test-id" }]);
97
+ });
98
+
99
+ it("getWishlistProducts with custom criteria", async () => {
100
+ const { vm, injections } = useSetup(() => useSyncWishlist());
101
+ injections.apiClient.invoke.mockResolvedValue({
102
+ data: {
103
+ products: {
104
+ elements: [],
105
+ total: 0,
106
+ },
107
+ },
108
+ });
109
+
110
+ await vm.getWishlistProducts({ limit: 10, page: 2 });
111
+
112
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
113
+ expect.stringContaining("readCustomerWishlist"),
114
+ expect.objectContaining({
115
+ body: expect.objectContaining({
116
+ limit: 10,
117
+ page: 2,
118
+ "total-count-mode": "exact",
119
+ }),
120
+ }),
121
+ );
122
+ });
123
+
124
+ it("getWishlistProducts with null total, page, limit uses defaults", async () => {
125
+ const { vm, injections } = useSetup(() => useSyncWishlist());
126
+ injections.apiClient.invoke.mockResolvedValue({
127
+ data: {
128
+ products: {
129
+ elements: [{ id: "id-1" }],
130
+ },
131
+ },
132
+ });
133
+
134
+ await vm.getWishlistProducts();
135
+
136
+ expect(vm.count).toBe(0);
137
+ expect(vm.currentPage).toBe(1);
138
+ expect(vm.limit).toBe(15);
87
139
  });
88
140
  });
89
141
 
@@ -1,14 +1,7 @@
1
- import { buildUrlPrefix } from "@shopware/helpers";
2
- import { describe, expect, it, vi } from "vitest";
1
+ import { describe, expect, it } from "vitest";
3
2
  import { useSetup } from "../_test";
4
3
  import { useUrlResolver } from "./useUrlResolver";
5
4
 
6
- vi.mock("@shopware/helpers", async () => {
7
- return {
8
- buildUrlPrefix: vi.fn(),
9
- };
10
- });
11
-
12
5
  describe("useUrlResolver", () => {
13
6
  it("resolve url", async () => {
14
7
  const { vm } = await useSetup(useUrlResolver);
@@ -16,10 +9,11 @@ describe("useUrlResolver", () => {
16
9
  expect(() => vm.resolveUrl("x".repeat(2084))).toThrow();
17
10
  });
18
11
 
19
- it("resolve url with navigation pattern", async () => {
20
- const { vm } = await useSetup(useUrlResolver);
21
- vm.resolveUrl("/de/navigation/123");
12
+ it("resolve url with navigation pattern and urlPrefix", async () => {
13
+ const { vm } = await useSetup(useUrlResolver, {
14
+ urlPrefix: "shop",
15
+ } as Parameters<typeof useSetup>[1]);
22
16
 
23
- expect(buildUrlPrefix).toHaveBeenCalled();
17
+ expect(vm.resolveUrl("/en/navigation/123")).toBe("/shop/en/navigation/123");
24
18
  });
25
19
  });
@@ -2,7 +2,8 @@ import { buildUrlPrefix } from "@shopware/helpers";
2
2
  import { inject } from "vue";
3
3
 
4
4
  export function useUrlResolver() {
5
- const getUrlPrefix = () => inject("urlPrefix", "");
5
+ const urlPrefix = inject("urlPrefix", "");
6
+ const getUrlPrefix = () => urlPrefix;
6
7
 
7
8
  const resolveUrl = (url: string) => {
8
9
  // @see: https://codeql.github.com/codeql-query-help/javascript/js-polynomial-redos/
@@ -11,14 +12,11 @@ export function useUrlResolver() {
11
12
  }
12
13
 
13
14
  const navigationPattern = /[a-zA-Z0-9]+\/navigation\/[a-zA-Z0-9]+/;
14
- const urlPrefix = getUrlPrefix();
15
+ const prefix = getUrlPrefix();
15
16
 
16
17
  if (navigationPattern.test(url)) {
17
18
  const newUrl = url.split("/").slice(1);
18
-
19
- if (newUrl.length > 0) {
20
- return `${buildUrlPrefix(newUrl.join("/"), urlPrefix)}`;
21
- }
19
+ return buildUrlPrefix(newUrl.join("/"), prefix).path;
22
20
  }
23
21
 
24
22
  return url;