tripstorekrabi-shared 1.26.3 → 1.26.5

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 +1 -1
  2. package/product.js +61 -33
  3. package/utils.js +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.26.3",
3
+ "version": "1.26.5",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
package/product.js CHANGED
@@ -2,6 +2,33 @@ import { calculateProductSellingPrice, countMinPeople } from './price.js';
2
2
 
3
3
  const MATCH_HTML_REGEXP = /(<([^>]+)>)/gi;
4
4
 
5
+ export const GUIDANCE_TYPES = [
6
+ 'Live Tour Guide',
7
+ 'Instructor',
8
+ 'Boat Crew / Staff',
9
+ 'Driver Only',
10
+ 'Audio Guide',
11
+ 'No Guide / Self-Guided'
12
+ ];
13
+
14
+ export const UNGUIDED_TYPES = ['No Guide / Self-Guided', 'Driver Only'];
15
+
16
+ export const DEFAULT_GUIDE_LANGUAGES = new Set(['english', 'thai']);
17
+
18
+ export const GUIDE_LANGUAGES = [
19
+ 'English',
20
+ 'Thai',
21
+ 'Chinese',
22
+ 'Russian',
23
+ 'German',
24
+ 'French',
25
+ 'Spanish',
26
+ 'Italian',
27
+ 'Arabic',
28
+ 'Korean',
29
+ 'Japanese'
30
+ ];
31
+
5
32
  function toIsoDateString(val) {
6
33
  if (!val) return null;
7
34
  if (typeof val.toDate === 'function') return val.toDate().toISOString();
@@ -40,8 +67,12 @@ export function buildIndex(id, product) {
40
67
 
41
68
  const safeIntPrice = isNaN(rawPrice) || !isFinite(rawPrice) ? 0 : Math.round(rawPrice);
42
69
 
70
+ const type = String(product.type || '').trim().toLowerCase() || (product.from ? 'transfer' : 'activity');
71
+ const isTransfer = type === 'transfer';
72
+
43
73
  let document = {
44
74
  id,
75
+ type,
45
76
  title: String(product.title || '').trim(),
46
77
  subtitle: String(product.subtitle || '').trim(),
47
78
  summary: String(product.summary || '').trim(),
@@ -65,35 +96,6 @@ export function buildIndex(id, product) {
65
96
  document.shortName = String(product.shortName).trim();
66
97
  }
67
98
 
68
- const isTransfer = Boolean(product.from && product.to);
69
-
70
- if (isTransfer) {
71
- // For transfers, derive destinations directly from `from` and `to`
72
- const transferDestinations = Array.from(
73
- new Set([product.from, product.to].map((d) => String(d || '').trim()).filter(Boolean))
74
- );
75
- if (transferDestinations.length > 0) {
76
- document.destinations = transferDestinations;
77
- }
78
- } else {
79
- // 1. Assign new `places` array directly
80
- if (Array.isArray(product.places) && product.places.length > 0) {
81
- document.places = product.places;
82
- }
83
-
84
- // 2. Keep legacy `destinations` array populated during transition
85
- const rawDestinations = Array.isArray(product.destinations) ? product.destinations : [];
86
-
87
- const cleanedDestinations = Array.from(
88
- new Set(rawDestinations.map((d) => String(d || '').trim()).filter(Boolean))
89
- );
90
-
91
- if (cleanedDestinations.length > 0) {
92
- document.destinations = cleanedDestinations;
93
- }
94
- }
95
-
96
- // Populate keywords array
97
99
  const validKeywords = Array.isArray(product.keywords)
98
100
  ? product.keywords.map((k) => String(k || '').trim()).filter(Boolean)
99
101
  : [];
@@ -101,8 +103,11 @@ export function buildIndex(id, product) {
101
103
  document.keywords = Array.from(new Set(validKeywords));
102
104
 
103
105
  if (isTransfer) {
104
- document.from = String(product.from).trim();
105
- document.to = String(product.to).trim();
106
+ const from = String(product.from || '').trim();
107
+ const to = String(product.to || '').trim();
108
+
109
+ if (from) document.from = from;
110
+ if (to) document.to = to;
106
111
 
107
112
  if (Array.isArray(product.waypoints) && product.waypoints.length > 0) {
108
113
  const startWp = product.waypoints[0]?.latLng;
@@ -115,9 +120,32 @@ export function buildIndex(id, product) {
115
120
  document.end = [endWp.lat, endWp.lng];
116
121
  }
117
122
  }
123
+ } else if (Array.isArray(product.places) && product.places.length > 0) {
124
+ document.places = product.places;
118
125
  }
119
126
 
120
- document.type = product.from ? 'transfer' : 'activity';
121
-
122
127
  return document;
128
+ }
129
+
130
+ export function requiresGuideLanguageSelection(product) {
131
+ const guidance = product?.guidance;
132
+ const type = typeof guidance?.type === 'string' ? guidance.type.trim() : '';
133
+
134
+ if (!type || UNGUIDED_TYPES.includes(type)) {
135
+ return false;
136
+ }
137
+
138
+ if (!Array.isArray(guidance.languages)) {
139
+ return false;
140
+ }
141
+
142
+ const validLanguages = guidance.languages
143
+ .map((lang) => (typeof lang === 'string' ? lang.trim() : ''))
144
+ .filter(Boolean);
145
+
146
+ if (validLanguages.length <= 1) {
147
+ return false;
148
+ }
149
+
150
+ return validLanguages.some((lang) => !DEFAULT_GUIDE_LANGUAGES.has(lang.toLowerCase()));
123
151
  }
package/utils.js CHANGED
@@ -208,8 +208,6 @@ export function isHotelPickup(value) {
208
208
  );
209
209
  }
210
210
 
211
-
212
-
213
211
  export function isHotelDropOff(value) {
214
212
  value = value.toLowerCase();
215
213
  return (