@meetelise/chat 1.63.1 → 1.64.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.
@@ -0,0 +1,43 @@
1
+ import type { LeadSourceSubmittedListItem } from "../LeadSourceMultitouchClient";
2
+ import type { BookingAttribution, BookingContact, BookingRequest, PlanRequest, PlanResponse, TourTypeId } from "./tourItineraryApi";
3
+ /** What the prospect has chosen on the schedule step. */
4
+ export interface ItineraryChoice {
5
+ /** New stops, in the prospect's order. */
6
+ buildingIds: number[];
7
+ tourType: TourTypeId;
8
+ date: string;
9
+ /** "HH:mm" picked for the first new stop, or null for the earliest. */
10
+ firstStart: string | null;
11
+ /** ISO starts picked for later new stops, by building id. */
12
+ laterStarts: Record<number, string>;
13
+ /** Booked events this itinerary extends, in order; the last one is fixed first. */
14
+ existingEventIds: number[];
15
+ }
16
+ export declare const buildPlanRequest: (choice: ItineraryChoice) => PlanRequest;
17
+ /**
18
+ * Lead-source attribution, built the way tour-scheduler.ts builds the same
19
+ * fields for /v2/scheduleMe.
20
+ */
21
+ export declare const buildAttribution: ({ orgSlug, selectedLeadSource, currentLeadSource, touchpoints, search, referrer, googleReferral, }: {
22
+ orgSlug: string;
23
+ /** Picked in the "How did you hear about us?" dropdown. */
24
+ selectedLeadSource: string | null;
25
+ /** Derived from the referrer and query params. */
26
+ currentLeadSource: string;
27
+ touchpoints: LeadSourceSubmittedListItem[];
28
+ search: string;
29
+ referrer: string;
30
+ googleReferral: {
31
+ rwgToken: string;
32
+ buildingId: number;
33
+ environment: string;
34
+ } | null;
35
+ }) => BookingAttribution;
36
+ export declare const buildBookingRequest: ({ choice, plan, contact, attribution, conversationTrackingId, cancelExistingTours, }: {
37
+ choice: ItineraryChoice;
38
+ plan: PlanResponse;
39
+ contact: BookingContact;
40
+ attribution: BookingAttribution;
41
+ conversationTrackingId: string | null;
42
+ cancelExistingTours: boolean;
43
+ }) => BookingRequest;
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Client for the widget tour itinerary endpoints (communities, plan, book).
3
+ * The schemas follow the contract shared with the backend; the server owns
4
+ * ranking, caps, chaining and every prospect-facing reason, and the widget only
5
+ * renders what comes back.
6
+ */
7
+ export declare type TourTypeId = "escorted-tour" | "self-guided-tour" | "live-virtual-tour";
8
+ export interface CommunityAddress {
9
+ line1: string | null;
10
+ city: string | null;
11
+ state: string | null;
12
+ }
13
+ export interface Community {
14
+ building_id: number;
15
+ name: string;
16
+ address: CommunityAddress | null;
17
+ timezone: string | null;
18
+ distance_mi: number | null;
19
+ /** In US dollars. */
20
+ price_from: {
21
+ bedrooms: number;
22
+ amount: number;
23
+ } | null;
24
+ next_available: {
25
+ date: string;
26
+ time: string;
27
+ } | null;
28
+ best_match: boolean;
29
+ image_url: string | null;
30
+ tourable: boolean;
31
+ /** The text to show when the community can't be toured. */
32
+ unavailable_reason: string | null;
33
+ }
34
+ /**
35
+ * Most stops in one itinerary, counting ones already booked. The server's cap,
36
+ * mirrored here for the picker; booking enforces the real one.
37
+ */
38
+ export declare const MAX_ITINERARY_STOPS = 3;
39
+ /** The top communities after filtering; there's no paging. */
40
+ export interface CommunitiesResponse {
41
+ anchor: {
42
+ building_id: number;
43
+ name: string;
44
+ is_general_building: boolean;
45
+ };
46
+ communities: Community[];
47
+ }
48
+ export interface CommunityFilters {
49
+ bedrooms: number[];
50
+ moveIn: string | null;
51
+ maxBudget: number | null;
52
+ }
53
+ /** Adding a stop after a booking: the widget sends what it knows of that booking. */
54
+ export interface ExtendQuery {
55
+ /** ISO 8601 with offset: when the last booked stop ends. */
56
+ availableAfter: string;
57
+ tourType: TourTypeId;
58
+ /** The last booked stop's building, which distances are measured from. */
59
+ nearBuildingId: number;
60
+ /** Every building already in the itinerary. */
61
+ excludeBuildingIds: number[];
62
+ }
63
+ export interface CommunityQuery extends CommunityFilters {
64
+ extend?: ExtendQuery;
65
+ }
66
+ export interface PlanRequest {
67
+ building_ids: number[];
68
+ tour_type: TourTypeId;
69
+ date: string;
70
+ start_time: string | null;
71
+ stop_starts: Record<string, string> | null;
72
+ fixed_first: {
73
+ calendar_event_id: number;
74
+ } | null;
75
+ }
76
+ export interface PlanStop {
77
+ building_id: number;
78
+ start: string;
79
+ end: string;
80
+ timezone: string;
81
+ distance_from_prev_mi: number | null;
82
+ alternatives: string[];
83
+ fixed: boolean;
84
+ }
85
+ export interface PlanResponse {
86
+ bookable_dates: string[];
87
+ tour_types: TourTypeId[];
88
+ stops: PlanStop[];
89
+ changed: {
90
+ building_id: number;
91
+ reason: string;
92
+ text: string;
93
+ }[];
94
+ unchainable: {
95
+ building_id: number;
96
+ reason: string;
97
+ text: string;
98
+ }[];
99
+ }
100
+ export declare type BookingStopRequest = {
101
+ existing_calendar_event_id: number;
102
+ } | {
103
+ building_id: number;
104
+ start: string;
105
+ };
106
+ export interface BookingContact {
107
+ first_name: string;
108
+ last_name: string;
109
+ email: string;
110
+ phone_e164: string;
111
+ bedrooms: number[];
112
+ move_in: string | null;
113
+ notes: string;
114
+ }
115
+ /** The attribution /v2/scheduleMe takes today, under the same names. */
116
+ export interface BookingAttribution {
117
+ lead_sources: string[];
118
+ lead_sources_with_timestamps: Record<string, unknown>[];
119
+ query_params: Record<string, string>;
120
+ referrer: string;
121
+ google_rwg_token: string | null;
122
+ google_referral_building_id: number | null;
123
+ google_environment: string | null;
124
+ }
125
+ export interface BookingRequest {
126
+ tour_type: TourTypeId;
127
+ stops: BookingStopRequest[];
128
+ contact: BookingContact;
129
+ lead_sources: BookingAttribution;
130
+ conversation_tracking_id: string | null;
131
+ cancel_existing_tours: boolean;
132
+ }
133
+ export declare type BookedStopStatus = "booked" | "existing" | "failed";
134
+ export interface BookedStop {
135
+ building_id: number;
136
+ calendar_event_id: number | null;
137
+ start: string | null;
138
+ end: string | null;
139
+ status: BookedStopStatus;
140
+ error: {
141
+ code: string;
142
+ message: string;
143
+ } | null;
144
+ }
145
+ export interface BookingResponse {
146
+ itinerary_id: string | null;
147
+ stops: BookedStop[];
148
+ }
149
+ export declare type TourApiErrorCode = "SLOT_TAKEN" | "EXISTING_TOUR" | "MAX_STOPS" | "NOT_IN_GROUP" | "INVALID_STOPS" | "RATE_LIMITED";
150
+ export declare class TourApiError extends Error {
151
+ readonly status: number;
152
+ readonly code: TourApiErrorCode | null;
153
+ constructor(status: number, code: TourApiErrorCode | null, message: string);
154
+ }
155
+ export interface TourItineraryApi {
156
+ getCommunities(query: CommunityQuery): Promise<CommunitiesResponse>;
157
+ plan(request: PlanRequest): Promise<PlanResponse>;
158
+ book(request: BookingRequest, idempotencyKey: string): Promise<BookingResponse>;
159
+ }
160
+ /** Query string for GET tour-communities; empty filters are left out. */
161
+ export declare const communitiesSearchParams: (query: CommunityQuery) => URLSearchParams;
162
+ export declare const createTourItineraryApi: ({ orgSlug, buildingSlug, getSessionToken, host, }: {
163
+ orgSlug: string;
164
+ buildingSlug: string;
165
+ getSessionToken: () => string | null;
166
+ host?: string | undefined;
167
+ }) => TourItineraryApi;
@@ -0,0 +1,26 @@
1
+ import type { TourTypeId } from "./tourItineraryApi";
2
+ /** "2026-10-15T10:45:00-05:00" -> "2026-10-15" */
3
+ export declare const isoDate: (iso: string) => string;
4
+ /** "2026-10-15T10:45:00-05:00" -> "10:45" */
5
+ export declare const isoHourMinute: (iso: string) => string;
6
+ /** "14:30" -> "2:30pm" */
7
+ export declare const formatHourMinute: (hourMinute: string) => string;
8
+ /** ISO start -> "10:45am" */
9
+ export declare const formatTime: (iso: string) => string;
10
+ /** "10:00–10:30am", or "11:30am–12:00pm" across noon. */
11
+ export declare const formatTimeRange: (startIso: string, endIso: string) => string;
12
+ /** A calendar date, read as that date wherever the visitor is. */
13
+ export declare const dateFromIsoDate: (date: string) => Date;
14
+ /** "2026-10-15" -> "Thu, Oct 15" */
15
+ export declare const formatShortDate: (date: string) => string;
16
+ /** "2026-10-15" -> "Oct 15" */
17
+ export declare const formatMonthDay: (date: string) => string;
18
+ /** "2026-10-15" -> "Thu, Oct 15, 2026" */
19
+ export declare const formatLongDate: (date: string) => string;
20
+ /** A Date as the "YYYY-MM-DD" the API uses. */
21
+ export declare const toIsoDate: (date: Date) => string;
22
+ export declare const TOUR_TYPE_COPY: Record<TourTypeId, {
23
+ label: string;
24
+ subtitle: string;
25
+ }>;
26
+ export declare const TOUR_TYPE_ORDER: TourTypeId[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetelise/chat",
3
- "version": "1.63.1",
3
+ "version": "1.64.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/MeetElise/chat-ui#readme",
@@ -0,0 +1,123 @@
1
+ import { getDefaultLeadSourceAttribution } from "../LeadSourceClient";
2
+ import type { LeadSourceSubmittedListItem } from "../LeadSourceMultitouchClient";
3
+ import { snakify } from "../../utils";
4
+ import type {
5
+ BookingAttribution,
6
+ BookingContact,
7
+ BookingRequest,
8
+ PlanRequest,
9
+ PlanResponse,
10
+ TourTypeId,
11
+ } from "./tourItineraryApi";
12
+
13
+ /** What the prospect has chosen on the schedule step. */
14
+ export interface ItineraryChoice {
15
+ /** New stops, in the prospect's order. */
16
+ buildingIds: number[];
17
+ tourType: TourTypeId;
18
+ date: string;
19
+ /** "HH:mm" picked for the first new stop, or null for the earliest. */
20
+ firstStart: string | null;
21
+ /** ISO starts picked for later new stops, by building id. */
22
+ laterStarts: Record<number, string>;
23
+ /** Booked events this itinerary extends, in order; the last one is fixed first. */
24
+ existingEventIds: number[];
25
+ }
26
+
27
+ export const buildPlanRequest = (choice: ItineraryChoice): PlanRequest => {
28
+ const laterStarts = Object.fromEntries(
29
+ choice.buildingIds
30
+ .slice(1)
31
+ .filter((id) => choice.laterStarts[id])
32
+ .map((id) => [String(id), choice.laterStarts[id]])
33
+ );
34
+ const fixedEventId =
35
+ choice.existingEventIds[choice.existingEventIds.length - 1];
36
+ return {
37
+ building_ids: choice.buildingIds,
38
+ tour_type: choice.tourType,
39
+ date: choice.date,
40
+ start_time: choice.firstStart,
41
+ stop_starts: Object.keys(laterStarts).length > 0 ? laterStarts : null,
42
+ fixed_first:
43
+ fixedEventId === undefined ? null : { calendar_event_id: fixedEventId },
44
+ };
45
+ };
46
+
47
+ /**
48
+ * Lead-source attribution, built the way tour-scheduler.ts builds the same
49
+ * fields for /v2/scheduleMe.
50
+ */
51
+ export const buildAttribution = ({
52
+ orgSlug,
53
+ selectedLeadSource,
54
+ currentLeadSource,
55
+ touchpoints,
56
+ search,
57
+ referrer,
58
+ googleReferral,
59
+ }: {
60
+ orgSlug: string;
61
+ /** Picked in the "How did you hear about us?" dropdown. */
62
+ selectedLeadSource: string | null;
63
+ /** Derived from the referrer and query params. */
64
+ currentLeadSource: string;
65
+ touchpoints: LeadSourceSubmittedListItem[];
66
+ search: string;
67
+ referrer: string;
68
+ googleReferral: {
69
+ rwgToken: string;
70
+ buildingId: number;
71
+ environment: string;
72
+ } | null;
73
+ }): BookingAttribution => {
74
+ const parsedLeadSource = selectedLeadSource || currentLeadSource || null;
75
+ const defaultLeadSource = getDefaultLeadSourceAttribution(orgSlug);
76
+ return {
77
+ lead_sources: [
78
+ ...new Set(
79
+ parsedLeadSource
80
+ ? [parsedLeadSource, defaultLeadSource]
81
+ : [defaultLeadSource]
82
+ ),
83
+ ],
84
+ lead_sources_with_timestamps: touchpoints.map((source) =>
85
+ snakify({ ...source })
86
+ ),
87
+ query_params: Object.fromEntries(new URLSearchParams(search).entries()),
88
+ referrer,
89
+ google_rwg_token: googleReferral?.rwgToken ?? null,
90
+ google_referral_building_id: googleReferral?.buildingId ?? null,
91
+ google_environment: googleReferral?.environment ?? null,
92
+ };
93
+ };
94
+
95
+ export const buildBookingRequest = ({
96
+ choice,
97
+ plan,
98
+ contact,
99
+ attribution,
100
+ conversationTrackingId,
101
+ cancelExistingTours,
102
+ }: {
103
+ choice: ItineraryChoice;
104
+ plan: PlanResponse;
105
+ contact: BookingContact;
106
+ attribution: BookingAttribution;
107
+ conversationTrackingId: string | null;
108
+ cancelExistingTours: boolean;
109
+ }): BookingRequest => ({
110
+ tour_type: choice.tourType,
111
+ stops: [
112
+ ...choice.existingEventIds.map((id) => ({
113
+ existing_calendar_event_id: id,
114
+ })),
115
+ ...plan.stops
116
+ .filter((stop) => !stop.fixed)
117
+ .map((stop) => ({ building_id: stop.building_id, start: stop.start })),
118
+ ],
119
+ contact,
120
+ lead_sources: attribution,
121
+ conversation_tracking_id: conversationTrackingId,
122
+ cancel_existing_tours: cancelExistingTours,
123
+ });
@@ -0,0 +1,256 @@
1
+ import axios, { AxiosError } from "axios";
2
+
3
+ /**
4
+ * Client for the widget tour itinerary endpoints (communities, plan, book).
5
+ * The schemas follow the contract shared with the backend; the server owns
6
+ * ranking, caps, chaining and every prospect-facing reason, and the widget only
7
+ * renders what comes back.
8
+ */
9
+
10
+ export type TourTypeId =
11
+ | "escorted-tour"
12
+ | "self-guided-tour"
13
+ | "live-virtual-tour";
14
+
15
+ export interface CommunityAddress {
16
+ line1: string | null;
17
+ city: string | null;
18
+ state: string | null;
19
+ }
20
+
21
+ export interface Community {
22
+ building_id: number;
23
+ name: string;
24
+ address: CommunityAddress | null;
25
+ timezone: string | null;
26
+ distance_mi: number | null;
27
+ /** In US dollars. */
28
+ price_from: { bedrooms: number; amount: number } | null;
29
+ next_available: { date: string; time: string } | null;
30
+ best_match: boolean;
31
+ image_url: string | null;
32
+ tourable: boolean;
33
+ /** The text to show when the community can't be toured. */
34
+ unavailable_reason: string | null;
35
+ }
36
+
37
+ /**
38
+ * Most stops in one itinerary, counting ones already booked. The server's cap,
39
+ * mirrored here for the picker; booking enforces the real one.
40
+ */
41
+ export const MAX_ITINERARY_STOPS = 3;
42
+
43
+ /** The top communities after filtering; there's no paging. */
44
+ export interface CommunitiesResponse {
45
+ anchor: { building_id: number; name: string; is_general_building: boolean };
46
+ communities: Community[];
47
+ }
48
+
49
+ export interface CommunityFilters {
50
+ bedrooms: number[];
51
+ moveIn: string | null;
52
+ maxBudget: number | null;
53
+ }
54
+
55
+ /** Adding a stop after a booking: the widget sends what it knows of that booking. */
56
+ export interface ExtendQuery {
57
+ /** ISO 8601 with offset: when the last booked stop ends. */
58
+ availableAfter: string;
59
+ tourType: TourTypeId;
60
+ /** The last booked stop's building, which distances are measured from. */
61
+ nearBuildingId: number;
62
+ /** Every building already in the itinerary. */
63
+ excludeBuildingIds: number[];
64
+ }
65
+
66
+ export interface CommunityQuery extends CommunityFilters {
67
+ extend?: ExtendQuery;
68
+ }
69
+
70
+ export interface PlanRequest {
71
+ building_ids: number[];
72
+ tour_type: TourTypeId;
73
+ date: string;
74
+ start_time: string | null;
75
+ stop_starts: Record<string, string> | null;
76
+ fixed_first: { calendar_event_id: number } | null;
77
+ }
78
+
79
+ export interface PlanStop {
80
+ building_id: number;
81
+ start: string;
82
+ end: string;
83
+ timezone: string;
84
+ distance_from_prev_mi: number | null;
85
+ alternatives: string[];
86
+ fixed: boolean;
87
+ }
88
+
89
+ export interface PlanResponse {
90
+ bookable_dates: string[];
91
+ tour_types: TourTypeId[];
92
+ stops: PlanStop[];
93
+ changed: { building_id: number; reason: string; text: string }[];
94
+ unchainable: { building_id: number; reason: string; text: string }[];
95
+ }
96
+
97
+ export type BookingStopRequest =
98
+ | { existing_calendar_event_id: number }
99
+ | { building_id: number; start: string };
100
+
101
+ export interface BookingContact {
102
+ first_name: string;
103
+ last_name: string;
104
+ email: string;
105
+ phone_e164: string;
106
+ bedrooms: number[];
107
+ move_in: string | null;
108
+ notes: string;
109
+ }
110
+
111
+ /** The attribution /v2/scheduleMe takes today, under the same names. */
112
+ export interface BookingAttribution {
113
+ lead_sources: string[];
114
+ lead_sources_with_timestamps: Record<string, unknown>[];
115
+ query_params: Record<string, string>;
116
+ referrer: string;
117
+ google_rwg_token: string | null;
118
+ google_referral_building_id: number | null;
119
+ google_environment: string | null;
120
+ }
121
+
122
+ export interface BookingRequest {
123
+ tour_type: TourTypeId;
124
+ stops: BookingStopRequest[];
125
+ contact: BookingContact;
126
+ lead_sources: BookingAttribution;
127
+ conversation_tracking_id: string | null;
128
+ cancel_existing_tours: boolean;
129
+ }
130
+
131
+ export type BookedStopStatus = "booked" | "existing" | "failed";
132
+
133
+ export interface BookedStop {
134
+ building_id: number;
135
+ calendar_event_id: number | null;
136
+ start: string | null;
137
+ end: string | null;
138
+ status: BookedStopStatus;
139
+ error: { code: string; message: string } | null;
140
+ }
141
+
142
+ export interface BookingResponse {
143
+ itinerary_id: string | null;
144
+ stops: BookedStop[];
145
+ }
146
+
147
+ export type TourApiErrorCode =
148
+ | "SLOT_TAKEN"
149
+ | "EXISTING_TOUR"
150
+ | "MAX_STOPS"
151
+ | "NOT_IN_GROUP"
152
+ | "INVALID_STOPS"
153
+ | "RATE_LIMITED";
154
+
155
+ export class TourApiError extends Error {
156
+ constructor(
157
+ readonly status: number,
158
+ readonly code: TourApiErrorCode | null,
159
+ message: string
160
+ ) {
161
+ super(message);
162
+ this.name = "TourApiError";
163
+ }
164
+ }
165
+
166
+ export interface TourItineraryApi {
167
+ getCommunities(query: CommunityQuery): Promise<CommunitiesResponse>;
168
+ plan(request: PlanRequest): Promise<PlanResponse>;
169
+ book(
170
+ request: BookingRequest,
171
+ idempotencyKey: string
172
+ ): Promise<BookingResponse>;
173
+ }
174
+
175
+ const GENERIC_ERROR = "Something went wrong. Please try again.";
176
+
177
+ const toTourApiError = (e: unknown): TourApiError => {
178
+ const error = e as AxiosError<{
179
+ error?: { code?: TourApiErrorCode; message?: string };
180
+ }>;
181
+ const body = error.response?.data?.error;
182
+ return new TourApiError(
183
+ error.response?.status ?? 0,
184
+ body?.code ?? null,
185
+ body?.message || GENERIC_ERROR
186
+ );
187
+ };
188
+
189
+ /** Query string for GET tour-communities; empty filters are left out. */
190
+ export const communitiesSearchParams = (
191
+ query: CommunityQuery
192
+ ): URLSearchParams => {
193
+ const params = new URLSearchParams();
194
+ query.bedrooms.forEach((n) => params.append("bedrooms", String(n)));
195
+ if (query.moveIn) params.set("move_in", query.moveIn);
196
+ if (query.maxBudget !== null) {
197
+ params.set("max_budget", String(query.maxBudget));
198
+ }
199
+ if (query.extend) {
200
+ params.set("available_after", query.extend.availableAfter);
201
+ params.set("tour_type", query.extend.tourType);
202
+ params.set("near_building_id", String(query.extend.nearBuildingId));
203
+ query.extend.excludeBuildingIds.forEach((id) =>
204
+ params.append("exclude_building_ids", String(id))
205
+ );
206
+ }
207
+ return params;
208
+ };
209
+
210
+ export const createTourItineraryApi = ({
211
+ orgSlug,
212
+ buildingSlug,
213
+ getSessionToken,
214
+ host = "https://app.meetelise.com",
215
+ }: {
216
+ orgSlug: string;
217
+ buildingSlug: string;
218
+ getSessionToken: () => string | null;
219
+ host?: string;
220
+ }): TourItineraryApi => {
221
+ const baseUrl = `${host}/platformApi/webchat`;
222
+ const headers = (): Record<string, string> => ({
223
+ "X-Session-Token": getSessionToken() ?? "",
224
+ "org-slug": orgSlug,
225
+ "building-slug": buildingSlug,
226
+ });
227
+ const call = async <T>(request: () => Promise<{ data: T }>): Promise<T> => {
228
+ try {
229
+ return (await request()).data;
230
+ } catch (e) {
231
+ throw toTourApiError(e);
232
+ }
233
+ };
234
+
235
+ return {
236
+ getCommunities: (query) =>
237
+ call(() =>
238
+ axios.get<CommunitiesResponse>(
239
+ `${baseUrl}/tour-communities?${communitiesSearchParams(query)}`,
240
+ { headers: headers() }
241
+ )
242
+ ),
243
+ plan: (request) =>
244
+ call(() =>
245
+ axios.post<PlanResponse>(`${baseUrl}/tour-itineraries/plan`, request, {
246
+ headers: headers(),
247
+ })
248
+ ),
249
+ book: (request, idempotencyKey) =>
250
+ call(() =>
251
+ axios.post<BookingResponse>(`${baseUrl}/tour-itineraries`, request, {
252
+ headers: { ...headers(), "Idempotency-Key": idempotencyKey },
253
+ })
254
+ ),
255
+ };
256
+ };
@@ -0,0 +1,82 @@
1
+ import format from "date-fns/format";
2
+ import type { TourTypeId } from "./tourItineraryApi";
3
+
4
+ /*
5
+ * The API sends each time as ISO 8601 in its building's own time zone
6
+ * (e.g. "2026-10-15T10:45:00-05:00"), so the wall-clock time a prospect should
7
+ * see is the text of the string itself. Reading it directly avoids converting
8
+ * through the visitor's time zone.
9
+ */
10
+
11
+ /** "2026-10-15T10:45:00-05:00" -> "2026-10-15" */
12
+ export const isoDate = (iso: string): string => iso.slice(0, 10);
13
+
14
+ /** "2026-10-15T10:45:00-05:00" -> "10:45" */
15
+ export const isoHourMinute = (iso: string): string => iso.slice(11, 16);
16
+
17
+ const parts = (hourMinute: string): { hour: number; minute: string } => {
18
+ const [hour, minute] = hourMinute.split(":");
19
+ return { hour: parseInt(hour, 10), minute };
20
+ };
21
+
22
+ const meridiem = (hour: number): string => (hour < 12 ? "am" : "pm");
23
+
24
+ const clock = (hour: number, minute: string): string =>
25
+ `${hour % 12 === 0 ? 12 : hour % 12}:${minute}`;
26
+
27
+ /** "14:30" -> "2:30pm" */
28
+ export const formatHourMinute = (hourMinute: string): string => {
29
+ const { hour, minute } = parts(hourMinute);
30
+ return `${clock(hour, minute)}${meridiem(hour)}`;
31
+ };
32
+
33
+ /** ISO start -> "10:45am" */
34
+ export const formatTime = (iso: string): string =>
35
+ formatHourMinute(isoHourMinute(iso));
36
+
37
+ /** "10:00–10:30am", or "11:30am–12:00pm" across noon. */
38
+ export const formatTimeRange = (startIso: string, endIso: string): string => {
39
+ const start = parts(isoHourMinute(startIso));
40
+ const end = parts(isoHourMinute(endIso));
41
+ const startText =
42
+ meridiem(start.hour) === meridiem(end.hour)
43
+ ? clock(start.hour, start.minute)
44
+ : formatHourMinute(isoHourMinute(startIso));
45
+ return `${startText}–${formatHourMinute(isoHourMinute(endIso))}`;
46
+ };
47
+
48
+ /** A calendar date, read as that date wherever the visitor is. */
49
+ export const dateFromIsoDate = (date: string): Date => {
50
+ const [year, month, day] = date.split("-").map((n) => parseInt(n, 10));
51
+ return new Date(year, month - 1, day);
52
+ };
53
+
54
+ /** "2026-10-15" -> "Thu, Oct 15" */
55
+ export const formatShortDate = (date: string): string =>
56
+ format(dateFromIsoDate(date), "EEE, MMM d");
57
+
58
+ /** "2026-10-15" -> "Oct 15" */
59
+ export const formatMonthDay = (date: string): string =>
60
+ format(dateFromIsoDate(date), "MMM d");
61
+
62
+ /** "2026-10-15" -> "Thu, Oct 15, 2026" */
63
+ export const formatLongDate = (date: string): string =>
64
+ format(dateFromIsoDate(date), "EEE, MMM d, yyyy");
65
+
66
+ /** A Date as the "YYYY-MM-DD" the API uses. */
67
+ export const toIsoDate = (date: Date): string => format(date, "yyyy-MM-dd");
68
+
69
+ export const TOUR_TYPE_COPY: Record<
70
+ TourTypeId,
71
+ { label: string; subtitle: string }
72
+ > = {
73
+ "escorted-tour": { label: "Escorted Tour", subtitle: "With an agent" },
74
+ "live-virtual-tour": { label: "Virtual Tour", subtitle: "Over video" },
75
+ "self-guided-tour": { label: "Self-Guided Tour", subtitle: "On your own" },
76
+ };
77
+
78
+ export const TOUR_TYPE_ORDER: TourTypeId[] = [
79
+ "escorted-tour",
80
+ "live-virtual-tour",
81
+ "self-guided-tour",
82
+ ];