@shopware/nuxt-module 1.5.2 → 1.6.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.
- package/README.md +40 -7
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +5 -0
- package/package.json +4 -4
- package/plugin.ts +54 -8
package/README.md
CHANGED
|
@@ -114,6 +114,35 @@ More about Nuxt configuration can be found [HERE](https://nuxt.com/docs/getting-
|
|
|
114
114
|
}
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
## API Client timeout
|
|
118
|
+
|
|
119
|
+
`apiClientConfig.timeout` aborts a Store API request when its response headers do not arrive within the given number of milliseconds. Unset by default.
|
|
120
|
+
|
|
121
|
+
It guards against a request that hangs before the server answers. The timer starts before the connection is opened, so a DNS lookup, TCP connect or TLS handshake that hangs is aborted too. A response that stalls after its headers arrived is not aborted, because the timer is cleared once the headers land. A call that passes its own `signal` is the exception: the combined timer keeps running, so a stalled body is aborted too.
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"runtimeConfig": {
|
|
126
|
+
"public": {
|
|
127
|
+
"apiClientConfig": {
|
|
128
|
+
"timeout": 10000
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Only a positive number of milliseconds arms it, and a numeric string is coerced, so `"5000"` works. Leaving it out is silent. Setting it to anything else is ignored and logged once as a warning naming the config path the value came from.
|
|
136
|
+
|
|
137
|
+
`shopware: { apiClientConfig: { timeout } }` still works as a deprecated fallback, read only when neither `runtimeConfig` path holds a valid value. Nuxt warns at build time when a timeout is set there. Move it to `runtimeConfig.apiClientConfig`; it goes away in the next major.
|
|
138
|
+
|
|
139
|
+
Once set:
|
|
140
|
+
|
|
141
|
+
- The error carries no HTTP status and is not an `ApiClientError`. Detect it with `isTimeoutError()` from `@shopware/api-client`.
|
|
142
|
+
- A timed-out `GET` uses up its one automatic retry without reaching the server again.
|
|
143
|
+
- Your own `signal` on a single call is combined with the timeout, so whichever fires first aborts the request.
|
|
144
|
+
- `NUXT_API_CLIENT_CONFIG_TIMEOUT` and `NUXT_PUBLIC_API_CLIENT_CONFIG_TIMEOUT` only apply if the key is already in `nuxt.config`.
|
|
145
|
+
|
|
117
146
|
## Register custom API types (tailored for your Shopware instance)
|
|
118
147
|
|
|
119
148
|
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.
|
|
@@ -163,13 +192,17 @@ The API Client instance is aware of your custom API types thanks to declaring `#
|
|
|
163
192
|
|
|
164
193
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/nuxt-module/CHANGELOG.md)
|
|
165
194
|
|
|
166
|
-
### Latest changes: 1.
|
|
195
|
+
### Latest changes: 1.6.0
|
|
167
196
|
|
|
168
|
-
###
|
|
197
|
+
### Minor Changes
|
|
198
|
+
|
|
199
|
+
- [#2693](https://github.com/shopware/frontends/pull/2693) [`9d4710c`](https://github.com/shopware/frontends/commit/9d4710ca02ab35f35c65ea39bebd384630f4e1a7) Thanks [@mkucmus](https://github.com/mkucmus)! - `apiClientConfig.timeout` now works. Set it in milliseconds under `runtimeConfig.apiClientConfig` or `runtimeConfig.public.apiClientConfig`, next to `headers`, and the plugin forwards it to the API client. Unset by default. Only a positive number arms it, and a numeric string is coerced. Any other value is ignored and logged once as a warning naming the config path the value came from, instead of being dropped silently. It aborts a request whose response headers do not arrive in time, including one still opening its connection. It does not abort a response that stalls after its headers arrived, unless the call passes its own `signal`.
|
|
169
200
|
|
|
170
|
-
|
|
201
|
+
`apiClientConfig` under the `shopware` module options is deprecated, and now works as a fallback. It had never been read before, so a value set there in the past becomes active with this release. It is read last, only when neither `runtimeConfig` path holds a valid value, and Nuxt warns at build time when a timeout is set there. Move to `runtimeConfig.apiClientConfig`; the fallback goes away in the next major.
|
|
202
|
+
|
|
203
|
+
### Patch Changes
|
|
171
204
|
|
|
172
|
-
-
|
|
173
|
-
|
|
174
|
-
- @shopware/
|
|
175
|
-
- @shopware/
|
|
205
|
+
- [#2777](https://github.com/shopware/frontends/pull/2777) [`fb7e480`](https://github.com/shopware/frontends/commit/fb7e480af6202013adc3d602d58918789156a3ee) Thanks [@grenzenlos-digital](https://github.com/grenzenlos-digital)! - Resolve plugin configuration types from the published package entrypoint.
|
|
206
|
+
- Updated dependencies [[`44ece9d`](https://github.com/shopware/frontends/commit/44ece9dac2e4d0248c2270f7eff496c258632f5b), [`46d6daa`](https://github.com/shopware/frontends/commit/46d6daade81e3d9e443f3badfeba2ca0e2751477), [`7dbca8b`](https://github.com/shopware/frontends/commit/7dbca8bf8bca1225b365bc03e4dbc07d3764c2e1), [`74a477b`](https://github.com/shopware/frontends/commit/74a477bfa88e3c518d3a0336e4d301c823122ba8), [`74a477b`](https://github.com/shopware/frontends/commit/74a477bfa88e3c518d3a0336e4d301c823122ba8), [`5961f55`](https://github.com/shopware/frontends/commit/5961f55b9f7cebad626cc073ae0bf857aa26f91b), [`c78188a`](https://github.com/shopware/frontends/commit/c78188ac6c95ae19b070f5ea3361a60f21dff281), [`0df4c17`](https://github.com/shopware/frontends/commit/0df4c17b18ec38fc4d0c33f1cb6396f8f532a65d), [`4b43e64`](https://github.com/shopware/frontends/commit/4b43e64a8d78be6eca1f8d9c24140e046193af41)]:
|
|
207
|
+
- @shopware/api-client@1.7.0
|
|
208
|
+
- @shopware/composables@1.14.0
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,11 @@ import * as _nuxt_schema from '@nuxt/schema';
|
|
|
2
2
|
|
|
3
3
|
declare const _default: _nuxt_schema.NuxtModule<ShopwareNuxtOptions, ShopwareNuxtOptions, false>;
|
|
4
4
|
|
|
5
|
+
type ApiClientRuntimeConfig = {
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
/** Milliseconds to wait for response headers. A numeric string is coerced. */
|
|
8
|
+
timeout?: number | string;
|
|
9
|
+
};
|
|
5
10
|
type ShopwareNuxtOptions = {
|
|
6
11
|
/**
|
|
7
12
|
* Endpoint for your shopware backend.
|
|
@@ -13,6 +18,12 @@ type ShopwareNuxtOptions = {
|
|
|
13
18
|
accessToken?: string;
|
|
14
19
|
shopwareAccessToken?: string;
|
|
15
20
|
devStorefrontUrl?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Read last. Positive milliseconds, or a numeric string.
|
|
23
|
+
*
|
|
24
|
+
* @deprecated Use `runtimeConfig.apiClientConfig` or
|
|
25
|
+
* `runtimeConfig.public.apiClientConfig`. Removed in the next major.
|
|
26
|
+
*/
|
|
16
27
|
apiClientConfig?: {
|
|
17
28
|
timeout?: number | string;
|
|
18
29
|
};
|
|
@@ -37,4 +48,4 @@ type ShopwareNuxtOptions = {
|
|
|
37
48
|
};
|
|
38
49
|
|
|
39
50
|
export { _default as default };
|
|
40
|
-
export type { ShopwareNuxtOptions };
|
|
51
|
+
export type { ApiClientRuntimeConfig, ShopwareNuxtOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import * as _nuxt_schema from '@nuxt/schema';
|
|
|
2
2
|
|
|
3
3
|
declare const _default: _nuxt_schema.NuxtModule<ShopwareNuxtOptions, ShopwareNuxtOptions, false>;
|
|
4
4
|
|
|
5
|
+
type ApiClientRuntimeConfig = {
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
/** Milliseconds to wait for response headers. A numeric string is coerced. */
|
|
8
|
+
timeout?: number | string;
|
|
9
|
+
};
|
|
5
10
|
type ShopwareNuxtOptions = {
|
|
6
11
|
/**
|
|
7
12
|
* Endpoint for your shopware backend.
|
|
@@ -13,6 +18,12 @@ type ShopwareNuxtOptions = {
|
|
|
13
18
|
accessToken?: string;
|
|
14
19
|
shopwareAccessToken?: string;
|
|
15
20
|
devStorefrontUrl?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Read last. Positive milliseconds, or a numeric string.
|
|
23
|
+
*
|
|
24
|
+
* @deprecated Use `runtimeConfig.apiClientConfig` or
|
|
25
|
+
* `runtimeConfig.public.apiClientConfig`. Removed in the next major.
|
|
26
|
+
*/
|
|
16
27
|
apiClientConfig?: {
|
|
17
28
|
timeout?: number | string;
|
|
18
29
|
};
|
|
@@ -37,4 +48,4 @@ type ShopwareNuxtOptions = {
|
|
|
37
48
|
};
|
|
38
49
|
|
|
39
50
|
export { _default as default };
|
|
40
|
-
export type { ShopwareNuxtOptions };
|
|
51
|
+
export type { ApiClientRuntimeConfig, ShopwareNuxtOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -36,6 +36,11 @@ const index = defineNuxtModule({
|
|
|
36
36
|
"You are using deprecated configuration (shopwareEndpoint or shopwareAccessToken). 'shopware' prefix is not needed anymore. Please update your _nuxt.config.ts_ "
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
+
if (resolvedPublicShopwareConfig?.apiClientConfig?.timeout !== void 0 || resolvedPrivateShopwareConfig?.apiClientConfig?.timeout !== void 0) {
|
|
40
|
+
logger.warn(
|
|
41
|
+
"shopware.apiClientConfig is deprecated and will be removed in the next major. Move timeout to runtimeConfig.apiClientConfig or runtimeConfig.public.apiClientConfig."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
39
44
|
const envPublicEndpoint = process.env.NUXT_PUBLIC_SHOPWARE_ENDPOINT || process.env.NUXT_PUBLIC_SHOPWARE_SHOPWARE_ENDPOINT;
|
|
40
45
|
const envPrivateEndpoint = process.env.NUXT_SHOPWARE_ENDPOINT || process.env.NUXT_SHOPWARE_SHOPWARE_ENDPOINT;
|
|
41
46
|
const csrEndpoint = envPublicEndpoint || resolvedPublicShopwareConfig?.endpoint || resolvedPublicShopwareConfig?.shopwareEndpoint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/nuxt-module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Nuxt 3 module for Shopware Frontends",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"defu": "6.1.7",
|
|
39
39
|
"h3": "1.15.11",
|
|
40
40
|
"js-cookie": "3.0.7",
|
|
41
|
-
"@shopware/composables": "1.13.0",
|
|
42
41
|
"@shopware/helpers": "1.8.0",
|
|
43
|
-
"@shopware/api-client": "1.
|
|
42
|
+
"@shopware/api-client": "1.7.0",
|
|
43
|
+
"@shopware/composables": "1.14.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@nuxt/schema": "4.5.2",
|
|
47
47
|
"@typescript/native-preview": "7.0.0-dev.20260205.1",
|
|
48
48
|
"nuxt": "4.5.2",
|
|
49
49
|
"unbuild": "3.6.1",
|
|
50
|
-
"vitest": "
|
|
50
|
+
"vitest": "5.0.0",
|
|
51
51
|
"tsconfig": "0.0.0"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
package/plugin.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { createAPIClient } from "@shopware/api-client";
|
|
2
2
|
import { isMaintenanceMode } from "@shopware/helpers";
|
|
3
|
+
import type {
|
|
4
|
+
ApiClientRuntimeConfig,
|
|
5
|
+
ShopwareNuxtOptions,
|
|
6
|
+
} from "@shopware/nuxt-module";
|
|
3
7
|
import { getCookie } from "h3";
|
|
4
8
|
import type { H3Event } from "h3";
|
|
5
9
|
import Cookies from "js-cookie";
|
|
@@ -16,8 +20,6 @@ import {
|
|
|
16
20
|
} from "#imports";
|
|
17
21
|
import type { ApiClient } from "#shopware";
|
|
18
22
|
|
|
19
|
-
import type { ShopwareNuxtOptions } from "./src";
|
|
20
|
-
|
|
21
23
|
type ShopwarePluginInjections = {
|
|
22
24
|
shopwareApiClient: ApiClient;
|
|
23
25
|
};
|
|
@@ -55,6 +57,31 @@ function getApiErrors(data: unknown): ApiError[] {
|
|
|
55
57
|
return Array.isArray(errors) ? errors.filter(isApiError) : [];
|
|
56
58
|
}
|
|
57
59
|
|
|
60
|
+
const warnedTimeouts = new Set<string>();
|
|
61
|
+
|
|
62
|
+
function toTimeout(value: unknown, source: string): number | undefined {
|
|
63
|
+
if (value === undefined || value === null) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const timeout = typeof value === "string" ? Number(value) : value;
|
|
68
|
+
|
|
69
|
+
if (typeof timeout === "number" && Number.isFinite(timeout) && timeout > 0) {
|
|
70
|
+
return timeout;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const message = `[shopware] Ignoring ${source}.timeout: expected a positive number of milliseconds, got ${
|
|
74
|
+
typeof value === "number" ? String(value) : JSON.stringify(value)
|
|
75
|
+
}.`;
|
|
76
|
+
|
|
77
|
+
if (!warnedTimeouts.has(message)) {
|
|
78
|
+
warnedTimeouts.add(message);
|
|
79
|
+
console.warn(message);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
58
85
|
function setupShopwarePlugin(NuxtApp: ShopwarePluginNuxtApp): {
|
|
59
86
|
provide: ShopwarePluginInjections;
|
|
60
87
|
} {
|
|
@@ -99,13 +126,31 @@ function setupShopwarePlugin(NuxtApp: ShopwarePluginNuxtApp): {
|
|
|
99
126
|
? getCookie(NuxtApp.ssrContext.event, "sw-context-token")
|
|
100
127
|
: Cookies.get("sw-context-token");
|
|
101
128
|
|
|
102
|
-
type ApiClientConfig = {
|
|
103
|
-
headers?: Record<string, string>;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
129
|
const privateApiClientConfig = import.meta.server
|
|
107
|
-
? (runtimeConfig.apiClientConfig as
|
|
130
|
+
? (runtimeConfig.apiClientConfig as ApiClientRuntimeConfig | undefined)
|
|
108
131
|
: undefined;
|
|
132
|
+
const publicApiClientConfig = runtimeConfig.public?.apiClientConfig as
|
|
133
|
+
| ApiClientRuntimeConfig
|
|
134
|
+
| undefined;
|
|
135
|
+
|
|
136
|
+
// Both deprecated tiers report as shopware.apiClientConfig, the name nuxt.config uses.
|
|
137
|
+
const timeout =
|
|
138
|
+
toTimeout(
|
|
139
|
+
privateApiClientConfig?.timeout,
|
|
140
|
+
"runtimeConfig.apiClientConfig",
|
|
141
|
+
) ??
|
|
142
|
+
toTimeout(
|
|
143
|
+
publicApiClientConfig?.timeout,
|
|
144
|
+
"runtimeConfig.public.apiClientConfig",
|
|
145
|
+
) ??
|
|
146
|
+
toTimeout(
|
|
147
|
+
shopwareRuntimeConfig?.apiClientConfig?.timeout,
|
|
148
|
+
"shopware.apiClientConfig",
|
|
149
|
+
) ??
|
|
150
|
+
toTimeout(
|
|
151
|
+
shopwareRuntimeConfigPublic?.apiClientConfig?.timeout,
|
|
152
|
+
"shopware.apiClientConfig",
|
|
153
|
+
);
|
|
109
154
|
|
|
110
155
|
const apiClient = createAPIClient({
|
|
111
156
|
baseURL: shopwareEndpoint,
|
|
@@ -115,7 +160,8 @@ function setupShopwarePlugin(NuxtApp: ShopwarePluginNuxtApp): {
|
|
|
115
160
|
: "",
|
|
116
161
|
defaultHeaders:
|
|
117
162
|
(NuxtApp.ssrContext && privateApiClientConfig?.headers) ||
|
|
118
|
-
|
|
163
|
+
publicApiClientConfig?.headers,
|
|
164
|
+
...(timeout === undefined ? {} : { fetchOptions: { timeout } }),
|
|
119
165
|
});
|
|
120
166
|
|
|
121
167
|
apiClient.hook("onContextChanged", (newContextToken) => {
|