@scayle/storefront-product-detail 1.5.6 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,76 @@
1
1
  # @scayle/storefront-product-detail
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added utility functions `sellableTimeframeStartsInFuture`, `sellableTimeframeEndsInPast`, and `isInSellableTimeframe` for checking whether a product's sellable timeframe is currently active. Also introduced the `useSellableTimeFrame()` composable for convenient access to these checks within your components.
8
+
9
+ **Usage Examples:**
10
+
11
+ **`sellableTimeframeStartsInFuture`:**
12
+
13
+ ```ts
14
+ import { sellableTimeframeStartsInFuture } from '@scayle/storefront-product-detail'
15
+
16
+ // Example timeframe
17
+ const timeframe = {
18
+ sellableFrom: '2099-01-01T00:00:00Z',
19
+ sellableTo: '2100-01-01T00:00:00Z',
20
+ }
21
+
22
+ const inFuture = sellableTimeframeStartsInFuture(timeframe)
23
+ console.log(inFuture) // true if current date is before 2099-01-01
24
+ ```
25
+
26
+ **`sellableTimeframeEndsInPast`:**
27
+
28
+ ```ts
29
+ import { sellableTimeframeEndsInPast } from '@scayle/storefront-product-detail'
30
+
31
+ const timeframe = {
32
+ sellableFrom: '2018-01-01T00:00:00Z',
33
+ sellableTo: '2020-01-01T00:00:00Z',
34
+ }
35
+
36
+ const ended = sellableTimeframeEndsInPast(timeframe)
37
+ console.log(ended) // true if current date is after 2020-01-01
38
+ ```
39
+
40
+ **`isInSellableTimeframe`:**
41
+
42
+ ```ts
43
+ import { isInSellableTimeframe } from '@scayle/storefront-product-detail'
44
+
45
+ const timeframe = {
46
+ sellableFrom: '2023-01-01T00:00:00Z',
47
+ sellableTo: '2025-01-01T00:00:00Z',
48
+ }
49
+
50
+ const active = isInSellableTimeframe(timeframe)
51
+ console.log(active) // true if current date is between 2023-01-01 and 2025-01-01
52
+ ```
53
+
54
+ **`useSellableTimeFrame`:**
55
+
56
+ ```ts
57
+ import { useSellableTimeFrame } from '@scayle/storefront-product-detail'
58
+
59
+ const timeframe = {
60
+ sellableFrom: '2023-01-01T00:00:00Z',
61
+ sellableTo: '2025-01-01T00:00:00Z',
62
+ }
63
+ const {
64
+ isInSellableTimeframe,
65
+ sellableTimeframeStartsInFuture,
66
+ sellableTimeframeEndsInPast,
67
+ } = useSellableTimeFrame(timeframe)
68
+
69
+ console.log(isInSellableTimeframe) // true if the timeframe is active
70
+ console.log(sellableTimeframeStartsInFuture) // true if the time frame starts in the future
71
+ console.log(sellableTimeframeEndsInPast) // true if the timeframe ended in the past
72
+ ```
73
+
3
74
  ## 1.5.6
4
75
 
5
76
  ### Patch Changes
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-product-detail",
3
3
  "configKey": "product-detail",
