@scayle/storefront-nuxt 8.25.6 → 8.26.1

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,29 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 8.26.1
4
+
5
+ ### Patch Changes
6
+
7
+ **Dependencies**
8
+
9
+ **@scayle/storefront-core v8.26.1**
10
+
11
+ - No changes in this release.
12
+
13
+ ## 8.26.0
14
+
15
+ ### Minor Changes
16
+
17
+ - **\[Utilities\]** Added `useProductPrice` composable to simplify accessing price data like total price, strike-through prices, and applied reductions.
18
+
19
+ ### Patch Changes
20
+
21
+ **Dependencies**
22
+
23
+ **@scayle/storefront-core v8.26.0**
24
+
25
+ - No changes in this release.
26
+
3
27
  ## 8.25.6
4
28
 
5
29
  ### Patch Changes
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "8.25.6",
3
+ "version": "8.26.1",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -54,7 +54,7 @@ export default {
54
54
  }`;
55
55
  }
56
56
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
57
- const PACKAGE_VERSION = "8.25.6";
57
+ const PACKAGE_VERSION = "8.26.1";
58
58
  const logger = createConsola({
59
59
  fancy: true,
60
60
  formatOptions: {
@@ -387,6 +387,7 @@ const module = defineNuxtModule({
387
387
  });
388
388
  addImportsDir(resolve("runtime/composables/storefront"));
389
389
  addImportsDir(resolve("runtime/composables/core"));
390
+ addImportsDir(resolve("runtime/composables"));
390
391
  addImportsDir(resolve("runtime/utils"));
391
392
  const keyedComposables = [
392
393
  "useBrand",
@@ -31,3 +31,4 @@ export * from './storefront/useStorefrontSearch.js';
31
31
  export * from './storefront/useUserAddresses.js';
32
32
  export * from './storefront/useVariant.js';
33
33
  export * from './storefront/useWishlist.js';
34
+ export * from './useProductPrice.js';
@@ -31,3 +31,4 @@ export * from "./storefront/useStorefrontSearch.js";
31
31
  export * from "./storefront/useUserAddresses.js";
32
32
  export * from "./storefront/useVariant.js";
33
33
  export * from "./storefront/useWishlist.js";
34
+ export * from "./useProductPrice.js";
@@ -0,0 +1,26 @@
1
+ import type { ComputedRef, MaybeRefOrGetter } from 'vue';
2
+ import type { AppliedReduction, BasketItem, CentAmount, OrderItem, Price } from '@scayle/storefront-core';
3
+ type RelativeReductions = {
4
+ value: number;
5
+ category: 'promotion' | 'sale' | 'campaign' | 'voucher';
6
+ };
7
+ export type BasketItemPrice = BasketItem['price']['total'];
8
+ export type OrderPrice = OrderItem['price'];
9
+ export interface UseProductPriceReturn {
10
+ /** Ordered applied reductions. The first applied reduction will be in the first position of the array. */
11
+ appliedReductions: ComputedRef<AppliedReduction[]>;
12
+ /** Strike through prices, calculated by adding the reduction prices to the original price. */
13
+ strikeThroughPrices: ComputedRef<CentAmount[]>;
14
+ /** Reductions representing the relative amount and their respective categories. */
15
+ relativeReductions: ComputedRef<RelativeReductions[]>;
16
+ /** Total price with tax. */
17
+ totalPrice: ComputedRef<CentAmount>;
18
+ }
19
+ /**
20
+ * Composable for extracted product price data.
21
+ *
22
+ * @param price - Product or basket item price object containing all price relevant data.
23
+ * @returns An {@link UseProductPriceReturn} object containing product price reactive data.
24
+ */
25
+ export declare function useProductPrice(price: MaybeRefOrGetter<Price | BasketItemPrice | OrderPrice>): UseProductPriceReturn;
26
+ export {};
@@ -0,0 +1,36 @@
1
+ import { computed, toValue } from "vue";
2
+ export function useProductPrice(price) {
3
+ const appliedReductions = computed(() => {
4
+ const reductions = toValue(price).appliedReductions ?? [];
5
+ return reductions.toReversed();
6
+ });
7
+ const strikeThroughPrices = computed(() => {
8
+ return appliedReductions.value.reduce(
9
+ ({ prices, currentPrice }, { amount }) => {
10
+ currentPrice += amount.absoluteWithTax;
11
+ return {
12
+ currentPrice,
13
+ prices: [...prices, currentPrice]
14
+ };
15
+ },
16
+ {
17
+ prices: [],
18
+ currentPrice: toValue(price).withTax
19
+ }
20
+ ).prices;
21
+ });
22
+ const relativeReductions = computed(
23
+ () => appliedReductions.value.map(({ amount, category }) => {
24
+ return { value: Math.round(amount.relative * 100), category };
25
+ })
26
+ );
27
+ const totalPrice = computed(() => {
28
+ return toValue(price).withTax;
29
+ });
30
+ return {
31
+ appliedReductions,
32
+ strikeThroughPrices,
33
+ relativeReductions,
34
+ totalPrice
35
+ };
36
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "8.25.6",
4
+ "version": "8.26.1",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -75,13 +75,13 @@
75
75
  "package:lint": "publint",
76
76
  "verify-packaging": "attw --pack . --profile esm-only",
77
77
  "test": "vitest run",
78
- "test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit --outputFile=./coverage/junit.xml",
78
+ "test:ci": "vitest --run --coverage --reporter=default --reporter=junit --outputFile=./coverage/junit.xml",
79
79
  "test:watch": "vitest watch"
80
80
  },
81
81
  "dependencies": {
82
82
  "@opentelemetry/api": "^1.9.0",
83
83
  "@scayle/h3-session": "0.6.1",
84
- "@scayle/storefront-core": "8.25.6",
84
+ "@scayle/storefront-core": "8.26.1",
85
85
  "@scayle/unstorage-compression-driver": "^0.2.7",
86
86
  "@vercel/nft": "0.29.3",
87
87
  "@vueuse/core": "13.2.0",
@@ -102,18 +102,18 @@
102
102
  "devDependencies": {
103
103
  "@arethetypeswrong/cli": "0.18.1",
104
104
  "@eslint/eslintrc": "3.3.1",
105
- "@nuxt/eslint": "1.4.0",
105
+ "@nuxt/eslint": "1.4.1",
106
106
  "@nuxt/kit": "3.16.2",
107
107
  "@nuxt/module-builder": "1.0.1",
108
108
  "@nuxt/schema": "3.16.2",
109
- "@nuxt/test-utils": "3.19.0",
109
+ "@nuxt/test-utils": "3.18.0",
110
110
  "@scayle/eslint-config-storefront": "4.5.2",
111
111
  "@scayle/eslint-plugin-vue-composable": "0.2.1",
112
112
  "@scayle/unstorage-scayle-kv-driver": "0.1.2",
113
- "@types/node": "22.15.18",
114
- "dprint": "0.49.1",
113
+ "@types/node": "22.15.19",
114
+ "dprint": "0.50.0",
115
115
  "eslint-formatter-gitlab": "6.0.0",
116
- "eslint": "9.26.0",
116
+ "eslint": "9.27.0",
117
117
  "fishery": "2.3.1",
118
118
  "h3": "1.15.3",
119
119
  "nitropack": "2.11.12",
@@ -124,7 +124,7 @@
124
124
  "publint": "0.2.12",
125
125
  "typescript": "5.8.3",
126
126
  "unbuild": "3.5.0",
127
- "vitest": "3.1.3",
127
+ "vitest": "3.1.4",
128
128
  "vue-tsc": "2.2.10"
129
129
  },
130
130
  "peerDependencies": {
@@ -138,6 +138,6 @@
138
138
  "vue": "^3.4.0"
139
139
  },
140
140
  "volta": {
141
- "node": "22.15.0"
141
+ "node": "22.15.1"
142
142
  }
143
143
  }