@scayle/storefront-nuxt 7.88.0 → 7.89.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 CHANGED
@@ -1,5 +1,51 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.89.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `category` test factory and expose all test factories. Moreover, `fishery` has
8
+ been added to the `peerDependencies` as it is main dependency for the test factories.
9
+ They can be used as follows:
10
+
11
+ ```ts
12
+ import { categoryFactory } from '@scayle/storefront-nuxt/test-factories'
13
+
14
+ categoryFactory.build()
15
+ ```
16
+
17
+ - Introduce `seo` and `category` utilities within the module and expose them as externals.
18
+ The category utilities consist of various functions that manage category tree-structured data.
19
+ The SEO utilities focus primarily on generating schemas and manipulating URLs for SEO purposes.
20
+
21
+ They are exposed externally and can be used as follows:
22
+
23
+ ```ts
24
+ import { sanitizeCanonicalURL } from '@scayle/storefront-nuxt'
25
+
26
+ sanitizeCanonicalURL('/en/women-2045')
27
+ ```
28
+
29
+ ### Patch Changes
30
+
31
+ - Added dependency `schema-dts@1.1.2`
32
+ - Updated dependency `ufo@^1.5.3` to `ufo@^1.5.4`
33
+ **Dependencies**
34
+
35
+ - Updated dependency to @scayle/unstorage-compression-driver@0.1.5
36
+
37
+ ## 7.88.1
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependency `@vueuse/core@11.1.0` to `@vueuse/core@11.2.0`
42
+ - Handle error when reading from or saving to the redirect cache
43
+
44
+ With this change, when the application fails to read from the redirect cache it will log the error and fallback to using the SAPI endpoint.
45
+ **Dependencies**
46
+
47
+ - Updated dependency to @scayle/storefront-core@7.66.1
48
+
3
49
  ## 7.88.0
4
50
 
5
51
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { e as AdditionalShopConfig, A as AppKeys, B as BapiConfig, i as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, j as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, d as SapiConfig, a as SessionConfig, f as ShopConfig, g as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, h as StorefrontConfig } from './shared/storefront-nuxt.80aa5060.mjs';
2
2
  export { rpcCall } from '../dist/runtime/rpc/rpcCall.js';
3
3
  export { extendPromise } from '../dist/runtime/utils/promise.js';
4
+ export * from '../dist/runtime/utils/category.js';
5
+ export * from '../dist/runtime/utils/seo.js';
4
6
  export * from '@scayle/storefront-core';
5
7
  export { LogLevel } from '@scayle/storefront-core';
6
8
  export { unwrap } from '@scayle/storefront-core/dist/utils/response';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { e as AdditionalShopConfig, A as AppKeys, B as BapiConfig, i as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, j as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, d as SapiConfig, a as SessionConfig, f as ShopConfig, g as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, h as StorefrontConfig } from './shared/storefront-nuxt.80aa5060.js';
2
2
  export { rpcCall } from '../dist/runtime/rpc/rpcCall.js';
3
3
  export { extendPromise } from '../dist/runtime/utils/promise.js';
4
+ export * from '../dist/runtime/utils/category.js';
5
+ export * from '../dist/runtime/utils/seo.js';
4
6
  export * from '@scayle/storefront-core';
5
7
  export { LogLevel } from '@scayle/storefront-core';
6
8
  export { unwrap } from '@scayle/storefront-core/dist/utils/response';
package/dist/index.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  export { rpcCall } from '../dist/runtime/rpc/rpcCall.js';
2
2
  export { extendPromise } from '../dist/runtime/utils/promise.js';
3
+ export * from '../dist/runtime/utils/category.js';
4
+ export * from '../dist/runtime/utils/seo.js';
3
5
  export * from '@scayle/storefront-core';
