@wix/himalaya-cli 0.1661.0 → 0.1663.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 (73) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +17 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/audio-record/src/index.d.ts +4 -1
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +26 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/members-v1/src/index.d.ts +26 -0
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +3 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +8 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-members.mjs +4 -0
  8. package/dist/browser-plane/assets.json +5 -5
  9. package/dist/browser-plane/preview-deferred/{fcafca348b6b973cfc2eadc938ddec3c515c641874cbca1667a43b22e1bf7a39.bin → 5fe817d61d13666ee8e6951d96a873f768ef305462735f6030cce105f1c21488.bin} +1 -1
  10. package/dist/browser-plane/sw.js +8 -8
  11. package/dist/cli.mjs +1147 -731
  12. package/dist/preview-assets.generated.bin +0 -0
  13. package/fixtures/wix-canned.json +1 -0
  14. package/guides/component-reference.json +13 -4
  15. package/guides/component-reference.md +26 -6
  16. package/guides/himi-json-output.md +8 -0
  17. package/guides/index.json +1 -1
  18. package/guides/one-app-section-mappings.md +3 -4
  19. package/guides/one-app-to-himi-app.md +20 -1
  20. package/guides/sdk-reference.json +24 -1
  21. package/package.json +2 -2
  22. package/templates/beauty-salon/recipes/announcement-card.json +72 -0
  23. package/templates/beauty-salon/tier5-src/_shared/announcement-section.ts +122 -0
  24. package/templates/beauty-salon/tier5-src/_shared/engine-intl.ts +8 -0
  25. package/templates/beauty-salon-owner/tier5-src/_shared/engine-intl.ts +8 -0
  26. package/templates/branded-lite/dev/index.ts +791 -169
  27. package/templates/branded-lite/l10n/en.json +46 -13
  28. package/templates/branded-lite/l10n/he.json +59 -7
  29. package/templates/branded-lite/recipes/announcement-card.json +72 -0
  30. package/templates/branded-lite/tier5-src/_shared/announcement-section.ts +122 -0
  31. package/templates/branded-lite/tier5-src/_shared/engine-intl.ts +8 -0
  32. package/templates/branded-lite/tier5-src/wix-spaces-member-detail/index.ts +367 -63
  33. package/templates/community-club/l10n/he.json +2 -2
  34. package/templates/community-club/recipes/announcement-card.json +72 -0
  35. package/templates/community-club/tier5-src/_shared/announcement-section.ts +122 -0
  36. package/templates/community-club/tier5-src/_shared/engine-intl.ts +8 -0
  37. package/templates/community-club-owner/tier5-src/_shared/engine-intl.ts +8 -0
  38. package/templates/conference/tier5-src/_shared/engine-intl.ts +8 -0
  39. package/templates/events-meetups/recipes/announcement-card.json +72 -0
  40. package/templates/events-meetups/tier5-src/_shared/announcement-section.ts +122 -0
  41. package/templates/events-meetups/tier5-src/_shared/engine-intl.ts +8 -0
  42. package/templates/events-meetups-owner/tier5-src/_shared/engine-intl.ts +8 -0
  43. package/templates/gym-fitness/recipes/announcement-card.json +72 -0
  44. package/templates/gym-fitness/tier5-src/_shared/announcement-section.ts +122 -0
  45. package/templates/gym-fitness/tier5-src/_shared/engine-intl.ts +8 -0
  46. package/templates/gym-fitness-owner/tier5-src/_shared/engine-intl.ts +8 -0
  47. package/templates/nonprofit-cause/recipes/announcement-card.json +72 -0
  48. package/templates/nonprofit-cause/tier5-src/_shared/announcement-section.ts +122 -0
  49. package/templates/nonprofit-cause/tier5-src/_shared/engine-intl.ts +8 -0
  50. package/templates/nonprofit-cause-owner/tier5-src/_shared/engine-intl.ts +8 -0
  51. package/templates/owner-lite/tier5-src/_shared/engine-intl.ts +8 -0
  52. package/templates/podcast-creator/recipes/announcement-card.json +72 -0
  53. package/templates/podcast-creator/tier5-src/_shared/announcement-section.ts +122 -0
  54. package/templates/podcast-creator/tier5-src/_shared/engine-intl.ts +8 -0
  55. package/templates/podcast-creator-owner/tier5-src/_shared/engine-intl.ts +8 -0
  56. package/templates/portfolio-creative/recipes/announcement-card.json +72 -0
  57. package/templates/portfolio-creative/tier5-src/_shared/announcement-section.ts +122 -0
  58. package/templates/portfolio-creative/tier5-src/_shared/engine-intl.ts +8 -0
  59. package/templates/portfolio-creative-owner/tier5-src/_shared/engine-intl.ts +8 -0
  60. package/templates/restaurant/recipes/announcement-card.json +72 -0
  61. package/templates/restaurant/tier5-src/_shared/announcement-section.ts +122 -0
  62. package/templates/restaurant/tier5-src/_shared/engine-intl.ts +8 -0
  63. package/templates/restaurant-owner/tier5-src/_shared/engine-intl.ts +8 -0
  64. package/templates/retail-store/recipes/announcement-card.json +72 -0
  65. package/templates/retail-store/tier5-src/_shared/announcement-section.ts +122 -0
  66. package/templates/retail-store/tier5-src/_shared/engine-intl.ts +8 -0
  67. package/templates/retail-store-owner/tier5-src/_shared/engine-intl.ts +8 -0
  68. package/templates/salon-spa/tier5-src/_shared/engine-intl.ts +8 -0
  69. package/templates/wholesale-store/tier5-src/_shared/engine-intl.ts +8 -0
  70. package/templates/yoga-studio/recipes/announcement-card.json +72 -0
  71. package/templates/yoga-studio/tier5-src/_shared/announcement-section.ts +122 -0
  72. package/templates/yoga-studio/tier5-src/_shared/engine-intl.ts +8 -0
  73. package/templates/yoga-studio-owner/tier5-src/_shared/engine-intl.ts +8 -0
