@shopware/composables 1.9.0 → 1.9.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.
- package/README.md +5 -9
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +9 -2
- package/package.json +8 -8
- package/src/types/cmsElementTypes.ts +1 -1
- package/src/useCountries/useCountries.test.ts +41 -0
- package/src/useCountries/useCountries.ts +16 -0
- package/src/useNavigationSearch/useNavigationSearch.test.ts +21 -0
- package/src/useNavigationSearch/useNavigationSearch.ts +6 -3
- package/src/usePrice/usePrice.test.ts +3 -3
package/README.md
CHANGED
|
@@ -165,15 +165,11 @@ All composable functions are fully typed with TypeScript and they are registed g
|
|
|
165
165
|
|
|
166
166
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/composables/CHANGELOG.md)
|
|
167
167
|
|
|
168
|
-
### Latest changes: 1.9.
|
|
169
|
-
|
|
170
|
-
### Minor Changes
|
|
171
|
-
|
|
172
|
-
- [#1812](https://github.com/shopware/frontends/pull/1812) [`c28810d`](https://github.com/shopware/frontends/commit/c28810d0ca503b97c232438e200bbf5ba5dab403) Thanks [@patzick](https://github.com/patzick)! - `useShopwareContext` - added `browserLocale` field. With nuxt-module it's automatically injected into context. Should be used for proper date formatting.
|
|
173
|
-
|
|
174
|
-
- [#1737](https://github.com/shopware/frontends/pull/1737) [`bd70905`](https://github.com/shopware/frontends/commit/bd70905b8443fd57d8d8cb3cfc6501a9117dea49) Thanks [@mdanilowicz](https://github.com/mdanilowicz)! - Set `setDefaultPaymentMethod` as a deprecated method from `useUser` composable. The API endpoint is removed in the 6.7 version. The default payment method is now set on the checkout process
|
|
168
|
+
### Latest changes: 1.9.1
|
|
175
169
|
|
|
176
170
|
### Patch Changes
|
|
177
171
|
|
|
178
|
-
-
|
|
179
|
-
|
|
172
|
+
- [#1877](https://github.com/shopware/frontends/pull/1877) [`ab040bb`](https://github.com/shopware/frontends/commit/ab040bb6cc05541001a983c26d5cb6dbf3192394) Thanks [@mkucmus](https://github.com/mkucmus)! - Adjust `readSeoUrl` request in case of trailing slash when technical URL is used
|
|
173
|
+
|
|
174
|
+
- Updated dependencies [[`c8fa438`](https://github.com/shopware/frontends/commit/c8fa438b38de6dbc43a2895f2d1906907447c384)]:
|
|
175
|
+
- @shopware/helpers@1.5.0
|
package/dist/index.d.mts
CHANGED
|
@@ -177,7 +177,7 @@ type YouTubeVideoElementConfig = {
|
|
|
177
177
|
previewMedia: ElementConfig<string>;
|
|
178
178
|
showControls: ElementConfig<boolean>;
|
|
179
179
|
needsConfirmation: ElementConfig<boolean>;
|
|
180
|
-
|
|
180
|
+
advancedPrivacyMode: ElementConfig<boolean>;
|
|
181
181
|
};
|
|
182
182
|
type CmsElementYoutubeVideo = Schemas["CmsSlot"] & {
|
|
183
183
|
type: "youtube-video";
|
|
@@ -917,6 +917,10 @@ type UseCountriesReturn = {
|
|
|
917
917
|
getCountries: ComputedRef<Schemas["Country"][]>;
|
|
918
918
|
fetchCountries(): Promise<operations["readCountry post /country"]["response"]>;
|
|
919
919
|
getStatesForCountry(countryId: string): Schemas["CountryState"][] | null;
|
|
920
|
+
getCountriesOptions: ComputedRef<{
|
|
921
|
+
label: string;
|
|
922
|
+
value: string;
|
|
923
|
+
}[]>;
|
|
920
924
|
};
|
|
921
925
|
/**
|
|
922
926
|
* Composable to manage countries
|
package/dist/index.d.ts
CHANGED
|
@@ -177,7 +177,7 @@ type YouTubeVideoElementConfig = {
|
|
|
177
177
|
previewMedia: ElementConfig<string>;
|
|
178
178
|
showControls: ElementConfig<boolean>;
|
|
179
179
|
needsConfirmation: ElementConfig<boolean>;
|
|
180
|
-
|
|
180
|
+
advancedPrivacyMode: ElementConfig<boolean>;
|
|
181
181
|
};
|
|
182
182
|
type CmsElementYoutubeVideo = Schemas["CmsSlot"] & {
|
|
183
183
|
type: "youtube-video";
|
|
@@ -917,6 +917,10 @@ type UseCountriesReturn = {
|
|
|
917
917
|
getCountries: ComputedRef<Schemas["Country"][]>;
|
|
918
918
|
fetchCountries(): Promise<operations["readCountry post /country"]["response"]>;
|
|
919
919
|
getStatesForCountry(countryId: string): Schemas["CountryState"][] | null;
|
|
920
|
+
getCountriesOptions: ComputedRef<{
|
|
921
|
+
label: string;
|
|
922
|
+
value: string;
|
|
923
|
+
}[]>;
|
|
920
924
|
};
|
|
921
925
|
/**
|
|
922
926
|
* Composable to manage countries
|
package/dist/index.mjs
CHANGED
|
@@ -696,6 +696,12 @@ function useCountries() {
|
|
|
696
696
|
const getCountries = computed(() => {
|
|
697
697
|
return _sharedCountries.value ?? [];
|
|
698
698
|
});
|
|
699
|
+
const getCountriesOptions = computed(() => {
|
|
700
|
+
return _sharedCountries.value?.map((element) => ({
|
|
701
|
+
label: element.translated.name,
|
|
702
|
+
value: element.id
|
|
703
|
+
})) ?? [];
|
|
704
|
+
});
|
|
699
705
|
const mountedCallback = async () => {
|
|
700
706
|
if (!_sharedCountries.value) {
|
|
701
707
|
await fetchCountries();
|
|
@@ -711,7 +717,8 @@ function useCountries() {
|
|
|
711
717
|
mountedCallback,
|
|
712
718
|
fetchCountries,
|
|
713
719
|
getStatesForCountry,
|
|
714
|
-
getCountries
|
|
720
|
+
getCountries,
|
|
721
|
+
getCountriesOptions
|
|
715
722
|
};
|
|
716
723
|
}
|
|
717
724
|
|
|
@@ -1290,7 +1297,7 @@ function useNavigationSearch() {
|
|
|
1290
1297
|
};
|
|
1291
1298
|
}
|
|
1292
1299
|
const isTechnicalUrl = path.startsWith("/navigation/") || path.startsWith("/detail/") || path.startsWith("/landingPage/");
|
|
1293
|
-
const normalizedPath = isTechnicalUrl ? path : path.substring(1);
|
|
1300
|
+
const normalizedPath = isTechnicalUrl ? path.endsWith("/") ? path.slice(0, -1) : path : path.substring(1);
|
|
1294
1301
|
const seoResult = await apiClient.invoke("readSeoUrl post /seo-url", {
|
|
1295
1302
|
body: {
|
|
1296
1303
|
filter: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/composables",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.1",
|
|
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.
|
|
54
|
+
"@vueuse/core": "13.3.0",
|
|
55
55
|
"defu": "6.1.4",
|
|
56
56
|
"scule": "1.3.0",
|
|
57
|
-
"@shopware/helpers": "1.
|
|
57
|
+
"@shopware/helpers": "1.5.0",
|
|
58
58
|
"@shopware/api-client": "1.3.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@biomejs/biome": "1.8.3",
|
|
62
|
-
"@nuxt/kit": "3.
|
|
63
|
-
"@vitest/coverage-v8": "3.
|
|
62
|
+
"@nuxt/kit": "3.17.5",
|
|
63
|
+
"@vitest/coverage-v8": "3.2.3",
|
|
64
64
|
"@vue/test-utils": "2.4.6",
|
|
65
|
-
"happy-dom": "
|
|
65
|
+
"happy-dom": "18.0.1",
|
|
66
66
|
"typescript": "5.8.3",
|
|
67
67
|
"unbuild": "2.0.0",
|
|
68
|
-
"vitest": "3.
|
|
69
|
-
"vue": "3.5.
|
|
68
|
+
"vitest": "3.2.3",
|
|
69
|
+
"vue": "3.5.16",
|
|
70
70
|
"tsconfig": "0.0.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
@@ -159,7 +159,7 @@ type YouTubeVideoElementConfig = {
|
|
|
159
159
|
previewMedia: ElementConfig<string>;
|
|
160
160
|
showControls: ElementConfig<boolean>;
|
|
161
161
|
needsConfirmation: ElementConfig<boolean>;
|
|
162
|
-
|
|
162
|
+
advancedPrivacyMode: ElementConfig<boolean>;
|
|
163
163
|
};
|
|
164
164
|
export type CmsElementYoutubeVideo = Schemas["CmsSlot"] & {
|
|
165
165
|
type: "youtube-video";
|
|
@@ -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
|
});
|
|
@@ -10,6 +10,12 @@ export type UseCountriesReturn = {
|
|
|
10
10
|
operations["readCountry post /country"]["response"]
|
|
11
11
|
>;
|
|
12
12
|
getStatesForCountry(countryId: string): Schemas["CountryState"][] | null;
|
|
13
|
+
getCountriesOptions: ComputedRef<
|
|
14
|
+
{
|
|
15
|
+
label: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}[]
|
|
18
|
+
>;
|
|
13
19
|
};
|
|
14
20
|
|
|
15
21
|
/**
|
|
@@ -39,6 +45,15 @@ export function useCountries(): UseCountriesReturn {
|
|
|
39
45
|
return _sharedCountries.value ?? [];
|
|
40
46
|
});
|
|
41
47
|
|
|
48
|
+
const getCountriesOptions = computed(() => {
|
|
49
|
+
return (
|
|
50
|
+
_sharedCountries.value?.map((element: Schemas["Country"]) => ({
|
|
51
|
+
label: element.translated.name,
|
|
52
|
+
value: element.id,
|
|
53
|
+
})) ?? []
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
42
57
|
const mountedCallback = async () => {
|
|
43
58
|
if (!_sharedCountries.value) {
|
|
44
59
|
await fetchCountries();
|
|
@@ -60,5 +75,6 @@ export function useCountries(): UseCountriesReturn {
|
|
|
60
75
|
fetchCountries,
|
|
61
76
|
getStatesForCountry,
|
|
62
77
|
getCountries,
|
|
78
|
+
getCountriesOptions,
|
|
63
79
|
};
|
|
64
80
|
}
|
|
@@ -76,6 +76,27 @@ describe("useNavigationSearch", () => {
|
|
|
76
76
|
}),
|
|
77
77
|
);
|
|
78
78
|
});
|
|
79
|
+
it("should resolve technical url with trailing slash", async () => {
|
|
80
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
81
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
82
|
+
|
|
83
|
+
await vm.resolvePath("/detail/test/");
|
|
84
|
+
|
|
85
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
86
|
+
expect.stringContaining("readSeoUrl"),
|
|
87
|
+
expect.objectContaining({
|
|
88
|
+
body: {
|
|
89
|
+
filter: [
|
|
90
|
+
{
|
|
91
|
+
type: "equals",
|
|
92
|
+
field: "pathInfo",
|
|
93
|
+
value: "/detail/test",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
});
|
|
79
100
|
it("should not invoke api call for / search ", async () => {
|
|
80
101
|
const { vm, injections } = useSetup(useNavigationSearch);
|
|
81
102
|
injections.apiClient.invoke.mockResolvedValue({
|
|
@@ -35,9 +35,12 @@ export function useNavigationSearch(): UseNavigationSearchReturn {
|
|
|
35
35
|
path.startsWith("/detail/") ||
|
|
36
36
|
path.startsWith("/landingPage/");
|
|
37
37
|
|
|
38
|
-
// remove leading slash in case of seo url
|
|
39
|
-
const normalizedPath = isTechnicalUrl
|
|
40
|
-
|
|
38
|
+
// remove leading slash in case of seo url or remove trailing slash in case of technical url
|
|
39
|
+
const normalizedPath = isTechnicalUrl
|
|
40
|
+
? path.endsWith("/")
|
|
41
|
+
? path.slice(0, -1)
|
|
42
|
+
: path
|
|
43
|
+
: path.substring(1);
|
|
41
44
|
|
|
42
45
|
const seoResult = await apiClient.invoke("readSeoUrl post /seo-url", {
|
|
43
46
|
body: {
|
|
@@ -42,7 +42,7 @@ describe("usePrice", () => {
|
|
|
42
42
|
it("should use navigator language if locale is not provided", () => {
|
|
43
43
|
const { vm } = useSetup(usePrice, {
|
|
44
44
|
shopware: {
|
|
45
|
-
browserLocale: "
|
|
45
|
+
browserLocale: "de-DE",
|
|
46
46
|
},
|
|
47
47
|
});
|
|
48
48
|
vm.update({
|
|
@@ -50,8 +50,8 @@ describe("usePrice", () => {
|
|
|
50
50
|
localeCode: undefined,
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
expect(vm.currencyLocale).toBe("
|
|
54
|
-
expect(vm.getFormattedPrice(2.55)).toMatchInlineSnapshot(
|
|
53
|
+
expect(vm.currencyLocale).toBe("de-DE");
|
|
54
|
+
expect(vm.getFormattedPrice(2.55)).toMatchInlineSnapshot(`"2,55 $"`);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
it("should init price object", () => {
|