4
6
  export { unwrap } from '@scayle/storefront-core/dist/utils/response';
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "7.88.0",
3
+ "version": "7.89.0",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -48,7 +48,7 @@ export default {
48
48
  }`;
49
49
  }
50
50
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
51
- const PACKAGE_VERSION = "7.88.0";
51
+ const PACKAGE_VERSION = "7.89.0";
52
52
  const logger = createConsola({
53
53
  fancy: true,
54
54
  formatOptions: {
@@ -5,13 +5,17 @@ import { useRuntimeConfig } from "#imports";
5
5
  const REDIS_REDIRECT_PREFIX = ":REDIRECT";
6
6
  const REDIRECT_NOT_SET = "REDIRECT_NOT_SET";
7
7
  const REDIRECT_CACHE_TTL = 120;
8
- async function fetchRedirectWithCache(sourceUrl, storefrontAPIClient, redirectCache, log) {
9
- const cachedResult = await redirectCache.get(sourceUrl);
10
- if (cachedResult) {
11
- if (cachedResult === REDIRECT_NOT_SET) {
12
- return null;
8
+ async function fetchRedirectWithCache(sourceUrl, storefrontAPIClient, redirectCache, log, waitUntil) {
9
+ try {
10
+ const cachedResult = await redirectCache.get(sourceUrl);
11
+ if (cachedResult) {
12
+ if (cachedResult === REDIRECT_NOT_SET) {
13
+ return null;
14
+ }
15
+ return cachedResult;
13
16
  }
14
- return cachedResult;
17
+ } catch (e) {
18
+ log.error("Error fetching redirect from cache", e);
15
19
  }
16
20
  log.debug("No cached result for redirect; querying SAPI");
17
21
  let sapiResult;
@@ -27,16 +31,22 @@ async function fetchRedirectWithCache(sourceUrl, storefrontAPIClient, redirectCa
27
31
  return redirect && redirect?.source && redirect?.target && redirect.source !== redirect.target;
28
32
  };
29
33
  if (!sapiResult || !isValidRedirect(sapiResult)) {
30
- await redirectCache.set(sourceUrl, REDIRECT_NOT_SET, REDIRECT_CACHE_TTL);
34
+ waitUntil(
35
+ redirectCache.set(sourceUrl, REDIRECT_NOT_SET, REDIRECT_CACHE_TTL).catch(
36
+ (e) => log.error("Error saving redirect to cache", e)
37
+ )
38
+ );
31
39
  return null;
32
40
  }
33
- await redirectCache.set(
34
- sapiResult.source,
35
- {
36
- target: sapiResult.target,
37
- statusCode: sapiResult.statusCode
38
- },
39
- REDIRECT_CACHE_TTL
41
+ waitUntil(
42
+ redirectCache.set(
43
+ sapiResult.source,
44
+ {
45
+ target: sapiResult.target,
46
+ statusCode: sapiResult.statusCode
47
+ },
48
+ REDIRECT_CACHE_TTL
49
+ ).catch((e) => log.error("Error saving redirect to cache", e))
40
50
  );
41
51
  return sapiResult;
42
52
  }
@@ -62,8 +72,20 @@ export async function useRedirects(event) {
62
72
  queryParamWhitelist
63
73
  );
64
74
  const [relativeRedirect, absoluteRedirect] = await Promise.all([
65
- fetchRedirectWithCache(relativeSourceUrl, sapiClient, redirectCache, log),
66
- fetchRedirectWithCache(absoluteSourceUrl, sapiClient, redirectCache, log)
75
+ fetchRedirectWithCache(
76
+ relativeSourceUrl,
77
+ sapiClient,
78
+ redirectCache,
79
+ log,
80
+ event.waitUntil
81
+ ),
82
+ fetchRedirectWithCache(
83
+ absoluteSourceUrl,
84
+ sapiClient,
85
+ redirectCache,
86
+ log,
87
+ event.waitUntil
88
+ )
67
89
  ]);
68
90
  if (relativeRedirect && absoluteRedirect) {
69
91
  log.info(`There are multiple valid redirects for: ${url.toString()}`);
@@ -0,0 +1,4 @@
1
+ import type { Category } from '@scayle/storefront-core';
2
+ export declare const getCategoryAncestors: (category: Category, categories?: Category[]) => Category[];
3
+ export declare const isSaleCategory: (category: Category) => boolean;
4
+ export declare const flattenCategoryTree: (categoryTree: Category[]) => Category[];
@@ -0,0 +1,20 @@
1
+ export const getCategoryAncestors = (category, categories = []) => {
2
+ if (!category?.parent) {
3
+ return categories;
4
+ }
5
+ return getCategoryAncestors(category.parent, [category.parent, ...categories]);
6
+ };
7
+ export const isSaleCategory = (category) => {
8
+ return category.properties.some(({ name }) => name === "sale");
9
+ };
10
+ export const flattenCategoryTree = (categoryTree) => {
11
+ const flattenedCategoryTreeList = categoryTree.flatMap((categoryNode) => [
12
+ categoryNode,
13
+ ...categoryNode.children ? flattenCategoryTree(categoryNode.children) : []
14
+ ]);
15
+ return [
16
+ ...new Map(
17
+ flattenedCategoryTreeList.map((item) => [item.id, item])
18
+ ).values()
19
+ ];
20
+ };
@@ -0,0 +1,4 @@
1
+ import type { WithContext, BreadcrumbList } from 'schema-dts';
2
+ import type { BreadcrumbItem } from '@scayle/storefront-core';
3
+ export declare const sanitizeCanonicalURL: (url: string, whitelistParams?: string[]) => string;
4
+ export declare const generateCategoryBreadcrumbSchema: (breadcrumbs: BreadcrumbItem[]) => WithContext<BreadcrumbList>;
@@ -0,0 +1,28 @@
1
+ import { parseURL, stringifyParsedURL, parseQuery, stringifyQuery } from "ufo";
2
+ const CANONICAL_PARAMS_WHITELIST = ["page"];
3
+ export const sanitizeCanonicalURL = (url, whitelistParams = CANONICAL_PARAMS_WHITELIST) => {
4
+ const parsedURL = parseURL(url);
5
+ if (!parsedURL.search) {
6
+ return url;
7
+ }
8
+ const parsedQuery = parseQuery(parsedURL.search);
9
+ const purifiedQuery = Object.fromEntries(
10
+ Object.entries(parsedQuery).filter(
11
+ ([key]) => whitelistParams.includes(key)
12
+ )
13
+ );
14
+ return stringifyParsedURL({
15
+ ...parsedURL,
16
+ search: stringifyQuery(purifiedQuery)
17
+ });
18
+ };
19
+ export const generateCategoryBreadcrumbSchema = (breadcrumbs) => ({
20
+ "@context": "https://schema.org",
21
+ "@type": "BreadcrumbList",
22
+ itemListElement: breadcrumbs.map((item, index) => ({
23
+ "@type": "ListItem",
24
+ position: index + 1,
25
+ name: item.value,
26
+ item: item.to
27
+ }))
28
+ });
@@ -0,0 +1,3 @@
1
+ import type { Category } from '@scayle/storefront-core';
2
+ import { Factory } from 'fishery';
3
+ export declare const categoryFactory: Factory<Category, any, Category>;
@@ -0,0 +1,18 @@
1
+ import { Factory } from "fishery";
2
+ export const categoryFactory = Factory.define(() => {
3
+ return {
4
+ id: 1,
5
+ path: "/women",
6
+ name: "women",
7
+ slug: "test",
8
+ parentId: 2048,
9
+ rootlineIds: [2045, 2048, 2058],
10
+ childrenIds: [],
11
+ properties: [],
12
+ isHidden: false,
13
+ depth: 3,
14
+ supportedFilter: ["color", "brand", "size"],
15
+ shopLevelCustomData: {},
16
+ countryLevelCustomData: {}
17
+ };
18
+ });
@@ -0,0 +1,4 @@
1
+ export * from './category';
2
+ export * from './moduleOptions';
3
+ export * from './shopConfig';
4
+ export * from './rpcContext';
@@ -0,0 +1,4 @@
1
+ export * from "./category.mjs";
2
+ export * from "./moduleOptions.mjs";
3
+ export * from "./shopConfig.mjs";
4
+ export * from "./rpcContext.mjs";
@@ -0,0 +1,7 @@
1
+ import { Factory } from 'fishery';
2
+ import type { ModuleBaseOptions, ShopConfig } from '../../src/module';
3
+ interface ModuleOptionsFactoryParams {
4
+ shops: ShopConfig[];
5
+ }
6
+ export declare const moduleOptionsFactory: Factory<ModuleBaseOptions, ModuleOptionsFactoryParams, ModuleBaseOptions>;
7
+ export {};
@@ -0,0 +1,27 @@
1
+ import { Factory } from "fishery";
2
+ import { HashAlgorithm } from "@scayle/storefront-core";
3
+ export const moduleOptionsFactory = Factory.define(({ transientParams }) => {
4
+ return {
5
+ sapi: {
6
+ host: "sapiHost",
7
+ token: "sapiToken"
8
+ },
9
+ oauth: {
10
+ apiHost: "oauthHost",
11
+ clientId: "clientId",
12
+ clientSecret: "clientSecret"
13
+ },
14
+ appKeys: {
15
+ basketKey: "basketKey",
16
+ wishlistKey: "wishlistKey",
17
+ hashAlgorithm: HashAlgorithm.MD5
18
+ },
19
+ shopSelector: "path",
20
+ shops: (transientParams?.shops || []).reduce((acc, curr) => {
21
+ return {
22
+ [curr.shopId]: curr,
23
+ ...acc
24
+ };
25
+ }, {})
26
+ };
27
+ });
@@ -0,0 +1,7 @@
1
+ import { Factory } from 'fishery';
2
+ import { type RpcContext } from '@scayle/storefront-core';
3
+ interface RpcContextFactoryParams {
4
+ isLoggedIn: boolean;
5
+ }
6
+ export declare const rpcContextFactory: Factory<RpcContext, RpcContextFactoryParams, RpcContext>;
7
+ export {};
@@ -0,0 +1,57 @@
1
+ import { Factory } from "fishery";
2
+ import { vi } from "vitest";
3
+ import {
4
+ StorefrontAPIClient
5
+ } from "@scayle/storefront-core";
6
+ import { Log } from "../../src/runtime/log";
7
+ export const rpcContextFactory = Factory.define(({ transientParams }) => {
8
+ return {
9
+ locale: "de",
10
+ checkout: {
11
+ url: "",
12
+ token: "",
13
+ secret: "",
14
+ user: ""
15
+ },
16
+ bapiClient: new StorefrontAPIClient({ host: "", shopId: 1001 }),
17
+ sapiClient: new StorefrontAPIClient({ host: "", shopId: 1001 }),
18
+ cached: (fn, _options) => {
19
+ return async (...args) => {
20
+ return await fn(...args);
21
+ };
22
+ },
23
+ isCmsPreview: false,
24
+ shopId: 1001,
25
+ domain: "localhost",
26
+ destroySessionsForUserId: vi.fn(),
27
+ generateBasketKeyForUserId: (userId) => Promise.resolve(`basket-${userId}`),
28
+ generateWishlistKeyForUserId: (userId) => Promise.resolve(`wishlist-${userId}`),
29
+ log: new Log(),
30
+ auth: {},
31
+ runtimeConfiguration: {},
32
+ headers: new Headers(),
33
+ ...transientParams.isLoggedIn ? {
34
+ wishlistKey: "wishlistKey",
35
+ basketKey: "basketKey",
36
+ sessionId: "sessionId",
37
+ user: void 0,
38
+ accessToken: void 0,
39
+ refreshToken: void 0,
40
+ destroySession: vi.fn(),
41
+ createUserBoundSession: vi.fn(),
42
+ updateUser: vi.fn(),
43
+ updateTokens: vi.fn()
44
+ } : {
45
+ wishlistKey: void 0,
46
+ basketKey: void 0,
47
+ sessionId: void 0,
48
+ user: void 0,
49
+ accessToken: void 0,
50
+ refreshToken: void 0,
51
+ destroySession: void 0,
52
+ createUserBoundSession: void 0,
53
+ updateUser: void 0,
54
+ updateTokens: void 0
55
+ }
56
+ };
57
+ });
@@ -0,0 +1,3 @@
1
+ import { Factory } from 'fishery';
2
+ import type { ShopConfig } from '../../src/module';
3
+ export declare const shopConfigFactory: Factory<ShopConfig, any, ShopConfig>;
@@ -0,0 +1,19 @@
1
+ import { Factory } from "fishery";
2
+ export const shopConfigFactory = Factory.define(() => {
3
+ return {
4
+ shopId: 1,
5
+ domain: "localhost",
6
+ locale: "en-US",
7
+ currency: "USD",
8
+ checkout: {
9
+ host: "checkoutHost",
10
+ secret: "checkoutSecret",
11
+ token: "checkoutToken",
12
+ user: "checkoutUser"
13
+ },
14
+ auth: {
15
+ resetPasswordUrl: "resetPasswordUrl"
16
+ },
17
+ paymentProviders: []
18
+ };
19
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "7.88.0",
4
+ "version": "7.89.0",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -29,6 +29,10 @@
29
29
  "types": "./dist/runtime/composables/index.d.ts",
30
30
  "import": "./dist/runtime/composables/index.js"
31
31
  },
32
+ "./test-factories": {
33
+ "types": "./dist/test-factories/index.d.ts",
34
+ "default": "./dist/test-factories/index.mjs"
35
+ },
32
36
  ".": {
33
37
  "types": "./dist/index.d.ts",
34
38
  "default": "./dist/index.mjs"
@@ -65,9 +69,9 @@
65
69
  "@nuxt/kit": "^3.12.2",
66
70
  "@opentelemetry/api": "^1.9.0",
67
71
  "@scayle/h3-session": "^0.4.1",
68
- "@scayle/storefront-core": "7.66.0",
69
- "@scayle/unstorage-compression-driver": "^0.1.4",
70
- "@vueuse/core": "11.1.0",
72
+ "@scayle/storefront-core": "7.66.1",
73
+ "@scayle/unstorage-compression-driver": "^0.1.5",
74
+ "@vueuse/core": "11.2.0",
71
75
  "consola": "^3.2.3",
72
76
  "core-js": "^3.37.1",
73
77
  "defu": "^6.1.4",
@@ -76,11 +80,12 @@
76
80
  "knitwork": "^1.1.0",
77
81
  "nitropack": "^2.9.7",
78
82
  "ofetch": "^1.3.4",
79
- "ufo": "^1.5.3",
83
+ "ufo": "^1.5.4",
80
84
  "uncrypto": "^0.1.3",
81
85
  "unstorage": "^1.10.2",
82
86
  "vue-router": "^4.4.0",
83
- "zod": "^3.23.8"
87
+ "zod": "^3.23.8",
88
+ "schema-dts": "1.1.2"
84
89
  },
85
90
  "devDependencies": {
86
91
  "@nuxt/eslint": "0.6.1",
@@ -89,9 +94,9 @@
89
94
  "@nuxt/test-utils": "3.14.4",
90
95
  "@scayle/eslint-config-storefront": "4.3.2",
91
96
  "@scayle/eslint-plugin-vue-composable": "0.2.1",
92
- "@types/node": "22.8.4",
97
+ "@types/node": "22.8.7",
93
98
  "dprint": "0.47.5",
94
- "eslint": "9.13.0",
99
+ "eslint": "9.14.0",
95
100
  "eslint-formatter-gitlab": "5.1.0",
96
101
  "fishery": "2.2.2",
97
102
  "h3": "1.13.0",
@@ -100,13 +105,14 @@
100
105
  "nuxt": "3.13.2",
101
106
  "publint": "0.2.12",
102
107
  "vitest": "2.1.4",
103
- "vue-tsc": "2.1.8"
108
+ "vue-tsc": "2.1.10"
104
109
  },
105
110
  "peerDependencies": {
106
111
  "h3": "^1.10.0",
107
112
  "nuxt": ">=3.10.0",
108
113
  "unstorage": ">= 1.10.1",
109
- "vue": ">=3.4.0"
114
+ "vue": ">=3.4.0",
115
+ "fishery": "^2.2.2"
110
116
  },
111
117
  "resolutions": {
112
118
  "h3": "1.13.0",
@@ -115,6 +121,6 @@
115
121
  "@nuxt/schema": "3.13.2"
116
122
  },
117
123
  "volta": {
118
- "node": "22.10.0"
124
+ "node": "22.11.0"
119
125
  }
120
126
  }