@@ -1,93 +1,283 @@
1
1
  // Tier-5 bundle: Wix Spaces clone — Member detail (ON-DEVICE, site-scoped, REAL writes).
2
- // himalaya.input.id carries the member id; fetched via getMember. The Follow control is
3
- // two-state and reflects the live relationship: load() reads getFollowCounts +
4
- // isFollowingMember (each defensively, so a 403 never blanks the screen), and
5
- // toggleFollow flips it via the real Members v3 MemberFollowers API.
6
- import { defineService } from "@himalaya/state";
2
+ // himalaya.input.id carries the member id. load() reads the header first (getMember, the only read that
3
+ // can fail the screen), then About, badges and posts in parallel: each secondary read hides its own
4
+ // section when it fails or comes back empty, and never touches the header or the buttons.
5
+ // The Follow control reflects the live relationship (getFollowCounts + isFollowingMember, each read
6
+ // defensively, so a 403 never blanks the screen); toggleFollow writes through the real Members v3
7
+ // MemberFollowers API. A visitor never writes: Follow opens sign-in (the descriptor routes it).
8
+ import { classifyLoadError, defineService } from "@himalaya/state";
9
+ import { share as shareSheet } from "@himalaya/share";
7
10
  import {
8
11
  getMember,
9
12
  followMember,
10
13
  unfollowMember,
11
14
  getFollowCounts,
12
15
  isFollowingMember,
16
+ queryMemberAbouts,
13
17
  type WixMember,
14
18
  } from "@himalaya/wix-members";
15
- import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
19
+ import { query as queryBadges, queryBadgeAssignments } from "@himalaya/wix-badges";
20
+ import { queryPosts as queryBlogPosts, type WixPost as WixBlogPost } from "@himalaya/wix-blog";
21
+ import { queryPosts as queryForumPosts, type WixPost as WixForumPost } from "@himalaya/wix-forum";
22
+ import { wixMediaUrl } from "@himalaya/wix-media";
23
+ import { formatDateMedium, formatMonthYear } from "../_shared/engine-intl.js";
24
+ import { appLocale } from "../_shared/app-locale.js";
25
+ import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
26
+ import { presence, presenceAfterError, detailInputId, isNotFoundError, type PresenceFlags } from "../_shared/detail-presence.js";
16
27
 
17
- import { readAccess, assertReadAccess, readSignInFlags, NO_READ_SIGN_IN, type ReadAccess } from "../_shared/member-read.js";
28
+ import { readAccess, assertReadAccess, readAccessDenied, readSignInFlags, NO_READ_SIGN_IN, type ReadAccess } from "../_shared/member-read.js";
29
+
30
+ const POST_LIMIT = 3;
31
+ const POST_IMAGE = { width: 192, height: 192, quality: 85 }; // 64 pt rows at 3x.
32
+
33
+ interface PostRow {
34
+ id: string;
35
+ title: string;
36
+ meta: string;
37
+ thumb: string;
38
+ }
39
+ interface BadgeRow { id: string; title: string }
18
40
 
