@wix/himalaya-cli 0.1570.0 → 0.1571.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 (126) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/define-app.d.ts +8 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/auth-providers/wix/src/index.d.ts +7 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/blog-v3/src/extensions.d.ts +6 -3
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/auth.mjs +17 -7
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core/validation.mjs +17 -7
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +17 -7
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +17 -7
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/state.mjs +17 -7
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-auth.mjs +7 -1
  10. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-blog.mjs +1 -0
  11. package/dist/cli.mjs +1672 -1206
  12. package/dist/preview-assets.generated.bin +0 -0
  13. package/guides/base44-app-to-himi-app.md +1 -1
  14. package/guides/capabilities.md +7 -0
  15. package/guides/himi-json-output.md +11 -0
  16. package/guides/one-app-to-himi-app.md +122 -4
  17. package/guides/sdk-reference.json +2 -2
  18. package/guides/splash-screens.md +10 -1
  19. package/guides/trim-a-template.md +5 -0
  20. package/guides/wix-business-context.md +11 -2
  21. package/package.json +2 -2
  22. package/templates/beauty-salon/config.ts +1 -1
  23. package/templates/beauty-salon/dev/index.ts +31 -1
  24. package/templates/beauty-salon/tier5-src/_shared/member-read.ts +52 -0
  25. package/templates/beauty-salon/tier5-src/_shared/program-description.ts +11 -0
  26. package/templates/beauty-salon/tier5-src/himi-blog-post/index.ts +35 -12
  27. package/templates/beauty-salon/tier5-src/himi-branded-lite-home/index.ts +3 -3
  28. package/templates/beauty-salon/tier5-src/himi-store-product/index.ts +6 -9
  29. package/templates/beauty-salon-owner/config.ts +1 -1
  30. package/templates/branded-lite/config.ts +1 -1
  31. package/templates/branded-lite/dev/index.ts +163 -2
  32. package/templates/branded-lite/tier5-src/_shared/member-read.ts +52 -0
  33. package/templates/branded-lite/tier5-src/_shared/program-description.ts +11 -0
  34. package/templates/branded-lite/tier5-src/himi-blog-post/index.ts +35 -12
  35. package/templates/branded-lite/tier5-src/himi-branded-lite-home/index.ts +3 -3
  36. package/templates/branded-lite/tier5-src/himi-branded-lite-program/index.ts +16 -14
  37. package/templates/branded-lite/tier5-src/himi-branded-lite-programs/index.ts +3 -7
  38. package/templates/branded-lite/tier5-src/himi-events-my-events/index.ts +76 -42
  39. package/templates/branded-lite/tier5-src/himi-store-product/index.ts +6 -9
  40. package/templates/branded-lite/tier5-src/wix-spaces-chat-thread/index.ts +101 -34
  41. package/templates/branded-lite/tier5-src/wix-spaces-forum-post/index.ts +23 -6
  42. package/templates/branded-lite/tier5-src/wix-spaces-member-detail/index.ts +26 -11
  43. package/templates/community-club/config.ts +1 -1
  44. package/templates/community-club/dev/index.ts +65 -2
  45. package/templates/community-club/tier5-src/_shared/branded-load-state.ts +106 -0
  46. package/templates/community-club/tier5-src/_shared/member-read.ts +52 -0
  47. package/templates/community-club/tier5-src/_shared/program-description.ts +11 -0
  48. package/templates/community-club/tier5-src/himi-blog-post/index.ts +35 -12
  49. package/templates/community-club/tier5-src/himi-branded-lite-home/index.ts +3 -3
  50. package/templates/community-club/tier5-src/himi-events-my-events/index.ts +76 -42
  51. package/templates/community-club-owner/config.ts +1 -1
  52. package/templates/events-meetups/config.ts +1 -1
  53. package/templates/events-meetups/dev/index.ts +65 -2
  54. package/templates/events-meetups/tier5-src/_shared/branded-load-state.ts +106 -0
  55. package/templates/events-meetups/tier5-src/_shared/member-read.ts +52 -0
  56. package/templates/events-meetups/tier5-src/_shared/program-description.ts +11 -0
  57. package/templates/events-meetups/tier5-src/himi-blog-post/index.ts +35 -12
  58. package/templates/events-meetups/tier5-src/himi-branded-lite-home/index.ts +3 -3
  59. package/templates/events-meetups/tier5-src/himi-events-my-events/index.ts +76 -42
  60. package/templates/events-meetups-owner/config.ts +1 -1
  61. package/templates/gym-fitness/config.ts +1 -1
  62. package/templates/gym-fitness/dev/index.ts +65 -2
  63. package/templates/gym-fitness/tier5-src/_shared/member-read.ts +52 -0
  64. package/templates/gym-fitness/tier5-src/_shared/program-description.ts +11 -0
  65. package/templates/gym-fitness/tier5-src/himi-blog-post/index.ts +35 -12
  66. package/templates/gym-fitness/tier5-src/himi-branded-lite-home/index.ts +3 -3
  67. package/templates/gym-fitness/tier5-src/himi-events-my-events/index.ts +76 -42
  68. package/templates/gym-fitness/tier5-src/himi-store-product/index.ts +6 -9
  69. package/templates/gym-fitness-owner/config.ts +1 -1
  70. package/templates/nonprofit-cause/config.ts +1 -1
  71. package/templates/nonprofit-cause/dev/index.ts +65 -2
  72. package/templates/nonprofit-cause/tier5-src/_shared/branded-load-state.ts +106 -0
  73. package/templates/nonprofit-cause/tier5-src/_shared/member-read.ts +52 -0
  74. package/templates/nonprofit-cause/tier5-src/_shared/program-description.ts +11 -0
  75. package/templates/nonprofit-cause/tier5-src/himi-blog-post/index.ts +35 -12
  76. package/templates/nonprofit-cause/tier5-src/himi-branded-lite-home/index.ts +3 -3
  77. package/templates/nonprofit-cause/tier5-src/himi-events-my-events/index.ts +76 -42
  78. package/templates/nonprofit-cause-owner/config.ts +1 -1
  79. package/templates/owner-lite/config.ts +1 -1
  80. package/templates/podcast-creator/config.ts +1 -1
  81. package/templates/podcast-creator/dev/index.ts +65 -2
  82. package/templates/podcast-creator/tier5-src/_shared/branded-load-state.ts +106 -0
  83. package/templates/podcast-creator/tier5-src/_shared/member-read.ts +52 -0
  84. package/templates/podcast-creator/tier5-src/_shared/program-description.ts +11 -0
  85. package/templates/podcast-creator/tier5-src/himi-blog-post/index.ts +35 -12
  86. package/templates/podcast-creator/tier5-src/himi-branded-lite-home/index.ts +3 -3
  87. package/templates/podcast-creator/tier5-src/himi-events-my-events/index.ts +76 -42
  88. package/templates/podcast-creator-owner/config.ts +1 -1
  89. package/templates/portfolio-creative/config.ts +1 -1
  90. package/templates/portfolio-creative/dev/index.ts +65 -2
  91. package/templates/portfolio-creative/tier5-src/_shared/branded-load-state.ts +106 -0
  92. package/templates/portfolio-creative/tier5-src/_shared/member-read.ts +52 -0
  93. package/templates/portfolio-creative/tier5-src/_shared/program-description.ts +11 -0
  94. package/templates/portfolio-creative/tier5-src/himi-blog-post/index.ts +35 -12
  95. package/templates/portfolio-creative/tier5-src/himi-branded-lite-home/index.ts +3 -3
  96. package/templates/portfolio-creative/tier5-src/himi-events-my-events/index.ts +76 -42
  97. package/templates/portfolio-creative/tier5-src/himi-store-product/index.ts +6 -9
  98. package/templates/portfolio-creative-owner/config.ts +1 -1
  99. package/templates/restaurant/config.ts +1 -1
  100. package/templates/restaurant/dev/index.ts +65 -2
  101. package/templates/restaurant/tier5-src/_shared/branded-load-state.ts +106 -0
  102. package/templates/restaurant/tier5-src/_shared/member-read.ts +52 -0
  103. package/templates/restaurant/tier5-src/_shared/program-description.ts +11 -0
  104. package/templates/restaurant/tier5-src/himi-blog-post/index.ts +35 -12
  105. package/templates/restaurant/tier5-src/himi-branded-lite-home/index.ts +3 -3
  106. package/templates/restaurant/tier5-src/himi-events-my-events/index.ts +76 -42
  107. package/templates/restaurant-owner/config.ts +1 -1
  108. package/templates/retail-store/config.ts +1 -1
  109. package/templates/retail-store/dev/index.ts +31 -1
  110. package/templates/retail-store/tier5-src/_shared/branded-load-state.ts +106 -0
  111. package/templates/retail-store/tier5-src/_shared/member-read.ts +52 -0
  112. package/templates/retail-store/tier5-src/_shared/program-description.ts +11 -0
  113. package/templates/retail-store/tier5-src/himi-blog-post/index.ts +35 -12
  114. package/templates/retail-store/tier5-src/himi-branded-lite-home/index.ts +3 -3
  115. package/templates/retail-store/tier5-src/himi-store-product/index.ts +6 -9
  116. package/templates/retail-store-owner/config.ts +1 -1
  117. package/templates/yoga-studio/config.ts +1 -1
  118. package/templates/yoga-studio/dev/index.ts +93 -2
  119. package/templates/yoga-studio/tier5-src/_shared/member-read.ts +52 -0
  120. package/templates/yoga-studio/tier5-src/_shared/program-description.ts +11 -0
  121. package/templates/yoga-studio/tier5-src/himi-blog-post/index.ts +35 -12
  122. package/templates/yoga-studio/tier5-src/himi-branded-lite-home/index.ts +3 -3
  123. package/templates/yoga-studio/tier5-src/himi-branded-lite-program/index.ts +16 -14
  124. package/templates/yoga-studio/tier5-src/himi-branded-lite-programs/index.ts +3 -7
  125. package/templates/yoga-studio/tier5-src/himi-events-my-events/index.ts +76 -42
  126. package/templates/yoga-studio-owner/config.ts +1 -1
