@wix/himalaya-cli 0.1871.0 → 0.1872.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 (180) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-module.d.ts +3 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/portfolio/src/index.d.ts +19 -0
  3. package/dist/cli.mjs +89 -39
  4. package/fixtures/wix-canned.json +8 -0
  5. package/guides/release-notes.md +18 -0
  6. package/guides/sdk-reference.json +8 -1
  7. package/package.json +2 -2
  8. package/template-icons/professional-services.png +0 -0
  9. package/templates/bare-fashion/config.ts +37 -2
  10. package/templates/bare-fashion/dev/index.ts +4006 -48
  11. package/templates/bare-fashion/himalaya.content.json +15 -0
  12. package/templates/bare-fashion/tier5-src/_shared/member-account-routes.ts +56 -0
  13. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  14. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  15. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  16. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  17. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  18. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  19. package/templates/branded-lite/dev/index.ts +2 -1
  20. package/templates/branded-lite/tier5-src/_shared/portfolio-details.ts +70 -0
  21. package/templates/branded-lite/tier5-src/himi-branded-lite-coupons/index.ts +13 -2
  22. package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
  23. package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
  24. package/templates/branded-lite/tier5-src/himi-events-list/index.ts +5 -1
  25. package/templates/community-club/tier5-src/himi-events-list/index.ts +5 -1
  26. package/templates/conference/config.ts +43 -1
  27. package/templates/conference/dev/index.ts +4127 -0
  28. package/templates/conference/himalaya.content.json +18 -0
  29. package/templates/conference/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  30. package/templates/conference/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  31. package/templates/conference/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  32. package/templates/conference/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  33. package/templates/conference/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  34. package/templates/conference/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  35. package/templates/conference/tier5-src/himi-events-list/index.ts +5 -1
  36. package/templates/conference/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  37. package/templates/events-meetups/tier5-src/himi-events-list/index.ts +5 -1
  38. package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +5 -1
  39. package/templates/medical-services/config.ts +42 -0
  40. package/templates/medical-services/dev/index.ts +4136 -0
  41. package/templates/medical-services/himalaya.content.json +18 -0
  42. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  43. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  44. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  45. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  46. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  47. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  48. package/templates/medical-services/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  49. package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +5 -1
  50. package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +5 -1
  51. package/templates/portfolio-creative/dev/index.ts +2 -1
  52. package/templates/portfolio-creative/tier5-src/_shared/portfolio-details.ts +70 -0
  53. package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
  54. package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
  55. package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +5 -1
  56. package/templates/professional-services/README.md +55 -0
  57. package/templates/professional-services/config.ts +436 -0
  58. package/templates/professional-services/dev/index.ts +44772 -0
  59. package/templates/professional-services/himalaya.content.json +100 -0
  60. package/templates/professional-services/himalaya.template.json +16 -0
  61. package/templates/professional-services/icon.png +0 -0
  62. package/templates/professional-services/platforms.json +1 -0
  63. package/templates/professional-services/tier5-src/_shared/app-locale.ts +70 -0
  64. package/templates/professional-services/tier5-src/_shared/booking-location.ts +147 -0
  65. package/templates/professional-services/tier5-src/_shared/booking-session.ts +224 -0
  66. package/templates/professional-services/tier5-src/_shared/branded-lite-hosted.ts +282 -0
  67. package/templates/professional-services/tier5-src/_shared/branded-load-state.ts +109 -0
  68. package/templates/professional-services/tier5-src/_shared/business-chat-copy.ts +40 -0
  69. package/templates/professional-services/tier5-src/_shared/business-chat-history.ts +51 -0
  70. package/templates/professional-services/tier5-src/_shared/business-chat-message-model.ts +177 -0
  71. package/templates/professional-services/tier5-src/_shared/business-chat-model.ts +56 -0
  72. package/templates/professional-services/tier5-src/_shared/business-chat-presenter.ts +587 -0
  73. package/templates/professional-services/tier5-src/_shared/business-chat-transport.ts +164 -0
  74. package/templates/professional-services/tier5-src/_shared/chat-live.ts +242 -0
  75. package/templates/professional-services/tier5-src/_shared/collection-contract.ts +232 -0
  76. package/templates/professional-services/tier5-src/_shared/collection-query.ts +201 -0
  77. package/templates/professional-services/tier5-src/_shared/collection-service.ts +429 -0
  78. package/templates/professional-services/tier5-src/_shared/detail-presence.ts +51 -0
  79. package/templates/professional-services/tier5-src/_shared/engine-intl.ts +538 -0
  80. package/templates/professional-services/tier5-src/_shared/event-registration.ts +86 -0
  81. package/templates/professional-services/tier5-src/_shared/events-inline-options.ts +77 -0
  82. package/templates/professional-services/tier5-src/_shared/faq-list.ts +405 -0
  83. package/templates/professional-services/tier5-src/_shared/featured-event.ts +63 -0
  84. package/templates/professional-services/tier5-src/_shared/group-member-count.ts +15 -0
  85. package/templates/professional-services/tier5-src/_shared/group-privacy.ts +14 -0
  86. package/templates/professional-services/tier5-src/_shared/guest-sign-in.ts +36 -0
  87. package/templates/professional-services/tier5-src/_shared/himi-account.ts +222 -0
  88. package/templates/professional-services/tier5-src/_shared/himi-blog-hidden.ts +66 -0
  89. package/templates/professional-services/tier5-src/_shared/himi-blog-post-row.ts +214 -0
  90. package/templates/professional-services/tier5-src/_shared/himi-blog-saved.ts +64 -0
  91. package/templates/professional-services/tier5-src/_shared/himi-booking-saved.ts +88 -0
  92. package/templates/professional-services/tier5-src/_shared/himi-bookings.ts +318 -0
  93. package/templates/professional-services/tier5-src/_shared/himi-copy.ts +123 -0
  94. package/templates/professional-services/tier5-src/_shared/himi-events.ts +92 -0
  95. package/templates/professional-services/tier5-src/_shared/himi-media.ts +33 -0
  96. package/templates/professional-services/tier5-src/_shared/himi-store.ts +7 -0
  97. package/templates/professional-services/tier5-src/_shared/himi-text.ts +24 -0
  98. package/templates/professional-services/tier5-src/_shared/host-events.ts +66 -0
  99. package/templates/professional-services/tier5-src/_shared/hosted-checkout.ts +70 -0
  100. package/templates/professional-services/tier5-src/_shared/iap-attendance-form.ts +106 -0
  101. package/templates/professional-services/tier5-src/_shared/iap-attendance-purchase.ts +235 -0
  102. package/templates/professional-services/tier5-src/_shared/iap-attendance.ts +38 -0
  103. package/templates/professional-services/tier5-src/_shared/iap-worker.ts +127 -0
  104. package/templates/professional-services/tier5-src/_shared/inbox-rooms.ts +163 -0
  105. package/templates/professional-services/tier5-src/_shared/local-preferences.ts +38 -0
  106. package/templates/professional-services/tier5-src/_shared/member-access.ts +63 -0
  107. package/templates/professional-services/tier5-src/_shared/member-account-routes.ts +56 -0
  108. package/templates/professional-services/tier5-src/_shared/member-avatar.ts +76 -0
  109. package/templates/professional-services/tier5-src/_shared/member-bookings.ts +107 -0
  110. package/templates/professional-services/tier5-src/_shared/member-read.ts +82 -0
  111. package/templates/professional-services/tier5-src/_shared/member-screen.ts +99 -0
  112. package/templates/professional-services/tier5-src/_shared/notification-target.ts +141 -0
  113. package/templates/professional-services/tier5-src/_shared/offset-page.ts +10 -0
  114. package/templates/professional-services/tier5-src/_shared/online-actions.ts +76 -0
  115. package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +348 -0
  116. package/templates/professional-services/tier5-src/_shared/payment-setup.ts +6 -0
  117. package/templates/professional-services/tier5-src/_shared/portfolio-details.ts +70 -0
  118. package/templates/professional-services/tier5-src/_shared/pricing-plan-display.ts +64 -0
  119. package/templates/professional-services/tier5-src/_shared/relative-time.ts +21 -0
  120. package/templates/professional-services/tier5-src/_shared/result-snackbar.ts +26 -0
  121. package/templates/professional-services/tier5-src/_shared/rich-body.ts +78 -0
  122. package/templates/professional-services/tier5-src/_shared/rich-content-link.ts +34 -0
  123. package/templates/professional-services/tier5-src/_shared/sign-in-sheet.ts +18 -0
  124. package/templates/professional-services/tier5-src/_shared/staff-name.ts +18 -0
  125. package/templates/professional-services/tier5-src/_shared/weekly-goal.ts +111 -0
  126. package/templates/professional-services/tier5-src/_shared/wix-bi.ts +85 -0
  127. package/templates/professional-services/tier5-src/_shared/wix-member-links.ts +114 -0
  128. package/templates/professional-services/tier5-src/_shared/wix-service-price.ts +146 -0
  129. package/templates/professional-services/tier5-src/business-chat/index.ts +797 -0
  130. package/templates/professional-services/tier5-src/business-contact/index.ts +6 -0
  131. package/templates/professional-services/tier5-src/himi-blog-feed/index.ts +444 -0
  132. package/templates/professional-services/tier5-src/himi-blog-post/index.ts +1239 -0
  133. package/templates/professional-services/tier5-src/himi-booking-account/index.ts +278 -0
  134. package/templates/professional-services/tier5-src/himi-booking-bookings/index.ts +475 -0
  135. package/templates/professional-services/tier5-src/himi-booking-service/index.ts +1197 -0
  136. package/templates/professional-services/tier5-src/himi-booking-services/index.ts +795 -0
  137. package/templates/professional-services/tier5-src/himi-booking-time/index.ts +1840 -0
  138. package/templates/professional-services/tier5-src/himi-branded-lite-coupons/index.ts +96 -0
  139. package/templates/professional-services/tier5-src/himi-branded-lite-faq/index.ts +6 -0
  140. package/templates/professional-services/tier5-src/himi-branded-lite-file-share/index.ts +12 -0
  141. package/templates/professional-services/tier5-src/himi-branded-lite-group/index.ts +310 -0
  142. package/templates/professional-services/tier5-src/himi-branded-lite-group-about/index.ts +240 -0
  143. package/templates/professional-services/tier5-src/himi-branded-lite-my-groups/index.ts +237 -0
  144. package/templates/professional-services/tier5-src/himi-branded-lite-notifications/index.ts +263 -0
  145. package/templates/professional-services/tier5-src/himi-branded-lite-plans/index.ts +498 -0
  146. package/templates/professional-services/tier5-src/himi-branded-lite-portfolio/index.ts +136 -0
  147. package/templates/professional-services/tier5-src/himi-branded-lite-portfolio-project/index.ts +198 -0
  148. package/templates/professional-services/tier5-src/himi-events-detail/index.ts +1306 -0
  149. package/templates/professional-services/tier5-src/himi-events-list/index.ts +171 -0
  150. package/templates/professional-services/tier5-src/himi-events-my-events/index.ts +227 -0
  151. package/templates/professional-services/tier5-src/himi-events-rsvp/index.ts +230 -0
  152. package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts +318 -0
  153. package/templates/professional-services/tier5-src/himi-professional-services-home/index.ts +772 -0
  154. package/templates/professional-services/tier5-src/himi-store-account/index.ts +1514 -0
  155. package/templates/professional-services/tier5-src/wix-spaces-coupon-detail/index.ts +43 -0
  156. package/templates/professional-services/tier5-src/wix-spaces-my-subscriptions/index.ts +89 -0
  157. package/templates/professional-services/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
  158. package/templates/professional-services/tokens.json +456 -0
  159. package/templates/restaurant/tier5-src/himi-events-list/index.ts +5 -1
  160. package/templates/salon-spa/config.ts +42 -0
  161. package/templates/salon-spa/dev/index.ts +4136 -0
  162. package/templates/salon-spa/himalaya.content.json +18 -0
  163. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  164. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  165. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  166. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  167. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  168. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  169. package/templates/salon-spa/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  170. package/templates/wholesale-store/config.ts +43 -1
  171. package/templates/wholesale-store/dev/index.ts +4136 -0
  172. package/templates/wholesale-store/himalaya.content.json +18 -0
  173. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  174. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  175. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  176. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  177. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  178. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  179. package/templates/wholesale-store/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  180. package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +5 -1