19
41
  interface S extends PresenceFlags {
20
42
  signInRequired: boolean; noSignIn: boolean;
21
43
  status: "loading" | "ready";
22
44
  id: string;
23
45
  name: string;
24
- email: string;
25
46
  initial: string;
26
- subtitle: string;
27
47
  photo: string;
28
- followHint: string;
48
+ joined: string;
49
+ hasJoined: boolean;
50
+ slug: string;
51
+ shareUrl: string;
52
+ /** Hides the top-bar Share action once a loaded member turns out to have no public profile page. */
53
+ noShare: boolean;
29
54
  isFollowing: boolean;
30
55
  followers: number | null;
31
56
  following: number | null;
32
- followLabel: string;
33
57
  followCount: string;
58
+ /** "Follow" / "Following ✓": the wix-spaces-clone fixture binds its follow control to it. */
59
+ followLabel: string;
60
+ followBusy: boolean;
61
+ /** True for a visitor: Follow and Message open sign-in instead of acting. */
62
+ isGuest: boolean;
63
+ /** `server` or `offline`, only meaningful while the load has failed. */
64
+ errorVariant: string;
65
+ hasAbout: boolean;
66
+ aboutJson: string;
67
+ hasBadges: boolean;
68
+ badges: BadgeRow[];
69
+ hasBlogPosts: boolean;
70
+ blogPosts: PostRow[];
71
+ hasForumPosts: boolean;
72
+ forumPosts: PostRow[];
73
+ /** One-shot snackbar after a failed follow write. */
74
+ snackbarMessage: string;
75
+ /** Which failure the snackbar reports; the descriptor holds one literal-copy Snackbar per kind (a native Snackbar does not resolve a bound message). */
76
+ snackbarKind: "" | "follow" | "unfollow";
77
+ noSnackbar: boolean;
78
+ noFollowError: boolean;
79
+ noUnfollowError: boolean;
80
+ /** The Follow / Following swap, and the guest variant of Follow. */
81
+ hideFollow: boolean;
82
+ hideFollowing: boolean;
83
+ /** Section gates, the negation of the `has*` flags. */
84
+ hideAbout: boolean;
85
+ hideBadges: boolean;
86
+ hideBlogPosts: boolean;
87
+ hideForumPosts: boolean;
88
+ hideCounts: boolean;
89
+ hideJoined: boolean;
90
+ /** Visitor buttons (open sign-in) and member buttons (act) never show together. */
91
+ hideGuestActions: boolean;
92
+ hideMemberActions: boolean;
93
+ /** The retryable ErrorState: hidden unless the load failed for a reason other than sign-in. */
94
+ hideError: boolean;
95
+ unfollowTitle: string;
34
96
  }
35
97
 
36
98
  function name(m: WixMember): string {
37
99
  const nick = m.profile?.nickname?.trim();
38
100
  if (nick) return nick;
39
101
  const full = [m.contact?.firstName, m.contact?.lastName].filter(Boolean).join(" ").trim();
40
- return full || m.loginEmail?.trim() || "Member";
41
- }
42
- function followLabelFor(isFollowing: boolean): string {
43
- return isFollowing ? "Following ✓" : "Follow";
102
+ return full || "Member";
44
103
  }
45
104
  /** Each counter on its own: a missing one is hidden, never shown as 0, and an explicit 0 stays visible. */
46
105
  function followCountFor(followers: number | null, following: number | null): string {
47
106
  return [
48
- followers === null ? "" : followers + (followers === 1 ? " Follower" : " Followers"),
49
- following === null ? "" : following + " Following",
107
+ followers === null ? "" : followers === 1 ? copyParam("member.followers.one", "1 follower") : copyTemplate("member.followers.other", "{count} followers", { count: followers }),
108
+ following === null ? "" : copyTemplate("member.following", "{count} following", { count: following }),
50
109
  ].filter(Boolean).join(" · ");
51
110
  }