4
- "version": "1.5.6",
4
+ "version": "1.6.0",
5
5
  "compatibility": {
6
6
  "bridge": false,
7
7
  "nuxt": ">=3.13"
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.5.6";
4
+ const PACKAGE_VERSION = "1.6.0";
5
5
  const module$1 = defineNuxtModule({
6
6
  meta: {
7
7
  name: PACKAGE_NAME,
@@ -0,0 +1,25 @@
1
+ import type { Product } from '@scayle/storefront-nuxt';
2
+ /**
3
+ * Helper composable to check a sellable timeframes current status.
4
+ *
5
+ * @param timeFrame The sellable timeframe to check
6
+ * @param now (optional) The current date and time used to check if the timeframe is active
7
+ * @returns An object containing different computed values indicating the current status of the sellable timeframe
8
+ */
9
+ export declare function useSellableTimeFrame(timeFrame: Product['sellableTimeframe'], now?: Date): {
10
+ /**
11
+ * Whether the sellable timeframe is currently active.
12
+ * Returns true if the sellable timeframe is currently active, false otherwise.
13
+ */
14
+ isInSellableTimeframe: import("vue").ComputedRef<boolean>;
15
+ /**
16
+ * Whether the sellable timeframe starts in the future.
17
+ * Returns true if the sellable timeframe starts in the future, false otherwise.
18
+ */
19
+ sellableTimeframeStartsInFuture: import("vue").ComputedRef<boolean>;
20
+ /**
21
+ * Whether the sellable timeframe ends in the past.
22
+ * Returns true if the sellable timeframe ends in the past, false otherwise.
23
+ */
24
+ sellableTimeframeEndsInPast: import("vue").ComputedRef<boolean>;
25
+ };
@@ -0,0 +1,31 @@
1
+ import { computed } from "vue";
2
+ import {
3
+ isInSellableTimeframe,
4
+ sellableTimeframeEndsInPast,
5
+ sellableTimeframeStartsInFuture
6
+ } from "../utils/product.js";
7
+ export function useSellableTimeFrame(timeFrame, now = /* @__PURE__ */ new Date()) {
8
+ return {
9
+ /**
10
+ * Whether the sellable timeframe is currently active.
11
+ * Returns true if the sellable timeframe is currently active, false otherwise.
12
+ */
13
+ isInSellableTimeframe: computed(
14
+ () => isInSellableTimeframe(timeFrame, now)
15
+ ),
16
+ /**
17
+ * Whether the sellable timeframe starts in the future.
18
+ * Returns true if the sellable timeframe starts in the future, false otherwise.
19
+ */
20
+ sellableTimeframeStartsInFuture: computed(
21
+ () => sellableTimeframeStartsInFuture(timeFrame, now)
22
+ ),
23
+ /**
24
+ * Whether the sellable timeframe ends in the past.
25
+ * Returns true if the sellable timeframe ends in the past, false otherwise.
26
+ */
27
+ sellableTimeframeEndsInPast: computed(
28
+ () => sellableTimeframeEndsInPast(timeFrame, now)
29
+ )
30
+ };
31
+ }
@@ -1,4 +1,4 @@
1
- import type { AdvancedAttribute } from '@scayle/storefront-nuxt';
1
+ import type { AdvancedAttribute, Product } from '@scayle/storefront-nuxt';
2
2
  /**
3
3
  * Extracts and returns an array of product IDs from an advanced attribute.
4
4
  *
@@ -67,3 +67,31 @@ import type { AdvancedAttribute } from '@scayle/storefront-nuxt';
67
67
  * ```
68
68
  */
69
69
  export declare const getCombineWithProductIds: (attribute?: AdvancedAttribute) => number[];
70
+ /**
71
+ * Checks if a timeframe is currently active.
72
+ * A timeframe is considered active if the current time is between the start and end date.
73
+ * If the timeframe is not set, it is considered active.
74
+ *
75
+ * @param timeframe The timeframe to check
76
+ * @param now (optional) The current date and time used to check if the timeframe is active
77
+ * @returns True if the timeframe is active, false otherwise
78
+ */
79
+ export declare function isInSellableTimeframe(timeframe: Product['sellableTimeframe'], now?: Date): boolean;
80
+ /**
81
+ * Checks if a sellable timeframe starts in the future.
82
+ * If the timeframe is not set, the timeframe is considered to be currently started.
83
+ *
84
+ * @param timeframe The timeframe to check
85
+ * @param now (optional) The current date and time used to check if the timeframe is active
86
+ * @returns True if the timeframe starts in the future, false otherwise
87
+ */
88
+ export declare function sellableTimeframeStartsInFuture(timeframe: Product['sellableTimeframe'], now?: Date): boolean;
89
+ /**
90
+ * Checks if a sellable timeframe ends in the past.
91
+ * If the timeframe or the sellableTo date is not set, the timeframe is considered to be currently active.
92
+ *
93
+ * @param timeframe The timeframe to check
94
+ * @param now (optional) The current date and time used to check if the timeframe is active
95
+ * @returns True if the timeframe ends in the past, false otherwise
96
+ */
97
+ export declare function sellableTimeframeEndsInPast(timeframe: Product['sellableTimeframe'], now?: Date): boolean;
@@ -5,3 +5,23 @@ export const getCombineWithProductIds = (attribute) => {
5
5
  }
6
6
  return getFlattenedAdvancedAttribute(attribute.values)?.map((item) => Number.parseInt(item.value))?.filter((value) => !Number.isNaN(value)) || [];
7
7
  };
8
+ export function isInSellableTimeframe(timeframe, now = /* @__PURE__ */ new Date()) {
9
+ if (!timeframe || !timeframe.sellableFrom && !timeframe.sellableTo) {
10
+ return true;
11
+ }
12
+ return !sellableTimeframeStartsInFuture(timeframe, now) && !sellableTimeframeEndsInPast(timeframe, now);
13
+ }
14
+ export function sellableTimeframeStartsInFuture(timeframe, now = /* @__PURE__ */ new Date()) {
15
+ if (!timeframe || !timeframe.sellableFrom) {
16
+ return false;
17
+ }
18
+ const sellableFrom = new Date(timeframe.sellableFrom);
19
+ return sellableFrom > now;
20
+ }
21
+ export function sellableTimeframeEndsInPast(timeframe, now = /* @__PURE__ */ new Date()) {
22
+ if (!timeframe || !timeframe.sellableTo) {
23
+ return false;
24
+ }
25
+ const sellableTo = new Date(timeframe.sellableTo);
26
+ return sellableTo < now;
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-product-detail",
3
- "version": "1.5.6",
3
+ "version": "1.6.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",
@@ -40,25 +40,25 @@
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.20.1",
44
- "@types/node": "22.19.1",
45
- "@vitest/coverage-v8": "4.0.14",
43
+ "@nuxt/test-utils": "3.21.0",
44
+ "@types/node": "22.19.2",
45
+ "@vitest/coverage-v8": "4.0.15",
46
46
  "@vueuse/core": "13.9.0",
47
47
  "dprint": "0.50.2",
48
- "eslint-formatter-gitlab": "6.0.1",
48
+ "eslint-formatter-gitlab": "7.0.1",
49
49
  "eslint": "9.39.1",
50
- "happy-dom": "20.0.10",
50
+ "happy-dom": "20.0.11",
51
51
  "nuxt": "3.20.0",
52
- "publint": "0.3.15",
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.14",
56
+ "vitest": "4.0.15",
57
57
  "vue-router": "4.6.3",
58
- "vue-tsc": "3.1.5",
58
+ "vue-tsc": "3.1.8",
59
59
  "vue": "3.5.25",
60
- "@scayle/eslint-config-storefront": "4.7.14",
61
- "@scayle/storefront-nuxt": "8.53.3",
60
+ "@scayle/eslint-config-storefront": "4.7.17",
61
+ "@scayle/storefront-nuxt": "8.56.0",
62
62
  "@scayle/vitest-config-storefront": "1.0.0"
63
63
  },
64
64
  "scripts": {