@scayle/storefront-product-detail 1.6.3 → 1.8.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 +43 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +5 -1
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/composables/useSimilarProducts.d.ts +26 -0
- package/dist/runtime/composables/useSimilarProducts.js +7 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/rpc/methods/recommendations.d.ts +26 -0
- package/dist/runtime/rpc/methods/recommendations.js +37 -0
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @scayle/storefront-product-detail
|
|
2
2
|
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added the `useSimilarProducts` composable and `getSimilarProducts` RPC method to enable fetching product recommendations based on a given product ID.
|
|
8
|
+
|
|
9
|
+
The `useSimilarProducts` composable provides a convenient way to retrieve similar products with support for filtering, limiting results, and configuring product data inclusion. The underlying `getSimilarProducts` RPC method accepts a `productId` and optional configuration parameters including `with` (product data to include), `limit` (maximum number of recommendations), `where` (product search filters), `pricePromotionKey`, `campaignKey`, and `ignoreSameMasterKey` (whether to exclude products with the same master key). Results are cached for 5 minutes to improve performance.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const { data, status, error } = useSimilarProducts({
|
|
13
|
+
params: {
|
|
14
|
+
productId: 123,
|
|
15
|
+
limit: 10,
|
|
16
|
+
with: { attributes: 'all', images: { attributes: 'all' } },
|
|
17
|
+
where: {
|
|
18
|
+
attributes: [
|
|
19
|
+
{
|
|
20
|
+
type: 'attributes',
|
|
21
|
+
key: 'brand',
|
|
22
|
+
values: [456],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
ignoreSameMasterKey: true,
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 1.7.0
|
|
32
|
+
|
|
33
|
+
### Minor Changes
|
|
34
|
+
|
|
35
|
+
- Introduced support for Nuxt 4 while maintaining full backward compatibility with Nuxt 3.
|
|
36
|
+
This enables consumers to migrate to Nuxt 4 ahead of the Nuxt 3 end of support on 31 Jan 2026.
|
|
37
|
+
|
|
38
|
+
- **Version Requirements:**
|
|
39
|
+
- Nuxt 3: `v3.13.0+`
|
|
40
|
+
- Nuxt 4: `v4.2.0+`
|
|
41
|
+
|
|
42
|
+
**NOTE:** Please be aware that the SCAYLE Storefront Application itself does not yet support Nuxt 4. These package updates are a prerequisite. We recommend remaining on Nuxt 3 for your Storefront implementation until further notice.
|
|
43
|
+
|
|
44
|
+
See the [Nuxt 4 Migration Guide](https://nuxt.com/docs/4.x/getting-started/upgrade) for general upgrade details.
|
|
45
|
+
|
|
3
46
|
## 1.6.3
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addImportsDir } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const PACKAGE_NAME = "@scayle/storefront-product-detail";
|
|
4
|
-
const PACKAGE_VERSION = "1.
|
|
4
|
+
const PACKAGE_VERSION = "1.8.0";
|
|
5
5
|
const module$1 = defineNuxtModule({
|
|
6
6
|
meta: {
|
|
7
7
|
name: PACKAGE_NAME,
|
|
@@ -24,6 +24,10 @@ const module$1 = defineNuxtModule({
|
|
|
24
24
|
source: await resolvePath("./runtime/rpc/methods/products"),
|
|
25
25
|
names: ["getAllShopProductsForId"]
|
|
26
26
|
});
|
|
27
|
+
customRpcs.push({
|
|
28
|
+
source: await resolvePath("./runtime/rpc/methods/recommendations"),
|
|
29
|
+
names: ["getSimilarProducts"]
|
|
30
|
+
});
|
|
27
31
|
});
|
|
28
32
|
nuxt.options.optimization.keyedComposables.push({
|
|
29
33
|
name: "useAllShopProductsForId",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RpcMethodParameters } from '@scayle/storefront-nuxt';
|
|
2
|
+
import type { NormalizedRpcResponse, UseRpcOptions, UseRpcCacheKey, KeysOf, UseRpcReturn } from '@scayle/storefront-nuxt/composables';
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves similar products for a given product ID using the `getSimilarProducts` RPC method.
|
|
6
|
+
*
|
|
7
|
+
* This function acts as a wrapper around the `useRpc` composable,
|
|
8
|
+
* simplifying the process of fetching data. It internally calls `useRpc`
|
|
9
|
+
* with the provided parameters and options.
|
|
10
|
+
*
|
|
11
|
+
* @template DataT The type of the normalized RPC response data. Defaults to `NormalizedRpcResponse<'getSimilarProducts'>`.
|
|
12
|
+
* @template PickKeys The keys to pick from the data. Defaults to all keys of `DataT`.
|
|
13
|
+
* @template DefaultT The default value to use if data is not available. Defaults to `null`.
|
|
14
|
+
*
|
|
15
|
+
* @param params The parameters for the `getSimilarProducts` RPC method.
|
|
16
|
+
* @param params.params The parameters for the `getSimilarProducts` RPC method.
|
|
17
|
+
* @param params.options The options for the underlying `useRpc` call, controlling data handling and loading state.
|
|
18
|
+
* @param key A unique key for this RPC call. Used internally by `useRpc` for caching and state management.
|
|
19
|
+
*
|
|
20
|
+
* @returns The result of the `useRpc` call, which includes the fetched data,
|
|
21
|
+
* loading state, and any error information.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useSimilarProducts<DataT = NormalizedRpcResponse<'getSimilarProducts'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options, }?: Partial<{
|
|
24
|
+
params: MaybeRefOrGetter<RpcMethodParameters<'getSimilarProducts'>>;
|
|
25
|
+
options: UseRpcOptions<'getSimilarProducts', DataT, PickKeys, DefaultT>;
|
|
26
|
+
}>, key?: UseRpcCacheKey): UseRpcReturn<'getSimilarProducts', DataT, PickKeys, DefaultT>;
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './composables/useProductSeoData.js';
|
|
2
2
|
export * from './composables/useAllShopProductsForId.js';
|
|
3
3
|
export * from './composables/useSellableTimeFrame.js';
|
|
4
|
+
export * from './composables/useSimilarProducts.js';
|
|
4
5
|
export * from './utils/product.js';
|
|
5
6
|
export * from './utils/attribute.js';
|
|
6
7
|
export * from './utils/seo.js';
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./composables/useProductSeoData.js";
|
|
2
2
|
export * from "./composables/useAllShopProductsForId.js";
|
|
3
3
|
export * from "./composables/useSellableTimeFrame.js";
|
|
4
|
+
export * from "./composables/useSimilarProducts.js";
|
|
4
5
|
export * from "./utils/product.js";
|
|
5
6
|
export * from "./utils/attribute.js";
|
|
6
7
|
export * from "./utils/seo.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProductWith, ProductSearchQuery, RpcHandler, Product } from '@scayle/storefront-nuxt';
|
|
2
|
+
interface FetchSimilarProductsParams {
|
|
3
|
+
productId: number;
|
|
4
|
+
with?: ProductWith;
|
|
5
|
+
pricePromotionKey?: string;
|
|
6
|
+
where?: ProductSearchQuery;
|
|
7
|
+
limit?: number;
|
|
8
|
+
ignoreSameMasterKey?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves similar products for a given product ID.
|
|
12
|
+
*
|
|
13
|
+
* @param options The options for retrieving similar products.
|
|
14
|
+
* @param options.productId The ID of the product to retrieve similar products for.
|
|
15
|
+
* @param options.with The 'with' parameter for including additional data.
|
|
16
|
+
* @param options.pricePromotionKey The price promotion key.
|
|
17
|
+
* @param options.where The where clause to filter the products.
|
|
18
|
+
* @params options.where.attributes The attributes to filter the products by.
|
|
19
|
+
* @param options.limit The limit of products to retrieve.
|
|
20
|
+
* @param options.ignoreSameMasterKey Whether to ignore products with the same master key.
|
|
21
|
+
* @param context The RPC context.
|
|
22
|
+
*
|
|
23
|
+
* @returns A Promise that resolves with an array of products.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getSimilarProducts: RpcHandler<FetchSimilarProductsParams, Product[]>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ErrorResponse,
|
|
3
|
+
FetchError,
|
|
4
|
+
MINUTE,
|
|
5
|
+
MIN_WITH_PARAMS_PRODUCT
|
|
6
|
+
} from "@scayle/storefront-nuxt";
|
|
7
|
+
export const getSimilarProducts = async function getProductsByReferenceKeys(options, context) {
|
|
8
|
+
const { sapiClient, cached, withParams } = context;
|
|
9
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
10
|
+
const { productId, with: withParameter, ...rest } = options;
|
|
11
|
+
const fetch = async (productId2, params) => {
|
|
12
|
+
try {
|
|
13
|
+
return sapiClient.recommendations.getSimilarProducts(productId2, params);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
if (e instanceof FetchError) {
|
|
16
|
+
const response = e.response;
|
|
17
|
+
return new ErrorResponse(
|
|
18
|
+
response.status,
|
|
19
|
+
response.statusText,
|
|
20
|
+
"Failed to fetch similar products"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return await cached(
|
|
27
|
+
fetch,
|
|
28
|
+
{
|
|
29
|
+
cacheKeyPrefix: "getSimilarProducts-products",
|
|
30
|
+
ttl: 5 * MINUTE
|
|
31
|
+
}
|
|
32
|
+
)(productId, {
|
|
33
|
+
with: withParameter ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
34
|
+
campaignKey,
|
|
35
|
+
...rest
|
|
36
|
+
});
|
|
37
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-product-detail",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Collection of essential composables and utilities to work with product detail",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"#storefront-product-detail": "./dist/runtime/index.js"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@nuxt/kit": ">=3.13.0",
|
|
31
|
+
"@nuxt/kit": ">=3.13.0 || >=4.2.0",
|
|
32
32
|
"@scayle/storefront-nuxt": "^8.0.0",
|
|
33
33
|
"@vueuse/core": "^12.8.2 || ^13.0.0 || ^14.0.0",
|
|
34
34
|
"schema-dts": "^1.1.5",
|
|
@@ -40,26 +40,26 @@
|
|
|
40
40
|
"@nuxt/kit": "3.20.0",
|
|
41
41
|
"@nuxt/module-builder": "1.0.2",
|
|
42
42
|
"@nuxt/schema": "3.20.0",
|
|
43
|
-
"@nuxt/test-utils": "3.
|
|
44
|
-
"@types/node": "22.19.
|
|
45
|
-
"@vitest/coverage-v8": "4.0.
|
|
43
|
+
"@nuxt/test-utils": "3.23.0",
|
|
44
|
+
"@types/node": "22.19.7",
|
|
45
|
+
"@vitest/coverage-v8": "4.0.17",
|
|
46
46
|
"@vueuse/core": "14.1.0",
|
|
47
|
-
"dprint": "0.
|
|
47
|
+
"dprint": "0.51.1",
|
|
48
48
|
"eslint-formatter-gitlab": "7.0.1",
|
|
49
49
|
"eslint": "9.39.2",
|
|
50
|
-
"happy-dom": "20.
|
|
50
|
+
"happy-dom": "20.3.4",
|
|
51
51
|
"nuxt": "3.20.0",
|
|
52
52
|
"publint": "0.3.16",
|
|
53
53
|
"schema-dts": "1.1.5",
|
|
54
54
|
"typescript": "5.9.3",
|
|
55
55
|
"unbuild": "3.6.1",
|
|
56
|
-
"vitest": "4.0.
|
|
56
|
+
"vitest": "4.0.17",
|
|
57
57
|
"vue-router": "4.6.4",
|
|
58
|
-
"vue-tsc": "3.
|
|
58
|
+
"vue-tsc": "3.2.2",
|
|
59
59
|
"vue": "3.5.26",
|
|
60
|
-
"@scayle/
|
|
61
|
-
"@scayle/storefront
|
|
62
|
-
"@scayle/
|
|
60
|
+
"@scayle/vitest-config-storefront": "1.0.0",
|
|
61
|
+
"@scayle/eslint-config-storefront": "4.7.21",
|
|
62
|
+
"@scayle/storefront-nuxt": "8.59.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "nuxt-module-build build",
|