@wix/himalaya-cli 0.1750.0 → 0.1752.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.
Files changed (185) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-config.d.ts +1 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-module.d.ts +3 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +3 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/define-app.d.ts +16 -1
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/himi-package.d.ts +478 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/host-compatibility.d.ts +56 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/icon-catalog.generated.d.ts +1 -1
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +4 -0
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-shell.d.ts +154 -7
  10. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/validator.d.ts +3 -0
  11. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/auth-providers/wix/src/index.d.ts +1 -1
  12. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/auth-providers/wix/src/native-engine.d.ts +49 -3
  13. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/auth/src/copy.generated.d.ts +16 -1
  14. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/auth/src/feedback.d.ts +1 -1
  15. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/index.d.ts +2 -0
  16. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/podcast-service.d.ts +105 -0
  17. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/podcast.d.ts +116 -0
  18. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/auth.mjs +27 -2
  19. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +326 -13
  20. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +757 -83
  21. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +156 -0
  22. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-auth/worker.mjs +133 -13
  23. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-auth.mjs +139 -13
  24. package/dist/browser-plane/assets.json +5 -5
  25. package/dist/browser-plane/preview-deferred/{b40ea5d0d6251898ff5617139fde8be008dd11e99a70b14c1052093685401700.bin → 2671d1cadb15daa5e59440f4c924e30c221ab3d405e8a56a0ab1cdbe4764af3d.bin} +1 -1
  26. package/dist/browser-plane/sw.js +7 -7
  27. package/dist/cli.mjs +37219 -33014
  28. package/dist/preview-assets.generated.bin +0 -0
  29. package/guides/app-config.md +1 -1
  30. package/guides/component-reference.json +1 -1
  31. package/guides/component-reference.md +4 -0
  32. package/guides/designing-himi-screens.md +7 -0
  33. package/guides/getting-started.md +2 -0
  34. package/guides/headless-loop.md +1 -1
  35. package/guides/himi-json-output.md +25 -3
  36. package/guides/himi-skill.md +2 -0
  37. package/guides/index.json +6 -0
  38. package/guides/push-cli-onboarding.md +13 -0
  39. package/guides/qa-builds.md +15 -2
  40. package/guides/recipe-podcast.md +149 -0
  41. package/guides/releasing-with-himi-serve.md +51 -0
  42. package/guides/store-submission.md +46 -1
  43. package/guides/tier-5-add-a-screen.md +16 -2
  44. package/guides/wix-business-context.md +29 -0
  45. package/guides/wix-platform-usage.md +7 -2
  46. package/package.json +10 -10
  47. package/template-icons/fitness-gym.png +0 -0
  48. package/templates/beauty-salon/dev/index.ts +1 -1
  49. package/templates/beauty-salon/l10n/en.json +1 -1
  50. package/templates/beauty-salon/tier5-src/_shared/program-fields.ts +16 -0
  51. package/templates/beauty-salon/tier5-src/_shared/programs-section.ts +5 -8
  52. package/templates/beauty-salon/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  53. package/templates/branded-lite/dev/index.ts +101 -1
  54. package/templates/branded-lite/l10n/en.json +22 -1
  55. package/templates/branded-lite/l10n/es.json +22 -0
  56. package/templates/branded-lite/l10n/fr.json +18 -0
  57. package/templates/branded-lite/l10n/he.json +15 -0
  58. package/templates/branded-lite/tier5-src/_shared/program-fields.ts +16 -0
  59. package/templates/branded-lite/tier5-src/_shared/programs-section.ts +5 -8
  60. package/templates/branded-lite/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  61. package/templates/branded-lite/tier5-src/himi-branded-lite-podcasts/index.ts +14 -234
  62. package/templates/brandy/README.md +33 -0
  63. package/templates/brandy/config.ts +51 -7
  64. package/templates/brandy/dev/index.ts +23 -9
  65. package/templates/community-club/l10n/en.json +1 -1
  66. package/templates/community-club/tier5-src/_shared/program-fields.ts +16 -0
  67. package/templates/community-club/tier5-src/_shared/programs-section.ts +5 -8
  68. package/templates/events-meetups/l10n/en.json +1 -1
  69. package/templates/events-meetups/tier5-src/_shared/program-fields.ts +16 -0
  70. package/templates/events-meetups/tier5-src/_shared/programs-section.ts +5 -8
  71. package/templates/fitness-gym/README.md +53 -0
  72. package/templates/fitness-gym/config.ts +560 -0
  73. package/templates/fitness-gym/dev/index.ts +25787 -0
  74. package/templates/fitness-gym/himalaya.content.json +64 -0
  75. package/templates/fitness-gym/himalaya.template.json +15 -0
  76. package/templates/fitness-gym/icon.png +0 -0
  77. package/templates/fitness-gym/platforms.json +1 -0
  78. package/templates/fitness-gym/tier5-src/_shared/app-locale.ts +61 -0
  79. package/templates/fitness-gym/tier5-src/_shared/booking-location.ts +147 -0
  80. package/templates/fitness-gym/tier5-src/_shared/booking-session.ts +224 -0
  81. package/templates/fitness-gym/tier5-src/_shared/branded-lite-hosted.ts +280 -0
  82. package/templates/fitness-gym/tier5-src/_shared/branded-load-state.ts +109 -0
  83. package/templates/fitness-gym/tier5-src/_shared/business-chat-copy.ts +40 -0
  84. package/templates/fitness-gym/tier5-src/_shared/business-chat-history.ts +51 -0
  85. package/templates/fitness-gym/tier5-src/_shared/business-chat-message-model.ts +177 -0
  86. package/templates/fitness-gym/tier5-src/_shared/business-chat-model.ts +56 -0
  87. package/templates/fitness-gym/tier5-src/_shared/business-chat-presenter.ts +576 -0
  88. package/templates/fitness-gym/tier5-src/_shared/business-chat-transport.ts +148 -0
  89. package/templates/fitness-gym/tier5-src/_shared/collection-contract.ts +228 -0
  90. package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +193 -0
  91. package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +400 -0
  92. package/templates/fitness-gym/tier5-src/_shared/detail-presence.ts +51 -0
  93. package/templates/fitness-gym/tier5-src/_shared/engine-intl.ts +523 -0
  94. package/templates/fitness-gym/tier5-src/_shared/himi-account.ts +194 -0
  95. package/templates/fitness-gym/tier5-src/_shared/himi-booking-saved.ts +88 -0
  96. package/templates/fitness-gym/tier5-src/_shared/himi-bookings.ts +318 -0
  97. package/templates/fitness-gym/tier5-src/_shared/himi-copy.ts +116 -0
  98. package/templates/fitness-gym/tier5-src/_shared/himi-media.ts +29 -0
  99. package/templates/fitness-gym/tier5-src/_shared/himi-store.ts +7 -0
  100. package/templates/fitness-gym/tier5-src/_shared/himi-text.ts +24 -0
  101. package/templates/fitness-gym/tier5-src/_shared/host-events.ts +66 -0
  102. package/templates/fitness-gym/tier5-src/_shared/hosted-checkout.ts +70 -0
  103. package/templates/fitness-gym/tier5-src/_shared/iap-attendance-form.ts +106 -0
  104. package/templates/fitness-gym/tier5-src/_shared/iap-attendance-purchase.ts +216 -0
  105. package/templates/fitness-gym/tier5-src/_shared/iap-attendance.ts +38 -0
  106. package/templates/fitness-gym/tier5-src/_shared/iap-worker.ts +127 -0
  107. package/templates/fitness-gym/tier5-src/_shared/inbox-rooms.ts +68 -0
  108. package/templates/fitness-gym/tier5-src/_shared/local-preferences.ts +38 -0
  109. package/templates/fitness-gym/tier5-src/_shared/member-access.ts +63 -0
  110. package/templates/fitness-gym/tier5-src/_shared/member-account-routes.ts +52 -0
  111. package/templates/fitness-gym/tier5-src/_shared/member-bookings.ts +107 -0
  112. package/templates/fitness-gym/tier5-src/_shared/member-screen.ts +99 -0
  113. package/templates/fitness-gym/tier5-src/_shared/notification-target.ts +141 -0
  114. package/templates/fitness-gym/tier5-src/_shared/offset-page.ts +10 -0
  115. package/templates/fitness-gym/tier5-src/_shared/online-actions.ts +76 -0
  116. package/templates/fitness-gym/tier5-src/_shared/owner-load-error.ts +348 -0
  117. package/templates/fitness-gym/tier5-src/_shared/payment-setup.ts +6 -0
  118. package/templates/fitness-gym/tier5-src/_shared/pricing-plan-display.ts +64 -0
  119. package/templates/fitness-gym/tier5-src/_shared/program-description.ts +11 -0
  120. package/templates/fitness-gym/tier5-src/_shared/program-fields.ts +16 -0
  121. package/templates/fitness-gym/tier5-src/_shared/program-standing.ts +46 -0
  122. package/templates/fitness-gym/tier5-src/_shared/rich-body.ts +78 -0
  123. package/templates/fitness-gym/tier5-src/_shared/rich-content-link.ts +34 -0
  124. package/templates/fitness-gym/tier5-src/_shared/sign-in-sheet.ts +18 -0
  125. package/templates/fitness-gym/tier5-src/_shared/staff-name.ts +18 -0
  126. package/templates/fitness-gym/tier5-src/_shared/weekly-goal.ts +107 -0
  127. package/templates/fitness-gym/tier5-src/_shared/wix-bi.ts +85 -0
  128. package/templates/fitness-gym/tier5-src/_shared/wix-member-links.ts +114 -0
  129. package/templates/fitness-gym/tier5-src/_shared/wix-service-price.ts +146 -0
  130. package/templates/fitness-gym/tier5-src/business-chat/index.ts +732 -0
  131. package/templates/fitness-gym/tier5-src/business-contact/index.ts +6 -0
  132. package/templates/fitness-gym/tier5-src/himi-booking-account/index.ts +267 -0
  133. package/templates/fitness-gym/tier5-src/himi-booking-bookings/index.ts +468 -0
  134. package/templates/fitness-gym/tier5-src/himi-booking-service/index.ts +1190 -0
  135. package/templates/fitness-gym/tier5-src/himi-booking-services/index.ts +791 -0
  136. package/templates/fitness-gym/tier5-src/himi-booking-time/index.ts +1729 -0
  137. package/templates/fitness-gym/tier5-src/himi-branded-lite-agenda/index.ts +988 -0
  138. package/templates/fitness-gym/tier5-src/himi-branded-lite-member-programs/index.ts +656 -0
  139. package/templates/fitness-gym/tier5-src/himi-branded-lite-notifications/index.ts +256 -0
  140. package/templates/fitness-gym/tier5-src/himi-branded-lite-plans/index.ts +495 -0
  141. package/templates/fitness-gym/tier5-src/himi-branded-lite-program/facts.ts +52 -0
  142. package/templates/fitness-gym/tier5-src/himi-branded-lite-program/index.ts +845 -0
  143. package/templates/fitness-gym/tier5-src/himi-fitcoach-goal/index.ts +190 -0
  144. package/templates/fitness-gym/tier5-src/himi-fitcoach-home/index.ts +619 -0
  145. package/templates/fitness-gym/tier5-src/himi-store-account/index.ts +1007 -0
  146. package/templates/fitness-gym/tier5-src/wix-spaces-my-subscriptions/index.ts +84 -0
  147. package/templates/fitness-gym/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
  148. package/templates/fitness-gym/tokens.json +414 -0
  149. package/templates/gym-fitness/dev/index.ts +1 -1
  150. package/templates/gym-fitness/l10n/en.json +1 -1
  151. package/templates/gym-fitness/tier5-src/_shared/program-fields.ts +16 -0
  152. package/templates/gym-fitness/tier5-src/_shared/programs-section.ts +5 -8
  153. package/templates/gym-fitness/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  154. package/templates/medical-services/dev/index.ts +2 -1
  155. package/templates/medical-services/tier5-src/himi-booking-account/index.ts +16 -1
  156. package/templates/nonprofit-cause/l10n/en.json +1 -1
  157. package/templates/nonprofit-cause/tier5-src/_shared/program-fields.ts +16 -0
  158. package/templates/nonprofit-cause/tier5-src/_shared/programs-section.ts +5 -8
  159. package/templates/personal-fitness-trainer/dev/index.ts +2 -2
  160. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  161. package/templates/podcast-creator/dev/index.ts +100 -0
  162. package/templates/podcast-creator/l10n/en.json +22 -1
  163. package/templates/podcast-creator/l10n/es.json +22 -0
  164. package/templates/podcast-creator/l10n/fr.json +18 -0
  165. package/templates/podcast-creator/l10n/he.json +15 -0
  166. package/templates/podcast-creator/tier5-src/_shared/program-fields.ts +16 -0
  167. package/templates/podcast-creator/tier5-src/_shared/programs-section.ts +5 -8
  168. package/templates/podcast-creator/tier5-src/himi-branded-lite-podcasts/index.ts +14 -234
  169. package/templates/portfolio-creative/l10n/en.json +1 -1
  170. package/templates/portfolio-creative/tier5-src/_shared/program-fields.ts +16 -0
  171. package/templates/portfolio-creative/tier5-src/_shared/programs-section.ts +5 -8
  172. package/templates/restaurant/l10n/en.json +1 -1
  173. package/templates/restaurant/tier5-src/_shared/program-fields.ts +16 -0
  174. package/templates/restaurant/tier5-src/_shared/programs-section.ts +5 -8
  175. package/templates/retail-store/l10n/en.json +1 -1
  176. package/templates/retail-store/tier5-src/_shared/program-fields.ts +16 -0
  177. package/templates/retail-store/tier5-src/_shared/programs-section.ts +5 -8
  178. package/templates/salon-spa/dev/index.ts +1 -1
  179. package/templates/salon-spa/tier5-src/himi-booking-account/index.ts +16 -1
  180. package/templates/salon-spa/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  181. package/templates/yoga-studio/dev/index.ts +1 -1
  182. package/templates/yoga-studio/l10n/en.json +1 -1
  183. package/templates/yoga-studio/tier5-src/_shared/program-fields.ts +16 -0
  184. package/templates/yoga-studio/tier5-src/_shared/programs-section.ts +5 -8
  185. package/templates/yoga-studio/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
