@shopware/nuxt-module 1.5.1 → 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 CHANGED
@@ -5,7 +5,7 @@
5
5
  [![](https://img.shields.io/github/issues/shopware/frontends/nuxt-module?label=nuxt-module%20issues&logo=github)](https://github.com/shopware/frontends/issues?q=is%3Aopen+is%3Aissue+label%3Anuxt-module)
6
6
  [![](https://img.shields.io/github/license/shopware/frontends?color=blue)](#)
7
7
 
8
- Nuxt [module](https://nuxt.com/docs/guide/going-further/modules) that allows you to set up a Nuxt 3 project with Shopware Frontends. It provides the composables and api-client packages.
8
+ Nuxt [module](https://nuxt.com/docs/guide/going-further/modules) that allows you to set up a Nuxt project with Shopware Frontends. It provides the composables and api-client packages.
9
9
 
10
10
  If you want to use these packages with a different Vue.js framework, see [the guide](https://developer.shopware.com/frontends/introduction/templates/custom-vue-project.html) for using Shopware Frontends in a custom project.
11
11
 
@@ -41,7 +41,7 @@ export default defineNuxtConfig({
41
41
  // set the module config
42
42
  shopware: {
43
43
  // connect to your Shopware 6 API instance
44
- endpoint: "https://demo-frontends.shopware.store",
44
+ endpoint: "https://demo-frontends.shopware.store/store-api/",
45
45
  accessToken: "SWSCBHFSNTVMAWNZDNFKSHLAYW",
46
46
  },
47
47
  // or directly in the runtime config
@@ -49,7 +49,7 @@ export default defineNuxtConfig({
49
49
  runtimeConfig: {
50
50
  public: {
51
51
  shopware: {
52
- endpoint: "https://demo-frontends.shopware.store",
52
+ endpoint: "https://demo-frontends.shopware.store/store-api/",
53
53
  accessToken: "SWSCBHFSNTVMAWNZDNFKSHLAYW",
54
54
  },
55
55
  },
@@ -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,11 +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.5.1
195
+ ### Latest changes: 1.6.0
196
+
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`.
200
+
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.
167
202
 
168
203
  ### Patch Changes
169
204
 
170
- - Updated dependencies [[`6315350`](https://github.com/shopware/frontends/commit/6315350add0464abef153343897d42f5808f2003), [`b767721`](https://github.com/shopware/frontends/commit/b767721847bf3391f9067eca7a045089fb22fce0), [`f16c5a0`](https://github.com/shopware/frontends/commit/f16c5a0785d6187b73c3edcf37feab7c90bd7988), [`978b02c`](https://github.com/shopware/frontends/commit/978b02c969ca4b16f5fc1d7a953ec4cce3d98173), [`6572aa8`](https://github.com/shopware/frontends/commit/6572aa84431e1f4a34d6cf04e549037692d638a6), [`744833b`](https://github.com/shopware/frontends/commit/744833b9d7d2f8ea1f5dfe65be3fa554dbe4a09f), [`e03c91b`](https://github.com/shopware/frontends/commit/e03c91be172374894d90b7a0111855b76719fee1), [`33facb1`](https://github.com/shopware/frontends/commit/33facb178792c8cb26b47ab984ac48c08ab4b72b), [`9137475`](https://github.com/shopware/frontends/commit/91374753cedb2034385f642e6af11314f2971caa), [`474d3fe`](https://github.com/shopware/frontends/commit/474d3fed346816135b0c7c797990b215a8b691c0), [`38379a5`](https://github.com/shopware/frontends/commit/38379a5d52ab09008774533ef417ebe2cde3f7fd)]:
171
- - @shopware/composables@1.12.1
172
- - @shopware/api-client@1.5.1
173
- - @shopware/helpers@1.7.2
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.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "Nuxt 3 module for Shopware Frontends",
5
5
  "author": "Shopware",
6
6
  "repository": {
@@ -34,20 +34,20 @@
34
34
  "index.cjs"
35
35
  ],
36
36
  "dependencies": {
37
- "@nuxt/kit": "4.4.8",
37
+ "@nuxt/kit": "4.5.2",
38
38
  "defu": "6.1.7",
39
39
  "h3": "1.15.11",
40
40
  "js-cookie": "3.0.7",
41
- "@shopware/composables": "1.12.1",
42
- "@shopware/helpers": "1.7.2",
43
- "@shopware/api-client": "1.5.1"
41
+ "@shopware/helpers": "1.8.0",
42
+ "@shopware/api-client": "1.7.0",
43
+ "@shopware/composables": "1.14.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@nuxt/schema": "4.4.8",
46
+ "@nuxt/schema": "4.5.2",
47
47
  "@typescript/native-preview": "7.0.0-dev.20260205.1",
48
- "nuxt": "4.4.8",
48
+ "nuxt": "4.5.2",
49
49
  "unbuild": "3.6.1",
50
- "vitest": "4.1.10",
50
+ "vitest": "5.0.0",
51
51
  "tsconfig": "0.0.0"
52
52
  },
53
53
  "scripts": {
package/plugin.ts CHANGED
@@ -1,9 +1,15 @@
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";
8
+ import type { H3Event } from "h3";
4
9
  import Cookies from "js-cookie";
5
10
  import { ref } from "vue";
6
11
 
12
+ import type { Plugin } from "#app";
7
13
  import {
8
14
  createShopwareContext,
9
15
  defineNuxtPlugin,
@@ -14,21 +20,71 @@ import {
14
20
  } from "#imports";
15
21
  import type { ApiClient } from "#shopware";
16
22
 
17
- import type { ShopwareNuxtOptions } from "./src";
23
+ type ShopwarePluginInjections = {
24
+ shopwareApiClient: ApiClient;
25
+ };
18
26
 
19
- declare module "#app" {
20
- interface NuxtApp {
21
- $shopwareApiClient: ApiClient;
27
+ type ShopwarePluginNuxtApp = {
28
+ ssrContext?: {
29
+ event: H3Event;
30
+ };
31
+ vueApp: {
32
+ provide: (name: string, value: unknown) => void;
33
+ };
34
+ };
35
+
36
+ type ApiError = {
37
+ code?: string;
38
+ };
39
+
40
+ function isApiError(error: unknown): error is ApiError {
41
+ if (!error || typeof error !== "object") {
42
+ return false;
22
43
  }
44
+
45
+ const { code } = error as { code?: unknown };
46
+
47
+ return code === undefined || typeof code === "string";
23
48
  }
24
49
 
25
- declare module "vue" {
26
- interface ComponentCustomProperties {
27
- $shopwareApiClient: ApiClient;
50
+ function getApiErrors(data: unknown): ApiError[] {
51
+ if (!data || typeof data !== "object" || !("errors" in data)) {
52
+ return [];
28
53
  }
54
+
55
+ const { errors } = data as { errors?: unknown };
56
+
57
+ return Array.isArray(errors) ? errors.filter(isApiError) : [];
29
58
  }
30
59
 
31
- export default defineNuxtPlugin((NuxtApp) => {
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
+
85
+ function setupShopwarePlugin(NuxtApp: ShopwarePluginNuxtApp): {
86
+ provide: ShopwarePluginInjections;
87
+ } {
32
88
  const runtimeConfig = useRuntimeConfig();
33
89
 
34
90
  const shopwareRuntimeConfigPublic = runtimeConfig.public
@@ -70,13 +126,31 @@ export default defineNuxtPlugin((NuxtApp) => {
70
126
  ? getCookie(NuxtApp.ssrContext.event, "sw-context-token")
71
127
  : Cookies.get("sw-context-token");
72
128
 
73
- type ApiClientConfig = {
74
- headers?: Record<string, string>;
75
- };
76
-
77
129
  const privateApiClientConfig = import.meta.server
78
- ? (runtimeConfig.apiClientConfig as ApiClientConfig)
130
+ ? (runtimeConfig.apiClientConfig as ApiClientRuntimeConfig | undefined)
79
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
+ );
80
154
 
81
155
  const apiClient = createAPIClient({
82
156
  baseURL: shopwareEndpoint,
@@ -86,7 +160,8 @@ export default defineNuxtPlugin((NuxtApp) => {
86
160
  : "",
87
161
  defaultHeaders:
88
162
  (NuxtApp.ssrContext && privateApiClientConfig?.headers) ||
89
- (runtimeConfig.public?.apiClientConfig as ApiClientConfig)?.headers,
163
+ publicApiClientConfig?.headers,
164
+ ...(timeout === undefined ? {} : { fetchOptions: { timeout } }),
90
165
  });
91
166
 
92
167
  apiClient.hook("onContextChanged", (newContextToken) => {
@@ -99,8 +174,7 @@ export default defineNuxtPlugin((NuxtApp) => {
99
174
  });
100
175
 
101
176
  apiClient.hook("onResponseError", (response) => {
102
- // @ts-expect-error TODO: check maintenance mode and fix typongs here
103
- const error = isMaintenanceMode(response._data?.errors ?? []);
177
+ const error = isMaintenanceMode(getApiErrors(response._data));
104
178
  if (error) {
105
179
  throw showError({
106
180
  statusCode: 503,
@@ -142,4 +216,9 @@ export default defineNuxtPlugin((NuxtApp) => {
142
216
  shopwareApiClient: apiClient as ApiClient,
143
217
  },
144
218
  };
145
- });
219
+ }
220
+
221
+ const shopwarePlugin: Plugin<ShopwarePluginInjections> =
222
+ defineNuxtPlugin<ShopwarePluginInjections>(setupShopwarePlugin);
223
+
224
+ export default shopwarePlugin;