@shopware/nuxt-module 1.4.0 → 1.4.2
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 +43 -10
- package/dist/index.d.mts +0 -21
- package/dist/index.d.ts +0 -21
- package/dist/index.mjs +5 -4
- package/package.json +9 -8
- package/plugin.ts +25 -12
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ Now you can use any composable function you need without extra import:
|
|
|
74
74
|
The information about the session is kept in a cookie (`sw-context-token`) and used in every request made by any composable or directly, invoked by `api instance`:
|
|
75
75
|
|
|
76
76
|
```html
|
|
77
|
-
<script>
|
|
77
|
+
<script setup>
|
|
78
78
|
const { apiClient } = useShopwareContext();
|
|
79
79
|
const apiResponse = await apiClient.invoke(/** params omitted */);
|
|
80
80
|
</script>
|
|
@@ -114,25 +114,58 @@ More about Nuxt configuration can be found [HERE](https://nuxt.com/docs/getting-
|
|
|
114
114
|
}
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
## Register custom API types (tailored for your Shopware instance)
|
|
118
|
+
|
|
119
|
+
To use custom API types generated by the `api-gen` package, create a `shopware.d.ts` file in your project and register the types for the `#shopware` module. This enables type-safe usage of your custom API types throughout your Nuxt application.
|
|
120
|
+
|
|
121
|
+
**Example of using a local type definitions:**
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
// shopware.d.ts
|
|
125
|
+
declare module "#shopware" {
|
|
126
|
+
import type { createAPIClient } from "@shopware/api-client";
|
|
127
|
+
|
|
128
|
+
// Use default Shopware types:
|
|
129
|
+
// export type operations =
|
|
130
|
+
// import("@shopware/api-client/store-api-types").operations;
|
|
131
|
+
// export type Schemas =
|
|
132
|
+
// import("@shopware/api-client/store-api-types").components["schemas"];
|
|
133
|
+
|
|
134
|
+
// Or use your locally generated types (placed in ./api-types folder):
|
|
135
|
+
export type operations = import("./api-types/storeApiTypes").operations;
|
|
136
|
+
export type Schemas = import("./api-types/storeApiTypes").components["schemas"];
|
|
137
|
+
|
|
138
|
+
// Export your own Api Client definition:
|
|
139
|
+
export type ApiClient = ReturnType<typeof createAPIClient<operations>>;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Import your custom types from local files and export them as shown above. This approach keeps your types local, allows merging or overriding defaults, and ensures full type safety for API operations and schemas.
|
|
144
|
+
|
|
145
|
+
### Apply custom types for `@shopware/api-client`
|
|
146
|
+
|
|
147
|
+
The API Client instance is aware of your custom API types thanks to declaring `#shopware` module from the step above. So now, whenever `apiClient` instance is used, the proper types are registered.
|
|
148
|
+
|
|
117
149
|
## Links
|
|
118
150
|
|
|
119
151
|
- [📘 Documentation](https://frontends.shopware.com)
|
|
120
152
|
|
|
121
|
-
- [
|
|
153
|
+
- [📦 API Gen - Types Generator for Shopware 6 OpenAPI Schema](https://npmjs.com/@shopware/api-gen)
|
|
154
|
+
|
|
155
|
+
- [📦 API Client - REST API Client for Shopware 6](https://npmjs.com/@shopware/api-client)
|
|
156
|
+
|
|
157
|
+
- [👥 Community](https://discord.com/channels/1308047705309708348/1405501315160739951) (`#composable-frontend`)
|
|
122
158
|
<!-- AUTO GENERATED CHANGELOG -->
|
|
123
159
|
|
|
124
160
|
## Changelog
|
|
125
161
|
|
|
126
162
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/nuxt-module/CHANGELOG.md)
|
|
127
163
|
|
|
128
|
-
### Latest changes: 1.4.
|
|
129
|
-
|
|
130
|
-
### Minor Changes
|
|
131
|
-
|
|
132
|
-
- [#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.
|
|
164
|
+
### Latest changes: 1.4.2
|
|
133
165
|
|
|
134
166
|
### Patch Changes
|
|
135
167
|
|
|
136
|
-
- Updated dependencies [[`
|
|
137
|
-
- @shopware/
|
|
138
|
-
- @shopware/
|
|
168
|
+
- Updated dependencies [[`87771c3`](https://github.com/shopware/frontends/commit/87771c3b7a4521fcdba43cb4c967b61f5db01b3e), [`22ff62e`](https://github.com/shopware/frontends/commit/22ff62e354f024599d64ea8096af57695248851c), [`a44d871`](https://github.com/shopware/frontends/commit/a44d8712d9ae5ee196c03ac8b894f3d1392d0e68), [`e43d9b7`](https://github.com/shopware/frontends/commit/e43d9b7f559af21be8b66f2021cea2d14940e4aa), [`2cbda25`](https://github.com/shopware/frontends/commit/2cbda257a1056454e12f2fba9052f83eecb6d986), [`2cbda25`](https://github.com/shopware/frontends/commit/2cbda257a1056454e12f2fba9052f83eecb6d986), [`7fe2ef9`](https://github.com/shopware/frontends/commit/7fe2ef96a9d9d156683b85d31f0a660458c9fbfd), [`70dcf95`](https://github.com/shopware/frontends/commit/70dcf95d4370c63964d877a5cab113a53f93ca19), [`56cd178`](https://github.com/shopware/frontends/commit/56cd178e25fe2399b7170ccac3044e980621f041), [`c647baf`](https://github.com/shopware/frontends/commit/c647baf93e7174b849f5961ee5803add99d78602), [`e1fae3e`](https://github.com/shopware/frontends/commit/e1fae3eb6430e5c8e133456fbaf7f215f80c36f6), [`c647baf`](https://github.com/shopware/frontends/commit/c647baf93e7174b849f5961ee5803add99d78602), [`c77daa6`](https://github.com/shopware/frontends/commit/c77daa6a11e96c7f3688b16f7da010b54c7f5e8b)]:
|
|
169
|
+
- @shopware/composables@1.10.0
|
|
170
|
+
- @shopware/helpers@1.6.0
|
|
171
|
+
- @shopware/api-client@1.4.0
|
package/dist/index.d.mts
CHANGED
|
@@ -24,26 +24,5 @@ type ShopwareNuxtOptions = {
|
|
|
24
24
|
*/
|
|
25
25
|
useUserContextInSSR?: boolean;
|
|
26
26
|
};
|
|
27
|
-
declare module "@nuxt/schema" {
|
|
28
|
-
interface NuxtConfig {
|
|
29
|
-
shopware?: ShopwareNuxtOptions;
|
|
30
|
-
}
|
|
31
|
-
interface NuxtOptions {
|
|
32
|
-
shopware?: ShopwareNuxtOptions;
|
|
33
|
-
}
|
|
34
|
-
interface ApiClientConfig {
|
|
35
|
-
headers?: {
|
|
36
|
-
[key: string]: string;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
interface RuntimeConfig {
|
|
40
|
-
shopware?: Pick<ShopwareNuxtOptions, "endpoint" | "shopwareEndpoint" | "useUserContextInSSR">;
|
|
41
|
-
apiClientConfig?: ApiClientConfig;
|
|
42
|
-
}
|
|
43
|
-
interface PublicRuntimeConfig {
|
|
44
|
-
shopware: ShopwareNuxtOptions;
|
|
45
|
-
apiClientConfig?: ApiClientConfig;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
27
|
|
|
49
28
|
export { type ShopwareNuxtOptions, _default as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -24,26 +24,5 @@ type ShopwareNuxtOptions = {
|
|
|
24
24
|
*/
|
|
25
25
|
useUserContextInSSR?: boolean;
|
|
26
26
|
};
|
|
27
|
-
declare module "@nuxt/schema" {
|
|
28
|
-
interface NuxtConfig {
|
|
29
|
-
shopware?: ShopwareNuxtOptions;
|
|
30
|
-
}
|
|
31
|
-
interface NuxtOptions {
|
|
32
|
-
shopware?: ShopwareNuxtOptions;
|
|
33
|
-
}
|
|
34
|
-
interface ApiClientConfig {
|
|
35
|
-
headers?: {
|
|
36
|
-
[key: string]: string;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
interface RuntimeConfig {
|
|
40
|
-
shopware?: Pick<ShopwareNuxtOptions, "endpoint" | "shopwareEndpoint" | "useUserContextInSSR">;
|
|
41
|
-
apiClientConfig?: ApiClientConfig;
|
|
42
|
-
}
|
|
43
|
-
interface PublicRuntimeConfig {
|
|
44
|
-
shopware: ShopwareNuxtOptions;
|
|
45
|
-
apiClientConfig?: ApiClientConfig;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
27
|
|
|
49
28
|
export { type ShopwareNuxtOptions, _default as default };
|
package/dist/index.mjs
CHANGED
|
@@ -21,22 +21,23 @@ const index = defineNuxtModule({
|
|
|
21
21
|
async setup(options, nuxt) {
|
|
22
22
|
const logger = useLogger(MODULE_ID);
|
|
23
23
|
const resolver = createResolver(import.meta.url);
|
|
24
|
+
const shopwareConfig = nuxt.options.runtimeConfig?.public?.shopware ?? void 0;
|
|
24
25
|
nuxt.options.runtimeConfig.public.shopware = defu(
|
|
25
26
|
nuxt.options.runtimeConfig.public.shopware || {},
|
|
26
27
|
options || {}
|
|
27
28
|
);
|
|
28
|
-
if (isConfigDeprecated(
|
|
29
|
+
if (isConfigDeprecated(shopwareConfig)) {
|
|
29
30
|
logger.warn(
|
|
30
31
|
"You are using deprecated configuration (shopwareEndpoint or shopwareAccessToken). 'shopware' prefix is not needed anymore. Please update your _nuxt.config.ts_ "
|
|
31
32
|
);
|
|
32
33
|
}
|
|
33
|
-
if (
|
|
34
|
+
if (shopwareConfig?.endpoint) {
|
|
34
35
|
logger.info(
|
|
35
|
-
`You are using SSR Shopware API endpoint: ${
|
|
36
|
+
`You are using SSR Shopware API endpoint: ${shopwareConfig.endpoint}`
|
|
36
37
|
);
|
|
37
38
|
}
|
|
38
39
|
logger.info(
|
|
39
|
-
`CSR Shopware API endpoint: ${
|
|
40
|
+
`CSR Shopware API endpoint: ${shopwareConfig?.endpoint ?? shopwareConfig?.shopwareEndpoint}`
|
|
40
41
|
);
|
|
41
42
|
addPlugin({
|
|
42
43
|
src: resolver.resolve("../plugin.ts")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/nuxt-module",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Nuxt 3 module for Shopware Frontends",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
@@ -34,18 +34,19 @@
|
|
|
34
34
|
"index.cjs"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nuxt/kit": "
|
|
37
|
+
"@nuxt/kit": "4.2.1",
|
|
38
38
|
"defu": "6.1.4",
|
|
39
|
+
"h3": "1.15.4",
|
|
39
40
|
"js-cookie": "3.0.5",
|
|
40
|
-
"@shopware/composables": "1.
|
|
41
|
-
"@shopware/helpers": "1.
|
|
42
|
-
"@shopware/api-client": "1.
|
|
41
|
+
"@shopware/composables": "1.10.0",
|
|
42
|
+
"@shopware/helpers": "1.6.0",
|
|
43
|
+
"@shopware/api-client": "1.4.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@biomejs/biome": "1.8.3",
|
|
46
|
-
"@nuxt/schema": "
|
|
47
|
-
"nuxt": "
|
|
48
|
-
"typescript": "5.
|
|
47
|
+
"@nuxt/schema": "4.2.1",
|
|
48
|
+
"nuxt": "4.2.1",
|
|
49
|
+
"typescript": "5.9.3",
|
|
49
50
|
"unbuild": "2.0.0",
|
|
50
51
|
"tsconfig": "0.0.0"
|
|
51
52
|
},
|
package/plugin.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
useState,
|
|
13
13
|
} from "#imports";
|
|
14
14
|
import type { ApiClient } from "#shopware";
|
|
15
|
+
import type { ShopwareNuxtOptions } from "./src";
|
|
15
16
|
|
|
16
17
|
declare module "#app" {
|
|
17
18
|
interface NuxtApp {
|
|
@@ -27,12 +28,17 @@ declare module "vue" {
|
|
|
27
28
|
|
|
28
29
|
export default defineNuxtPlugin((NuxtApp) => {
|
|
29
30
|
const runtimeConfig = useRuntimeConfig();
|
|
31
|
+
|
|
32
|
+
const shopwareRuntimeConfigPublic = runtimeConfig.public
|
|
33
|
+
.shopware as ShopwareNuxtOptions;
|
|
34
|
+
const shopwareRuntimeConfig = runtimeConfig.shopware as ShopwareNuxtOptions;
|
|
35
|
+
|
|
30
36
|
const shopwareEndpointCSR =
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
shopwareRuntimeConfigPublic?.endpoint ??
|
|
38
|
+
shopwareRuntimeConfigPublic?.shopwareEndpoint;
|
|
33
39
|
|
|
34
40
|
const shopwareEndpointSSR =
|
|
35
|
-
(NuxtApp.ssrContext &&
|
|
41
|
+
(NuxtApp.ssrContext && shopwareRuntimeConfig?.endpoint) ||
|
|
36
42
|
shopwareEndpointCSR;
|
|
37
43
|
|
|
38
44
|
const shopwareEndpoint = import.meta.server
|
|
@@ -40,8 +46,8 @@ export default defineNuxtPlugin((NuxtApp) => {
|
|
|
40
46
|
: shopwareEndpointCSR;
|
|
41
47
|
|
|
42
48
|
const shopwareAccessToken =
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
shopwareRuntimeConfigPublic?.accessToken ??
|
|
50
|
+
shopwareRuntimeConfigPublic?.shopwareAccessToken;
|
|
45
51
|
|
|
46
52
|
if (!shopwareEndpoint || !shopwareAccessToken) {
|
|
47
53
|
throw new Error(
|
|
@@ -51,13 +57,17 @@ export default defineNuxtPlugin((NuxtApp) => {
|
|
|
51
57
|
|
|
52
58
|
const shouldUseSessionContextInServerRender =
|
|
53
59
|
!NuxtApp.ssrContext ||
|
|
54
|
-
!!
|
|
55
|
-
!!
|
|
60
|
+
!!shopwareRuntimeConfigPublic?.useUserContextInSSR ||
|
|
61
|
+
!!shopwareRuntimeConfig?.useUserContextInSSR;
|
|
56
62
|
|
|
57
63
|
const contextTokenFromCookie = NuxtApp.ssrContext
|
|
58
|
-
? getCookie(NuxtApp.ssrContext
|
|
64
|
+
? getCookie(NuxtApp.ssrContext.event, "sw-context-token")
|
|
59
65
|
: Cookies.get("sw-context-token");
|
|
60
66
|
|
|
67
|
+
type ApiClientConfig = {
|
|
68
|
+
headers?: Record<string, string>;
|
|
69
|
+
};
|
|
70
|
+
|
|
61
71
|
const apiClient = createAPIClient({
|
|
62
72
|
baseURL: shopwareEndpoint,
|
|
63
73
|
accessToken: shopwareAccessToken,
|
|
@@ -65,8 +75,9 @@ export default defineNuxtPlugin((NuxtApp) => {
|
|
|
65
75
|
? contextTokenFromCookie
|
|
66
76
|
: "",
|
|
67
77
|
defaultHeaders:
|
|
68
|
-
(NuxtApp.ssrContext &&
|
|
69
|
-
|
|
78
|
+
(NuxtApp.ssrContext &&
|
|
79
|
+
(runtimeConfig.apiClientConfig as ApiClientConfig)?.headers) ||
|
|
80
|
+
(runtimeConfig.public?.apiClientConfig as ApiClientConfig)?.headers,
|
|
70
81
|
});
|
|
71
82
|
|
|
72
83
|
apiClient.hook("onContextChanged", (newContextToken) => {
|
|
@@ -101,9 +112,11 @@ export default defineNuxtPlugin((NuxtApp) => {
|
|
|
101
112
|
|
|
102
113
|
NuxtApp.vueApp.provide("apiClient", apiClient);
|
|
103
114
|
// Shopware context
|
|
104
|
-
|
|
115
|
+
// TODO fix type App<Element>
|
|
116
|
+
// biome-ignore lint: ignore type error
|
|
117
|
+
const shopwareContext = createShopwareContext(NuxtApp.vueApp as any, {
|
|
105
118
|
enableDevtools: true,
|
|
106
|
-
devStorefrontUrl:
|
|
119
|
+
devStorefrontUrl: shopwareRuntimeConfigPublic?.devStorefrontUrl || null,
|
|
107
120
|
browserLocale,
|
|
108
121
|
});
|
|
109
122
|
NuxtApp.vueApp.provide("shopware", shopwareContext);
|