52
-
53
- const INITIAL: S = {
54
- status: "loading",
55
- id: "",
56
- name: "",
57
- email: "",
58
- initial: "",
59
- subtitle: "",
60
- photo: "",
61
- followHint: "",
62
- isFollowing: false,
63
- followers: null,
64
- following: null,
65
- followLabel: "Follow",
66
- followCount: "",
67
- ...presence("loading"), ...NO_READ_SIGN_IN,
111
+ /** An About has content when a node holds text or media; a cleared About leaves empty paragraphs behind. */
112
+ function hasAboutContent(nodes: unknown[]): boolean {
113
+ return nodes.some((n) => {
114
+ const node = n as { type?: string; textData?: { text?: string }; nodes?: unknown[] } | null;
115
+ if (!node || typeof node !== "object") return false;
116
+ if (typeof node.textData?.text === "string" && node.textData.text.trim()) return true;
117
+ if (["IMAGE", "VIDEO", "GALLERY", "GIF", "FILE"].includes(String(node.type))) return true;
118
+ return Array.isArray(node.nodes) && hasAboutContent(node.nodes);
119
+ });
120
+ }
121
+ /** "Jul 2026" from the member's createdDate; "" when the date is missing or unreadable. */
122
+ function joinedFor(createdDate: string | undefined): string {
123
+ if (!createdDate) return "";
124
+ const d = new Date(createdDate);
125
+ if (Number.isNaN(d.getTime())) return "";
126
+ const month = formatMonthYear(d, appLocale());
127
+ return copyTemplate("member.joined", "Joined {month}", { month });
128
+ }
129
+ /** `<siteUrl>/profile/<slug>/profile`, the website's own path; "" without a real http(s) site or a slug. */
130
+ export function profileUrl(siteUrl: string, slug: string): string {
131
+ if (!siteUrl || !slug) return "";
132
+ const m = /^(https?):\/\/([^\s/?#\\@]+)((?:\/[^\s?#\\]*)?)(?:[?#].*)?$/i.exec(siteUrl);
133
+ if (!m) return "";
134
+ return `${m[1].toLowerCase()}://${m[2].toLowerCase()}${m[3].replace(/\/$/, "")}/profile/${encodeURIComponent(slug)}/profile`;
135
+ }
136
+ function derive(s: S): S {
137
+ // The counts line is gated on the text it will show, so a header built from INITIAL (followCount "") still shows known counts.
138
+ const followCount = followCountFor(s.followers, s.following);
139
+ return {
140
+ ...s,
141
+ hideFollow: s.isGuest || s.isFollowing, hideFollowing: s.isGuest || !s.isFollowing,
142
+ hideGuestActions: !s.isGuest, hideMemberActions: s.isGuest,
143
+ hideError: s.hideLoadError || s.signInRequired,
144
+ unfollowTitle: copyTemplate("member.unfollowTitle", "Unfollow {name}?", { name: s.name }),
145
+ hideAbout: !s.hasAbout, hideBadges: !s.hasBadges, hideBlogPosts: !s.hasBlogPosts, hideForumPosts: !s.hasForumPosts,
146
+ hideCounts: !followCount, hideJoined: !s.hasJoined,
147
+ noSnackbar: !s.snackbarMessage,
148
+ noFollowError: s.snackbarKind !== "follow" || !s.snackbarMessage, noUnfollowError: s.snackbarKind !== "unfollow" || !s.snackbarMessage,
149
+ followCount,
150
+ followLabel: s.isFollowing ? "Following ✓" : "Follow",
68
151
  };
152
+ }
153
+ function postMeta(date: string | undefined, minutes: number | undefined): string {
154
+ const bits: string[] = [];
155
+ if (date) { const d = new Date(date); if (!Number.isNaN(d.getTime())) bits.push(formatDateMedium(d, appLocale())); }
156
+ if (minutes) bits.push(copyTemplate("member.readTime", "{minutes} min read", { minutes }));
157
+ return bits.join(" · ");
158
+ }
159
+ function blogRow(p: WixBlogPost): PostRow {
160
+ const m = p.media;
161
+ return { id: p.id, title: p.title || "", meta: postMeta(p.firstPublishedDate, p.minutesToRead), thumb: wixMediaUrl(m?.wixMedia?.image?.url || m?.embedMedia?.thumbnail?.url, POST_IMAGE) };
162
+ }
163
+ function forumRow(p: WixForumPost): PostRow {
164
+ const first = (p.images ?? [])[0] as { url?: string } | string | undefined;
165
+ return { id: p.id, title: p.title || "", meta: postMeta(p.createdDate, undefined), thumb: wixMediaUrl(typeof first === "string" ? first : first?.url, POST_IMAGE) };
166
+ }
167
+
168
+ const INITIAL: S = derive({
169
+ status: "loading",
170
+ id: "",
171
+ name: "",
172
+ initial: "",
173
+ photo: "",
174
+ joined: "",
175
+ hasJoined: false,
176
+ slug: "",
177
+ shareUrl: "",
178
+ noShare: true,
179
+ isFollowing: false,
180
+ followers: null,
181
+ following: null,
182
+ followCount: "",
183
+ followLabel: "Follow",
184
+ followBusy: false,
185
+ isGuest: true,
186
+ errorVariant: "server",
187
+ hasAbout: false,
188
+ aboutJson: "",
189
+ hasBadges: false,
190
+ badges: [],
191
+ hasBlogPosts: false,
192
+ blogPosts: [],
193
+ hasForumPosts: false,
194
+ forumPosts: [],
195
+ snackbarMessage: "",
196
+ snackbarKind: "",
197
+ noSnackbar: true,
198
+ noFollowError: true,
199
+ noUnfollowError: true,
200
+ hideFollow: false,
201
+ hideFollowing: true,
202
+ hideAbout: true,
203
+ hideBadges: true,
204
+ hideBlogPosts: true,
205
+ hideForumPosts: true,
206
+ hideCounts: true,
207
+ hideJoined: true,
208
+ hideGuestActions: false,
209
+ hideMemberActions: true,
210
+ hideError: true,
211
+ unfollowTitle: "",
212
+ ...presence("loading"), ...NO_READ_SIGN_IN,
213
+ });
69
214
  let loadVersion = 0;
70
215
  let loadedAccess: ReadAccess | undefined;
216
+ /** The reader (tenant, scope, email) the cached sections were read for. */
217
+ let loadedReader = "";
218
+ const readerKeyOf = (a: ReadAccess): string => JSON.stringify([a.tenant, a.member.scope, a.member.email]);
219
+ let siteUrlParam = "";
220
+ let sectionsEnabled = false;
221
+ let blogEnabled = false;
222
+ let forumEnabled = false;
71
223
  const pendingFollows = new Set<string>();
72
224
 
73
- const svc = defineService<S, {
225
+ /** The platform's own classification: `offline` only for a connectivity failure, `server` for anything else. */
226
+ function errorVariantOf(e: unknown): string {
227
+ return classifyLoadError(e) === "offline" ? "offline" : "server";
228
+ }
229
+
230
+ type Actions = {
74
231
  prepare: (s: S) => S;
75
- load: (s: S) => Promise<S | undefined>;
232
+ resetToSkeleton: (s: S) => S;
233
+ load: (s: S, arg?: unknown) => Promise<S | undefined>;
234
+ retry: (s: S) => Promise<S | undefined>;
76
235
  toggleFollow: (s: S) => Promise<S | undefined>;
77
- }>("spacesMemberDetail", {
236
+ follow: (s: S) => Promise<S | undefined>;
237
+ unfollow: (s: S) => Promise<S | undefined>;
238
+ share: (s: S) => Promise<S | undefined>;
239
+ applySections: (s: S) => S | undefined;
240
+ setBusy: (s: S, busy: boolean) => S;
241
+ dismissSnackbar: (s: S) => S;
242
+ };
243
+ const svc: ReturnType<typeof defineService<S, Actions>> = defineService<S, Actions>("spacesMemberDetail", {
78
244
  state: INITIAL,
79
245
  actions: {
80
- prepare: (s) => { loadedAccess = undefined; return { ...s, ...INITIAL }; },
81
- load: async (s): Promise<S | undefined> => {
246
+ // A revisit keeps the cached profile on screen: only the first load starts from the skeleton.
247
+ // A revisit keeps the cached profile (buttons off until the reload lands, and no old failure snackbar). Load then starts over
248
+ // from the skeleton if another reader is looking.
249
+ prepare: (s): S => {
250
+ loadedAccess = undefined;
251
+ return s.found && s.id === detailInputId() ? derive({ ...s, followBusy: true, snackbarMessage: "", snackbarKind: "" }) : { ...s, ...INITIAL };
252
+ },
253
+ resetToSkeleton: (s): S => ({ ...s, ...INITIAL }),
254
+ load: async (s, arg): Promise<S | undefined> => {
255
+ stashCopy(arg);
256
+ if (arg && typeof arg === "object") {
257
+ const a = arg as Record<string, unknown>;
258
+ if (typeof a.siteUrl === "string") siteUrlParam = a.siteUrl.trim();
259
+ sectionsEnabled = a.sections === "1" || a.sections === true;
260
+ if (a.blog !== undefined) blogEnabled = a.blog === "1" || a.blog === true;
261
+ if (a.forum !== undefined) forumEnabled = a.forum === "1" || a.forum === true;
262
+ }
82
263
  const version = ++loadVersion;
83
264
  await svc.prepare();
84
265
  const id = detailInputId();
85
266
  if (!id) return { ...INITIAL, status: "ready", ...presence("missing") };
86
267
  try {
87
268
  const access = await readAccess();
269
+ if (s.found && s.id === id && readerKeyOf(access) !== loadedReader) await svc.resetToSkeleton();
88
270
  const res = await getMember(id);
89
271
  const m = ((res as unknown as { member?: WixMember }).member) ?? (res as unknown as WixMember);
90
272
  const n = name(m);
273
+ // The public profile never shows a member who is not public and approved (a private member's About must not be read).
274
+ // An anonymous read carries "UNKNOWN" for both fields (the public fieldset): that is not a refusal, so it passes.
275
+ const known = (v: string | undefined): v is string => !!v && v !== "UNKNOWN";
276
+ const hidden = (known(m.privacyStatus) && m.privacyStatus !== "PUBLIC") || (known(m.status) && m.status !== "APPROVED");
277
+ if (hidden) {
278
+ await assertReadAccess(access);
279
+ return version === loadVersion ? { ...INITIAL, status: "ready", id, ...presence("missing") } : undefined;
280
+ }
91
281
 
92
282
  // A forbidden/missing aggregate is unknown, while the public profile
93
283
  // remains readable. The descriptor collapses an empty count label.
@@ -107,33 +297,48 @@ const svc = defineService<S, {
107
297
  await assertReadAccess(access);
108
298
  if (version !== loadVersion) return undefined;
109
299
  loadedAccess = access;
110
- return {
111
- ...INITIAL, status: "ready",
300
+ const readerKey = readerKeyOf(access);
301
+ const slug = m.profile?.slug?.trim() || "";
302
+ const shareUrl = profileUrl(siteUrlParam, slug);
303
+ const joined = joinedFor(m.createdDate);
304
+ // A revisit keeps the sections it already showed until their re-reads land, so nothing shifts.
305
+ // Another reader (signed out, another account, another site) never inherits the previous reader's sections.
306
+ const prior = s.found && s.id === id && readerKey === loadedReader ? s : undefined;
307
+ loadedReader = readerKey;
308
+ const header = derive({
309
+ ...INITIAL, ...(prior ? sectionsOf(prior) : {}), status: "ready",
112
310
  id,
113
311
  name: n,
114
- email: m.loginEmail || "",
115
312
  initial: (n[0] || "#").toUpperCase(),
116
- subtitle: m.status && m.status !== "UNKNOWN" ? m.status.charAt(0) + m.status.slice(1).toLowerCase() : "",
117
313
  photo: m.profile?.photo?.url || "",
118
- followHint: "",
314
+ joined, hasJoined: !!joined,
315
+ slug, shareUrl, noShare: !shareUrl,
119
316
  isFollowing,
120
317
  followers,
121
318
  following,
122
- followLabel: followLabelFor(isFollowing),
123
- followCount: followCountFor(followers, following),
319
+ isGuest: !access.member.email,
124
320
  ...presence("found"),
125
- };
321
+ });
322
+ // The header paints now; the secondary sections arrive one by one below.
323
+ sections = {};
324
+ if (sectionsEnabled) void publishSections(id, version, access);
325
+ return header;
126
326
  } catch (e) {
127
327
  const flags = await readSignInFlags(e);
128
- return version === loadVersion ? { ...INITIAL, status: "ready", id, ...presenceAfterError(e), ...flags } : undefined;
328
+ return version === loadVersion ? derive({ ...INITIAL, status: "ready", id, ...presenceAfterError(e), ...flags, errorVariant: errorVariantOf(e) }) : undefined;
129
329
  }
130
330
  },
131
- // REAL WRITE: two-state toggle. Flips the relationship and optimistically
132
- // adjusts the follower total, then recomputes the label + count strings.
331
+ retry: async (): Promise<S | undefined> => svc.load(),
332
+ // The buttons name their direction, so a tap that outlives a state change (a revisit, another reader) never does the opposite write.
333
+ follow: async (s): Promise<S | undefined> => (s.isFollowing ? undefined : svc.toggleFollow()),
334
+ unfollow: async (s): Promise<S | undefined> => (s.isFollowing ? svc.toggleFollow() : undefined),
335
+ // REAL WRITE: two-state toggle. A visitor never reaches it (the descriptor opens sign-in), and a
336
+ // guest that does is ignored. Flips the relationship, then adjusts the follower total.
133
337
  toggleFollow: async (s) => {
134
- if (!s.id) return { ...s, followHint: "No member selected." };
338
+ if (!s.id) return s;
135
339
  const access = loadedAccess;
136
340
  if (!access || detailInputId() !== s.id) return undefined;
341
+ if (!access.member.email) return undefined;
137
342
  const pendingKey = JSON.stringify([access.tenant, access.member.scope, access.member.email, s.id]);
138
343
  if (pendingFollows.has(pendingKey)) return undefined;
139
344
  const version = loadVersion;
@@ -142,6 +347,8 @@ const svc = defineService<S, {
142
347
  // navigation back to it. Another member or reader/site can act while this request is
143
348
  // pending. Separate worker instances are isolated contexts and cannot share this guard.
144
349
  pendingFollows.add(pendingKey);
350
+ // The button is disabled while the write is in flight, at its final size.
351
+ await svc.setBusy(true);
145
352
  try {
146
353
  await assertReadAccess(access);
147
354
  if (!current()) return undefined;
@@ -156,28 +363,125 @@ const svc = defineService<S, {
156
363
  }
157
364
  const isFollowing = !s.isFollowing;
158
365
  const followers = s.followers === null ? null : Math.max(0, s.followers + (isFollowing ? 1 : -1));
159
- return {
160
- ...s,
161
- isFollowing,
162
- followers,
163
- followLabel: followLabelFor(isFollowing),
164
- followCount: followCountFor(followers, s.following),
165
- followHint: isFollowing ? "Following ✓" : "Unfollowed.",
166
- };
366
+ return derive({ ...svc.getState(), isFollowing, followers, followBusy: false, snackbarMessage: "", snackbarKind: "" });
167
367
  } catch {
168
- // A failed write belongs only to the reader who loaded this profile.
169
- // Compare explicitly: a context change discards this completion, while a
170
- // failure for the same reader produces the retry hint below.
368
+ // A failed write belongs only to the reader who loaded this profile. Compare explicitly: a
369
+ // context change discards this completion; a failure for the same reader keeps the old state
370
+ // and raises the retry snackbar.
171
371
  const now = await readAccess();
172
- if (now.member.email !== access.member.email || now.member.scope !== access.member.scope || now.tenant !== access.tenant) return undefined;
372
+ if (now.member.email !== access.member.email || now.member.scope !== access.member.scope || now.tenant !== access.tenant) { if (version === loadVersion) await svc.setBusy(false); return undefined; }
173
373
  if (!current()) return undefined;
174
- return { ...s, followHint: s.isFollowing ? "Couldn't unfollow — try again." : "Couldn't follow — try again." };
374
+ return derive({
375
+ ...svc.getState(), followBusy: false,
376
+ snackbarKind: s.isFollowing ? "unfollow" : "follow",
377
+ snackbarMessage: s.isFollowing ? copyParam("member.unfollowError", "Couldn't unfollow. Try again.") : copyParam("member.followError", "Couldn't follow. Try again."),
378
+ });
175
379
  } finally {
176
380
  pendingFollows.delete(pendingKey);
177
381
  }
178
382
  },
383
+ applySections: (s) => (s.found && s.id === detailInputId() ? derive({ ...s, ...sections }) : undefined),
384
+ setBusy: (s, busy) => derive({ ...s, followBusy: busy, ...(busy ? { snackbarMessage: "", snackbarKind: "" as const } : {}) }),
385
+ dismissSnackbar: (s) => derive({ ...s, snackbarMessage: "", snackbarKind: "" }),
386
+ // Returns nothing: the sheet stays open while reads land, and a returned copy of the old state would erase them.
387
+ share: async (s): Promise<S | undefined> => {
388
+ if (!s.shareUrl) return undefined;
389
+ try { await shareSheet({ subject: s.name, url: s.shareUrl }); } catch { /* a cancelled sheet is not an error */ }
390
+ return undefined;
391
+ },
179
392
  },
180
393
  });
394
+
395
+ /** What each secondary read has found so far; `applySections` folds it into the state. */
396
+ let sections: Partial<S> = {};
397
+ function sectionsOf(s: S): Partial<S> {
398
+ return {
399
+ hasAbout: s.hasAbout, aboutJson: s.aboutJson, hasBadges: s.hasBadges, badges: s.badges,
400
+ hasBlogPosts: s.hasBlogPosts, blogPosts: s.blogPosts, hasForumPosts: s.hasForumPosts, forumPosts: s.forumPosts,
401
+ };
402
+ }
403
+
404
+ /** Each secondary read lands in its own state write, so a slow read never delays another section and a
405
+ * failed one only hides its own. A transient failure keeps a revisit's last valid section, while an
406
+ * authorization refusal clears it. Results from a previous reader or site never publish. */
407
+ async function publishSections(id: string, version: number, access: ReadAccess): Promise<void> {
408
+ const still = () => version === loadVersion && loadedAccess === access && detailInputId() === id;
409
+ const land = async (patch: Partial<S>) => {
410
+ if (!still()) return;
411
+ try { await assertReadAccess(access); }
412
+ catch {
413
+ if (still()) { loadedAccess = undefined; sections = {}; await svc.resetToSkeleton(); }
414
+ return;
415
+ }
416
+ if (!still()) return;
417
+ sections = { ...sections, ...patch };
418
+ await svc.applySections();
419
+ };
420
+ const reads: Array<Promise<void>> = [];
421
+ reads.push((async () => {
422
+ try {
423
+ const res = await queryMemberAbouts({ query: { filter: { memberId: id } } });
424
+ const content = res.memberAbouts?.find((a) => a.memberId === id || !a.memberId)?.content;
425
+ const nodes = (content as { nodes?: unknown[] } | undefined)?.nodes;
426
+ await land(content && Array.isArray(nodes) && hasAboutContent(nodes) ? { hasAbout: true, aboutJson: JSON.stringify(content) } : { hasAbout: false, aboutJson: "" });
427
+ } catch (e) {
428
+ // A 404 means "no About" (the by-id read answers it for a member with none); any other failure keeps the section as it was.
429
+ if (isNotFoundError(e) || readAccessDenied(e)) await land({ hasAbout: false, aboutJson: "" });
430
+ }
431
+ })());
432
+ reads.push((async () => {
433
+ try {
434
+ // Badges v4 (a Visitor can read both): the badges this member holds, then the site's badges that match them.
435
+ // The site's badge list is paged until every held badge is found, so a held badge is never lost past page one.
436
+ const ids = new Set<string>();
437
+ let assignmentCursor: string | undefined;
438
+ let assignmentsComplete = false;
439
+ for (let page = 0; page < 10; page++) {
440
+ // The cursor encodes the filter, so only the first page carries it (and a follow-up sends no limit).
441
+ const held = await queryBadgeAssignments({ query: assignmentCursor ? { cursorPaging: { cursor: assignmentCursor } } : { filter: { memberId: { $in: [id] } }, cursorPaging: { limit: 100 } } });
442
+ for (const a of held.badgeAssignments ?? []) if (a.badgeId) ids.add(a.badgeId);
443
+ assignmentCursor = held.pagingMetadata?.cursors?.next;
444
+ if (!held.pagingMetadata?.hasNext) { assignmentsComplete = true; break; }
445
+ if (!assignmentCursor) throw new Error("Badge assignments have no next cursor");
446
+ }
447
+ if (!assignmentsComplete) throw new Error("Badge assignments are longer than the pages read");
448
+ const badges: Array<{ id: string; title: string }> = [];
449
+ let cursor: string | undefined;
450
+ let catalogComplete = ids.size === 0;
451
+ for (let page = 0; page < 50 && ids.size > 0; page++) {
452
+ // A follow-up page carries the cursor alone: Badges v4 rejects a limit beside it.
453
+ const res = await queryBadges({ query: { cursorPaging: cursor ? { cursor } : { limit: 100 } } });
454
+ for (const b of res.badges ?? []) if (b.id && ids.has(b.id) && (b.title || "").trim()) {
455
+ badges.push({ id: b.id, title: (b.title as string).trim() });
456
+ ids.delete(b.id);
457
+ }
458
+ cursor = res.pagingMetadata?.cursors?.next;
459
+ if (!res.pagingMetadata?.hasNext || ids.size === 0) { catalogComplete = true; break; }
460
+ if (!cursor) throw new Error("Badge catalog has no next cursor");
461
+ }
462
+ if (!catalogComplete) throw new Error("Badge catalog is longer than the pages read");
463
+ await land({ hasBadges: badges.length > 0, badges });
464
+ } catch (e) { if (readAccessDenied(e)) await land({ hasBadges: false, badges: [] }); }
465
+ })());
466
+ if (blogEnabled) reads.push((async () => {
467
+ try {
468
+ const res = await queryBlogPosts({ query: { filter: { memberId: id }, paging: { limit: POST_LIMIT } } });
469
+ const rows = (res.posts ?? []).slice(0, POST_LIMIT).filter((p) => p.id).map(blogRow);
470
+ await land({ hasBlogPosts: rows.length > 0, blogPosts: rows });
471
+ } catch (e) { if (readAccessDenied(e)) await land({ hasBlogPosts: false, blogPosts: [] }); }
472
+ })());
473
+ if (forumEnabled) reads.push((async () => {
474
+ try {
475
+ // Observed live: the Forum posts query takes a top-level body. `filter.ownerId` needs `{ $eq }` (a bare value answers 400), and a
476
+ // `{ query: … }` wrapper is ignored whole, so every owner would get the same posts. The owner is also checked here.
477
+ const res = await queryForumPosts({ filter: { ownerId: { $eq: id } }, paging: { limit: POST_LIMIT } });
478
+ const rows = (res.posts ?? []).filter((p) => p.id && (p as { ownerId?: string }).ownerId === id).slice(0, POST_LIMIT).map(forumRow);
479
+ await land({ hasForumPosts: rows.length > 0, forumPosts: rows });
480
+ } catch (e) { if (readAccessDenied(e)) await land({ hasForumPosts: false, forumPosts: [] }); }
481
+ })());
482
+ await Promise.all(reads);
483
+ }
484
+
181
485
  svc.prepare();
182
486
  svc.load();
183
487
  export { svc };
@@ -1046,8 +1046,8 @@
1046
1046
  },
1047
1047
  "h_a00ed42505ab": {
1048
1048
  "source": "No collections match your search.",
1049
- "translation": "אין אוספים שתואמים לחיפוש.",
1050
- "key": "cms.searchEmptyText"
1049
+ "key": "cms.searchEmptyText",
1050
+ "translation": "אין אוספים שתואמים לחיפוש."
1051
1051
  },
1052
1052
  "h_03e89418ffdf": {
1053
1053
  "source": "Your Home",
@@ -0,0 +1,72 @@
1
+ {
2
+ "_recipe": "The business's latest announcement (title, rich body, creator and date), read at runtime. Service: registerAnnouncementSection(svc). Hidden whole while there is nothing to show.",
3
+ "_placeholders": {
4
+ "svc": "service name the page worker registered with registerAnnouncementSection",
5
+ "id": "unique node id prefix (e.g. the screen id)",
6
+ "heading": "the source section's own title when it shows one, else an empty string"
7
+ },
8
+ "node": {
9
+ "id": "{{id}}.announcement",
10
+ "body": {
11
+ "package": "himalaya",
12
+ "type": "VStack",
13
+ "props": {
14
+ "spacing": 8,
15
+ "alignment": "leading",
16
+ "children": [
17
+ {
18
+ "id": "{{id}}.heading",
19
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "{{heading}}", "style": "title3", "collapseWhenEmpty": true } }
20
+ },
21
+ {
22
+ "id": "{{id}}.title",
23
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.title", "style": "bodyEmphasis", "collapseWhenEmpty": true } },
24
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noTitle" }
25
+ },
26
+ {
27
+ "id": "{{id}}.body_rich",
28
+ "body": {
29
+ "package": "himalaya",
30
+ "type": "RichContent",
31
+ "props": {
32
+ "documentJsonPath": "$service:{{svc}}.bodyJson",
33
+ "onLink": { "actionId": "tier5.{{svc}}.openLink" },
34
+ "fallback": { "id": "{{id}}.body_rich_fallback", "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.body", "style": "body", "color": "textSecondary" } } }
35
+ }
36
+ },
37
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noBodyJson" }
38
+ },
39
+ {
40
+ "id": "{{id}}.body",
41
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.body", "style": "body", "color": "textSecondary", "collapseWhenEmpty": true } },
42
+ "modifiers": { "hiddenPath": "$service:{{svc}}.hasBodyJson" }
43
+ },
44
+ {
45
+ "id": "{{id}}.meta",
46
+ "body": {
47
+ "package": "himalaya",
48
+ "type": "HStack",
49
+ "props": {
50
+ "spacing": 8,
51
+ "alignment": "center",
52
+ "children": [
53
+ {
54
+ "id": "{{id}}.creator",
55
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.creator", "style": "caption", "color": "textSecondary", "collapseWhenEmpty": true } },
56
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noCreator" }
57
+ },
58
+ {
59
+ "id": "{{id}}.created",
60
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.created", "style": "caption", "color": "textSecondary", "collapseWhenEmpty": true } },
61
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noCreated" }
62
+ }
63
+ ]
64
+ }
65
+ }
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noAnnouncement", "padding": { "leading": 16, "trailing": 16, "top": 16, "bottom": 16 } }
71
+ }
72
+ }