@scayle/storefront-nuxt 8.62.9 → 8.64.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/CHANGELOG.md +108 -0
- package/README.md +37 -0
- package/dist/module.d.mts +2 -2
- package/dist/module.json +2 -2
- package/dist/module.mjs +10 -1
- package/dist/runtime/JSONReporter.d.ts +4 -0
- package/dist/runtime/JSONReporter.js +11 -1
- package/dist/runtime/api/rpcHandler.d.ts +4 -1
- package/dist/runtime/api/rpcHandler.js +1 -1
- package/dist/runtime/context.js +6 -2
- package/dist/runtime/error/handler.d.ts +18 -8
- package/dist/runtime/error/handler.js +17 -24
- package/dist/runtime/plugin/log.client.d.ts +2 -2
- package/dist/runtime/plugin/log.server.d.ts +2 -2
- package/dist/runtime/plugin/shop.d.ts +2 -2
- package/dist/runtime/server/middleware/redirects.d.ts +9 -0
- package/dist/runtime/server/middleware/redirects.js +59 -3
- package/dist/runtime/utils/clientIp.d.ts +23 -0
- package/dist/runtime/utils/clientIp.js +8 -0
- package/dist/runtime/utils/zodSchema.d.ts +14 -3
- package/dist/runtime/utils/zodSchema.js +65 -1
- package/dist/test/factories.d.mts +3 -3
- package/package.json +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,113 @@
|
|
|
1
1
|
# @scayle/storefront-nuxt
|
|
2
2
|
|
|
3
|
+
## 8.64.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added the `redirects.lookupAbsoluteUrl` runtime config option, so your shop can halve its SCAYLE Panel redirect lookups. Each request looks up its path and its absolute URL, such as `https://example.com/men`, and each lookup costs a Storefront API call on a cache miss and counts against your rate limit. The absolute lookup finds only sources stored as absolute URLs and regular expressions that match the host. If none of your shops has such a source, set the option to `false` to send only the path lookup, for the `before-request` and the `on-missing` strategy. A redirect whose source is an absolute URL or a regular expression that matches the host then never applies. The option applies to every shop of the application, so keep the default if any shop has such a source. To check, list the redirects of every shop with `GET /v1/redirects` of the Storefront API.
|
|
8
|
+
|
|
9
|
+
The default `true` keeps the current behavior, and `NUXT_STOREFRONT_REDIRECTS_LOOKUP_ABSOLUTE_URL` overrides it.
|
|
10
|
+
|
|
11
|
+
- Added the `redirects.skipLookupPaths` and `redirects.skipLookupPatterns` runtime config options, so your shop can skip the SCAYLE Panel redirect lookup for paths you know have no redirect, such as crawler and AI agent requests for `/llms.txt` or `/.well-known/` paths. Each lookup costs Storefront API calls on a cache miss and counts against your rate limit, and Storefront Core can't skip these paths by default, because a regex redirect in the SCAYLE Panel can match a file path.
|
|
12
|
+
|
|
13
|
+
A `skipLookupPaths` entry matches that path and every path below it, so `'/de/.well-known'` covers the directory and its files but not `/de/.well-known-guide`. A trailing slash on the entry makes no difference. The entry `'/'` or `''` would match every path, so it fails the runtime config validation at startup. A `skipLookupPatterns` entry is the source of a regular expression, compiled with `new RegExp(pattern)` without flags. An entry that doesn't compile fails the runtime config validation at startup. Both match the path the relative lookup sends: decoded, without the query string and a trailing slash, and with `app.baseURL` and the shop path prefix, so with the `path` shop selector `/llms.txt` arrives as `/de/llms.txt`. A matching request skips the cache read and both Storefront API lookups, for the `before-request` and the `on-missing` strategy. The default `[]` keeps the current behavior.
|
|
14
|
+
|
|
15
|
+
`NUXT_STOREFRONT_REDIRECTS_SKIP_LOOKUP_PATHS` and `NUXT_STOREFRONT_REDIRECTS_SKIP_LOOKUP_PATTERNS` override the lists, each with a JSON array. The module now also sets `redirects.enabled` to `false` by default, so `NUXT_STOREFRONT_REDIRECTS_ENABLED` takes effect even when your Nuxt config has no `redirects` key.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
export default defineNuxtConfig({
|
|
19
|
+
runtimeConfig: {
|
|
20
|
+
storefront: {
|
|
21
|
+
redirects: {
|
|
22
|
+
enabled: true,
|
|
23
|
+
skipLookupPaths: ['/de/.well-known'],
|
|
24
|
+
skipLookupPatterns: ['/llms\\.txt$'],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- Changed the redirects middleware to send fewer redirect lookups to the Storefront API. Every lookup counts against the rate limit that all Storefront API endpoints share, and many of them could never return a Panel redirect.
|
|
32
|
+
|
|
33
|
+
- Requests with a method other than `GET` or `HEAD` no longer send a lookup.
|
|
34
|
+
- Requests whose path after `app.baseURL` starts with `/_i18n/`, `/_ipx/` or `app.buildAssetsDir` no longer send a lookup.
|
|
35
|
+
- Lookup results, with or without a matching redirect, are now cached for 15 minutes instead of 120 seconds. The Storefront API already caches each match for 15 minutes, so the shorter cache repeated lookups without applying Panel changes sooner. A new or changed redirect in the SCAYLE Panel can now take up to about 30 minutes to apply, up from about 17.
|
|
36
|
+
|
|
37
|
+
All three changes apply to the `before-request` and the `on-missing` strategy.
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependency `@vercel/nft@1.11.1` to `@vercel/nft@1.11.12`
|
|
42
|
+
- Fixed `originalIp` on the RPC context returning the address of the proxy in front of the Storefront Application instead of the user's IP. The Authentication API received that proxy address in the `x-original-client-ip` header, which made sign-in requests from different users indistinguishable. `originalIp` now reads the last entry of the `X-Forwarded-For` header and is `undefined` when that entry is missing or not a valid IP address, so the header is left out instead of carrying an internal address.
|
|
43
|
+
|
|
44
|
+
**Dependencies**
|
|
45
|
+
|
|
46
|
+
**@scayle/storefront-core v8.64.0**
|
|
47
|
+
|
|
48
|
+
- Patch
|
|
49
|
+
- Fixed the `getOrderById` RPC accepting an `orderId` that is not a positive integer. It now returns its `404` `ErrorResponse` for such a value without calling the Customer Account API, and `CustomerAPIClient.getOrder` URL-encodes the `orderId` in the request path.
|
|
50
|
+
- Fixed the `updatePassword` RPC reporting success when the Authentication API or the Customer Account API rejected the password change with a status other than 401, 403 or 404, such as a 400 or 422. It now returns an `ErrorResponse` with that status, so `useUser().updatePassword` rejects instead of resolving while the old password stays valid.
|
|
51
|
+
|
|
52
|
+
## 8.63.0
|
|
53
|
+
|
|
54
|
+
### Minor Changes
|
|
55
|
+
|
|
56
|
+
- Added the OpenTelemetry trace context to server-side JSON logs. With `storefront.log.json` enabled, a log line written while an OpenTelemetry span is active, for example during a request traced by `@scayle/nuxt-opentelemetry`, now carries top-level `trace_id` and `span_id` fields, so log backends can link each line to its trace. This covers the Storefront logger (`useLog`, `event.context.$log`, and the `log` of the RPC context) and `console` output on the server. The field names follow the OpenTelemetry convention for trace context in non-OTLP log formats, the same fields the JSON logs of Storefront Application V3 carry.
|
|
57
|
+
|
|
58
|
+
Lines written outside a span, or while the active span has an invalid span context, keep their previous shape. Logs without `storefront.log.json` and browser logs are unchanged.
|
|
59
|
+
|
|
60
|
+
- Stopped RPC error responses from exposing the message of the error an RPC method threw. The RPC handler copied that message into the `statusMessage` and `message` of the response. For a failed Storefront API call, the message holds the full request URL, which can include the basket or wishlist key and the query parameters, so that URL reached the browser.
|
|
61
|
+
|
|
62
|
+
The response now depends on the thrown error:
|
|
63
|
+
|
|
64
|
+
- An `H3Error`, for example from `createError({ statusCode: 404 })`, is sent with its own `statusCode`, `statusMessage`, and `data`. Before, it became a `500`.
|
|
65
|
+
- A `FetchError` from `ofetch` keeps the status code of the failed request, with the standard reason phrase of that code as `statusMessage` and `message`, for example `NOT FOUND`.
|
|
66
|
+
- Any other error, including a `FetchError` from `@scayle/storefront-api`, becomes a `500` with `INTERNAL SERVER ERROR` as `statusMessage` and `message`.
|
|
67
|
+
|
|
68
|
+
The server log and the `storefront:rpc:error` hook still receive the original error, and the response error carries it as `cause`. Error tracking that reads the `statusMessage` of an RPC error, like `trackError` in the Storefront Application, now receives the reason phrase.
|
|
69
|
+
|
|
70
|
+
If a custom RPC method has a message meant for the client, throw it as an `H3Error` and put the details into `data`, or return an `ErrorResponse`:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { createError } from 'h3'
|
|
74
|
+
|
|
75
|
+
throw createError({
|
|
76
|
+
statusCode: 409,
|
|
77
|
+
statusMessage: 'Conflict',
|
|
78
|
+
data: { reason: 'item-unavailable' },
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- Updated dependency `@vercel/nft@1.11.0` to `@vercel/nft@1.11.1`
|
|
85
|
+
|
|
86
|
+
**Dependencies**
|
|
87
|
+
|
|
88
|
+
**@scayle/storefront-core v8.63.0**
|
|
89
|
+
|
|
90
|
+
- Minor
|
|
91
|
+
- Added the RPC methods `updateBasketItems` and `updateWishlistItems`. They apply a list of add, update and remove operations to the basket (add and remove for the wishlist) in one Storefront API request, for example for a reorder or a bundle. Before, mixing adds, updates and removes needed one call per operation.
|
|
92
|
+
|
|
93
|
+
`updateBasketItems` is not the plural of `updateBasketItem`. That method sets the quantity of one existing item, while this one takes a list of operations of mixed types.
|
|
94
|
+
|
|
95
|
+
Both methods return the basket or wishlist after all operations plus one result per operation, in the order you sent the operations. A failed operation does not fail the call, so read `results` for the outcome of each one. An empty list returns `400`, and a request the Storefront API rejects returns a `Response` with its status only. After a `500` the operations may be partly applied, so fetch the basket or wishlist before you retry. The operation rules and the `pricePromotionKey` handling are the ones of `bulkUpdateItems` in `@scayle/storefront-api`.
|
|
96
|
+
|
|
97
|
+
The methods do not update the state of `useBasket` and `useWishlist`, so call their `refresh()` afterwards or use the returned basket or wishlist.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
const { basket, results } = await rpc('updateBasketItems', {
|
|
101
|
+
operations: [
|
|
102
|
+
{ action: 'add', variantId: 338316, quantity: 2 },
|
|
103
|
+
{ action: 'update', key: 'aec0f393', quantity: 3 },
|
|
104
|
+
{ action: 'remove', key: 'b12d4e8a' },
|
|
105
|
+
],
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`@scayle/storefront-core` now requires `@scayle/storefront-api` 19.9.0 or later, the first version with `bulkUpdateItems`.
|
|
110
|
+
|
|
3
111
|
## 8.62.9
|
|
4
112
|
|
|
5
113
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -40,6 +40,43 @@ Visit the [Quickstart Guide](https://scayle.dev/en/core-documentation/storefront
|
|
|
40
40
|
|
|
41
41
|
Visit the [Docs](https://scayle.dev) to learn more about our system requirements.
|
|
42
42
|
|
|
43
|
+
## JSON logs
|
|
44
|
+
|
|
45
|
+
Set `storefront.log.json` to `true` in the public runtime config, or `NUXT_PUBLIC_STOREFRONT_LOG_JSON=true` in the
|
|
46
|
+
environment, to write server-side logs as one JSON object per line. This covers the Storefront logger (`useLog`,
|
|
47
|
+
`event.context.$log`, and the `log` of the RPC context) and all `console` output on the server. Browser logs keep
|
|
48
|
+
their format.
|
|
49
|
+
|
|
50
|
+
Each line carries:
|
|
51
|
+
|
|
52
|
+
- `timestamp`: ISO 8601 string of the log entry's date.
|
|
53
|
+
- `message`: the formatted message, prefixed with the log space (for example `[storefront-nuxt.sfc]`), including
|
|
54
|
+
stack traces and causes of logged errors.
|
|
55
|
+
- `severity`: the consola log type, for example `info`, `warn`, `error`, or `debug`.
|
|
56
|
+
- `trace_id` and `span_id`: lowercase hex ids of the OpenTelemetry span that was active when the log was written,
|
|
57
|
+
for example the request span of [`@scayle/nuxt-opentelemetry`](https://www.npmjs.com/package/@scayle/nuxt-opentelemetry).
|
|
58
|
+
Omitted when no span is active, for example during startup or when the OpenTelemetry SDK is not initialized, and
|
|
59
|
+
when the active span has an invalid span context. The field names follow the OpenTelemetry
|
|
60
|
+
[trace context in non-OTLP log formats](https://opentelemetry.io/docs/specs/otel/compatibility/logging_trace_context/)
|
|
61
|
+
convention, so log backends can link each line to its trace.
|
|
62
|
+
|
|
63
|
+
Consola collapses an identical message that is logged more than five times in a row, each within a second of the
|
|
64
|
+
previous one, into one line ending in `(repeated N times)`. That line carries the `trace_id` and `span_id` of the log
|
|
65
|
+
call that writes it, which can belong to a different request than the repeated messages.
|
|
66
|
+
|
|
67
|
+
For example, `event.context.$log.info('Basket updated')` in a server route handler writes this line during a traced
|
|
68
|
+
request, spread over several lines here for reading:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"timestamp": "2026-11-06T12:00:00.000Z",
|
|
73
|
+
"message": "[storefront-nuxt] Basket updated",
|
|
74
|
+
"severity": "info",
|
|
75
|
+
"trace_id": "0af7651916cd43dd8448eb211c80319c",
|
|
76
|
+
"span_id": "b7ad6b7169203331"
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
43
80
|
## What is SCAYLE?
|
|
44
81
|
|
|
45
82
|
[SCAYLE](https://scayle.com) is a full-featured e-commerce software solution that comes with flexible APIs.
|
package/dist/module.d.mts
CHANGED
|
@@ -54,12 +54,12 @@ declare module '@nuxt/schema' {
|
|
|
54
54
|
declare const _default: _nuxt_schema.NuxtModule<{
|
|
55
55
|
rpcDir?: string | undefined;
|
|
56
56
|
rpcMethodNames?: string[] | undefined;
|
|
57
|
-
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
57
|
+
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "updateBasketItems" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "updateWishlistItems" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
58
58
|
apiBasePath?: string | undefined;
|
|
59
59
|
}, {
|
|
60
60
|
rpcDir?: string | undefined;
|
|
61
61
|
rpcMethodNames?: string[] | undefined;
|
|
62
|
-
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
62
|
+
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "updateBasketItems" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "updateWishlistItems" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
63
63
|
apiBasePath?: string | undefined;
|
|
64
64
|
}, false>;
|
|
65
65
|
|
package/dist/module.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-nuxt",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.64.0",
|
|
4
4
|
"configKey": "storefront",
|
|
5
5
|
"compatibility": {
|
|
6
6
|
"nuxt": ">=3.13"
|
|
7
7
|
},
|
|
8
8
|
"builder": {
|
|
9
|
-
"@nuxt/module-builder": "1.0.
|
|
9
|
+
"@nuxt/module-builder": "1.0.4",
|
|
10
10
|
"unbuild": "3.6.1"
|
|
11
11
|
}
|
|
12
12
|
}
|
package/dist/module.mjs
CHANGED
|
@@ -57,7 +57,7 @@ export default {
|
|
|
57
57
|
}`;
|
|
58
58
|
}
|
|
59
59
|
const PACKAGE_NAME = "@scayle/storefront-nuxt";
|
|
60
|
-
const PACKAGE_VERSION = "8.
|
|
60
|
+
const PACKAGE_VERSION = "8.64.0";
|
|
61
61
|
const logger = createConsola({
|
|
62
62
|
fancy: true,
|
|
63
63
|
formatOptions: {
|
|
@@ -391,6 +391,15 @@ const module$1 = defineNuxtModule({
|
|
|
391
391
|
// maxAge: undefined,
|
|
392
392
|
},
|
|
393
393
|
shopSelector: "domain",
|
|
394
|
+
// Nuxt applies a `NUXT_` environment variable only to a key that exists
|
|
395
|
+
// at build time, so the skip lists and `lookupAbsoluteUrl` need a
|
|
396
|
+
// default here.
|
|
397
|
+
redirects: {
|
|
398
|
+
enabled: false,
|
|
399
|
+
skipLookupPaths: [],
|
|
400
|
+
skipLookupPatterns: [],
|
|
401
|
+
lookupAbsoluteUrl: true
|
|
402
|
+
},
|
|
394
403
|
oauth: {
|
|
395
404
|
apiHost: "",
|
|
396
405
|
clientId: "",
|
|
@@ -3,6 +3,10 @@ import type { LogObject, ConsolaReporter, FormatOptions, ConsolaOptions } from '
|
|
|
3
3
|
* This custom Consola reporter formats log objects in a JSON string.
|
|
4
4
|
* It is a modified version of the built-in BasicReporter
|
|
5
5
|
* https://github.com/unjs/consola/blob/main/src/reporters/basic.ts
|
|
6
|
+
*
|
|
7
|
+
* Each line carries `timestamp`, `message` and `severity`. A line written while
|
|
8
|
+
* an OpenTelemetry span is active also carries the span's `trace_id` and
|
|
9
|
+
* `span_id`, so log backends can link it to its trace.
|
|
6
10
|
*/
|
|
7
11
|
export declare class JSONReporter implements ConsolaReporter {
|
|
8
12
|
formatStack(stack: string, message: string, opts: FormatOptions): string;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { formatWithOptions } from "node:util";
|
|
2
2
|
import { sep } from "node:path";
|
|
3
|
+
import { isSpanContextValid, trace } from "@opentelemetry/api";
|
|
3
4
|
function parseStack(stack, message) {
|
|
4
5
|
const cwd = process.cwd() + sep;
|
|
5
6
|
const lines = stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
|
|
6
7
|
return lines;
|
|
7
8
|
}
|
|
9
|
+
function getActiveSpanContext() {
|
|
10
|
+
const spanContext = trace.getActiveSpan()?.spanContext();
|
|
11
|
+
return spanContext && isSpanContextValid(spanContext) ? spanContext : void 0;
|
|
12
|
+
}
|
|
8
13
|
export class JSONReporter {
|
|
9
14
|
formatStack(stack, message, opts) {
|
|
10
15
|
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
|
@@ -39,10 +44,15 @@ ${stack}${causedError}`;
|
|
|
39
44
|
}
|
|
40
45
|
formatLogObj(logObj, opts) {
|
|
41
46
|
const message = this.formatArgs(logObj.args, opts);
|
|
47
|
+
const spanContext = getActiveSpanContext();
|
|
42
48
|
return JSON.stringify({
|
|
43
49
|
timestamp: logObj.date.toISOString(),
|
|
44
50
|
message,
|
|
45
|
-
severity: logObj.type
|
|
51
|
+
severity: logObj.type,
|
|
52
|
+
...spanContext && {
|
|
53
|
+
trace_id: spanContext.traceId,
|
|
54
|
+
span_id: spanContext.spanId
|
|
55
|
+
}
|
|
46
56
|
});
|
|
47
57
|
}
|
|
48
58
|
log(logObj, ctx) {
|
|
@@ -48,7 +48,10 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
48
48
|
type: undefined;
|
|
49
49
|
} | import("@scayle/storefront-api").ShopConfiguration | {
|
|
50
50
|
user?: import("@scayle/storefront-core").ShopUser;
|
|
51
|
-
} | import("@scayle/storefront-api").Wishlist | Response |
|
|
51
|
+
} | import("@scayle/storefront-api").Wishlist | Response | {
|
|
52
|
+
wishlist: import("@scayle/storefront-api").Wishlist;
|
|
53
|
+
results: import("@scayle/storefront-api").WishlistBulkResult[];
|
|
54
|
+
} | import("@scayle/storefront-core").ShopUserAddress[] | {
|
|
52
55
|
accessToken: string | undefined;
|
|
53
56
|
checkoutJwt: string;
|
|
54
57
|
} | import("@scayle/storefront-api").VariantDetail[] | import("@scayle/storefront-api").NavigationAllEndpointResponseData | import("@scayle/storefront-api").NavigationTree | import("@scayle/storefront-api").PromotionsEndpointResponseData | {
|
|
@@ -107,7 +107,7 @@ export default defineEventHandler(async (event) => {
|
|
|
107
107
|
$rpcContext,
|
|
108
108
|
e
|
|
109
109
|
);
|
|
110
|
-
result =
|
|
110
|
+
result = resolveError(e);
|
|
111
111
|
if (e instanceof Error) {
|
|
112
112
|
span.recordException(e);
|
|
113
113
|
if (e.cause && e.cause instanceof Error) {
|
package/dist/runtime/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getRequestIP, getRequestHeaders } from "h3";
|
|
1
|
+
import { getRequestIP, getRequestHeader, getRequestHeaders } from "h3";
|
|
2
2
|
import {
|
|
3
3
|
createAndPurifyHeaders,
|
|
4
4
|
StorefrontAPIClient,
|
|
@@ -11,6 +11,7 @@ import { useNitroApp } from "nitropack/runtime";
|
|
|
11
11
|
import { getCachedFunction } from "./cached.js";
|
|
12
12
|
import { getApiBasePath } from "./server/middleware/bootstrap-utils.js";
|
|
13
13
|
import { fetchCampaignKey } from "./campaignKey.js";
|
|
14
|
+
import { getClientIpFromForwardedFor } from "./utils/clientIp.js";
|
|
14
15
|
import * as moduleOptions from "#internal/storefront-options.mjs";
|
|
15
16
|
import { rpcHttpMethods } from "#virtual/rpcHttpMethods";
|
|
16
17
|
async function getWishlistKey(appKeys, session, $log, $shopConfig) {
|
|
@@ -121,8 +122,11 @@ export const buildContext = async (context) => {
|
|
|
121
122
|
get ip() {
|
|
122
123
|
return getRequestIP(event, { xForwardedFor: true });
|
|
123
124
|
},
|
|
125
|
+
// The socket peer is the hosting proxy, not the user, so it is never a fallback.
|
|
124
126
|
get originalIp() {
|
|
125
|
-
return
|
|
127
|
+
return getClientIpFromForwardedFor(
|
|
128
|
+
getRequestHeader(event, "x-forwarded-for")
|
|
129
|
+
);
|
|
126
130
|
},
|
|
127
131
|
get headers() {
|
|
128
132
|
return createAndPurifyHeaders(getRequestHeaders(event));
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
import type { H3Error } from 'h3';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Converts an error thrown by an RPC method into the `H3Error` the RPC handler
|
|
4
|
+
* responds with.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
6
|
+
* The response body reaches the browser, so only an `H3Error` keeps its own
|
|
7
|
+
* `statusMessage`, `message`, and `data`. An RPC method throws one on purpose
|
|
8
|
+
* to tell the client something. Any other error can carry internal details,
|
|
9
|
+
* like the message of a `FetchError` from `@scayle/storefront-api`, which
|
|
10
|
+
* holds the Storefront API request URL including any basket or wishlist key.
|
|
11
|
+
* For those, the response carries the standard reason phrase of the status
|
|
12
|
+
* code as `statusMessage` and `message` instead. The original error stays
|
|
13
|
+
* available as `cause` for server-side tracing.
|
|
5
14
|
*
|
|
6
|
-
* @
|
|
15
|
+
* @param error The error the RPC method threw.
|
|
16
|
+
*
|
|
17
|
+
* @returns The error itself if it is an `H3Error`. For a `FetchError` from
|
|
18
|
+
* `ofetch`, an `H3Error` with the HTTP status of the failed request, or `500`
|
|
19
|
+
* if the request got no response. For any other error, an `H3Error` with
|
|
20
|
+
* status `500`.
|
|
7
21
|
*/
|
|
8
|
-
declare const resolveError: (error:
|
|
9
|
-
statusCode: 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 506 | 507 | 508 | 510 | 511 | 306 | 505;
|
|
10
|
-
statusMessage: string;
|
|
11
|
-
name: string;
|
|
12
|
-
};
|
|
22
|
+
declare const resolveError: (error: unknown) => H3Error;
|
|
13
23
|
export { resolveError };
|
|
@@ -1,30 +1,23 @@
|
|
|
1
|
+
import { createError, isError } from "h3";
|
|
1
2
|
import { HttpStatusCode, HttpStatusMessage } from "@scayle/storefront-core";
|
|
2
3
|
import { FetchError } from "ofetch";
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
statusCode: error.status ?? HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
8
|
-
statusMessage: error.statusText ?? HttpStatusMessage.INTERNAL_SERVER_ERROR,
|
|
9
|
-
url
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
if (error instanceof Error) {
|
|
13
|
-
return {
|
|
14
|
-
statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
15
|
-
statusMessage: error.message ?? HttpStatusMessage.INTERNAL_SERVER_ERROR
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
20
|
-
statusMessage: HttpStatusMessage.INTERNAL_SERVER_ERROR
|
|
21
|
-
};
|
|
4
|
+
const getReasonPhrase = (statusCode) => {
|
|
5
|
+
const [key] = Object.entries(HttpStatusCode).find(([_, code]) => code === statusCode) ?? [];
|
|
6
|
+
return key ? HttpStatusMessage[key] : void 0;
|
|
22
7
|
};
|
|
23
8
|
const resolveError = (error) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
9
|
+
if (isError(error)) {
|
|
10
|
+
return error;
|
|
11
|
+
}
|
|
12
|
+
const statusCode = error instanceof FetchError ? error.status ?? HttpStatusCode.INTERNAL_SERVER_ERROR : HttpStatusCode.INTERNAL_SERVER_ERROR;
|
|
13
|
+
const reasonPhrase = getReasonPhrase(statusCode);
|
|
14
|
+
return createError({
|
|
15
|
+
statusCode,
|
|
16
|
+
statusMessage: reasonPhrase,
|
|
17
|
+
// Nitro sends `message` in the response body, so it must not come from
|
|
18
|
+
// `error`.
|
|
19
|
+
message: reasonPhrase,
|
|
20
|
+
cause: error
|
|
21
|
+
});
|
|
29
22
|
};
|
|
30
23
|
export { resolveError };
|
|
@@ -11,10 +11,10 @@ import type { Log } from '@scayle/storefront-core';
|
|
|
11
11
|
*
|
|
12
12
|
* @returns helper on the `NuxtApp` containing the 'log' and 'coreLog' instances.
|
|
13
13
|
*/
|
|
14
|
-
declare const _default: import("
|
|
14
|
+
declare const _default: import("nuxt/app").Plugin<{
|
|
15
15
|
log: Log;
|
|
16
16
|
coreLog: Log;
|
|
17
|
-
}> & import("
|
|
17
|
+
}> & import("nuxt/app").ObjectPlugin<{
|
|
18
18
|
log: Log;
|
|
19
19
|
coreLog: Log;
|
|
20
20
|
}>;
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* @returns A helper on the `NuxtApp` containing the `log` and
|
|
11
11
|
* `coreLog`instances, or undefined if ssrContext is missing.
|
|
12
12
|
*/
|
|
13
|
-
declare const _default: import("
|
|
13
|
+
declare const _default: import("nuxt/app").Plugin<{
|
|
14
14
|
log: import("@scayle/storefront-core").Log;
|
|
15
15
|
coreLog: import("@scayle/storefront-core").Log;
|
|
16
|
-
}> & import("
|
|
16
|
+
}> & import("nuxt/app").ObjectPlugin<{
|
|
17
17
|
log: import("@scayle/storefront-core").Log;
|
|
18
18
|
coreLog: import("@scayle/storefront-core").Log;
|
|
19
19
|
}>;
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* const { currentShop, availableShop } = useNuxtApp()
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
|
-
declare const _default: import("
|
|
16
|
+
declare const _default: import("nuxt/app").Plugin<{
|
|
17
17
|
currentShop: import("../../index.js").PublicShopConfig;
|
|
18
18
|
availableShops: import("../../index.js").PublicShopConfig[];
|
|
19
|
-
}> & import("
|
|
19
|
+
}> & import("nuxt/app").ObjectPlugin<{
|
|
20
20
|
currentShop: import("../../index.js").PublicShopConfig;
|
|
21
21
|
availableShops: import("../../index.js").PublicShopConfig[];
|
|
22
22
|
}>;
|
|
@@ -7,6 +7,15 @@ import type { H3Event } from 'h3';
|
|
|
7
7
|
* It utilizes a cache to store redirect results and falls back to the
|
|
8
8
|
* Storefront API if no cached redirect is available.
|
|
9
9
|
*
|
|
10
|
+
* Requests with a method other than `GET` or `HEAD`, requests for the
|
|
11
|
+
* `/_i18n/`, `/_ipx/` and `app.buildAssetsDir` routes, and requests whose path
|
|
12
|
+
* matches `redirects.skipLookupPaths` or `redirects.skipLookupPatterns` return
|
|
13
|
+
* without a lookup.
|
|
14
|
+
*
|
|
15
|
+
* A request looks up its path and its absolute URL in parallel, and a match
|
|
16
|
+
* for the path wins. With `redirects.lookupAbsoluteUrl` set to `false`, it
|
|
17
|
+
* looks up only the path.
|
|
18
|
+
*
|
|
10
19
|
* @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/features/redirects#overview
|
|
11
20
|
* @see https://scayle.dev/en/core-documentation/the-basics/shops/redirects
|
|
12
21
|
*
|
|
@@ -1,10 +1,51 @@
|
|
|
1
1
|
import { sendRedirect, getRequestURL } from "h3";
|
|
2
|
+
import { withoutBase } from "ufo";
|
|
2
3
|
import { UnstorageCache } from "@scayle/storefront-core";
|
|
3
4
|
import { getRedirectLookupUrls, getTargetLocation } from "./redirects.utils.js";
|
|
4
5
|
import { useRuntimeConfig } from "#imports";
|
|
5
6
|
const REDIS_REDIRECT_PREFIX = ":REDIRECT";
|
|
6
7
|
const REDIRECT_NOT_SET = "REDIRECT_NOT_SET";
|
|
7
|
-
const REDIRECT_CACHE_TTL =
|
|
8
|
+
const REDIRECT_CACHE_TTL = 900;
|
|
9
|
+
const APPLICATION_ROUTE_PREFIXES = ["/_i18n/", "/_ipx/"];
|
|
10
|
+
function isRedirectLookupCandidate(event, url, app) {
|
|
11
|
+
if (event.method !== "GET" && event.method !== "HEAD") {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const path = withoutBase(url.pathname, app.baseURL);
|
|
15
|
+
const skippedPrefixes = [...APPLICATION_ROUTE_PREFIXES, app.buildAssetsDir];
|
|
16
|
+
return !skippedPrefixes.some((prefix) => path.startsWith(prefix));
|
|
17
|
+
}
|
|
18
|
+
const compiledSkipLookupPatterns = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
function compileSkipLookupPatterns(skipLookupPatterns, log) {
|
|
20
|
+
const cached = compiledSkipLookupPatterns.get(skipLookupPatterns);
|
|
21
|
+
if (cached) {
|
|
22
|
+
return cached;
|
|
23
|
+
}
|
|
24
|
+
const compiled = skipLookupPatterns.flatMap((pattern) => {
|
|
25
|
+
try {
|
|
26
|
+
return [new RegExp(pattern)];
|
|
27
|
+
} catch (error) {
|
|
28
|
+
log.error(
|
|
29
|
+
`Ignoring the redirects.skipLookupPatterns entry ${JSON.stringify(pattern)}, it is not a valid regular expression`,
|
|
30
|
+
error
|
|
31
|
+
);
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
compiledSkipLookupPatterns.set(skipLookupPatterns, compiled);
|
|
36
|
+
return compiled;
|
|
37
|
+
}
|
|
38
|
+
function isSkippedLookupPath(url, skipLookupPaths, skipLookupPatterns) {
|
|
39
|
+
if (skipLookupPaths.length === 0 && skipLookupPatterns.length === 0) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const { relativeSourceUrl: lookupPath } = getRedirectLookupUrls(url);
|
|
43
|
+
return skipLookupPaths.some((rulePath) => isAtOrBelowPath(lookupPath, rulePath)) || skipLookupPatterns.some((pattern) => pattern.test(lookupPath));
|
|
44
|
+
}
|
|
45
|
+
function isAtOrBelowPath(path, rulePath) {
|
|
46
|
+
const base = rulePath.endsWith("/") ? rulePath.slice(0, -1) : rulePath;
|
|
47
|
+
return path === base || path.startsWith(`${base}/`);
|
|
48
|
+
}
|
|
8
49
|
async function fetchRedirectWithCache(sourceUrl, storefrontAPIClient, redirectCache, log, waitUntil) {
|
|
9
50
|
const cacheKey = encodeURIComponent(sourceUrl);
|
|
10
51
|
try {
|
|
@@ -63,7 +104,17 @@ export async function useRedirects(event) {
|
|
|
63
104
|
xForwardedProto: true,
|
|
64
105
|
xForwardedHost: true
|
|
65
106
|
});
|
|
107
|
+
if (!isRedirectLookupCandidate(event, url, config.app)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
66
110
|
const log = event.context.$rpcContext.log.space("sfc").space("redirects");
|
|
111
|
+
if (isSkippedLookupPath(
|
|
112
|
+
url,
|
|
113
|
+
options?.skipLookupPaths ?? [],
|
|
114
|
+
compileSkipLookupPatterns(options?.skipLookupPatterns ?? [], log)
|
|
115
|
+
)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
67
118
|
const shopCache = event.context.$cache;
|
|
68
119
|
const redirectCache = new UnstorageCache(
|
|
69
120
|
shopCache.storage,
|
|
@@ -76,6 +127,7 @@ export async function useRedirects(event) {
|
|
|
76
127
|
url,
|
|
77
128
|
queryParamWhitelist
|
|
78
129
|
);
|
|
130
|
+
const lookupAbsoluteUrl = options?.lookupAbsoluteUrl ?? true;
|
|
79
131
|
const [relativeRedirect, absoluteRedirect] = await Promise.all([
|
|
80
132
|
fetchRedirectWithCache(
|
|
81
133
|
relativeSourceUrl,
|
|
@@ -84,16 +136,20 @@ export async function useRedirects(event) {
|
|
|
84
136
|
log,
|
|
85
137
|
event.waitUntil
|
|
86
138
|
),
|
|
87
|
-
fetchRedirectWithCache(
|
|
139
|
+
lookupAbsoluteUrl ? fetchRedirectWithCache(
|
|
88
140
|
absoluteSourceUrl,
|
|
89
141
|
sapiClient,
|
|
90
142
|
redirectCache,
|
|
91
143
|
log,
|
|
92
144
|
event.waitUntil
|
|
93
|
-
)
|
|
145
|
+
) : null
|
|
94
146
|
]);
|
|
95
147
|
if (relativeRedirect && absoluteRedirect) {
|
|
96
148
|
log.info(`There are multiple valid redirects for: ${url.toString()}`);
|
|
149
|
+
} else if (absoluteRedirect) {
|
|
150
|
+
log.debug(
|
|
151
|
+
`Only the absolute URL lookup found a redirect for: ${url.toString()} (source: ${absoluteRedirect.source})`
|
|
152
|
+
);
|
|
97
153
|
}
|
|
98
154
|
const redirect = relativeRedirect ?? absoluteRedirect;
|
|
99
155
|
if (!redirect) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the user's IP address from an `X-Forwarded-For` header value.
|
|
3
|
+
*
|
|
4
|
+
* Used for `originalIp` on the RPC context, which the Authentication API
|
|
5
|
+
* requests forward as `x-original-client-ip`.
|
|
6
|
+
*
|
|
7
|
+
* Proxies append to `X-Forwarded-For`, so a request that passed several hops
|
|
8
|
+
* carries `client, proxy-1, proxy-2`. Only the last entry was written by the
|
|
9
|
+
* proxy in front of this server; entries to its left can be set by the client.
|
|
10
|
+
* Storefront Hosting overwrites the header with the IP address Cloudflare
|
|
11
|
+
* reports for the user.
|
|
12
|
+
*
|
|
13
|
+
* @param forwardedFor The raw `X-Forwarded-For` header value.
|
|
14
|
+
*
|
|
15
|
+
* @returns The last entry when it is a valid IPv4 or IPv6 address, otherwise
|
|
16
|
+
* `undefined`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* getClientIpFromForwardedFor('198.51.100.1, 203.0.113.7') // '203.0.113.7'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function getClientIpFromForwardedFor(forwardedFor: string | undefined): string | undefined;
|
|
@@ -7,6 +7,9 @@ export declare const RedirectsSchema: z.ZodMiniObject<{
|
|
|
7
7
|
"before-request": "before-request";
|
|
8
8
|
"on-missing": "on-missing";
|
|
9
9
|
}>>;
|
|
10
|
+
skipLookupPaths: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
11
|
+
skipLookupPatterns: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
12
|
+
lookupAbsoluteUrl: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
10
13
|
}, z.core.$strip>;
|
|
11
14
|
declare const SessionSchema: z.ZodMiniObject<{
|
|
12
15
|
sameSite: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
@@ -326,15 +329,15 @@ declare const ShopConfigSchema: z.ZodMiniObject<{
|
|
|
326
329
|
isDefault: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniString<string>]>>;
|
|
327
330
|
}, z.core.$strip>;
|
|
328
331
|
declare const ShopSelectorSchema: z.ZodMiniEnum<{
|
|
329
|
-
domain: "domain";
|
|
330
332
|
path: "path";
|
|
333
|
+
domain: "domain";
|
|
331
334
|
path_or_default: "path_or_default";
|
|
332
335
|
}>;
|
|
333
336
|
type ShopConfigType = z.infer<typeof ShopConfigSchema>;
|
|
334
337
|
declare const StorefrontRuntimeConfigSchema: z.ZodMiniObject<{
|
|
335
338
|
shopSelector: z.ZodMiniEnum<{
|
|
336
|
-
domain: "domain";
|
|
337
339
|
path: "path";
|
|
340
|
+
domain: "domain";
|
|
338
341
|
path_or_default: "path_or_default";
|
|
339
342
|
}>;
|
|
340
343
|
redirects: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
@@ -344,6 +347,9 @@ declare const StorefrontRuntimeConfigSchema: z.ZodMiniObject<{
|
|
|
344
347
|
"before-request": "before-request";
|
|
345
348
|
"on-missing": "on-missing";
|
|
346
349
|
}>>;
|
|
350
|
+
skipLookupPaths: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
351
|
+
skipLookupPatterns: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
352
|
+
lookupAbsoluteUrl: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
347
353
|
}, z.core.$strip>>;
|
|
348
354
|
shops: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
|
|
349
355
|
idp: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
@@ -781,8 +787,8 @@ declare const StorefrontPublicRuntimeConfigSchema: z.ZodMiniObject<{
|
|
|
781
787
|
export declare const RuntimeConfigSchema: z.ZodMiniObject<{
|
|
782
788
|
storefront: z.ZodMiniObject<{
|
|
783
789
|
shopSelector: z.ZodMiniEnum<{
|
|
784
|
-
domain: "domain";
|
|
785
790
|
path: "path";
|
|
791
|
+
domain: "domain";
|
|
786
792
|
path_or_default: "path_or_default";
|
|
787
793
|
}>;
|
|
788
794
|
redirects: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
@@ -792,6 +798,9 @@ export declare const RuntimeConfigSchema: z.ZodMiniObject<{
|
|
|
792
798
|
"before-request": "before-request";
|
|
793
799
|
"on-missing": "on-missing";
|
|
794
800
|
}>>;
|
|
801
|
+
skipLookupPaths: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
802
|
+
skipLookupPatterns: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
803
|
+
lookupAbsoluteUrl: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
795
804
|
}, z.core.$strip>>;
|
|
796
805
|
shops: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
|
|
797
806
|
idp: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
@@ -1256,6 +1265,7 @@ declare const ModuleOptionSchema: z.ZodMiniObject<{
|
|
|
1256
1265
|
updateBasketItem: "updateBasketItem";
|
|
1257
1266
|
getApplicablePromotionsByCode: "getApplicablePromotionsByCode";
|
|
1258
1267
|
updatePromotions: "updatePromotions";
|
|
1268
|
+
updateBasketItems: "updateBasketItems";
|
|
1259
1269
|
getBrands: "getBrands";
|
|
1260
1270
|
getBrandById: "getBrandById";
|
|
1261
1271
|
getRootCategories: "getRootCategories";
|
|
@@ -1276,6 +1286,7 @@ declare const ModuleOptionSchema: z.ZodMiniObject<{
|
|
|
1276
1286
|
getWishlist: "getWishlist";
|
|
1277
1287
|
addItemToWishlist: "addItemToWishlist";
|
|
1278
1288
|
removeItemFromWishlist: "removeItemFromWishlist";
|
|
1289
|
+
updateWishlistItems: "updateWishlistItems";
|
|
1279
1290
|
clearWishlist: "clearWishlist";
|
|
1280
1291
|
getOrderById: "getOrderById";
|
|
1281
1292
|
getOrderCustomData: "getOrderCustomData";
|
|
@@ -1,10 +1,74 @@
|
|
|
1
1
|
import * as z from "zod/mini";
|
|
2
2
|
import { rpcMethods } from "@scayle/storefront-core";
|
|
3
3
|
import { builtinDrivers } from "unstorage";
|
|
4
|
+
function isRegExpSource(pattern) {
|
|
5
|
+
try {
|
|
6
|
+
return new RegExp(pattern) instanceof RegExp;
|
|
7
|
+
} catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
export const RedirectsSchema = z.object({
|
|
5
12
|
enabled: z.boolean(),
|
|
6
13
|
queryParamWhitelist: z.optional(z.array(z.string())),
|
|
7
|
-
strategy: z.optional(z.enum(["before-request", "on-missing"]))
|
|
14
|
+
strategy: z.optional(z.enum(["before-request", "on-missing"])),
|
|
15
|
+
/**
|
|
16
|
+
* Paths that skip the redirect lookup, because you know the SCAYLE Panel
|
|
17
|
+
* has no redirect for them. A path matches itself and every path below it,
|
|
18
|
+
* so `'/de/.well-known'` covers the directory and its files but not
|
|
19
|
+
* `/de/.well-known-guide`. A trailing slash makes no difference. Defaults
|
|
20
|
+
* to `[]`.
|
|
21
|
+
*
|
|
22
|
+
* Entries match the path the lookup sends: decoded, without the query
|
|
23
|
+
* string and a trailing slash, and with `app.baseURL` and the shop path
|
|
24
|
+
* prefix. The entry `'/'` or `''` would match every path, so it fails the
|
|
25
|
+
* runtime config validation at startup. To skip every lookup, set
|
|
26
|
+
* `enabled` to `false`.
|
|
27
|
+
*
|
|
28
|
+
* Override with `NUXT_STOREFRONT_REDIRECTS_SKIP_LOOKUP_PATHS`, a JSON array.
|
|
29
|
+
*/
|
|
30
|
+
skipLookupPaths: z.optional(
|
|
31
|
+
z.array(
|
|
32
|
+
z.string().check(
|
|
33
|
+
z.refine((path) => path !== "/" && path !== "", {
|
|
34
|
+
error: (issue) => `${JSON.stringify(issue.input)} matches every path, set redirects.enabled to false to skip every lookup`
|
|
35
|
+
})
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
),
|
|
39
|
+
/**
|
|
40
|
+
* Regular expressions, as source strings, for paths that skip the redirect
|
|
41
|
+
* lookup, such as `'/llms\\.txt$'` for crawler requests for `/llms.txt`
|
|
42
|
+
* under every shop path. Each entry is compiled with `new RegExp(pattern)`,
|
|
43
|
+
* without flags, and tested against the same path as `skipLookupPaths`. An
|
|
44
|
+
* entry that doesn't compile fails the runtime config validation at
|
|
45
|
+
* startup. Defaults to `[]`.
|
|
46
|
+
*
|
|
47
|
+
* Override with `NUXT_STOREFRONT_REDIRECTS_SKIP_LOOKUP_PATTERNS`, a JSON
|
|
48
|
+
* array.
|
|
49
|
+
*/
|
|
50
|
+
skipLookupPatterns: z.optional(
|
|
51
|
+
z.array(
|
|
52
|
+
z.string().check(
|
|
53
|
+
z.refine(isRegExpSource, {
|
|
54
|
+
error: (issue) => `Invalid regular expression ${JSON.stringify(issue.input)}`
|
|
55
|
+
})
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
),
|
|
59
|
+
/**
|
|
60
|
+
* Looks up the absolute URL of a request, such as
|
|
61
|
+
* `https://example.com/men`, in addition to its path. The Storefront API
|
|
62
|
+
* compares a plain redirect source with the lookup URL character by
|
|
63
|
+
* character, so only sources stored as absolute URLs and regular
|
|
64
|
+
* expressions that match the host need this lookup. Set it to `false` when
|
|
65
|
+
* none of your shops has such a source, to halve the redirect lookups. The
|
|
66
|
+
* option applies to every shop, so keep the default if any shop has one.
|
|
67
|
+
* Defaults to `true`.
|
|
68
|
+
*
|
|
69
|
+
* Override with `NUXT_STOREFRONT_REDIRECTS_LOOKUP_ABSOLUTE_URL`.
|
|
70
|
+
*/
|
|
71
|
+
lookupAbsoluteUrl: z.optional(z.boolean())
|
|
8
72
|
});
|
|
9
73
|
const SessionSchema = z.object({
|
|
10
74
|
/**
|
|
@@ -15,17 +15,17 @@ declare const moduleRuntimeOptionsFactory: Factory<StorefrontRuntimeConfigType,
|
|
|
15
15
|
declare const moduleOptionsFactory: Factory<{
|
|
16
16
|
rpcDir?: string | undefined;
|
|
17
17
|
rpcMethodNames?: string[] | undefined;
|
|
18
|
-
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
18
|
+
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "updateBasketItems" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "updateWishlistItems" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
19
19
|
apiBasePath?: string | undefined;
|
|
20
20
|
}, any, {
|
|
21
21
|
rpcDir?: string | undefined;
|
|
22
22
|
rpcMethodNames?: string[] | undefined;
|
|
23
|
-
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
23
|
+
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "updateBasketItems" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "updateWishlistItems" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
24
24
|
apiBasePath?: string | undefined;
|
|
25
25
|
}, fishery.DeepPartialObject<{
|
|
26
26
|
rpcDir?: string | undefined;
|
|
27
27
|
rpcMethodNames?: string[] | undefined;
|
|
28
|
-
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
28
|
+
rpcMethodOverrides?: ("getProductById" | "getProductsByIds" | "getProductsByReferenceKeys" | "getProductsCount" | "fetchAllFiltersForCategory" | "getFilters" | "getProductsByCategory" | "oauthForgetPassword" | "oauthGuestLogin" | "oauthLogin" | "oauthRegister" | "oauthRevokeToken" | "refreshAccessToken" | "updatePasswordByHash" | "addItemToBasket" | "addItemsToBasket" | "getBasket" | "removeItemFromBasket" | "clearBasket" | "mergeBaskets" | "updateBasketItem" | "getApplicablePromotionsByCode" | "updatePromotions" | "updateBasketItems" | "getBrands" | "getBrandById" | "getRootCategories" | "getCategoryByPath" | "getCategoriesByPath" | "getCategoryById" | "getCategoryTree" | "getCampaign" | "getCampaignKey" | "getOrderDataByCbd" | "getSearchSuggestions" | "resolveSearch" | "getShopConfiguration" | "getUser" | "fetchUser" | "refreshUser" | "getAccessToken" | "getWishlist" | "addItemToWishlist" | "removeItemFromWishlist" | "updateWishlistItems" | "clearWishlist" | "getOrderById" | "getOrderCustomData" | "getShopUserAddresses" | "updateShopUser" | "updatePassword" | "getCheckoutToken" | "getVariantById" | "fetchAllNavigationTrees" | "fetchNavigationTreeById" | "fetchNavigationTreeByName" | "getPromotions" | "getCurrentPromotions" | "getPromotionsByIds" | "getExternalIdpRedirect" | "handleIDPLoginCallback")[] | undefined;
|
|
29
29
|
apiBasePath?: string | undefined;
|
|
30
30
|
}>>;
|
|
31
31
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.64.0",
|
|
5
5
|
"description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
|
|
6
6
|
"author": "SCAYLE Commerce Engine",
|
|
7
7
|
"license": "MIT",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"@nuxt/kit": ">=3.15.0 || >=4.2.0",
|
|
71
|
-
"@scayle/storefront-api": "^19.
|
|
71
|
+
"@scayle/storefront-api": "^19.9.0",
|
|
72
72
|
"fishery": "^2.2.2",
|
|
73
73
|
"h3": "^1.10.0",
|
|
74
74
|
"nitropack": "^2.9.7",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@opentelemetry/api": "^1.9.1",
|
|
81
81
|
"@scayle/h3-session": "0.7.2",
|
|
82
|
-
"@scayle/storefront-core": "8.
|
|
83
|
-
"@scayle/unstorage-compression-driver": "1.6.
|
|
84
|
-
"@vercel/nft": "1.11.
|
|
82
|
+
"@scayle/storefront-core": "8.64.0",
|
|
83
|
+
"@scayle/unstorage-compression-driver": "1.6.3",
|
|
84
|
+
"@vercel/nft": "1.11.12",
|
|
85
85
|
"@vueuse/core": "15.0.0",
|
|
86
86
|
"consola": "^3.4.2",
|
|
87
87
|
"core-js": "^3.49.0",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"uncrypto": "^0.1.3",
|
|
97
97
|
"unstorage": "1.17.6",
|
|
98
98
|
"utility-types": "^3.11.0",
|
|
99
|
-
"vue-router": "4.6.
|
|
99
|
+
"vue-router": "4.6.5",
|
|
100
100
|
"zod": "^4.6.7"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
@@ -104,28 +104,30 @@
|
|
|
104
104
|
"@nuxt/eslint-config": "1.16.0",
|
|
105
105
|
"@nuxt/kit": "^3.21.10",
|
|
106
106
|
"@nuxtjs/i18n": "10.5.0",
|
|
107
|
-
"@nuxt/module-builder": "1.0.
|
|
107
|
+
"@nuxt/module-builder": "1.0.4",
|
|
108
108
|
"@nuxt/schema": "^3.21.10",
|
|
109
109
|
"@nuxt/test-utils": "4.0.3",
|
|
110
|
+
"@opentelemetry/context-async-hooks": "^2.8.0",
|
|
111
|
+
"@opentelemetry/sdk-trace-base": "^2.8.0",
|
|
110
112
|
"@scayle/eslint-config-storefront": "^5.1.0",
|
|
111
113
|
"@scayle/eslint-plugin-vue-composable": "^1.1.0",
|
|
112
114
|
"@scayle/unstorage-scayle-kv-driver": "^3.0.0",
|
|
113
115
|
"@scayle/vitest-config-storefront": "1.0.0",
|
|
114
116
|
"@types/node": "^24",
|
|
115
|
-
"@vitest/coverage-v8": "5.
|
|
116
|
-
"eslint": "10.
|
|
117
|
+
"@vitest/coverage-v8": "5.1.1",
|
|
118
|
+
"eslint": "10.15.0",
|
|
117
119
|
"eslint-formatter-gitlab": "7.2.0",
|
|
118
120
|
"fishery": "2.4.0",
|
|
119
121
|
"h3": "1.15.11",
|
|
120
122
|
"happy-dom": "21.0.4",
|
|
121
123
|
"nitro-test-utils": "0.11.2",
|
|
122
|
-
"nitropack": "2.13.
|
|
124
|
+
"nitropack": "2.13.6",
|
|
123
125
|
"node-mocks-http": "1.18.1",
|
|
124
126
|
"nuxt": "^3.21.10",
|
|
125
127
|
"publint": "0.3.25",
|
|
126
128
|
"typescript": "6.0.3",
|
|
127
129
|
"unbuild": "3.6.1",
|
|
128
|
-
"vitest": "5.
|
|
130
|
+
"vitest": "5.1.1",
|
|
129
131
|
"vue-tsc": "3.3.14"
|
|
130
132
|
},
|
|
131
133
|
"scripts": {
|