@@ -9,6 +9,7 @@ import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
9
9
  import { formatDateMedium, formatMonthDay } from "../_shared/engine-intl.js";
10
10
  import { openRichLink } from "../_shared/rich-content-link.js";
11
11
  import { richBody, ROW_IMAGE_WIDTH } from "../_shared/rich-body.js";
12
+ import { readAccess, assertReadAccess, readAccessDenied, readSignInFlags, NO_READ_SIGN_IN } from "../_shared/member-read.js";
12
13
 
13
14
  // Offline-first (data-offline): the post body is a public read-through — when the
14
15
  // live fetch fails (offline) fall back to the last-synced row the feed cached under
@@ -34,6 +35,7 @@ interface CommentRow {
34
35
  }
35
36
 
36
37
  interface S {
38
+ signInRequired: boolean; noSignIn: boolean; signInScreenId: string;
37
39
  status: "loading" | "ready" | "error";
38
40
  id: string;
39
41
  title: string;
@@ -214,6 +216,7 @@ function derive(s: S): S {
214
216
  }
215
217
 
216
218
  const baseState: S = derive({
219
+ ...NO_READ_SIGN_IN, signInScreenId: "himi_account",
217
220
  status: "loading",
218
221
  id: "",
219
222
  title: "",
@@ -280,23 +283,28 @@ async function cachedPostState(s: S, id: string): Promise<S> {
280
283
  });
281
284
  }
282
285
 
283
- async function loadPostState(s: S): Promise<S> {
286
+ let loadVersion = 0;
287
+ async function loadPostState(s: S): Promise<S | undefined> {
288
+ const version = ++loadVersion;
289
+ await svc.prepare();
290
+ const clean = { ...baseState, signInScreenId: s.signInScreenId };
284
291
  const id = inputId();
285
292
  if (!id) {
286
- return derive({ ...s, status: "ready", emptyText: copyParam("blogPost.notFoundText", "Post not found.") });
293
+ return derive({ ...clean, status: "ready", emptyText: copyParam("blogPost.notFoundText", "Post not found.") });
287
294
  }
288
295
  try {
289
- const [postResult, commentsResult] = await Promise.allSettled([getPost(id), listBlogComments(id)]);
290
- if (postResult.status === "rejected") {
291
- return cachedPostState(s, id);
292
- }
296
+ const access = await readAccess();
297
+ const [postResult, commentsResult] = await Promise.allSettled([getPost(id, {}, { preserveAccessErrors: true }), listBlogComments(id)]);
298
+ if (postResult.status === "rejected") throw postResult.reason;
299
+ await assertReadAccess(access);
300
+ if (version !== loadVersion) return undefined;
293
301
  const post = (((postResult.value as unknown as { post?: WixPost }).post) ?? postResult.value) as PostWithExtras;
294
302
  const commentsUnavailable = commentsResult.status === "rejected";
295
303
  const comments = commentsResult.status === "fulfilled" ? commentsResult.value.map(toCommentRow) : [];
296
304
  const cover = imageUrl(post);
297
305
  const title = post.title || "Untitled post";
298
306
  return derive({
299
- ...s,
307
+ ...clean,
300
308
  status: "ready",
301
309
  id,
302
310
  title,
@@ -319,14 +327,23 @@ async function loadPostState(s: S): Promise<S> {
319
327
  errorText: "",
320
328
  emptyText: "",
321
329
  });
322
- } catch {
323
- return cachedPostState(s, id);
330
+ } catch (error) {
331
+ const flags = await readSignInFlags(error);
332
+ const failed = derive({ ...clean, ...flags, status: "error", id, errorText: copyParam("blogPost.errorText", "This post could not load.") });
333
+ if (version !== loadVersion) return undefined;
334
+ if (readAccessDenied(error)) return failed;
335
+ const access = await readAccess();
336
+ const cached = await cachedPostState(clean, id);
337
+ try { await assertReadAccess(access); }
338
+ catch { return version === loadVersion ? failed : undefined; }
339
+ return version === loadVersion ? cached : undefined;
324
340
  }
325
341
  }
326
342
 
327
343
  const svc = defineService<S, {
328
- load: (s: S, arg?: unknown) => Promise<S>;
329
- retry: (s: S) => Promise<S>;
344
+ prepare: (s: S) => S;
345
+ load: (s: S, arg?: unknown) => Promise<S | undefined>;
346
+ retry: (s: S) => Promise<S | undefined>;
330
347
  like: (s: S) => Promise<S>;
331
348
  unlike: (s: S) => Promise<S>;
332
349
  toggleSave: (s: S) => S;
@@ -338,7 +355,12 @@ const svc = defineService<S, {
338
355
  }>("himiBlogPost", {
339
356
  state: baseState,
340
357
  actions: {
341
- load: (s, arg) => { stashCopy(arg); return loadPostState(s); },
358
+ prepare: (s) => ({ ...s, ...baseState }),
359
+ load: (s, arg) => {
360
+ stashCopy(arg);
361
+ const target = (arg as { signInScreenId?: unknown })?.signInScreenId;
362
+ return loadPostState({ ...s, signInScreenId: target === "himi_sign_in" ? target : s.signInScreenId });
363
+ },
342
364
  retry: (s) => loadPostState({ ...s, status: "loading", errorText: "" }),
343
365
  like: async (s) => {
344
366
  if (!s.id) return derive({ ...s, actionMessage: copyParam("blogPost.noPostMessage", "No post selected.") });
@@ -409,5 +431,6 @@ const svc = defineService<S, {
409
431
  },
410
432
  });
411
433
 
434
+ svc.prepare();
412
435
  svc.load();
413
436
  export { svc };
@@ -1,3 +1,5 @@
1
+ import { descriptionBody } from "../_shared/rich-body.js";
2
+ import { programDescription } from "../_shared/program-description.js";
1
3
  import { fetchMemberBookings, type MemberBookingRow } from "../_shared/member-bookings.js";
2
4
  import { hostSiteFromInput, hostedExploreCards, hostedHiddenFlags, type HostedExploreCard } from "../_shared/branded-lite-hosted.js";
3
5
  import { memberAccess, assertMemberAccess } from "../_shared/member-access.js";
@@ -675,11 +677,9 @@ async function fetchHomePrograms(): Promise<ProgramCard[]> {
675
677
  .map((p: WixProgram) => {
676
678
  const desc = (p as { description?: unknown }).description;
677
679
  const nestedTitle = desc && typeof desc === "object" ? (desc as { title?: string }).title : undefined;
678
- const nestedDetails = desc && typeof desc === "object" ? (desc as { details?: string }).details : undefined;
679
680
  const name = cleanTitle(p.settings?.title ?? nestedTitle ?? p.title) || copyParam("home.programFallbackName", "Program");
680
681
  const image = programImage(p);
681
- const details = (p.settings?.description ?? nestedDetails ?? (typeof desc === "string" ? desc : "") ?? "")
682
- .replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
682
+ const details = descriptionBody(programDescription(p)).bodyText.replace(/\s+/g, " ").trim();
683
683
  return {
684
684
  id: p.id || name,
685
685
  name,
@@ -25,6 +25,9 @@ import { offlineWriteMessage, withOnlineWrites } from "../_shared/online-actions
25
25
  import { connectivity, defineService as registerService } from "@himalaya/state";
26
26
  import { programImage } from "../_shared/himi-media.js";
27
27
  import { WIX_DETAIL_IMAGE } from "@himalaya/wix-media";
28
+ import { descriptionBody } from "../_shared/rich-body.js";
29
+ import { programDescription } from "../_shared/program-description.js";
30
+ import { openRichLink } from "../_shared/rich-content-link.js";
28
31
  import {
29
32
  getProgram,
30
33
  joinProgram,
@@ -54,8 +57,10 @@ interface State {
54
57
  /** Outcome line for the Enrol CTA — joined / pending approval / payment / failure. */
55
58
  actionMessage: string;
56
59
  name: string;
57
- /** Full (untruncated) description, tags stripped. */
60
+ /** Full readable fallback, plus the bounded Ricos body when present. */
58
61
  description: string;
62
+ descriptionJson: string;
63
+ hasDescriptionJson: boolean;
59
64
  /** "N sections · M steps" / "Self-paced" — structure meta line. */
60
65
  meta: string;
61
66
  /** Formatted price when the payload carries one ("" for free/absent). */
@@ -101,6 +106,7 @@ function derive(state: State): State {
101
106
  const empty = state.status === "ready" && !state.name;
102
107
  return {
103
108
  ...state,
109
+ hasDescriptionJson: state.descriptionJson !== "",
104
110
  isLoading: state.status === "loading",
105
111
  notLoading: state.status !== "loading",
106
112
  isErrored: state.status === "error",
@@ -118,16 +124,6 @@ function titleOf(p: WixProgram): string {
118
124
  return cleanTitle(p.settings?.title ?? nested ?? p.title ?? p.details?.title) || copyParam("program.programFallbackName", "Program");
119
125
  }
120
126
 
121
- function detailsOf(p: WixProgram): string {
122
- const desc = (p as { description?: unknown }).description;
123
- const nested = desc && typeof desc === "object" ? (desc as { details?: string }).details : undefined;
124
- const flat = typeof desc === "string" ? desc : undefined;
125
- return (p.settings?.description ?? nested ?? flat ?? p.details?.description ?? "")
126
- .replace(/<[^>]+>/g, " ")
127
- .replace(/\s+/g, " ")
128
- .trim();
129
- }
130
-
131
127
  function metaOf(p: WixProgram): string {
132
128
  const summary = (p as { contentSummary?: { stepCount?: number; sectionCount?: number } }).contentSummary;
133
129
  const bits: string[] = [];
@@ -155,15 +151,17 @@ function priceOf(p: WixProgram): string {
155
151
  function ready(state: State, p: WixProgram | undefined): State {
156
152
  const stateOf = ((p?.state ?? p?.status ?? "") as string).toUpperCase();
157
153
  if (!p || stateOf === "DRAFT") {
158
- return derive({ ...state, status: "ready", name: "", description: "", meta: "", priceLine: "", image: "", initial: "", emptyText: copyParam("program.emptyText", "This program is no longer available.") });
154
+ return derive({ ...state, status: "ready", name: "", description: "", descriptionJson: "", meta: "", priceLine: "", image: "", initial: "", emptyText: copyParam("program.emptyText", "This program is no longer available.") });
159
155
  }
160
156
  const name = titleOf(p);
161
157
  const image = programImage(p, WIX_DETAIL_IMAGE);
158
+ const body = descriptionBody(programDescription(p), copyParam("program.descriptionFallback", "Follow this program at your own pace."));
162
159
  return derive({
163
160
  ...state,
164
161
  status: "ready",
165
162
  name,
166
- description: detailsOf(p) || copyParam("program.descriptionFallback", "Follow this program at your own pace."),
163
+ description: body.bodyText,
164
+ descriptionJson: body.bodyJson,
167
165
  meta: metaOf(p),
168
166
  priceLine: priceOf(p),
169
167
  image,
@@ -273,7 +271,7 @@ const pricing = commerce.pricing;
273
271
  const PRICING_NOT_HYDRATED = [
274
272
  "priceLine", "priceNote", "hidePriceRetry", "enrollDisabled", "enrollNote", "enrollHidden", "buyHidden", "buyLabel", "buyDisabled", "buyNote",
275
273
  ] as const;
276
- const CONTENT_KEYS = ["status", "name", "description", "meta", "image", "initial", "emptyText"] as const;
274
+ const CONTENT_KEYS = ["status", "name", "description", "descriptionJson", "meta", "image", "initial", "emptyText"] as const;
277
275
  type Content = Pick<State, (typeof CONTENT_KEYS)[number]>;
278
276
  const NO_PRICE: IapPriceFields = { priceText: "", priceNote: "", priceLoading: false, hidePriceRetry: true, actionDisabled: true, actionNote: "" };
279
277
  const NOT_APPLE: IapPurchaseFields = { appleRoute: false, accessReady: false, buyLabel: "", buyDisabled: true, buyBusy: false, buyNote: "" };
@@ -463,6 +461,8 @@ const INITIAL_STATE: State = derive({
463
461
  actionMessage: "",
464
462
  name: "",
465
463
  description: "",
464
+ descriptionJson: "",
465
+ hasDescriptionJson: false,
466
466
  meta: "",
467
467
  priceLine: "",
468
468
  image: "",
@@ -488,6 +488,7 @@ const INITIAL_STATE: State = derive({
488
488
  });
489
489
 
490
490
  type Actions = {
491
+ openLink: (state: State, arg?: unknown) => Promise<undefined>;
491
492
  load: (state: State, arg?: unknown) => Promise<State | undefined>;
492
493
  enroll: (state: State) => Promise<State | undefined>;
493
494
  buy: (state: State) => Promise<State | undefined>;
@@ -506,6 +507,7 @@ const svc = defineService<State, Actions>("himiBrandedProgram", {
506
507
  enroll: () => enroll(),
507
508
  buy,
508
509
  pricingPublish: pricedState,
510
+ openLink: async (_state, arg) => { await openRichLink(arg); return undefined; },
509
511
  pricingStart: pricedState,
510
512
  pricingRefresh: async () => { await priceProgram(); return undefined; },
511
513
  iapPoll: async () => { await commerce.poll(); void svc.pricingPublish(); return undefined; },
@@ -17,6 +17,8 @@ import { createIapCommerce } from "@himalaya/iap-checkout";
17
17
  import { programImage } from "../_shared/himi-media.js";
18
18
  import { cleanTitle, initials } from "../_shared/himi-text.js";
19
19
  import { copyParam, stashCopy } from "../_shared/himi-copy.js";
20
+ import { descriptionBody } from "../_shared/rich-body.js";
21
+ import { programDescription } from "../_shared/program-description.js";
20
22
  import { iapPriceCopy, resetUnhydratedKeysOnOlderRuntime } from "../_shared/iap-worker.js";
21
23
 
22
24
  const SERVICE = "himiBrandedPrograms";
@@ -76,13 +78,7 @@ function programTitle(p: WixProgram): string {
76
78
  }
77
79
 
78
80
  function programDetails(p: WixProgram): string {
79
- const desc = (p as { description?: unknown }).description;
80
- const nested = desc && typeof desc === "object" ? (desc as { details?: string }).details : undefined;
81
- const flat = typeof desc === "string" ? desc : undefined;
82
- const raw = (p.settings?.description ?? nested ?? flat ?? p.details?.description ?? "")
83
- .replace(/<[^>]+>/g, " ")
84
- .replace(/\s+/g, " ")
85
- .trim();
81
+ const raw = descriptionBody(programDescription(p)).bodyText.replace(/\s+/g, " ").trim();
86
82
  return raw.length > 140 ? `${raw.slice(0, 139).trimEnd()}…` : raw;
87
83
  }
88
84
 
@@ -5,6 +5,8 @@ import { queryEvents, type WixEvent } from "@himalaya/wix-events";
5
5
  import { getAll, upsert, type DbEntity } from "@himalaya/local-db";
6
6
  import { confirmedRsvpIds, eventStartMillis, normalizeEvent, type EventRow } from "../_shared/himi-events";
7
7
  import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
8
+ import { memberAccess } from "../_shared/member-access.js";
9
+ import { readAccess, assertReadAccess, readAccessDenied, readSignInFlags, NO_READ_SIGN_IN } from "../_shared/member-read.js";
8
10
 
9
11
  // Offline-first (data-offline): My Events is a read-through over the same `events`
10
12
  // catalog the list caches — paint the last-synced rows (filtered to this device's
@@ -27,6 +29,7 @@ async function writeCached(rows: CachedEventRow[]): Promise<void> {
27
29
  }
28
30
 
29
31
  interface S {
32
+ signInRequired: boolean; noSignIn: boolean; signInScreenId: string;
30
33
  status: "loading" | "ready";
31
34
  events: EventRow[];
32
35
  emptyText: string;
@@ -98,11 +101,10 @@ function unverifiedEvent(event: CachedEventRow): CachedEventRow {
98
101
  };
99
102
  }
100
103
 
101
- /** Keep only the candidate rows the member ACTUALLY still holds an RSVP for, asking
102
- * Wix per event. Fail-open per row: a network/permission blip must not blank a row the
103
- * member really has (that would look like their RSVP vanished), so an errored probe
104
- * keeps the row and only an explicit "no active RSVP" drops it. */
105
- async function confirmRsvps(candidates: CachedEventRow[]): Promise<{ events: CachedEventRow[]; verificationUnavailable: boolean }> {
104
+ /** Verify device-local candidates against the current member. Member-only mode
105
+ * requires successful verification; standalone mode retains failed probes as
106
+ * explicitly unverified device-local history. */
107
+ async function confirmRsvps(candidates: CachedEventRow[], memberOnly = false): Promise<{ events: CachedEventRow[]; verificationUnavailable: boolean }> {
106
108
  // Raw wixApi chokepoint rather than a generated client: the member RSVP read lives in
107
109
  // events **v2**, and `@himalaya/wix-events` is the v1 domain module. Adding a
108
110
  // `wix-events-v2` specifier is not an option — the umbrella package deliberately
@@ -122,7 +124,9 @@ async function confirmRsvps(candidates: CachedEventRow[]): Promise<{ events: Cac
122
124
  event: held ? { ...event, status: [event.status, copyParam("myEvents.rsvpConfirmed", "RSVP confirmed")].filter(Boolean).join(" · ") } : null,
123
125
  verificationUnavailable: false,
124
126
  };
125
- } catch {
127
+ } catch (error) {
128
+ // Device candidates carry no member ownership proof until this read succeeds.
129
+ if (memberOnly) throw error;
126
130
  // Fail-open, but never claim backend confirmation while its member-readable
127
131
  // probe is unavailable. The device id remains a candidate, explicitly labeled.
128
132
  return { event: unverifiedEvent(event), verificationUnavailable: true };
@@ -134,8 +138,8 @@ async function confirmRsvps(candidates: CachedEventRow[]): Promise<{ events: Cac
134
138
  };
135
139
  }
136
140
 
137
- const svc = defineService<S, { load: (s: S, arg?: unknown) => Promise<S> }>("himiMyEvents", {
138
- state: derive({
141
+ const INITIAL: S = derive({
142
+ ...NO_READ_SIGN_IN, signInScreenId: "himi_account",
139
143
  status: "loading",
140
144
  events: [],
141
145
  emptyText: "",
@@ -147,45 +151,75 @@ const svc = defineService<S, { load: (s: S, arg?: unknown) => Promise<S> }>("him
147
151
  isLoading: true,
148
152
  notLoading: false,
149
153
  noEmpty: true,
150
- }),
154
+ });
155
+ let memberOnlyRequested = false;
156
+ let loadVersion = 0;
157
+ const svc = defineService<S, { prepare: (s: S) => S; load: (s: S, arg?: unknown) => Promise<S | undefined> }>("himiMyEvents", {
158
+ state: INITIAL,
151
159
  actions: {
152
- load: async (s, arg) => {
160
+ prepare: (s) => ({ ...s, ...INITIAL }),
161
+ load: async (s, arg): Promise<S | undefined> => {
153
162
  stashCopy(arg);
154
- const confirmed = new Set(confirmedRsvpIds());
155
- const identity = await identityLine();
156
- // 1) Instant paint from the on-device cache (offline-safe; empty on first-ever run).
157
- const cached = await readCached();
158
- const cachedEvents = cached.filter((event) => confirmed.has(event.id)).map(displayEventRow);
159
- const base = cached.length
160
- ? derive({ ...s, status: "ready", errored: false, events: cachedEvents, identityLine: identity, verificationUnavailable: cachedEvents.length > 0 })
161
- : s;
162
- // 2) Revalidate from Wix and refresh the cache.
163
+ const version = ++loadVersion;
164
+ const options = arg as { memberOnly?: unknown; signInScreenId?: unknown } | undefined;
165
+ if (options?.memberOnly !== undefined) memberOnlyRequested = options.memberOnly === "1";
166
+ const memberOnly = memberOnlyRequested;
167
+ const clean = { ...INITIAL, signInScreenId: options?.signInScreenId === "himi_sign_in" ? "himi_sign_in" : s.signInScreenId };
168
+ await svc.prepare();
163
169
  try {
164
- const res = await queryEvents({ limit: 50 });
165
- const all = ((res as unknown as { events?: WixEvent[] }).events ?? []).map(cachedEventRow);
166
- await writeCached(all);
167
- // Phase 3c — make each row AUTHORITATIVE. The device list is only a candidate
168
- // set: it never forgets, so an RSVP cancelled elsewhere (web, or by the
169
- // business) would otherwise show here forever. Confirm each candidate against
170
- // Wix and drop the ones the member no longer holds.
171
- //
172
- // Per-event by necessity, not by choice: a member CANNOT enumerate their own
173
- // RSVPs. Verified live against a real member token — `queryRsvps` (cross-event)
174
- // 403s "WIX_EVENTS.READ_RSVP permission required", `listOrders` 403s
175
- // READ_ORDERS, and `/rsvps/current` 400s without an eventId. Only the
176
- // single-event read is member-readable, so the fan-out below IS the ceiling
177
- // until those member scopes exist server-side.
178
- const candidates = all.filter((event) => confirmed.has(event.id)).map(displayEventRow);
179
- const confirmation = await confirmRsvps(candidates);
180
- return derive({ ...base, status: "ready", errored: false, events: confirmation.events, identityLine: identity, verificationUnavailable: confirmation.verificationUnavailable });
181
- } catch {
182
- // Offline / fetch failure: keep the cached rows instead of a blank error state.
183
- return cached.length
184
- ? base
185
- : derive({ ...s, status: "ready", errored: true, events: [], identityLine: identity });
170
+ const member = memberOnly ? await readAccess() : null;
171
+ if (memberOnly && !member?.member.email) throw new Error("Unauthenticated: sign in to see your events");
172
+ const confirmed = new Set(confirmedRsvpIds());
173
+ const identity = await identityLine();
174
+ // 1) Instant paint from the on-device cache (offline-safe; empty on first-ever run).
175
+ // Device-local candidates have no member ownership proof. Branded must
176
+ // verify them online rather than show a previous member's cached RSVP list.
177
+ const cached = memberOnly ? [] : await readCached();
178
+ const cachedEvents = cached.filter((event) => confirmed.has(event.id)).map(displayEventRow);
179
+ const base = cached.length
180
+ ? derive({ ...clean, status: "ready", errored: false, events: cachedEvents, identityLine: identity, verificationUnavailable: cachedEvents.length > 0 })
181
+ : clean;
182
+ // 2) Revalidate from Wix and refresh the cache.
183
+ try {
184
+ const res = await queryEvents({ limit: 50 });
185
+ const all = ((res as unknown as { events?: WixEvent[] }).events ?? []).map(cachedEventRow);
186
+ if (member) await assertReadAccess(member);
187
+ if (version !== loadVersion) return undefined;
188
+ await writeCached(all);
189
+ // Phase 3c — make each row AUTHORITATIVE. The device list is only a candidate
190
+ // set: it never forgets, so an RSVP cancelled elsewhere (web, or by the
191
+ // business) would otherwise show here forever. Confirm each candidate against
192
+ // Wix and drop the ones the member no longer holds.
193
+ //
194
+ // Per-event by necessity, not by choice: a member CANNOT enumerate their own
195
+ // RSVPs. Verified live against a real member token — `queryRsvps` (cross-event)
196
+ // 403s "WIX_EVENTS.READ_RSVP permission required", `listOrders` 403s
197
+ // READ_ORDERS, and `/rsvps/current` 400s without an eventId. Only the
198
+ // single-event read is member-readable, so the fan-out below IS the ceiling
199
+ // until those member scopes exist server-side.
200
+ const candidates = all.filter((event) => confirmed.has(event.id)).map(displayEventRow);
201
+ const confirmation = await confirmRsvps(candidates, memberOnly);
202
+ if (member) await assertReadAccess(member);
203
+ if (version !== loadVersion) return undefined;
204
+ return derive({ ...base, status: "ready", errored: false, events: confirmation.events, identityLine: identity, verificationUnavailable: confirmation.verificationUnavailable });
205
+ } catch (error) {
206
+ if (memberOnly && readAccessDenied(error)) throw error;
207
+ if (member) await assertReadAccess(member);
208
+ if (version !== loadVersion) return undefined;
209
+ // Offline / fetch failure: keep the cached rows instead of a blank error state.
210
+ return cached.length
211
+ ? base
212
+ : derive({ ...clean, status: "ready", errored: true, events: [], identityLine: identity });
213
+ }
214
+ } catch (error) {
215
+ const failure = memberOnly && !(await memberAccess()).email ? new Error("Unauthenticated: sign in to see your events") : error;
216
+ const flags = await readSignInFlags(failure);
217
+ return version === loadVersion ? derive({ ...clean, ...flags, status: "ready", errored: true, events: [] }) : undefined;
186
218
  }
187
219
  },
188
220
  },
189
221
  });
190
- svc.load();
222
+ // Wait for the descriptor's load action to select member-only or device-local scope.
223
+ // An eager unconfigured read could briefly expose guest KV before Branded opts in.
224
+ svc.prepare();
191
225
  export { svc };
@@ -37,7 +37,7 @@ export default defineApp({
37
37
  actions: "http://localhost:8190/v1/actions",
38
38
  sync: "http://localhost:8190/v1/sync",
39
39
  },
40
- capabilities: ["live_activity","push","share","secure_storage","open_url","local_database","clipboard","ui","speech","camera","photos","file_picker","files","presigned_upload","app_info","biometrics","wix_platform","animation"],
40
+ capabilities: ["push","share","secure_storage","open_url","local_database","clipboard","ui","speech","camera","photos","file_picker","files","presigned_upload","app_info","biometrics","wix_platform","stream","wix_api"],
41
41
  designTokensPath: "./tokens.json",
42
42
  // Native fallback; the T5 splash descriptor owns the editable launch appearance.
43
43
  splash: {