@@ -0,0 +1,96 @@
1
+ // himi-branded-lite-coupons — reads the site's real Wix Coupons (queryCoupons).
2
+ // a failed query is an error with Retry (or Sign in when Wix refuses the
3
+ // visitor) and an empty one is a real empty state — never sample rows presented as
4
+ // the customer's own. Samples appear only in the host's explicit sample preview
5
+ // (_shared/branded-load-state.ts).
6
+ import { defineService } from "../_shared/collection-service.js";
7
+ import { LOADING, loaded, loadFailed, needsSignIn, type LoadCopy, type LoadFlags } from "../_shared/branded-load-state.js";
8
+ import { requireMemberRead, memberReadFailure } from "../_shared/member-read.js";
9
+ import { queryCoupons, type WixCoupon } from "@himalaya/wix-coupons";
10
+ import { copyParam, copyTemplate } from "../_shared/himi-copy.js";
11
+ import { isPastDate, formatMonthDay } from "../_shared/engine-intl.js";
12
+
13
+ interface Row { id: string; name: string; subtitle: string }
14
+ interface S extends LoadFlags {
15
+ coupons: Row[]; emptyText: string;
16
+ isMock: boolean; notMock: boolean; /** #2849 — hiddenWhen() hides on TRUE, so these are inverted: the empty-state banner
17
+ * shows only when the site really has none, and the unavailable one only when the
18
+ * query failed. A failed query must never render the sentence that claims the
19
+ * customer has no content. */
20
+ notMockEmpty: boolean; notMockUnavailable: boolean;
21
+ }
22
+
23
+ /** Rows from the live Coupons API. The query returns expired coupons alongside live ones, and the
24
+ * row used to show them identically — an offer that "ended Aug 31" still listed as available in
25
+ * September. An expired row now says so and sinks below the live ones;
26
+ * a live one with an end date says when it ends. Both the flat and the `specification` shape are
27
+ * read, because the stores v2 payload nests the name/code/expiry under `specification`. */
28
+ function norm(c: WixCoupon, now: number): Row & { expired: boolean } {
29
+ const cc = c as unknown as {
30
+ id?: string; name?: string; code?: string; expirationTime?: string; expired?: boolean;
31
+ specification?: { name?: string; code?: string; expirationTime?: string };
32
+ };
33
+ const code = cc.code || cc.specification?.code || "";
34
+ const name = cc.name || cc.specification?.name || code || "Coupon";
35
+ const ends = cc.expirationTime || cc.specification?.expirationTime || "";
36
+ const expired = cc.expired === true || isPastDate(ends, now);
37
+ const endLabel = ends && !Number.isNaN(Date.parse(ends))
38
+ ? copyTemplate("coupons.endsLabel", "ends {date}", { date: formatMonthDay(new Date(ends)) }) : "";
39
+ const status = expired ? copyParam("coupons.expiredLabel", "Expired") : endLabel;
40
+ const subtitle = [code ? copyTemplate("coupons.codeLabel", "Code: {code}", { code }) : "", status].filter(Boolean).join(" · ");
41
+ return { id: cc.id || code || "coupon", name, subtitle, expired };
42
+ }
43
+
44
+ /** Live offers first, expired ones after — stable within each group. */
45
+ export function couponRows(coupons: WixCoupon[], now: number = Date.now()): Row[] {
46
+ const rows = coupons.map((c) => norm(c, now));
47
+ return [...rows.filter((r) => !r.expired), ...rows.filter((r) => r.expired)].map(({ expired: _e, ...row }) => row);
48
+ }
49
+
50
+ // Sample rows carry no dates and no currency: a hardcoded "ends Aug 31" went stale the day after,
51
+ // and "$10 off" read as the wrong currency on a ₪ site.
52
+ const MOCK: Row[] = [
53
+ { id: "sample-welcome15", name: "Welcome — 15% off your first order", subtitle: "Code: WELCOME15" },
54
+ { id: "sample-freeship", name: "Free shipping", subtitle: "Code: FREESHIP · on eligible orders" },
55
+ { id: "sample-flash20", name: "Weekend flash — 20% off", subtitle: "Code: FLASH20 · this weekend only" },
56
+ { id: "sample-loyal10", name: "Loyalty reward — 10% off", subtitle: "Code: LOYAL10 · members only" },
57
+ ];
58
+
59
+ /** sample rows reach the screen ONLY in the host's explicit sample preview;
60
+ * a failed or empty query is an honest error / empty state (branded-load-state.ts). */
61
+ const COPY: LoadCopy<Row> = {
62
+ prefix: "coupons",
63
+ empty: "No offers right now — check back soon.",
64
+ error: "Offers couldn't be loaded.",
65
+ signIn: "Sign in to see offers available to you.",
66
+ sample: () => MOCK.map((r) => ({ ...r })),
67
+ };
68
+
69
+ const svc = defineService<S, { load: (s: S) => Promise<S> }>("himiBrandedCoupons", {
70
+ state: { ...LOADING, coupons: [], emptyText: "" },
71
+ actions: {
72
+ load: async (s) => {
73
+ try {
74
+ await requireMemberRead();
75
+ const r = await queryCoupons({ paging: { limit: 30 } } as never);
76
+ const coupons = couponRows(((r as unknown as { coupons?: WixCoupon[] }).coupons) ?? []);
77
+ return { ...s, ...loaded("coupons", coupons, COPY) };
78
+ } catch (err) {
79
+ const failure = await memberReadFailure(err);
80
+ // Wix answers a SIGNED-IN member 401 too ("Reading coupons is not permitted": coupons are
81
+ // readable by the site's owner only). Signing in cannot fix that, so the member sees that
82
+ // offers are not shown here, never a Sign in button while signed in. A visitor's
83
+ // failure is memberReadFailure's sign-in error and keeps its Sign in path.
84
+ if (failure === err && needsSignIn(err)) {
85
+ const next = loaded("coupons", [] as Row[], COPY);
86
+ // The owner's sample preview fills the list: its rows speak for themselves, with no empty line beside them.
87
+ if (next.coupons.length) return { ...s, ...next };
88
+ return { ...s, ...next, emptyText: copyParam("coupons.memberUnavailableText", "Offers aren't shown in the app yet.") };
89
+ }
90
+ return { ...s, ...loadFailed("coupons", failure, COPY) };
91
+ }
92
+ },
93
+ },
94
+ });
95
+ svc.load();
96
+ export { svc };
@@ -0,0 +1,6 @@
1
+ // The himi_faq screen's worker: the shared FAQ service under the screen's own service name. The whole worker lives in
2
+ // `_shared/faq-list.ts` so a migrated page can host the same FAQ next to other sections.
3
+ import { registerFaqList } from "../_shared/faq-list.js";
4
+
5
+ export const svc = registerFaqList("himiBrandedFaq");
6
+ export { sectionsFor, httpStatus, parseStaticFaq } from "../_shared/faq-list.js";
@@ -0,0 +1,12 @@
1
+ // himi-branded-lite-file-share — branded-lite "Documents" worker (Wix File Share).
2
+ //
3
+ // The worker is the shared `createFileShareService` from `@himalaya/screens`, the same service any
4
+ // generated app imports, so the File Share contract lives in one place. Branded Lite adds only its
5
+ // copy pack: the descriptor bakes the provisioned `fileShare.*` overrides into the onAppear params,
6
+ // and every service string is read through `copyParam`.
7
+ import { createFileShareService } from "@himalaya/screens";
8
+ import { copyParam, stashCopy } from "../_shared/himi-copy.js";
9
+
10
+ const svc = createFileShareService({ service: "himiBrandedFileShare", text: copyParam, onAppearArgs: stashCopy });
11
+
12
+ export { svc };
@@ -0,0 +1,310 @@
1
+ import { withOnlineWrites } from "../_shared/online-actions.js";
2
+ import { defineService as registerService } from "@himalaya/state";
3
+ import { getGroup, joinGroup, leaveGroup, queryMembers as queryGroupMembers, type WixGroup } from "@himalaya/wix-groups";
4
+ import { getMember } from "@himalaya/wix-members";
5
+ import { signedInEmail } from "../_shared/himi-account";
6
+ import { initials } from "../_shared/himi-text.js";
7
+ import { groupImage } from "../_shared/himi-media.js";
8
+ import { WIX_DETAIL_IMAGE } from "@himalaya/wix-media";
9
+ import { copyParam, stashCopy } from "../_shared/himi-copy.js";
10
+ import { cachedMemberCount, groupMemberCount } from "../_shared/group-member-count.js";
11
+ import { groupPrivacyLabel } from "../_shared/group-privacy.js";
12
+ import { get as dbGet, upsert as dbUpsert, type DbEntity } from "@himalaya/local-db";
13
+ import { isOfflineFailure, writeMayHaveLanded } from "../_shared/owner-load-error";
14
+ import { descriptionBody } from "../_shared/rich-body.js";
15
+ import { openRichLink } from "../_shared/rich-content-link.js";
16
+
17
+ interface MemberAvatar {
18
+ initials: string;
19
+ imageUrl: string;
20
+ }
21
+
22
+ // Offline-first (data-offline): the group detail READS through the shared `groups`
23
+ // cache (get by id) so a previously-synced group still renders offline. Join/leave
24
+ // are SERVER-CONFIRMED: the cached membership changes only after Wix accepts it; a
25
+ // failed one leaves it alone and tells the member why. No host replays a queued
26
+ // write, so nothing is queued.
27
+ // Every local-db call is wrapped so a build without the `local_database` grant
28
+ // behaves exactly as before (online-only).
29
+ const ENTITY = "groups";
30
+ async function readCachedGroup(id: string): Promise<DbEntity | null> {
31
+ try { return await dbGet(ENTITY, id); } catch { return null; }
32
+ }
33
+ async function cachePutMembership(state: State, joined: boolean): Promise<void> {
34
+ try {
35
+ // Merge onto the list's cached GroupRow when present (preserving its shape), or
36
+ // seed a list-compatible row so both list and detail render this group offline.
37
+ // WS-C — canonical param-less detail screenId, matching the groups list rows.
38
+ const existing = (await dbGet(ENTITY, state.id)) ?? {
39
+ id: state.id,
40
+ title: state.name,
41
+ subtitle: state.description,
42
+ count: state.memberTotal,
43
+ image: state.image,
44
+ initial: state.initial,
45
+ hasImage: state.hasImage,
46
+ noImage: state.noImage,
47
+ detailScreenId: "himi_group",
48
+ };
49
+ await dbUpsert(ENTITY, { ...existing, id: state.id, description: state.description,
50
+ descriptionJson: state.descriptionJson, joined: joined ? "true" : "false" });
51
+ } catch { /* capability not granted */ }
52
+ }
53
+
54
+ interface State {
55
+ status: "loading" | "ready" | "error";
56
+ id: string;
57
+ name: string;
58
+ description: string;
59
+ descriptionJson: string;
60
+ hasDescriptionJson: boolean;
61
+ /** The privacy label as painted (copy-pack translated); never compared, see `privacyKind`. */
62
+ privacy: string;
63
+ /** The raw status the label was made from (`public`, `private`, `secret`, `unknown`, …): what join logic reads. */
64
+ privacyKind: string;
65
+ memberCount: string;
66
+ /** The raw count behind `memberCount`, written to the offline cache instead of the label. */
67
+ memberTotal: number | null;
68
+ /** Member avatar strip (photo or initials per member) — best-effort: the
69
+ * per-group members query + member profile resolution both degrade to an
70
+ * empty (collapsed) strip, never a failed screen. */
71
+ memberAvatars: MemberAvatar[];
72
+ hasMemberAvatars: boolean;
73
+ noMemberAvatars: boolean;
74
+ image: string;
75
+ initial: string;
76
+ message: string;
77
+ hasImage: boolean;
78
+ noImage: boolean;
79
+ isLoading: boolean;
80
+ notLoading: boolean;
81
+ isErrored: boolean;
82
+ notErrored: boolean;
83
+ isJoined: boolean;
84
+ notJoined: boolean;
85
+ canJoin: boolean;
86
+ cannotJoin: boolean;
87
+ canLeave: boolean;
88
+ cannotLeave: boolean;
89
+ needsSignIn: boolean;
90
+ noSignIn: boolean;
91
+ hideContent: boolean;
92
+ }
93
+
94
+ function inputId(): string {
95
+ // WS-C — `himalaya.input.id` is the PRIMARY contract: hosts thread the row's
96
+ // `id` nav param (himi.open { screenId: "himi_group", id }) into worker input.
97
+ const input = (globalThis as { himalaya?: { input?: { id?: string; screenId?: string } } }).himalaya?.input;
98
+ if (input?.id) return input.id;
99
+ // #570 back-compat for pre-params releases with baked `himi_group_<id>`
100
+ // screenIds — do not author against this.
101
+ return input?.screenId?.startsWith("himi_group_") ? input.screenId.slice("himi_group_".length) : "";
102
+ }
103
+
104
+ function membershipState(state: State, joined: boolean, signedIn: boolean): State {
105
+ const isPublic = state.privacyKind === "public" || state.privacyKind === "unknown";
106
+ return {
107
+ ...state,
108
+ isJoined: joined,
109
+ notJoined: !joined,
110
+ canJoin: !joined && signedIn && isPublic,
111
+ cannotJoin: joined || !signedIn || !isPublic,
112
+ canLeave: joined && signedIn,
113
+ cannotLeave: !joined || !signedIn,
114
+ needsSignIn: !signedIn,
115
+ noSignIn: signedIn,
116
+ };
117
+ }
118
+
119
+ /** Up-to-5 member avatars for the strip: per-group member ids resolved to
120
+ * profile nickname/photo via the Members API. Fully best-effort. */
121
+ async function memberAvatarsOf(groupId: string): Promise<MemberAvatar[]> {
122
+ try {
123
+ const response = await queryGroupMembers(groupId, 5);
124
+ const ids = (response.members ?? [])
125
+ .map((member) => member.memberId ?? member.siteMemberId ?? "")
126
+ .filter(Boolean)
127
+ .slice(0, 5);
128
+ if (!ids.length) return [];
129
+ const resolved = await Promise.allSettled(ids.map((memberId) => getMember(memberId)));
130
+ return resolved
131
+ .map((result) => (result.status === "fulfilled" ? result.value.member : undefined))
132
+ .filter((member): member is NonNullable<typeof member> => Boolean(member))
133
+ .map((member) => ({
134
+ initials: initials(member.profile?.nickname || member.contact?.firstName || "Member"),
135
+ imageUrl: member.profile?.photo?.url ?? "",
136
+ }));
137
+ } catch {
138
+ return [];
139
+ }
140
+ }
141
+
142
+ const initial: State = {
143
+ status: "loading",
144
+ id: "",
145
+ name: "",
146
+ description: "",
147
+ descriptionJson: "",
148
+ hasDescriptionJson: false,
149
+ privacy: "",
150
+ privacyKind: "",
151
+ memberCount: "",
152
+ memberTotal: null,
153
+ memberAvatars: [],
154
+ hasMemberAvatars: false,
155
+ noMemberAvatars: true,
156
+ image: "",
157
+ initial: "G",
158
+ message: "",
159
+ hasImage: false,
160
+ noImage: true,
161
+ isLoading: true,
162
+ notLoading: false,
163
+ isErrored: false,
164
+ notErrored: true,
165
+ isJoined: false,
166
+ notJoined: true,
167
+ canJoin: false,
168
+ cannotJoin: true,
169
+ canLeave: false,
170
+ cannotLeave: true,
171
+ needsSignIn: false,
172
+ noSignIn: true,
173
+ hideContent: true,
174
+ };
175
+
176
+ const defineService = withOnlineWrites(registerService, ["join","leave"]);
177
+ const svc = defineService<State, {
178
+ load: (state: State, arg?: unknown) => Promise<State>;
179
+ join: (state: State) => Promise<State>;
180
+ leave: (state: State) => Promise<State>;
181
+ openLink: (state: State, arg?: unknown) => Promise<undefined>;
182
+ }>("himiBrandedGroup", {
183
+ state: initial,
184
+ actions: {
185
+ load: async (state, arg) => {
186
+ stashCopy(arg);
187
+ const id = inputId();
188
+ if (!id) return { ...state, status: "error", isLoading: false, notLoading: true, isErrored: true, notErrored: false };
189
+ try {
190
+ const response = await getGroup(id);
191
+ const group = ((response as unknown as { group?: WixGroup }).group ?? response) as WixGroup;
192
+ const name = (group.name || copyParam("group.groupFallbackName", "Group")).trim();
193
+ const image = groupImage(group, WIX_DETAIL_IMAGE);
194
+ const count = group.membersCount ?? group.memberCount;
195
+ const privacy = (group.privacyStatus || "UNKNOWN").toLowerCase();
196
+ const privacyLabel = groupPrivacyLabel(privacy);
197
+ const signedIn = Boolean(await signedInEmail());
198
+ const memberAvatars = await memberAvatarsOf(id);
199
+ const body = descriptionBody(group.description, descriptionBody(group.teaser,
200
+ copyParam("group.descriptionFallback", "Join this group to connect with other members.")).bodyText);
201
+ const loaded: State = {
202
+ ...state,
203
+ status: "ready",
204
+ id,
205
+ name,
206
+ description: body.bodyText,
207
+ descriptionJson: body.bodyJson,
208
+ hasDescriptionJson: body.bodyJson !== "",
209
+ privacy: privacyLabel,
210
+ privacyKind: privacy,
211
+ memberCount: count == null ? "" : groupMemberCount(count),
212
+ memberTotal: count ?? null,
213
+ memberAvatars,
214
+ hasMemberAvatars: memberAvatars.length > 0,
215
+ noMemberAvatars: memberAvatars.length === 0,
216
+ image,
217
+ initial: (name[0] || "G").toUpperCase(),
218
+ message: privacy === "public" || privacy === "unknown" ? "" : copyParam("group.privateInviteMessage", "Private groups are available by invitation."),
219
+ hasImage: Boolean(image),
220
+ noImage: !image,
221
+ isLoading: false,
222
+ notLoading: true,
223
+ isErrored: false,
224
+ notErrored: true,
225
+ hideContent: false,
226
+ };
227
+ return membershipState(loaded, false, signedIn);
228
+ } catch {
229
+ // Offline: render the last-synced group row from the shared `groups` cache.
230
+ const cached = await readCachedGroup(id);
231
+ if (cached) {
232
+ const name = (String(cached.title ?? cached.name ?? "Group")).trim() || "Group";
233
+ const image = String(cached.image ?? "");
234
+ const signedIn = Boolean(await signedInEmail());
235
+ const body = descriptionBody(cached.descriptionJson || cached.description || cached.subtitle,
236
+ copyParam("group.descriptionFallback", "Join this group to connect with other members."));
237
+ const loaded: State = {
238
+ ...state,
239
+ status: "ready",
240
+ id,
241
+ name,
242
+ description: body.bodyText,
243
+ descriptionJson: body.bodyJson,
244
+ hasDescriptionJson: body.bodyJson !== "",
245
+ privacy: groupPrivacyLabel("unknown"),
246
+ privacyKind: "unknown",
247
+ memberCount: cachedMemberCount(cached.count),
248
+ memberTotal: typeof cached.count === "number" ? cached.count : null,
249
+ image,
250
+ initial: (name[0] || "G").toUpperCase(),
251
+ message: "",
252
+ hasImage: Boolean(image),
253
+ noImage: !image,
254
+ isLoading: false,
255
+ notLoading: true,
256
+ isErrored: false,
257
+ notErrored: true,
258
+ hideContent: false,
259
+ };
260
+ return membershipState(loaded, cached.joined === "true", signedIn);
261
+ }
262
+ return { ...state, id, status: "error", isLoading: false, notLoading: true, isErrored: true, notErrored: false, hideContent: true };
263
+ }
264
+ },
265
+ openLink: async (_state, arg) => { await openRichLink(arg); return undefined; },
266
+ join: async (state) => {
267
+ const signedIn = Boolean(await signedInEmail());
268
+ if (!signedIn) return membershipState({ ...state, message: copyParam("group.joinSignInMessage", "Sign in from Profile to join groups.") }, false, false);
269
+ if (state.privacyKind !== "public" && state.privacyKind !== "unknown") {
270
+ return membershipState({ ...state, message: copyParam("group.privateInviteMessage", "Private groups are available by invitation.") }, false, true);
271
+ }
272
+ try {
273
+ await joinGroup(state.id);
274
+ // Wix confirmed it: persist the joined membership so it survives offline.
275
+ await cachePutMembership(state, true);
276
+ return membershipState({ ...state, message: copyParam("group.joinedMessage", "You joined the group.") }, true, true);
277
+ } catch (e) {
278
+ if (isOfflineFailure(e)) {
279
+ return membershipState({ ...state, message: copyParam("group.offlineFailedMessage", "You’re offline — nothing was saved. Try again when you reconnect.") }, false, true);
280
+ }
281
+ // It may have landed: neither "joined" nor "could not". (No "refresh to check": a load
282
+ // does not read the membership back.)
283
+ if (writeMayHaveLanded(e)) {
284
+ return membershipState({ ...state, message: copyParam("group.joinUnconfirmedMessage", "Wix didn’t confirm this, so you may already have joined the group.") }, false, true);
285
+ }
286
+ return membershipState({ ...state, message: copyParam("group.joinFailedMessage", "The group could not be joined. Try again.") }, false, true);
287
+ }
288
+ },
289
+ leave: async (state) => {
290
+ const signedIn = Boolean(await signedInEmail());
291
+ if (!signedIn) return membershipState({ ...state, message: copyParam("group.manageSignInMessage", "Sign in from Profile to manage groups.") }, state.isJoined, false);
292
+ try {
293
+ await leaveGroup(state.id);
294
+ // Wix confirmed it: persist the left membership so it survives offline.
295
+ await cachePutMembership(state, false);
296
+ return membershipState({ ...state, message: copyParam("group.leftMessage", "You left the group.") }, false, true);
297
+ } catch (e) {
298
+ if (isOfflineFailure(e)) {
299
+ return membershipState({ ...state, message: copyParam("group.offlineFailedMessage", "You’re offline — nothing was saved. Try again when you reconnect.") }, true, true);
300
+ }
301
+ if (writeMayHaveLanded(e)) {
302
+ return membershipState({ ...state, message: copyParam("group.leaveUnconfirmedMessage", "Wix didn’t confirm this, so you may already have left the group.") }, true, true);
303
+ }
304
+ return membershipState({ ...state, message: copyParam("group.leaveFailedMessage", "The group could not be left. Try again.") }, true, true);
305
+ }
306
+ },
307
+ },
308
+ });
309
+
310
+ export { svc };
@@ -0,0 +1,240 @@
1
+ import { defineService } from "@himalaya/state";
2
+ import { getGroup, listRules, type WixGroup, type WixGroupRule } from "@himalaya/wix-groups";
3
+ import { WIX_DETAIL_IMAGE } from "@himalaya/wix-media";
4
+ import { copyParam, stashCopy } from "../_shared/himi-copy.js";
5
+ import { groupMemberCount } from "../_shared/group-member-count.js";
6
+ import { groupPrivacyLabel } from "../_shared/group-privacy.js";
7
+ import { groupImage } from "../_shared/himi-media.js";
8
+ import { descriptionBody } from "../_shared/rich-body.js";
9
+ import { openRichLink } from "../_shared/rich-content-link.js";
10
+ import { formatDateMedium } from "../_shared/engine-intl.js";
11
+
12
+ // The About & rules page of ONE group. The group is `input.id`, never a fallback: a missing
13
+ // id is an error, not "the first group". The group read and the rules read are independent —
14
+ // the page renders the group's own facts when only the rules read failed, and says so in the
15
+ // rules region, so a rules outage is never shown as "this group has no rules".
16
+ //
17
+ // Read-only and online-only: no write exists on this page, so there is nothing to queue.
18
+
19
+ interface RuleRow {
20
+ id: string;
21
+ number: string;
22
+ title: string;
23
+ description: string;
24
+ }
25
+
26
+ type Failure = "forbidden" | "missing" | "failed";
27
+
28
+ interface State {
29
+ status: "loading" | "ready" | "error";
30
+ id: string;
31
+ name: string;
32
+ description: string;
33
+ descriptionJson: string;
34
+ hasDescriptionJson: boolean;
35
+ privacy: string;
36
+ createdDate: string;
37
+ memberCount: string;
38
+ image: string;
39
+ initial: string;
40
+ rules: RuleRow[];
41
+ /** The group read failed: the whole page says why. */
42
+ errorText: string;
43
+ /** The rules read alone failed: only the rules region says why. */
44
+ rulesErrorText: string;
45
+ hideLoading: boolean;
46
+ hideError: boolean;
47
+ hideContent: boolean;
48
+ hideImage: boolean;
49
+ hidePrivacy: boolean;
50
+ hideCreated: boolean;
51
+ hideMemberCount: boolean;
52
+ hideRules: boolean;
53
+ hideRulesEmpty: boolean;
54
+ hideRulesError: boolean;
55
+ }
56
+
57
+ const initial: State = {
58
+ status: "loading",
59
+ id: "",
60
+ name: "",
61
+ description: "",
62
+ descriptionJson: "",
63
+ hasDescriptionJson: false,
64
+ privacy: "",
65
+ createdDate: "",
66
+ memberCount: "",
67
+ image: "",
68
+ initial: "G",
69
+ rules: [],
70
+ errorText: "",
71
+ rulesErrorText: "",
72
+ hideLoading: false,
73
+ hideError: true,
74
+ hideContent: true,
75
+ hideImage: true,
76
+ hidePrivacy: true,
77
+ hideCreated: true,
78
+ hideMemberCount: true,
79
+ hideRules: true,
80
+ hideRulesEmpty: true,
81
+ hideRulesError: true,
82
+ };
83
+
84
+ /** Bumped by every group load, so a response that arrives after a newer load began is dropped. */
85
+ let loadSeq = 0;
86
+
87
+ function inputId(): string {
88
+ // `himalaya.input.id` is the contract: hosts thread the opener's `id` nav param
89
+ // (himi.open { screenId: "himi_group_about", id }) into worker input.
90
+ const input = (globalThis as { himalaya?: { input?: { id?: string } } }).himalaya?.input;
91
+ return typeof input?.id === "string" ? input.id : "";
92
+ }
93
+
94
+ function failureOf(e: unknown): Failure {
95
+ const message = String((e as Error)?.message ?? e);
96
+ if (/HTTP (401|403)\b/.test(message)) return "forbidden";
97
+ if (/HTTP 404\b/.test(message)) return "missing";
98
+ return "failed";
99
+ }
100
+
101
+ function groupFailureText(failure: Failure): string {
102
+ if (failure === "forbidden") return copyParam("groupAbout.forbiddenTitle", "You can’t view this group’s details.");
103
+ if (failure === "missing") return copyParam("groupAbout.missingTitle", "This group no longer exists.");
104
+ return copyParam("groupAbout.errorTitle", "This group’s details could not be loaded.");
105
+ }
106
+
107
+ function rulesFailureText(failure: Failure): string {
108
+ if (failure === "forbidden") return copyParam("groupAbout.rulesForbidden", "You can’t view this group’s rules.");
109
+ return copyParam("groupAbout.rulesError", "The rules could not be loaded.");
110
+ }
111
+
112
+ /** The rules the server sent, numbered from 1. `undefined` when the answer is not a rules list
113
+ * at all — a missing or non-array `rules` is a malformed answer, not an empty group. */
114
+ function ruleRowsOf(response: unknown): RuleRow[] | undefined {
115
+ const rules = (response as { rules?: unknown } | null | undefined)?.rules;
116
+ if (!Array.isArray(rules)) return undefined;
117
+ const rows: RuleRow[] = [];
118
+ for (const entry of rules as WixGroupRule[]) {
119
+ const title = typeof entry?.title === "string" ? entry.title.trim() : "";
120
+ const description = typeof entry?.description === "string" ? entry.description.trim() : "";
121
+ if (!title && !description) continue;
122
+ rows.push({ id: `rule_${rows.length + 1}`, number: String(rows.length + 1), title, description });
123
+ }
124
+ return rows;
125
+ }
126
+
127
+ function withRules(state: State, rules: RuleRow[] | undefined, failure: Failure | undefined): State {
128
+ if (failure || !rules) {
129
+ return {
130
+ ...state,
131
+ rules: [],
132
+ rulesErrorText: rulesFailureText(failure ?? "failed"),
133
+ hideRules: true,
134
+ hideRulesEmpty: true,
135
+ hideRulesError: false,
136
+ };
137
+ }
138
+ return {
139
+ ...state,
140
+ rules,
141
+ rulesErrorText: "",
142
+ hideRules: rules.length === 0,
143
+ hideRulesEmpty: rules.length > 0,
144
+ hideRulesError: true,
145
+ };
146
+ }
147
+
148
+ function createdLabel(value: unknown): string {
149
+ if (typeof value !== "string" || !value) return "";
150
+ const date = new Date(value);
151
+ return Number.isNaN(date.getTime()) ? "" : formatDateMedium(date);
152
+ }
153
+
154
+ function groupState(state: State, id: string, group: WixGroup): State {
155
+ const name = (group.name || (group as { title?: string }).title || copyParam("group.groupFallbackName", "Group")).trim();
156
+ const body = descriptionBody(group.description, descriptionBody(group.teaser, "").bodyText);
157
+ const privacy = groupPrivacyLabel(group.privacyStatus ?? "");
158
+ const created = createdLabel(group.createdDate);
159
+ const count = group.membersCount ?? group.memberCount;
160
+ const image = groupImage(group, WIX_DETAIL_IMAGE);
161
+ return {
162
+ ...state,
163
+ status: "ready",
164
+ id,
165
+ name,
166
+ description: body.bodyText,
167
+ descriptionJson: body.bodyJson,
168
+ hasDescriptionJson: body.bodyJson !== "",
169
+ privacy,
170
+ createdDate: created,
171
+ memberCount: typeof count === "number" ? groupMemberCount(count) : "",
172
+ image,
173
+ initial: (name[0] || "G").toUpperCase(),
174
+ errorText: "",
175
+ hideLoading: true,
176
+ hideError: true,
177
+ hideContent: false,
178
+ hideImage: !image,
179
+ hidePrivacy: !privacy,
180
+ hideCreated: !created,
181
+ hideMemberCount: typeof count !== "number",
182
+ };
183
+ }
184
+
185
+ function groupErrorState(id: string, failure: Failure): State {
186
+ return {
187
+ ...initial,
188
+ id,
189
+ status: "error",
190
+ errorText: groupFailureText(failure),
191
+ hideLoading: true,
192
+ hideError: false,
193
+ hideContent: true,
194
+ };
195
+ }
196
+
197
+ const svc = defineService<State, {
198
+ load: (state: State, arg?: unknown) => Promise<State | undefined>;
199
+ reloadRules: (state: State, arg?: unknown) => Promise<State | undefined>;
200
+ openLink: (state: State, arg?: unknown) => Promise<undefined>;
201
+ }>("himiBrandedGroupAbout", {
202
+ state: initial,
203
+ actions: {
204
+ load: async (state, arg) => {
205
+ stashCopy(arg);
206
+ const seq = ++loadSeq;
207
+ const id = inputId();
208
+ if (!id) return groupErrorState("", "missing");
209
+ const [groupResult, rulesResult] = await Promise.allSettled([getGroup(id), listRules(id)]);
210
+ // A newer load began while these reads were in flight: its answer owns the state.
211
+ if (seq !== loadSeq) return undefined;
212
+ if (groupResult.status === "rejected") return groupErrorState(id, failureOf(groupResult.reason));
213
+ // Social Groups wraps the entity as `{ group }`; the typed signature claims a bare group.
214
+ const group = ((groupResult.value as unknown as { group?: WixGroup }).group ?? groupResult.value) as WixGroup;
215
+ if (!group || typeof group !== "object" || (group.id && group.id !== id)) return groupErrorState(id, "failed");
216
+ const ready = groupState(state, id, group);
217
+ return rulesResult.status === "rejected"
218
+ ? withRules(ready, undefined, failureOf(rulesResult.reason))
219
+ : withRules(ready, ruleRowsOf(rulesResult.value), undefined);
220
+ },
221
+ // Retry for the rules region alone: the group's own facts stay on screen.
222
+ reloadRules: async (state, arg) => {
223
+ stashCopy(arg);
224
+ const id = state.id;
225
+ if (!id) return undefined;
226
+ const seq = loadSeq;
227
+ try {
228
+ const rules = ruleRowsOf(await listRules(id));
229
+ if (seq !== loadSeq || inputId() !== id) return undefined;
230
+ return withRules(state, rules, undefined);
231
+ } catch (e) {
232
+ if (seq !== loadSeq || inputId() !== id) return undefined;
233
+ return withRules(state, undefined, failureOf(e));
234
+ }
235
+ },
236
+ openLink: async (_state, arg) => { await openRichLink(arg); return undefined; },
237
+ },
238
+ });
239
+
240
+ export { svc };