@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,495 @@
1
+ import { memberAccess } from "../_shared/member-access.js";
2
+ import { planDuration } from "../_shared/pricing-plan-display.js";
3
+ import { detailInputId } from "../_shared/detail-presence.js";
4
+ import { descriptionBody } from "../_shared/rich-body.js";
5
+ import { paymentSetupMessage } from "../_shared/payment-setup.js";
6
+ import { offlineWriteMessage, offlineWritesEnabled, withOnlineWrites } from "../_shared/online-actions.js";
7
+ import { connectivity } from "@himalaya/state";
8
+ import { defineService as registerService } from "../_shared/collection-service.js";
9
+ import { createOnlineOrder, listPublicPlans, type WixPlan } from "@himalaya/wix-pricing-plans";
10
+ import { createRedirectSession } from "@himalaya/wix-redirects";
11
+ import { open as openUrl } from "@himalaya/open-url";
12
+ import { session as wixPlatformSession } from "@himalaya/wix-platform";
13
+ import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
14
+ import { activePlanIds, entitlement, isPaymentSetupFailure, payCashierOrder } from "@himalaya/checkout";
15
+ import { hostSessionFromGlobal, iapPriceFields, type IapCatalogItem } from "@himalaya/iap";
16
+ import { applePlanPeriod, createIapCommerce, isAppleSellablePlan, pricingPlanOrders } from "@himalaya/iap-checkout";
17
+ import { iapPriceCopy, iapPurchaseCopy, resetUnhydratedKeysOnOlderRuntime } from "../_shared/iap-worker.js";
18
+ import { formatCurrency } from "../_shared/engine-intl.js";
19
+ import { isHostedWorker, hostedSitePageOpener } from "../_shared/hosted-checkout.js";
20
+
21
+ /** Wix Pricing Plans appDefId — the vertical that owns a plan order, so the `appId` its
22
+ * cashier order is paid under (mirrors AppDefId.PRICING_PLANS in Wix's RN apps). */
23
+ const WIX_PRICING_PLANS_APP_ID = "1522827f-c56c-a5c9-2ac9-00f9e6ae12d3";
24
+
25
+ /** metaSiteId for the cashier payment config; "" is tolerated (the native cashier can
26
+ * resolve it from the app's signed Wix session). */
27
+ async function resolveMsid(): Promise<string> {
28
+ try {
29
+ const st = await wixPlatformSession.signedInstanceStatus();
30
+ return st.msid ?? "";
31
+ } catch {
32
+ return "";
33
+ }
34
+ }
35
+
36
+ interface PlanRow {
37
+ id: string;
38
+ name: string;
39
+ /** Plan description (owner-authored pitch) — collapses when absent. */
40
+ description: string;
41
+ /** "N-day free trial" badge from pricing.freeTrialDays — collapses at 0. */
42
+ trialBadge: string;
43
+ noTrialBadge: boolean;
44
+ /** Formatted price, e.g. "$29". */
45
+ priceLine: string;
46
+ /** Cadence / validity line, e.g. "per month" / "one-time". */
47
+ periodLine: string;
48
+ /** First 3 benefit strings (also flattened below for `$item.` bindings). */
49
+ perks: string[];
50
+ benefitRows: Array<{ id: string; text: string }>;
51
+ expanded: boolean; benefitsCollapsed: boolean; benefitsState: string;
52
+ validity: string;
53
+ terms: string;
54
+ noTerms: boolean;
55
+ noBenefits: boolean;
56
+ perk1: string;
57
+ perk2: string;
58
+ perk3: string;
59
+ /** "Popular" for the site's primary plan; "" otherwise. */
60
+ badge: string;
61
+ noBadge: boolean;
62
+ /** Inverse of noBadge — primary Join weight only on the recommended plan. */
63
+ hasBadge: boolean;
64
+ /** Purchasable URL when the plan data carries one; "" otherwise. */
65
+ joinUrl: string;
66
+ /** No price (or a zero price): an online order activates it at once, with nothing to pay. */
67
+ free: boolean;
68
+ joined: boolean;
69
+ appleSupported: boolean;
70
+ /** The App Store period Apple must renew it at ("" for a one-time plan): offered only on a matching price. */
71
+ applePeriod: string;
72
+ joinLabel: string;
73
+ joinDisabled: boolean;
74
+ joinNote: string;
75
+ }
76
+
77
+ interface State {
78
+ status: "loading" | "ready" | "error";
79
+ rows: PlanRow[];
80
+ emptyText: string;
81
+ actionMessage: string;
82
+ hideActionNotice: boolean;
83
+ hideOfflineError: boolean;
84
+ isLoading: boolean;
85
+ notLoading: boolean;
86
+ isErrored: boolean;
87
+ notErrored: boolean;
88
+ hasRows: boolean;
89
+ noRows: boolean;
90
+ noEmpty: boolean;
91
+ detail: PlanRow;
92
+ hideDetail: boolean;
93
+ hideDetailNotFound: boolean;
94
+ paymentUnavailable: boolean;
95
+ paymentAvailable: boolean;
96
+ needsSignIn: boolean;
97
+ noSignIn: boolean;
98
+ }
99
+
100
+ function money(plan: WixPlan): string {
101
+ const price = plan.pricing?.price;
102
+ const raw = price?.value;
103
+ if (raw == null || raw === "" || Number.isNaN(Number(raw))) return "";
104
+ try {
105
+ return price?.currency ? formatCurrency(Number(raw), price.currency) : raw;
106
+ } catch {
107
+ return `${raw}`;
108
+ }
109
+ }
110
+
111
+ function cycleText(count?: number, unit?: string): string {
112
+ const n = count ?? 0;
113
+ const u = (unit || "").toLowerCase();
114
+ if (!n || !u) return "";
115
+ const noun = u.endsWith("s") ? u.slice(0, -1) : u;
116
+ return n === 1 ? `per ${noun}` : `every ${n} ${noun}s`;
117
+ }
118
+
119
+ function period(plan: WixPlan): string {
120
+ const pricing = plan.pricing;
121
+ if (pricing?.subscription?.cycleDuration) {
122
+ const { count, unit } = pricing.subscription.cycleDuration;
123
+ return cycleText(count, unit) || copyParam("plans.periodRecurring", "recurring");
124
+ }
125
+ if (pricing?.singlePaymentForDuration) return copyParam("plans.periodOneTime", "One-time payment");
126
+ if (pricing?.singlePaymentUnlimited) return copyParam("plans.periodOneTime", "One-time payment");
127
+ return "";
128
+ }
129
+
130
+ /** A purchasable URL when the plan payload carries one (none of the documented
131
+ * fields is one today — raw payloads are probed defensively so a future field
132
+ * lights up open_url without a worker change). */
133
+ function joinUrl(plan: WixPlan): string {
134
+ const raw = plan as unknown as Record<string, unknown>;
135
+ for (const key of ["purchaseUrl", "checkoutUrl", "url"]) {
136
+ const value = raw[key];
137
+ if (typeof value === "string" && /^https?:\/\//i.test(value)) return value;
138
+ }
139
+ return "";
140
+ }
141
+
142
+ function isFreePlan(plan: WixPlan): boolean {
143
+ const raw = plan.pricing?.price?.value;
144
+ return raw !== undefined && raw !== "" && Number(raw) === 0;
145
+ }
146
+
147
+ /** Apple sells the plan only on the terms it bills: a recurring plan as a renewing App Store price. Only a
148
+ * settled price says whether it renews; while one reloads, the purchase fields keep the last route. */
149
+ function appleOffered(row: PlanRow, view: { route: string; renews?: true; subscriptionPeriod?: string }): boolean {
150
+ return row.appleSupported && (view.route !== "appleIap" || row.applePeriod === (view.renews ? view.subscriptionPeriod ?? "" : ""));
151
+ }
152
+
153
+ function planRow(plan: WixPlan): PlanRow {
154
+ const name = (plan.name || copyParam("plans.planFallbackName", "Plan")).trim();
155
+ const perks = (plan.perks?.values ?? [])
156
+ .map((perk) => (perk ?? "").trim())
157
+ .filter(Boolean);
158
+ const badge = plan.primary ? copyParam("plans.popularBadge", "Popular") : "";
159
+ const trialDays = plan.pricing?.freeTrialDays ?? 0;
160
+ const trialBadge = trialDays > 0 ? copyTemplate("plans.trialBadge", "{days}-day free trial", { days: trialDays }) : "";
161
+ return {
162
+ id: plan.id || "",
163
+ name,
164
+ description: descriptionBody(plan.description).bodyText,
165
+ trialBadge,
166
+ noTrialBadge: !trialBadge,
167
+ priceLine: money(plan),
168
+ periodLine: period(plan),
169
+ perks,
170
+ benefitRows: perks.map((text, index) => ({ id: `${plan.id}.benefit.${index}`, text })),
171
+ noBenefits: perks.length === 0,
172
+ expanded: false, benefitsCollapsed: true, benefitsState: "collapsed",
173
+ validity: planDuration(plan.pricing),
174
+ terms: (plan as WixPlan & { termsAndConditions?: string }).termsAndConditions ?? "",
175
+ noTerms: !(plan as WixPlan & { termsAndConditions?: string }).termsAndConditions,
176
+ perk1: perks[0] ?? "",
177
+ perk2: perks[1] ?? "",
178
+ perk3: perks[2] ?? "",
179
+ badge,
180
+ noBadge: !badge,
181
+ hasBadge: !!badge,
182
+ joinUrl: joinUrl(plan),
183
+ free: isFreePlan(plan),
184
+ appleSupported: isAppleSellablePlan(plan.pricing),
185
+ applePeriod: applePlanPeriod(plan.pricing),
186
+ joined: false, joinLabel: copyParam("plans.joinCta", "Continue"), joinDisabled: true, joinNote: "",
187
+ };
188
+ }
189
+
190
+ function ready(rows: PlanRow[], actionMessage = ""): State {
191
+ return {
192
+ status: "ready",
193
+ rows,
194
+ emptyText: rows.length ? "" : copyParam("plans.emptyText", "No membership plans are published yet."),
195
+ actionMessage,
196
+ hideActionNotice: !actionMessage || actionMessage === offlineWriteMessage || actionMessage === paymentSetupMessage("plans"),
197
+ hideOfflineError: actionMessage !== offlineWriteMessage,
198
+ isLoading: false,
199
+ notLoading: true,
200
+ isErrored: false,
201
+ notErrored: true,
202
+ hasRows: rows.length > 0,
203
+ noRows: rows.length === 0,
204
+ noEmpty: rows.length > 0,
205
+ detail: planRow({ id: "" }), hideDetail: true, hideDetailNotFound: true, paymentUnavailable: false, paymentAvailable: true, needsSignIn: false, noSignIn: true,
206
+ };
207
+ }
208
+
209
+ function idOf(arg: unknown): string {
210
+ if (typeof arg === "string") return arg;
211
+ const value = (arg as { id?: unknown } | undefined)?.id;
212
+ return typeof value === "string" ? value : "";
213
+ }
214
+
215
+ /** Detail actions carry no live service binding in their arguments. The worker owns the ID. */
216
+ function joinId(state: State, arg: unknown): string {
217
+ const id = idOf(arg);
218
+ const current = detailInputId();
219
+ // Input changes reach the worker before the next load reducer. An old detail
220
+ // can still be painted in that gap; neither its implicit nor explicit ID may charge it.
221
+ if (current) return state.detail.id === current && (!id || id === current) ? current : "";
222
+ return id;
223
+ }
224
+
225
+ const commerce = createIapCommerce({ adapters: [pricingPlanOrders], onChange: () => { void svc.pricingPublish(); } });
226
+ let detailMember = false;
227
+ const expandedPlans = new Set<string>();
228
+ let rows: PlanRow[] = [];
229
+ let items: IapCatalogItem[] = [];
230
+ let message = "";
231
+ let messagePlanId = "";
232
+ let started = false;
233
+ let loading = 0;
234
+ let contentReady = false;
235
+ const joining = new Set<string>();
236
+ /** A hosted paid plan's page is being prepared by the host (one ticket at a time). */
237
+ let hostedPlanOpenInFlight = false;
238
+ const memberSession = hostSessionFromGlobal();
239
+ let regularGeneration = -1;
240
+ let regularAccess = new Set<string>();
241
+
242
+
243
+ function pricedState(state: State): State {
244
+ if (!contentReady) return state;
245
+ const priced = rows.map(row => {
246
+ const reference = { kind: "pricingPlan", id: row.id };
247
+ const view = commerce.pricing.view(reference);
248
+ const price = iapPriceFields(view, iapPriceCopy("plans"));
249
+ const purchase = commerce.purchaseFields(reference, iapPurchaseCopy("plans"));
250
+ const apple = purchase.appleRoute;
251
+ const regularReady = regularGeneration === memberSession.current().generation && (!memberSession.identityBound || memberSession.current().kind === "member");
252
+ const joined = apple ? purchase.accessReady : regularReady && regularAccess.has(row.id);
253
+ return { ...row, expanded: expandedPlans.has(row.id), benefitsCollapsed: !expandedPlans.has(row.id), benefitsState: expandedPlans.has(row.id) ? "expanded" : "collapsed", priceLine: view.route === "disabled" ? row.priceLine : price.priceText,
254
+ periodLine: apple && !view.renews ? price.priceNote : view.route === "regular" || view.route === "disabled" || view.renews ? row.periodLine : "",
255
+ trialBadge: apple || price.actionDisabled ? "" : row.trialBadge,
256
+ validity: apple && !view.renews ? "" : row.validity,
257
+ noTrialBadge: apple || price.actionDisabled || row.noTrialBadge,
258
+ joined,
259
+ joinLabel: joined ? copyParam("plans.joinedLabel", "Current plan") : apple ? purchase.buyLabel : row.joinLabel,
260
+ joinDisabled: joined || (apple ? purchase.buyDisabled || !appleOffered(row, view) : price.actionDisabled || !regularReady) || joining.has(row.id),
261
+ joinNote: apple ? appleOffered(row, view) ? purchase.buyNote : iapPriceCopy("plans").purchaseUnavailable : price.actionNote };
262
+ });
263
+ const detail = priced.find(row => row.id === detailInputId()) ?? null;
264
+ const owned = detailInputId() ? detail?.joined ? detail : undefined : priced.find(row => row.joined);
265
+ const notice = !detailInputId() || messagePlanId === detailInputId() ? message : "";
266
+ const poll = commerce.pollDirective("himiBrandedPlans.iapPoll");
267
+ return { ...state, ...ready(priced, notice || (owned ? copyTemplate("plans.joinedMessage", "You've joined {name}.", { name: owned.name }) : "")), detail: detail ?? planRow({ id: "" }), hideDetail: !detail, hideDetailNotFound: Boolean(detail), paymentUnavailable: notice === paymentSetupMessage("plans"), paymentAvailable: notice !== paymentSetupMessage("plans"), needsSignIn: Boolean(detailInputId()) && !detailMember, noSignIn: !detailInputId() || detailMember, ...(poll ? { _poll: poll } : {}) };
268
+ }
269
+
270
+ async function regularJoinMessage(row: PlanRow, reference: { kind: string; id: string }): Promise<string> {
271
+ const generation = memberSession.current().generation;
272
+ const sourceDetail = detailInputId();
273
+ const isCurrent = (): boolean => generation === memberSession.current().generation && detailInputId() === sourceDetail;
274
+ const mayContinue = (): boolean => isCurrent() && commerce.pricing.continueCheckoutGuard(reference).allowed;
275
+ if (!mayContinue()) return "";
276
+ if (row.joinUrl) {
277
+ try {
278
+ const result = await openUrl(row.joinUrl, "in_app_browser");
279
+ if (result.opened) { return ""; }
280
+ } catch {
281
+ }
282
+ }
283
+ if (!mayContinue()) return "";
284
+ // Hosted inside a host shell (Spaces) a plan cannot be paid in-app: classic Pricing Plans is not on
285
+ // ecom, so the host's member checkout has no checkout to open, and the redirect session needs a
286
+ // headless OAuth client a hosted app does not have. An online order created here would only be
287
+ // left behind as a DRAFT, so none is — the member joins on the site: the HOST opens the site's own
288
+ // plans page signed in as the lent member (`himi.host.memberSitePage {page:"plans"}`), or this
289
+ // message stands when it cannot. A FREE plan has nothing to pay: its online order activates at
290
+ // once, so it still joins in-app.
291
+ if (isHostedWorker() && !row.free) {
292
+ // One host open at a time: the host keeps a single ticket, so a second plan's prepare would replace the
293
+ // first's and drop it. The checkout guard is re-read right before the host opens the page.
294
+ if (hostedPlanOpenInFlight) return "";
295
+ hostedPlanOpenInFlight = true;
296
+ let opened: boolean | "withdrawn";
297
+ try {
298
+ opened = await hostedSitePageOpener({ page: "plans", planId: row.id })(
299
+ async () => mayContinue());
300
+ } finally {
301
+ hostedPlanOpenInFlight = false;
302
+ }
303
+ if (!isCurrent()) return "";
304
+ if (opened === "withdrawn") return "";
305
+ if (opened === true) {
306
+ return copyTemplate("plans.continueOnSiteMessage", "Finish joining {name} on the site.", { name: row.name });
307
+ }
308
+ return copyTemplate("plans.joinOnSiteMessage", "Memberships are purchased on the website — visit the site to join {name}.", { name: row.name });
309
+ }
310
+ // A link may fail to open. Its fallback becomes a write and needs its own preflight.
311
+ if (!mayContinue()) return "";
312
+ if (offlineWritesEnabled && !connectivity().online) return offlineWriteMessage;
313
+ try {
314
+ const created = await createOnlineOrder(row.id);
315
+ const snapshotId = created.purchaseFlowId;
316
+ if (!isCurrent()) return "";
317
+ if (created.order?.status === "ACTIVE") {
318
+ regularAccess.add(row.id);
319
+ return copyTemplate("plans.joinedMessage", "You've joined {name}.", { name: row.name });
320
+ }
321
+ const pay = await payCashierOrder({
322
+ appId: WIX_PRICING_PLANS_APP_ID,
323
+ snapshotId: snapshotId ?? "",
324
+ msid: await resolveMsid(),
325
+ mayCharge: mayContinue,
326
+ cashierUrl: async () => {
327
+ if (!mayContinue()) return undefined;
328
+ const redirect = await createRedirectSession({
329
+ paidPlansCheckout: { planId: row.id },
330
+ callbacks: { postFlowUrl: "himalaya-himi-branded-lite://screen/himi_plans" },
331
+ });
332
+ return mayContinue() ? redirect.redirectSession?.fullUrl : undefined;
333
+ },
334
+ });
335
+ if (pay.kind === "paid") {
336
+ const access = await entitlement(row.id);
337
+ if (!isCurrent()) return "";
338
+ if (access.entitled) regularAccess.add(row.id);
339
+ return access.entitled
340
+ ? copyTemplate("plans.joinedMessage", "You've joined {name}.", { name: row.name })
341
+ : copyParam("plans.purchaseProcessingText", "Processing your purchase…");
342
+ }
343
+ if (pay.kind === "handoff") { return ""; }
344
+ if (pay.kind === "cancelled") {
345
+ return copyParam("plans.joinCancelledMessage", "Payment cancelled — you haven't joined.");
346
+ }
347
+ if (isPaymentSetupFailure(pay)) return paymentSetupMessage("plans");
348
+ } catch (error) {
349
+ if (isPaymentSetupFailure(error)) return paymentSetupMessage("plans");
350
+ }
351
+ return copyTemplate("plans.joinOnSiteMessage", "Memberships are purchased on the website — visit the site to join {name}.", { name: row.name });
352
+ }
353
+
354
+ const defineService = withOnlineWrites<State>(registerService, ["join"], {
355
+ messageFields: ["actionMessage"],
356
+ derive: state => ({ ...state, hideActionNotice: true, hideOfflineError: false }),
357
+ requiresConnectivity: (_action, state: State, arg) => {
358
+ const row = state.rows.find(candidate => candidate.id === joinId(state, arg));
359
+ if (!row || commerce.purchaseFields({ kind: "pricingPlan", id: row.id }, iapPurchaseCopy("plans")).appleRoute) return true;
360
+ return !row.joinUrl && !(isHostedWorker() && !row.free);
361
+ },
362
+ });
363
+ const svc = defineService<State, {
364
+ beginDetailLoad: (state: State) => State;
365
+ load: (state: State, arg?: unknown) => Promise<State | undefined>;
366
+ pricingPublish: (state: State) => State;
367
+ pricingRefresh: (state: State) => Promise<undefined>;
368
+ iapPoll: (state: State) => Promise<undefined>;
369
+ toggleBenefits: (state: State, arg?: unknown) => State;
370
+ join: (state: State, arg?: unknown) => Promise<State | undefined>;
371
+ }>("himiBrandedPlans", {
372
+ state: {
373
+ status: "loading",
374
+ rows: [],
375
+ emptyText: "",
376
+ actionMessage: "",
377
+ hideActionNotice: true,
378
+ hideOfflineError: true,
379
+ isLoading: true,
380
+ notLoading: false,
381
+ isErrored: false,
382
+ notErrored: true,
383
+ hasRows: false,
384
+ noRows: true,
385
+ noEmpty: true,
386
+ detail: planRow({ id: "" }), hideDetail: true, hideDetailNotFound: true, paymentUnavailable: false, paymentAvailable: true, needsSignIn: false, noSignIn: true,
387
+ },
388
+ notHydrated: ["rows", "actionMessage", "detail", "hideDetail", "hideDetailNotFound"],
389
+ actions: {
390
+ beginDetailLoad: state => ({ ...state, status: "loading", isLoading: true, notLoading: false,
391
+ notErrored: true, isErrored: false, noEmpty: true, detail: planRow({ id: "" }),
392
+ hideDetail: true, hideDetailNotFound: true, actionMessage: "", hideActionNotice: true, hideOfflineError: true }),
393
+ toggleBenefits: (state, arg) => {
394
+ const id = idOf(arg);
395
+ if (expandedPlans.has(id)) expandedPlans.delete(id); else expandedPlans.add(id);
396
+ return pricedState(state);
397
+ },
398
+ pricingPublish: pricedState,
399
+ pricingRefresh: async () => { await commerce.loadPrices(items); return undefined; },
400
+ iapPoll: async () => { await commerce.poll(); void svc.pricingPublish(); return undefined; },
401
+ load: async (state, arg) => {
402
+ stashCopy(arg);
403
+ const seq = ++loading;
404
+ if (detailInputId() && state.detail.id !== detailInputId()) {
405
+ contentReady = false;
406
+ void svc.beginDetailLoad();
407
+ }
408
+ const generation = memberSession.current().generation;
409
+ regularGeneration = -1;
410
+ regularAccess = new Set();
411
+ try {
412
+ const [response, member] = await Promise.all([listPublicPlans(), detailInputId() ? memberSession.identityBound ? Promise.resolve(memberSession.current().kind === "member") : memberAccess().then(value => Boolean(value.email)) : Promise.resolve(false)]);
413
+ if (seq !== loading || generation !== memberSession.current().generation) return undefined;
414
+ detailMember = member;
415
+ message = "";
416
+ contentReady = true;
417
+ rows = (response.plans ?? []).filter(plan => !plan.archived).map(planRow);
418
+ items = rows.map(row => ({ reference: { kind: "pricingPlan", id: row.id }, commerceDisplayPrice: row.priceLine }));
419
+ void svc.pricingPublish();
420
+ const access = rows.length > 0 && memberSession.current().kind === "member" ? await activePlanIds() : [];
421
+ if (seq !== loading || generation !== memberSession.current().generation) return undefined;
422
+ regularAccess = new Set(access);
423
+ regularGeneration = generation;
424
+ await commerce.loadPrices(items);
425
+ await (started ? commerce.reconcile() : commerce.start());
426
+ if (seq !== loading || generation !== memberSession.current().generation) return undefined;
427
+ started = true;
428
+ void svc.pricingPublish();
429
+ return undefined;
430
+ } catch {
431
+ if (seq !== loading || generation !== memberSession.current().generation) return undefined;
432
+ contentReady = false;
433
+ // Bridge errors (e.g. a 501 from a serve bridge without the route) land
434
+ // here — a graceful error card with retry, never a dead screen.
435
+ return {
436
+ ...state,
437
+ status: "error",
438
+ isLoading: false,
439
+ notLoading: true,
440
+ isErrored: true,
441
+ notErrored: false,
442
+ noEmpty: true,
443
+ detail: planRow({ id: "" }), hideDetail: true, hideDetailNotFound: true,
444
+ };
445
+ }
446
+ },
447
+ join: async (state, arg) => {
448
+ const row = state.rows.find((candidate) => candidate.id === joinId(state, arg));
449
+ if ((detailInputId() && !detailMember) || !row || joining.has(row.id)) return undefined;
450
+ const reference = { kind: "pricingPlan", id: row.id };
451
+ const purchase = commerce.purchaseFields(reference, iapPurchaseCopy("plans"));
452
+ if (purchase.accessReady) return undefined;
453
+ if (purchase.appleRoute) {
454
+ if (!appleOffered(row, commerce.pricing.view(reference))) return undefined;
455
+ await commerce.buy({ reference });
456
+ void svc.pricingPublish();
457
+ return undefined;
458
+ }
459
+ if (regularGeneration !== memberSession.current().generation || (memberSession.identityBound && memberSession.current().kind !== "member") || regularAccess.has(row.id) || !commerce.pricing.checkoutGuard(reference).allowed) return undefined;
460
+ joining.add(row.id);
461
+ void svc.pricingPublish();
462
+ const generation = memberSession.current().generation;
463
+ try {
464
+ const outcome = await regularJoinMessage(row, reference);
465
+ // An older plan's completion must not replace the current detail's notice.
466
+ if (generation === memberSession.current().generation && (!detailInputId() || detailInputId() === row.id)) {
467
+ message = outcome;
468
+ messagePlanId = row.id;
469
+ }
470
+ return undefined;
471
+ } finally {
472
+ joining.delete(row.id);
473
+ void svc.pricingPublish();
474
+ }
475
+ },
476
+ },
477
+ });
478
+
479
+ // Kick the first load at module scope, like every other list bundle
480
+ // (himi-store-shop, himi-booking-services, himi-events-list, himi-blog-feed …).
481
+ // Relying on the descriptor's onAppear alone left the screen pinned on its
482
+ // loading skeleton indefinitely on iOS. onAppear still fires afterwards and
483
+ // re-loads with the screen's copy pack; it passes no required params here
484
+ // (`appear(..., undefined, "<prefix>.")`), so a param-less first load is safe.
485
+ resetUnhydratedKeysOnOlderRuntime(svc, { ...svc.getState(), rows: [], actionMessage: "", detail: planRow({ id: "" }), hideDetail: true, hideDetailNotFound: true }, ["rows", "actionMessage", "detail", "hideDetail", "hideDetailNotFound"]);
486
+ memberSession.subscribe(() => {
487
+ message = "";
488
+ detailMember = false;
489
+ regularGeneration = -1;
490
+ regularAccess = new Set();
491
+ void svc.pricingPublish();
492
+ void svc.load();
493
+ });
494
+ svc.load();
495
+ export { svc };
@@ -0,0 +1,52 @@
1
+ import type { WixProgramFull } from "@himalaya/wix-online-programs";
2
+ import { copyParam } from "../_shared/himi-copy.js";
3
+ import { formatDateMedium } from "../_shared/engine-intl.js";
4
+
5
+ export interface ProgramFact { id: string; icon: string; title: string; body: string }
6
+
7
+ /** Only explicit Program fields establish a fact. Missing access is never public. */
8
+ export function programFacts(program: WixProgramFull, locale: string): ProgramFact[] {
9
+ const facts: ProgramFact[] = [];
10
+ const timeline = program.timeline;
11
+ if (timeline?.selfPaced === true) facts.push({
12
+ id: "pace", icon: "clock",
13
+ title: copyParam("program.facts.selfPacedTitle", "Self-paced"),
14
+ body: copyParam("program.facts.selfPacedBody", "Complete steps at your own pace."),
15
+ });
16
+ else if (timeline?.selfPaced === false) facts.push({
17
+ id: "pace", icon: "clock",
18
+ title: copyParam("program.facts.scheduledTitle", "Scheduled"),
19
+ body: copyParam("program.facts.scheduledBody", "Follow the program schedule."),
20
+ });
21
+
22
+ const rawStart = timeline?.startDate;
23
+ // A date-only field is a calendar day, not midnight in the viewer's time zone. Build it at LOCAL noon and
24
+ // format it in the local zone: that reads the same day with ECMA-402 and on engines without it (watch/Wear),
25
+ // whose fallback ignores a timeZone argument and reads local getters.
26
+ const dateOnly = typeof rawStart === "string" ? /^(\d{4})-(\d{2})-(\d{2})$/.exec(rawStart.trim()) : null;
27
+ const date = dateOnly ? new Date(Number(dateOnly[1]), Number(dateOnly[2]) - 1, Number(dateOnly[3]), 12)
28
+ : typeof rawStart === "string" && rawStart.trim() ? new Date(rawStart) : undefined;
29
+ if (date && Number.isFinite(date.getTime())) {
30
+ let body: string;
31
+ try { body = formatDateMedium(date, locale); }
32
+ catch { body = formatDateMedium(date, "en"); }
33
+ facts.push({ id: "start", icon: "calendar", title: copyParam("program.facts.fixedStartTitle", "Fixed start date"), body });
34
+ } else if (timeline?.selfPaced === true && (rawStart === undefined || rawStart === "")) facts.push({
35
+ id: "start", icon: "calendar",
36
+ title: copyParam("program.facts.flexibleStartTitle", "Flexible start date"),
37
+ body: copyParam("program.facts.flexibleStartBody", "Start whenever you're ready."),
38
+ });
39
+
40
+ const access = program.restrictions?.accessType?.toUpperCase();
41
+ if (access === "PUBLIC") facts.push({
42
+ id: "access", icon: "globe",
43
+ title: copyParam("program.facts.publicTitle", "Public"),
44
+ body: copyParam("program.facts.publicBody", "Anyone can join."),
45
+ });
46
+ else if (access === "PRIVATE") facts.push({
47
+ id: "access", icon: "lock",
48
+ title: copyParam("program.facts.privateTitle", "Private"),
49
+ body: copyParam("program.facts.privateBody", "Approval is required to join."),
50
+ });
51
+ return facts;
52
+ }