tripstorekrabi-shared 1.24.1 → 1.24.3

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.
Files changed (3) hide show
  1. package/package.json +4 -4
  2. package/price.js +2 -3
  3. package/product.js +13 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.24.1",
3
+ "version": "1.24.3",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
@@ -17,9 +17,9 @@
17
17
  "./telegram": "./telegram.js"
18
18
  },
19
19
  "dependencies": {
20
- "dayjs": "^1.11.20",
21
- "libphonenumber-js": "^1.12.41",
22
- "nanoid": "^5.1.7"
20
+ "dayjs": "^1.11.21",
21
+ "libphonenumber-js": "^1.13.5",
22
+ "nanoid": "^5.1.11"
23
23
  },
24
24
  "scripts": {
25
25
  "deploy": "npm publish"
package/price.js CHANGED
@@ -121,11 +121,10 @@ export function calculateInflatedSellingPrice(price, config, forceInflation = fa
121
121
  }
122
122
 
123
123
  function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE }) {
124
- const activeRevision = getActiveRevision(booking.date, pricing);
124
+ const activeRevision = getActiveRevision(booking.date, pricing) || pricing;
125
125
 
126
126
  if (!activeRevision) {
127
- console.warn("Pricing fail-safe triggered: No active pricing revision found.");
128
- return 0;
127
+ throw new Error(`Pricing fail-safe triggered: No active or standard pricing found for booking date ${booking.date}.`);
129
128
  }
130
129
 
131
130
  let activeVolumes = activeRevision.volumes || [];
package/product.js CHANGED
@@ -1,8 +1,18 @@
1
- import { calculateProductSellingPrice, countMinPeople } from "./price.js";
1
+ import dayjs from 'dayjs';
2
+ import { calculateProductSellingPrice, countMinPeople, getActiveRevision } from "./price.js";
2
3
 
3
4
  const MATCH_HTML_REGEXP = /(<([^>]+)>)/ig;
4
5
 
5
6
  export function buildIndex(id, product) {
7
+ const lightweightRevisions = (product.pricing?.revisions || []).map(rev => ({
8
+ id: rev.id,
9
+ startDate: rev.startDate.toDate(),
10
+ promotion: rev.promotion ? {
11
+ startDate: rev.promotion.startDate.toDate(),
12
+ endDate: rev.promotion.endDate.toDate()
13
+ } : null
14
+ }));
15
+
6
16
  let document = {
7
17
  id,
8
18
  title: product.title,
@@ -15,7 +25,8 @@ export function buildIndex(id, product) {
15
25
  price: calculateProductSellingPrice({ adults: countMinPeople(product.pricing), children: 0, infants: 0 }, product.pricing) / countMinPeople(product.pricing),
16
26
  priceType: product.pricing.type,
17
27
  availability: product.availability,
18
- live: product.live
28
+ live: product.live,
29
+ revisions: JSON.stringify(lightweightRevisions)
19
30
  };
20
31
 
21
32
  if (product.shortName) {