@@ -0,0 +1,194 @@
1
+ import { dispatch } from "@himalaya/dispatch";
2
+ // Relative for node resolution (see himi-store.ts note); rewritten off-repo.
3
+ import { displayName, getMyData, initials, type WixMyData } from "@himalaya/wix-users";
4
+ import { getMyMember } from "@himalaya/wix-members";
5
+ import { wixMediaUrl } from "@himalaya/wix-media";
6
+ import { formatDateMedium, formatWeekdayDateTime } from "../_shared/engine-intl.js";
7
+ import { copyParam } from "./himi-copy.js";
8
+
9
+ export interface AccountProfile {
10
+ isMember: boolean;
11
+ identityLine: string;
12
+ detailLine: string;
13
+ memberName: string;
14
+ memberEmail: string;
15
+ memberImage: string;
16
+ memberInitials: string;
17
+ hasMemberImage: boolean;
18
+ noMemberImage: boolean;
19
+ }
20
+
21
+ export interface AccountActivityRow {
22
+ id: string;
23
+ title: string;
24
+ subtitle: string;
25
+ meta: string;
26
+ status: string;
27
+ }
28
+
29
+ export function strOf(arg: unknown): string {
30
+ if (typeof arg === "string") return arg;
31
+ const a = arg as { value?: string; text?: string } | undefined;
32
+ return a?.value ?? a?.text ?? "";
33
+ }
34
+
35
+ export function titleCase(value?: string): string {
36
+ return (value || "")
37
+ .toLowerCase()
38
+ .split(/[_\s-]+/)
39
+ .filter(Boolean)
40
+ .map((part) => part[0].toUpperCase() + part.slice(1))
41
+ .join(" ");
42
+ }
43
+
44
+ export function fmtDate(value?: string): string {
45
+ if (!value) return "";
46
+ const date = new Date(value);
47
+ if (Number.isNaN(date.getTime())) return "";
48
+ return formatDateMedium(date);
49
+ }
50
+
51
+ export function fmtDateTime(value?: string): string {
52
+ if (!value) return "";
53
+ const date = new Date(value);
54
+ if (Number.isNaN(date.getTime())) return "";
55
+ return formatWeekdayDateTime(date);
56
+ }
57
+
58
+ function initialsFromName(value: string): string {
59
+ const parts = value.trim().split(/\s+/).filter(Boolean);
60
+ if (!parts.length) return "";
61
+ const first = parts[0]?.[0] ?? "";
62
+ const last = parts.length > 1 ? parts[parts.length - 1]?.[0] ?? "" : "";
63
+ return (first + last).toUpperCase();
64
+ }
65
+
66
+ function profileImage(data: WixMyData): string {
67
+ const profile = data.profile as { profileImage?: string; photo?: { url?: string }; imageUrl?: string } | undefined;
68
+ return profile?.profileImage || profile?.photo?.url || profile?.imageUrl || "";
69
+ }
70
+
71
+ function profileFromData(data: WixMyData, fallbackEmail = ""): AccountProfile {
72
+ const email = fallbackEmail || data.email || data.contactEmail || "";
73
+ const name = displayName(data) || email || "Member";
74
+ const image = profileImage(data);
75
+ return {
76
+ isMember: true,
77
+ identityLine: copyParam("account.signedIn", "Signed in"),
78
+ detailLine: email || name,
79
+ memberName: name,
80
+ memberEmail: email,
81
+ memberImage: image,
82
+ memberInitials: initials(data) || initialsFromName(name) || "M",
83
+ hasMemberImage: !!image,
84
+ noMemberImage: !image,
85
+ };
86
+ }
87
+
88
+ /** The signed-in site member's name and photo from their member record, or undefined when it
89
+ * cannot be read or names nobody (the caller then shows the email). */
90
+ async function siteMemberProfile(email: string): Promise<AccountProfile | undefined> {
91
+ try {
92
+ const member = (await getMyMember({ fieldsets: ["FULL"] }))?.member;
93
+ const name = [member?.contact?.firstName, member?.contact?.lastName].map((part) => (part ?? "").trim()).filter(Boolean).join(" ")
94
+ || (member?.profile?.nickname ?? "").trim();
95
+ if (!name) return undefined;
96
+ const image = wixMediaUrl(member?.profile?.photo?.url) || wixMediaUrl(member?.profile?.photo?.id) || "";
97
+ return {
98
+ isMember: true,
99
+ identityLine: copyParam("account.signedIn", "Signed in"),
100
+ detailLine: email || name,
101
+ memberName: name,
102
+ memberEmail: email || member?.loginEmail || "",
103
+ memberImage: image,
104
+ memberInitials: initialsFromName(name) || "M",
105
+ hasMemberImage: !!image,
106
+ noMemberImage: !image,
107
+ };
108
+ } catch {
109
+ return undefined;
110
+ }
111
+ }
112
+
113
+ export function guestProfile(detailLine: string): AccountProfile {
114
+ return {
115
+ isMember: false,
116
+ identityLine: copyParam("account.guestIdentity", "Browsing as a guest"),
117
+ detailLine,
118
+ memberName: "",
119
+ memberEmail: "",
120
+ memberImage: "",
121
+ memberInitials: "M",
122
+ hasMemberImage: false,
123
+ noMemberImage: true,
124
+ };
125
+ }
126
+
127
+ /** `himi.wix.memberIdentity`: the member's email ("" when none is known) and whether a member is
128
+ * signed in. `signedIn` is true only when the host says so explicitly — native hosts answer it
129
+ * for a member whose email is not known yet (an injected or hosted session before `members/my`
130
+ * answers); hosts that predate it answer the email alone. */
131
+ export async function memberIdentity(): Promise<{ email: string; signedIn: boolean }> {
132
+ try {
133
+ const identity = await dispatch("himi.wix.memberIdentity") as unknown;
134
+ const direct = identity as { email?: unknown; signedIn?: unknown } | null;
135
+ const wrapped = identity as { payload?: { email?: unknown; signedIn?: unknown } } | null;
136
+ const raw = direct?.email ?? wrapped?.payload?.email;
137
+ const email = typeof raw === "string" ? raw : "";
138
+ const signedIn = (direct?.signedIn ?? wrapped?.payload?.signedIn) === true;
139
+ return { email, signedIn: signedIn || !!email };
140
+ } catch {
141
+ return { email: "", signedIn: false };
142
+ }
143
+ }
144
+
145
+ export async function signedInEmail(): Promise<string> {
146
+ return (await memberIdentity()).email;
147
+ }
148
+
149
+ /** A signed-in member nothing names yet: signed in, with a neutral label rather than another
150
+ * member's name or the sign-in form. */
151
+ function neutralMemberProfile(): AccountProfile {
152
+ const name = copyParam("account.member", "Member");
153
+ return {
154
+ isMember: true,
155
+ identityLine: copyParam("account.signedIn", "Signed in"),
156
+ detailLine: name,
157
+ memberName: name,
158
+ memberEmail: "",
159
+ memberImage: "",
160
+ memberInitials: "M",
161
+ hasMemberImage: false,
162
+ noMemberImage: true,
163
+ };
164
+ }
165
+
166
+ export async function loadMemberProfile(guestDetailLine: string): Promise<AccountProfile> {
167
+ // `himi.wix.memberIdentity` is the session source of truth. Visitor-scoped
168
+ // getMyData can still return a site/account nickname (e.g. apptestercoowner)
169
+ // after sign-out or for anonymous — never treat that as a signed-in member.
170
+ const identity = await memberIdentity();
171
+ if (!identity.signedIn) return guestProfile(guestDetailLine);
172
+ const storedEmail = identity.email;
173
+ if (!storedEmail) return (await siteMemberProfile("")) ?? neutralMemberProfile();
174
+ try {
175
+ const data = await getMyData();
176
+ return profileFromData(data, storedEmail);
177
+ } catch {
178
+ // The account profile is an owner endpoint: the web host refuses it, and a site member need
179
+ // not have one. The member's own record (the Members API) still names them.
180
+ const member = await siteMemberProfile(storedEmail);
181
+ if (member) return member;
182
+ return {
183
+ isMember: true,
184
+ identityLine: copyParam("account.signedIn", "Signed in"),
185
+ detailLine: storedEmail,
186
+ memberName: storedEmail,
187
+ memberEmail: storedEmail,
188
+ memberImage: "",
189
+ memberInitials: initialsFromName(storedEmail) || "M",
190
+ hasMemberImage: false,
191
+ noMemberImage: true,
192
+ };
193
+ }
194
+ }
@@ -0,0 +1,88 @@
1
+ // Saved (favorite) booking services use the host's durable, app-scoped KV, shared by every
2
+ // screen worker — the service detail toggles a row (himi-booking-service `toggleSaved`), the
3
+ // Favorites list reads them (himi-booking-saved). Same model as _shared/himi-store-saved.ts: a
4
+ // failed write must never claim that a save succeeded.
5
+ export interface SavedService {
6
+ id: string;
7
+ name: string;
8
+ /** The price line as the detail showed it ("$250"), kept so the list paints offline. */
9
+ price: string;
10
+ /** The duration line ("1 hr"). */
11
+ duration: string;
12
+ image: string;
13
+ category: string;
14
+ /** A course: the list's Book passes `course` to the time screen, which then refuses a course
15
+ * whose record failed to load instead of offering its sessions one by one. */
16
+ course?: boolean;
17
+ }
18
+ type StorageLike = { getItem(key: string): string | null; setItem(key: string, value: string): void };
19
+ type Host = { himalaya?: { storage?: StorageLike; input?: Record<string, unknown> }; localStorage?: StorageLike };
20
+ const BASE = "himi-booking:saved-services:v1";
21
+ function storage(): StorageLike {
22
+ const host = globalThis as Host;
23
+ const kv = host.himalaya?.storage ?? host.localStorage;
24
+ if (!kv) throw new Error("Saved-service storage is unavailable");
25
+ return kv;
26
+ }
27
+ const validPart = (value: unknown): value is string => typeof value === "string" && /^[A-Za-z0-9_.:-]{1,128}$/.test(value) && value !== "default";
28
+ /** Saves belong to whoever made them. A signed-in member's live under the host's authenticated
29
+ * account + business — the partition collection preferences use, so a second member on the same
30
+ * device never sees them; a visitor's live on the device. A member's partition, read for the
31
+ * first time, takes the visitor's saves on this device (signing in carries them, like a cart),
32
+ * once — the device list is then emptied. */
33
+ function storeKey(kv: StorageLike): string {
34
+ const input = (globalThis as Host).himalaya?.input;
35
+ const account = input?.__himiPreferenceAccount, business = input?.__himiPreferenceBusiness;
36
+ if (!validPart(account) || !validPart(business)) return BASE;
37
+ const key = `${BASE}.${account}.${encodeURIComponent(business)}`;
38
+ if (kv.getItem(key) === null) {
39
+ const visitor = kv.getItem(BASE);
40
+ if (visitor !== null) {
41
+ kv.setItem(key, visitor);
42
+ // Empty the device list only once the member's copy is confirmed: a web host may swallow a
43
+ // failed write, and clearing then would lose the visitor's saves.
44
+ if (kv.getItem(key) === visitor) kv.setItem(BASE, "[]");
45
+ }
46
+ }
47
+ return key;
48
+ }
49
+ const str = (value: unknown): string => (typeof value === "string" ? value : "");
50
+ export function readSavedServices(): SavedService[] {
51
+ const kv = storage();
52
+ const raw = kv.getItem(storeKey(kv));
53
+ if (!raw) return [];
54
+ const parsed: unknown = JSON.parse(raw);
55
+ if (!Array.isArray(parsed)) throw new Error("Invalid saved-service data");
56
+ const rows = new Map<string, SavedService>();
57
+ for (const value of parsed) {
58
+ if (!value || typeof value !== "object") continue;
59
+ const row = value as Record<string, unknown>;
60
+ if (typeof row.id !== "string" || !row.id.trim() || typeof row.name !== "string") continue;
61
+ rows.set(row.id, { id: row.id, name: row.name, price: str(row.price), duration: str(row.duration), image: str(row.image), category: str(row.category), ...(row.course === true ? { course: true } : {}) });
62
+ }
63
+ return [...rows.values()];
64
+ }
65
+
66
+ export function isServiceSaved(id: string): boolean {
67
+ return readSavedServices().some(row => row.id === id);
68
+ }
69
+ export function writeSavedServices(rows: SavedService[]): void {
70
+ const kv = storage();
71
+ const key = storeKey(kv);
72
+ const value = JSON.stringify(rows);
73
+ kv.setItem(key, value);
74
+ // Web hosts may swallow quota/security errors. Confirm the synchronous write
75
+ // before displaying success; a missing/mismatched read is a failed save.
76
+ if (kv.getItem(key) !== value) throw new Error("Saved-service write did not persist");
77
+ }
78
+ /** Save or unsave; returns the new saved state. The newest save is listed first. */
79
+ export function toggleSavedService(service: SavedService): boolean {
80
+ if (!service.id.trim() || !service.name.trim()) throw new Error("No service to save");
81
+ const rows = readSavedServices();
82
+ const saved = !rows.some(row => row.id === service.id);
83
+ writeSavedServices(saved ? [service, ...rows] : rows.filter(row => row.id !== service.id));
84
+ return saved;
85
+ }
86
+ export function removeSavedService(id: string): void {
87
+ writeSavedServices(readSavedServices().filter(row => row.id !== id));
88
+ }
@@ -0,0 +1,318 @@
1
+ // Shared Wix Bookings shaping for himi workers (branded-lite `bookings`
2
+ // vertical): defensive extraction where the LIVE services payload drifts from
3
+ // the generated client's types. Used by BOTH the services-list worker
4
+ // (himi_services rows) and the service-detail worker so the two screens agree
5
+ // on one shape (the himi-restaurants.ts pattern).
6
+
7
+ /** Human-readable category name. The live services payload carries `category`
8
+ * as a STRUCTURED object (`{ id, name, sortOrder }`) while the generated
9
+ * client types it as a string — joined raw it rendered
10
+ * "[object Object] · 1 hr · $111" in the services rows (production sweep R3).
11
+ * Extract the name member; an id-only/unrecognizable shape yields "" so the
12
+ * caller omits the segment instead of stringifying the object. */
13
+ export function categoryName(value: unknown): string {
14
+ if (typeof value === "string") return value.trim();
15
+ if (!value || typeof value !== "object") return "";
16
+ const name = (value as { name?: unknown }).name;
17
+ return typeof name === "string" ? name.trim() : "";
18
+ }
19
+
20
+ import { businessTimeZone } from "./app-locale.js";
21
+ import { formatDateMedium, formatMonthDay, zoneOffsetAt } from "./engine-intl.js";
22
+ import { formatServiceMoney, formatServicePrice, serviceCurrency } from "./wix-service-price.js";
23
+
24
+ const HAS_OFFSET = /(?:Z|[+-]\d{2}:?\d{2})$/i;
25
+ const LOCAL_TIME = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?/;
26
+
27
+ /** The instant (ms) a slot starts. Wix may list a slot's `startDate` as a LOCAL wall time with its
28
+ * `timezone` beside it ("2026-11-02T18:30:00" in America/New_York is 23:30Z); a bare `Date.parse`
29
+ * would read that in the device's zone. So a local time is placed in the slot's own zone when this
30
+ * engine has Intl and knows the zone, and read in the device's zone only when it cannot be. */
31
+ export function slotStartInstant(slot: { startDate?: string; timezone?: unknown }): number {
32
+ const start = slot.startDate ?? "";
33
+ if (!start) return NaN;
34
+ const local = LOCAL_TIME.exec(start);
35
+ if (HAS_OFFSET.test(start) || !local || typeof slot.timezone !== "string" || !slot.timezone) return Date.parse(start);
36
+ const wall = Date.UTC(+local[1], +local[2] - 1, +local[3], +local[4], +local[5], +(local[6] ?? 0));
37
+ const offset = zoneOffsetAt(wall, slot.timezone);
38
+ if (!Number.isFinite(offset)) return Date.parse(start);
39
+ // Once more at the corrected instant, so a wall time beside a DST change lands on the right side.
40
+ const again = zoneOffsetAt(wall - offset, slot.timezone);
41
+ return wall - (Number.isFinite(again) ? again : offset);
42
+ }
43
+
44
+ /** `himi_time` reads the next two weeks. A host's `start` past them (an Agenda session weeks
45
+ * ahead) is read on its own — that session's local day only, never everything up to it — so it
46
+ * can be preselected while each read stays bounded. `undefined` when the start is inside the two
47
+ * weeks. */
48
+ export function availabilityBeyond(now: Date, start = ""): { from: Date; until: Date } | undefined {
49
+ const end = now.getTime() + 14 * 86_400_000;
50
+ const at = start ? Date.parse(start) : NaN;
51
+ if (!Number.isFinite(at) || at < end) return undefined;
52
+ const d = new Date(at);
53
+ const dayStart = new Date(d.getFullYear(), d.getMonth(), d.getDate());
54
+ // Never back into the two weeks already read: a slot in both would be listed twice.
55
+ return { from: new Date(Math.max(dayStart.getTime(), end)), until: new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1) };
56
+ }
57
+
58
+ /** The slot a host asked to open at (`himi_time` input `start`, an ISO 8601 instant): the id of the
59
+ * slot that starts at that same instant, or "" when none does (taken since, or out of the window).
60
+ * Compared as instants, so `…T16:30:00Z` finds a slot listed as `…T18:30:00+02:00`, or as a local
61
+ * `…T18:30:00` beside `timezone: "Asia/Jerusalem"`. */
62
+ export function slotIdAt(slots: Iterable<[string, { startDate?: string; timezone?: unknown }]>, start: string): string {
63
+ const at = start ? Date.parse(start) : NaN;
64
+ if (!Number.isFinite(at)) return "";
65
+ for (const [id, slot] of slots) {
66
+ if (slotStartInstant(slot) === at) return id;
67
+ }
68
+ return "";
69
+ }
70
+
71
+ // ---- Courses ----------------------------------------------------------------------
72
+ // One answer for the service screen's course button and the time screen's course booking, so
73
+ // the button never offers a course that the booking step then refuses.
74
+
75
+ type CoursePolicyShape = {
76
+ /** `timeZone`: the business's IANA zone, for a session time Wix lists as a bare local wall time. */
77
+ schedule?: { id?: string; firstSessionStart?: string; lastSessionEnd?: string; timeZone?: string };
78
+ bookingPolicy?: {
79
+ bookAfterStartPolicy?: { enabled?: boolean };
80
+ limitEarlyBookingPolicy?: { enabled?: boolean; earliestBookingInMinutes?: number };
81
+ limitLateBookingPolicy?: { enabled?: boolean; latestBookingInMinutes?: number };
82
+ };
83
+ };
84
+
85
+ /** A bare local wall time placed in `timeZone`, as an instant (ms). NaN when the value is not a bare local
86
+ * time, has an impossible calendar day, or the engine does not know the zone. */
87
+ function placedInstant(value: string, timeZone: string | undefined): number {
88
+ const local = LOCAL_TIME.exec(value);
89
+ if (HAS_OFFSET.test(value) || !local || !timeZone || !validDate(value)) return NaN;
90
+ const wall = Date.UTC(+local[1], +local[2] - 1, +local[3], +local[4], +local[5], +(local[6] ?? 0));
91
+ const offset = zoneOffsetAt(wall, timeZone);
92
+ if (!Number.isFinite(offset)) return NaN;
93
+ // Once more at the corrected instant, so a wall time beside a DST change lands on the right side.
94
+ const again = zoneOffsetAt(wall - offset, timeZone);
95
+ return wall - (Number.isFinite(again) ? again : offset);
96
+ }
97
+
98
+ /** The zone that places a course's bare local session times: the schedule's own, else the app's
99
+ * provisioned business zone. "" when there is none: a zone is never guessed. */
100
+ const courseZone = (schedule: { timeZone?: string } | undefined): string => schedule?.timeZone || businessTimeZone();
101
+
102
+ /** The instant (ms) of a course session time, for the "Ended" label. A time with an offset is exact. A
103
+ * bare local wall time is the BUSINESS's wall time, so it is placed in its zone — never in the device's,
104
+ * which would present another zone's clock as a confirmed instant. No zone, a date-only value, an
105
+ * impossible calendar day or an engine that does not know the zone: unknown (NaN). */
106
+ function sessionInstant(value: string, timeZone: string | undefined): number {
107
+ return HAS_OFFSET.test(value) ? validDate(value)?.getTime() ?? NaN : placedInstant(value, timeZone);
108
+ }
109
+
110
+ /** The same instant for the booking rules (window, read range): a bare local time the business zone can
111
+ * place is placed there, so the list label, the service screen and the time screen agree. Everything else
112
+ * keeps the read they always had (`Date.parse`), so an app with no provisioned zone is unchanged. */
113
+ function courseInstant(value: string | undefined, timeZone: string | undefined): number {
114
+ const text = value ?? "";
115
+ const placed = placedInstant(text, timeZone);
116
+ return Number.isFinite(placed) ? placed : Date.parse(text);
117
+ }
118
+
119
+ /** A completed course, independent of whether bookings are currently allowed. Missing,
120
+ * invalid or reversed dates are unknown, never evidence that a course has ended. A session time
121
+ * without an offset counts only when the schedule names the business's `timeZone`. */
122
+ export function courseHasEnded(service: CoursePolicyShape, now: number): boolean {
123
+ const zone = courseZone(service.schedule);
124
+ const first = sessionInstant(service.schedule?.firstSessionStart ?? "", zone);
125
+ const last = sessionInstant(service.schedule?.lastSessionEnd ?? "", zone);
126
+ return Number.isFinite(now) && Number.isFinite(first) && Number.isFinite(last) && first <= last && last <= now;
127
+ }
128
+
129
+ /** Does this course schedule hold a session time that is a bare local wall time, which only the
130
+ * business's zone can place? A caller reads the zone only when this is true. */
131
+ export function courseNeedsZone(schedule: { firstSessionStart?: string; lastSessionEnd?: string } | undefined): boolean {
132
+ return [schedule?.firstSessionStart, schedule?.lastSessionEnd].some((value) => !!value && !HAS_OFFSET.test(value) && LOCAL_TIME.test(value));
133
+ }
134
+
135
+ /** Whether the business takes course bookings at `now` (ms): the course has not ended, has not
136
+ * started (unless the policy lets people join late), and `now` is inside its booking window —
137
+ * which the early and late limits count from the first session. */
138
+ export function courseWindowOpen(service: CoursePolicyShape, now: number): boolean {
139
+ const zone = courseZone(service.schedule);
140
+ const first = courseInstant(service.schedule?.firstSessionStart, zone);
141
+ const last = courseInstant(service.schedule?.lastSessionEnd, zone);
142
+ if (!Number.isFinite(first) || !Number.isFinite(last) || last <= now) return false;
143
+ const policy = service.bookingPolicy;
144
+ if (first < now && policy?.bookAfterStartPolicy?.enabled !== true) return false;
145
+ const early = policy?.limitEarlyBookingPolicy;
146
+ if (early?.enabled && typeof early.earliestBookingInMinutes === "number" && now < first - early.earliestBookingInMinutes * 60_000) return false;
147
+ const late = policy?.limitLateBookingPolicy;
148
+ if (late?.enabled && typeof late.latestBookingInMinutes === "number" && now > first - late.latestBookingInMinutes * 60_000) return false;
149
+ return true;
150
+ }
151
+
152
+ /** How far ahead a course is read: the whole remaining course, up to a year. Both screens read the
153
+ * same sessions — from the later of its first session and now — so the service screen never
154
+ * offers a course that the booking step then refuses on a session the first did not read. */
155
+ export const COURSE_READ_DAYS = 366;
156
+ const DAY = 86_400_000;
157
+
158
+ /** The 14-day availability windows covering a course's remaining sessions, and whether they reach
159
+ * its last session (`complete`) and start at its first (`fromFirst`, so a count is the whole
160
+ * course). Empty when the course has no usable dates or has ended. */
161
+ export function courseReadWindows(service: CoursePolicyShape, now: number, chunkDays = 14): { windows: Array<[number, number]>; complete: boolean; fromFirst: boolean } {
162
+ const zone = courseZone(service.schedule);
163
+ const first = courseInstant(service.schedule?.firstSessionStart, zone);
164
+ const last = courseInstant(service.schedule?.lastSessionEnd, zone);
165
+ if (!Number.isFinite(first) || !Number.isFinite(last)) return { windows: [], complete: false, fromFirst: false };
166
+ const from = Math.max(first, now);
167
+ const courseEnd = last + DAY;
168
+ const until = Math.min(courseEnd, from + COURSE_READ_DAYS * DAY);
169
+ const windows: Array<[number, number]> = [];
170
+ for (let at = from; at < until; at += chunkDays * DAY) windows.push([at, Math.min(until, at + chunkDays * DAY)]);
171
+ return { windows, complete: courseEnd <= until, fromFirst: from === first };
172
+ }
173
+
174
+ type CourseEntryShape = { slot?: { startDate?: string; timezone?: unknown }; bookable?: boolean; openSpots?: number };
175
+
176
+ /** A course across EVERY upcoming session read: a customer books all of them at once, so the
177
+ * smallest open count is the course's, and one session that cannot be booked closes it. A start
178
+ * is read in the session's own zone (`slotStartInstant`). `found` is false when no upcoming
179
+ * session came back: both screens then treat the course as not bookable. So is a course whose
180
+ * read did not reach its last session (`readComplete`, from `courseReadWindows`): a session
181
+ * past the year read may be full, and the course is booked whole. */
182
+ export function courseSessionsAvailability(entries: readonly CourseEntryShape[], now: number, readComplete = true): { found: boolean; spots: number | undefined; bookable: boolean } {
183
+ const upcoming = entries.filter((entry) => {
184
+ const start = entry.slot ? slotStartInstant(entry.slot as { startDate?: string; timezone?: unknown }) : NaN;
185
+ return Number.isFinite(start) && start >= now;
186
+ });
187
+ if (!upcoming.length) return { found: false, spots: undefined, bookable: false };
188
+ const counts = upcoming.map((entry) => entry.openSpots).filter((n): n is number => typeof n === "number" && Number.isFinite(n) && n >= 0);
189
+ const spots = counts.length ? Math.min(...counts) : undefined;
190
+ return { found: true, spots, bookable: readComplete && upcoming.every((entry) => entry.bookable !== false) && spots !== 0 };
191
+ }
192
+
193
+ // ---- Price, duration and course dates ------------------------------------------------
194
+ // One answer for the services list and the service screen, so a row and the screen it opens
195
+ // say the same price and the same length. Each screen reads its own copy keys: the caller
196
+ // passes a `BookingLabel` reader bound to its prefix ("service." on the service screen,
197
+ // "services." on the list).
198
+
199
+ /** Reads one copy line by its key suffix ("priceFree", "days"). `values` fills {placeholders}. */
200
+ export type BookingLabel = (key: string, fallback: string, values?: Record<string, string | number>) => string;
201
+
202
+ type PricedServiceShape = {
203
+ type?: string;
204
+ duration?: unknown;
205
+ payment?: {
206
+ rateType?: unknown;
207
+ fixed?: { price?: unknown };
208
+ varied?: { minPrice?: unknown; defaultPrice?: unknown };
209
+ custom?: { description?: unknown };
210
+ };
211
+ schedule?: {
212
+ firstSessionStart?: string;
213
+ lastSessionEnd?: string;
214
+ availabilityConstraints?: {
215
+ sessionDurations?: unknown[];
216
+ durations?: Array<{ minutes?: unknown } | undefined>;
217
+ durationRange?: {
218
+ hourOptions?: { minDurationInMinutes?: unknown; maxDurationInMinutes?: unknown };
219
+ dayOptions?: { minDurationInDays?: unknown; maxDurationInDays?: unknown };
220
+ };
221
+ };
222
+ };
223
+ };
224
+
225
+ function trimmed(value: unknown): string {
226
+ return typeof value === "string" ? value.trim() : "";
227
+ }
228
+
229
+ function finiteNumber(value: unknown): number | undefined {
230
+ if (typeof value === "number") return Number.isFinite(value) ? value : undefined;
231
+ if (typeof value === "string" && value.trim()) {
232
+ const n = Number(value);
233
+ return Number.isNaN(n) ? undefined : n;
234
+ }
235
+ return undefined;
236
+ }
237
+
238
+ export interface ServicePriceLine { text: string; unit: string; isText: boolean }
239
+
240
+ /** The price line by rate type. FIXED → the price, no cents on a whole amount; VARIED →
241
+ * "From {price}"; CUSTOM → the owner's description, no unit; NO_FEE → "Free", no unit. */
242
+ export function servicePriceLine(service: PricedServiceShape, label: BookingLabel): ServicePriceLine {
243
+ const payment = service.payment ?? {};
244
+ const rate = trimmed(payment.rateType).toUpperCase();
245
+ const currency = serviceCurrency(service);
246
+ const unit = service.type === "COURSE"
247
+ ? label("unitParticipant", "per participant")
248
+ : label("unitSession", "per session");
249
+ if (rate === "NO_FEE") return { text: label("priceFree", "Free"), unit: "", isText: false };
250
+ if (rate === "CUSTOM") return { text: trimmed(payment.custom?.description), unit: "", isText: true };
251
+ if (rate === "VARIED") {
252
+ const from = formatServiceMoney(payment.varied?.minPrice, currency) || formatServiceMoney(payment.varied?.defaultPrice, currency);
253
+ return { text: from ? label("priceFrom", "From {price}", { price: from }) : "", unit: from ? unit : "", isText: false };
254
+ }
255
+ // FIXED, or a legacy payload with no rate type.
256
+ const text = formatServiceMoney(payment.fixed?.price, currency) || formatServicePrice(service);
257
+ return { text, unit: text ? unit : "", isText: false };
258
+ }
259
+
260
+ function minutesText(minutes: number): string {
261
+ if (minutes < 60) return `${minutes} min`;
262
+ const hours = Math.floor(minutes / 60);
263
+ const rest = minutes % 60;
264
+ return rest ? `${hours} hr ${rest} min` : `${hours} hr`;
265
+ }
266
+
267
+ /** "45 min", "1 hr 30 min"; a service with several lengths, or a flexible range the
268
+ * customer picks from: "30 min - 1 hr", "1 day - 3 days". "" when the record has none. */
269
+ export function serviceDurationText(service: PricedServiceShape, label: BookingLabel): string {
270
+ const constraints = service.schedule?.availabilityConstraints;
271
+ const positive = (values: unknown[]) => values.map(finiteNumber).filter((n): n is number => n != null && n > 0);
272
+ const listed = positive([
273
+ ...(constraints?.sessionDurations ?? []),
274
+ ...(constraints?.durations ?? []).map((d) => d?.minutes),
275
+ ]);
276
+ const hours = constraints?.durationRange?.hourOptions;
277
+ const range = positive([hours?.minDurationInMinutes, hours?.maxDurationInMinutes]);
278
+ const days = constraints?.durationRange?.dayOptions;
279
+ const dayRange = positive([days?.minDurationInDays, days?.maxDurationInDays]);
280
+ if (!listed.length && !range.length && dayRange.length) {
281
+ const dayText = (n: number) => (n === 1 ? label("day", "1 day") : label("days", "{n} days", { n }));
282
+ const first = Math.min(...dayRange);
283
+ const last = Math.max(...dayRange);
284
+ return first === last ? dayText(first) : `${dayText(first)} - ${dayText(last)}`;
285
+ }
286
+ const minutes = listed.length ? listed : range.length ? range : positive([service.duration]);
287
+ if (!minutes.length) return "";
288
+ const min = Math.min(...minutes);
289
+ const max = Math.max(...minutes);
290
+ return min === max ? minutesText(min) : `${minutesText(min)} - ${minutesText(max)}`;
291
+ }
292
+
293
+ function validDate(value: string | undefined): Date | undefined {
294
+ if (!value) return undefined;
295
+ const parts = /^(\d{4})-(\d{2})-(\d{2})(?:T|$)/i.exec(value);
296
+ if (!parts) return undefined;
297
+ const year = Number(parts[1]), month = Number(parts[2]) - 1, day = Number(parts[3]);
298
+ // Date accepts February 30 by rolling into March. Check the stated calendar day first;
299
+ // setUTCFullYear also preserves years 0–99, which Date.UTC would reinterpret as 1900–1999.
300
+ const calendar = new Date(0);
301
+ calendar.setUTCFullYear(year, month, day);
302
+ if (calendar.getUTCFullYear() !== year || calendar.getUTCMonth() !== month || calendar.getUTCDate() !== day) return undefined;
303
+ const date = new Date(value);
304
+ return Number.isFinite(date.getTime()) ? date : undefined;
305
+ }
306
+
307
+ function shortDate(date: Date, year: boolean): string {
308
+ return year ? formatDateMedium(date) : formatMonthDay(date);
309
+ }
310
+
311
+ /** A course's dates, "Nov 3 – Dec 15, 2026" (the year on the first date only when the two
312
+ * differ). "" when the record has no first or last session. */
313
+ export function courseDatesText(service: PricedServiceShape): string {
314
+ const first = validDate(service.schedule?.firstSessionStart);
315
+ const last = validDate(service.schedule?.lastSessionEnd);
316
+ if (!first || !last) return "";
317
+ return `${shortDate(first, first.getFullYear() !== last.getFullYear())} – ${shortDate(last, true)}`;
318
+ }