@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,6 @@
1
+ import { createBusinessContactService } from "@himalaya/screens";
2
+
3
+ // Contact values and the optional public total are build-time source evidence.
4
+ // No owner API, device location, or cross-site source URL is read by this worker.
5
+ const svc = createBusinessContactService();
6
+ export { svc };
@@ -0,0 +1,444 @@
1
+ // Tier-5 bundle: Himi Blog feed - public reader list/search/category browsing.
2
+ //
3
+ // The feed draws its own layout (one card per post: photo, author, title, excerpt, counts), so
4
+ // it is NOT a shared collection: no List/Grid toggle, no Refine, no "Saved" chip. Saved posts
5
+ // live on their own screen (himi_saved).
6
+ import { defineService } from "@himalaya/state";
7
+ import { queryCategories, queryPosts, type WixPost, type WixQueryPostsRequest } from "@himalaya/wix-blog";
8
+ import { stashCopy, copyParam, copyPlural } from "../_shared/himi-copy.js";
9
+ import { getAll, upsert, type DbEntity } from "@himalaya/local-db";
10
+ import { withoutHidden } from "../_shared/himi-blog-hidden.js";
11
+ import { authorFields, BLOG_CARD_IMAGE, countLabels, countsOf, coverOf, dateLineOf, dateOf, cachedCover, coverSourceOf, legacyRowFixes, LIST_FIELDSETS, NO_AUTHOR, resolveAuthors, type AuthorFields, type BlogPostShape, type CountLabels } from "../_shared/himi-blog-post-row.js";
12
+
13
+ const PAGE_SIZE = 20;
14
+
15
+ interface CategoryRow {
16
+ id: string;
17
+ label: string;
18
+ }
19
+
20
+ interface PostRow extends AuthorFields, CountLabels {
21
+ id: string;
22
+ title: string;
23
+ excerpt: string;
24
+ category: string;
25
+ categoryId: string;
26
+ /** Every category the post is filed under: a chip matches any of them, not only the first. */
27
+ categoryIds: string[];
28
+ /** "Jul 30, 2026 · 4 min read". */
29
+ meta: string;
30
+ /** The publish date alone (Saved reads it from the cached row). */
31
+ date: string;
32
+ likes: string;
33
+ views: string;
34
+ comments: string;
35
+ /** The row carries the site's counts. A row cached by an older build has none, and shows no
36
+ * counts row rather than invented zeros. */
37
+ hasCounts: boolean;
38
+ noCounts: boolean;
39
+ cover: string;
40
+ /** The photo as stored (unsized), cached so an offline post or Saved row sizes it for itself. */
41
+ coverSource: string;
42
+ hasCover: boolean;
43
+ noCover: boolean;
44
+ pinned: boolean;
45
+ notPinned: boolean;
46
+ memberId: string;
47
+ initial: string;
48
+ detailScreenId: string;
49
+ }
50
+
51
+ interface S {
52
+ status: "loading" | "ready" | "error";
53
+ query: string;
54
+ selectedCategoryId: string;
55
+ /** All + each category that has posts. */
56
+ categories: CategoryRow[];
57
+ /** The chips' selection: one id ("" = All). */
58
+ selectedCategoryIds: string[];
59
+ hideCategories: boolean;
60
+ /** The pinned-posts read failed: the feed shows the newest posts without them first. */
61
+ pinnedUnavailable: boolean;
62
+ allPosts: PostRow[];
63
+ posts: PostRow[];
64
+ offset: number;
65
+ total: number;
66
+ hasMore: boolean;
67
+ noMore: boolean;
68
+ /** RFC 0008 scroll load-more — `generation:offset` as a synthetic cursor ("" ⇒ exhausted). */
69
+ nextCursor: string;
70
+ /** One more each time a new list lands (load, retry, chip, clear). In the cursor, so a list that
71
+ * replaced one whose page was claimed never republishes that claimed cursor ("0:20" twice): the
72
+ * host pages only on a cursor it has not claimed, so the new list would never load page 2. */
73
+ generation: number;
74
+ emptyText: string;
75
+ errorText: string;
76
+ isLoading: boolean;
77
+ notLoading: boolean;
78
+ errored: boolean;
79
+ notErrored: boolean;
80
+ isEmpty: boolean;
81
+ noEmpty: boolean;
82
+ /** The empty state, split: no post matches the search or the category (with Clear filters), or
83
+ * the blog has no posts at all (no button). */
84
+ noMatchHidden: boolean;
85
+ noPostsHidden: boolean;
86
+ resultSummary: string;
87
+ }
88
+
89
+ type PostWithExtras = WixPost & BlogPostShape;
90
+
91
+ // Offline-first (data-offline): the reader feed is public read-through — paint the
92
+ // last-synced posts from the on-device store first (instant, works offline), then
93
+ // revalidate from Wix and refresh the cache. DEGRADES GRACEFULLY: every local-db
94
+ // call is wrapped so a build that ships in an app which hasn't granted
95
+ // `local_database` (+ declared the `blog_posts` entity) just falls back to today's
96
+ // online-only path — the capability fails closed per-entity.
97
+ const ENTITY = "blog_posts";
98
+ async function readCachedPosts(): Promise<PostRow[]> {
99
+ try {
100
+ // A row cached by an older build has no author or count fields. An unset gate fails open
101
+ // and paints an empty author row, so it reads as "no author" until the network refresh.
102
+ return ((await getAll(ENTITY)) as unknown as Array<Partial<PostRow>>).map((row): PostRow => {
103
+ const cover = cachedCover(row, BLOG_CARD_IMAGE);
104
+ return { ...NO_AUTHOR, likes: "", views: "", comments: "", likesLabel: "", viewsLabel: "", commentsLabel: "", hasCounts: false, noCounts: true, pinned: false, notPinned: true, memberId: "", date: "", coverSource: "", ...row, ...legacyRowFixes(row), cover, hasCover: !!cover, noCover: !cover, categoryIds: row.categoryIds ?? (row.categoryId ? [row.categoryId] : []) } as PostRow;
105
+ });
106
+ } catch { return []; }
107
+ }
108
+ async function writeCachedPosts(rows: PostRow[]): Promise<void> {
109
+ try { for (const r of rows) await upsert(ENTITY, r as unknown as DbEntity); } catch { /* capability not granted → online-only */ }
110
+ }
111
+
112
+ function strOf(arg: unknown): string {
113
+ if (typeof arg === "string") return arg;
114
+ const a = arg as { value?: string; text?: string; query?: string } | undefined;
115
+ return a?.value ?? a?.text ?? a?.query ?? "";
116
+ }
117
+
118
+ /** The chip the reader picked. FilterChips sends `{ selectedIds }` (an empty list when the
119
+ * selected chip is tapped again, which reads as All). The string / `{ categoryId }` arms are
120
+ * the older direct callers. */
121
+ function categoryIdOf(arg: unknown): string {
122
+ if (typeof arg === "string") return arg;
123
+ const a = arg as { categoryId?: string; id?: string; selectedIds?: unknown; args?: { selectedIds?: unknown } } | undefined;
124
+ const ids = a?.selectedIds ?? a?.args?.selectedIds;
125
+ if (Array.isArray(ids)) return typeof ids[0] === "string" ? ids[0] : "";
126
+ return a?.categoryId ?? a?.id ?? "";
127
+ }
128
+
129
+ function normalize(post: WixPost, categoryMap: Map<string, string>): PostRow {
130
+ const richPost = post as PostWithExtras;
131
+ const title = post.title || copyParam("blogCommon.untitled", "Untitled post");
132
+ const categoryId = (richPost.categoryIds ?? []).find((id) => categoryMap.has(id)) ?? richPost.categoryIds?.[0] ?? "";
133
+ // No id, no label: the map never names "" (that is the All chip, not a category).
134
+ const category = categoryId ? categoryMap.get(categoryId) ?? "" : "";
135
+ const cover = coverOf(richPost);
136
+ const counts = countsOf(richPost);
137
+ return {
138
+ ...NO_AUTHOR,
139
+ id: post.id,
140
+ title,
141
+ // No invented filler: a post with no excerpt shows none.
142
+ excerpt: (post.excerpt ?? "").trim(),
143
+ // A post with no category has none: no "Blog" stand-in, and so no chip for it either.
144
+ category,
145
+ categoryId,
146
+ categoryIds: (richPost.categoryIds ?? []).filter((id) => typeof id === "string" && id),
147
+ meta: dateLineOf(richPost),
148
+ date: dateOf(richPost),
149
+ // Unknown counts (a read without METRICS) show no counts row: never invented zeros.
150
+ likes: counts ? String(counts.likes) : "",
151
+ views: counts ? String(counts.views) : "",
152
+ comments: counts ? String(counts.comments) : "",
153
+ ...countLabels(counts),
154
+ hasCounts: !!counts,
155
+ noCounts: !counts,
156
+ cover,
157
+ coverSource: coverSourceOf(richPost),
158
+ hasCover: Boolean(cover),
159
+ noCover: !cover,
160
+ pinned: richPost.pinned === true,
161
+ notPinned: richPost.pinned !== true,
162
+ memberId: richPost.memberId ?? "",
163
+ initial: (title[0] || "#").toUpperCase(),
164
+ // WS-C — canonical param-less detail screenId; the descriptor row binds the
165
+ // separate `id` field as a first-class nav param. This also dissolves the
166
+ // himi_blog_post_<id> vs himi_blog linkable prefix collision (#570).
167
+ detailScreenId: "himi_blog_post",
168
+ };
169
+ }
170
+
171
+ async function withAuthors(rows: PostRow[]): Promise<PostRow[]> {
172
+ const authors = await resolveAuthors(rows.map((row) => row.memberId));
173
+ return rows.map((row) => ({ ...row, ...authorFields(authors.get(row.memberId)) }));
174
+ }
175
+
176
+ /** Pinned posts first; otherwise the site's own order (newest first). */
177
+ function pinnedFirst(rows: PostRow[]): PostRow[] {
178
+ return [...rows.filter((row) => row.pinned), ...rows.filter((row) => !row.pinned)];
179
+ }
180
+
181
+ function applyFilters(s: S): S {
182
+ const needle = s.query.trim().toLowerCase();
183
+ // Posts this device's reader hid (on the post screen) never show, whatever the cache or the live page holds.
184
+ // Pinned posts lead All only: a category shows its own posts in date order.
185
+ const visible = withoutHidden(s.allPosts);
186
+ const posts = (s.selectedCategoryId ? visible : pinnedFirst(visible)).filter((post) => {
187
+ const categoryOk = !s.selectedCategoryId || post.categoryIds.includes(s.selectedCategoryId);
188
+ const queryOk =
189
+ !needle ||
190
+ post.title.toLowerCase().includes(needle) ||
191
+ post.excerpt.toLowerCase().includes(needle) ||
192
+ post.category.toLowerCase().includes(needle) ||
193
+ post.authorName.toLowerCase().includes(needle);
194
+ return categoryOk && queryOk;
195
+ });
196
+ return derive({
197
+ ...s,
198
+ posts,
199
+ emptyText: posts.length
200
+ ? ""
201
+ : needle || s.selectedCategoryId
202
+ ? copyParam("blog.noMatchText", "No matching posts")
203
+ : copyParam("blog.emptyText", "No blog posts yet"),
204
+ resultSummary: copyPlural("blog.resultSummary", "{n, plural, one {# post} other {# posts}}", posts.length),
205
+ });
206
+ }
207
+
208
+ function derive(s: S): S {
209
+ const isLoading = s.status === "loading";
210
+ const errored = s.status === "error";
211
+ const isEmpty = !isLoading && !errored && s.posts.length === 0;
212
+ const filtered = !!s.query.trim() || !!s.selectedCategoryId;
213
+ return {
214
+ ...s,
215
+ selectedCategoryIds: [s.selectedCategoryId],
216
+ // No real category, or one that every loaded post is in, is no choice at all: All already
217
+ // shows the same posts. One category beside uncategorized posts still narrows the list.
218
+ // While a category is selected the chips always stay: they are the way back to All. While
219
+ // more pages are to come, a later page may hold an uncategorized post, so they stay too.
220
+ hideCategories: !s.selectedCategoryId && (s.categories.length <= 1
221
+ || (s.categories.length === 2 && !s.hasMore && s.allPosts.every((post) => post.categoryIds.includes(s.categories[1]!.id)))),
222
+ isLoading,
223
+ notLoading: !isLoading,
224
+ errored,
225
+ notErrored: !errored,
226
+ isEmpty,
227
+ noEmpty: !isEmpty,
228
+ noMatchHidden: !(isEmpty && filtered),
229
+ noPostsHidden: !(isEmpty && !filtered),
230
+ noMore: !s.hasMore,
231
+ nextCursor: s.hasMore ? `${s.generation}:${s.offset}` : "",
232
+ };
233
+ }
234
+
235
+ const allChip = (): CategoryRow => ({ id: "", label: copyParam("collection.all", "All") });
236
+
237
+ async function loadCategories(): Promise<{ rows: CategoryRow[]; map: Map<string, string>; failed?: true }> {
238
+ try {
239
+ const result = await queryCategories({ paging: { limit: 100 } });
240
+ const rows: CategoryRow[] = [allChip()];
241
+ const map = new Map<string, string>();
242
+ for (const category of result.categories ?? []) {
243
+ const label = (category.label || category.title || "").trim();
244
+ if (!category.id || !label) continue;
245
+ map.set(category.id, label);
246
+ // A category with no published post is a chip that always shows "No matching posts".
247
+ // `postCount` absent (an older payload) keeps the chip rather than guessing.
248
+ if (category.postCount === undefined || category.postCount > 0) rows.push({ id: category.id, label });
249
+ }
250
+ return { rows, map };
251
+ } catch {
252
+ return { rows: [allChip()], map: new Map<string, string>(), failed: true };
253
+ }
254
+ }
255
+
256
+ /** The category labels by id, from the chips (All, id "", is not a category). */
257
+ const labelsOf = (s: S): Map<string, string> => new Map(s.categories.filter((category) => category.id).map((category) => [category.id, category.label]));
258
+
259
+ /** One page of posts, newest first; with `categoryId`, that category's posts only, read on the
260
+ * server so a category whose posts fall on a later page still finds them. */
261
+ async function loadPosts(offset: number, categoryMap: Map<string, string>, categoryId = ""): Promise<{ rows: PostRow[]; total: number; nextOffset: number; hasMore: boolean }> {
262
+ const paging = { limit: PAGE_SIZE, offset };
263
+ const filter = categoryId ? { filter: { categoryIds: { $hasSome: [categoryId] } } } : {};
264
+ let result;
265
+ try {
266
+ result = await queryPosts({ query: { ...filter, paging, sort: [{ fieldName: "firstPublishedDate", order: "DESC" }] }, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest);
267
+ } catch {
268
+ result = await queryPosts({ query: { ...filter, paging }, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest);
269
+ }
270
+ const rawPosts = result.posts ?? [];
271
+ const rows = await withAuthors(rawPosts.map((post) => normalize(post, categoryMap)));
272
+ const total = result.pagingMetadata?.total ?? offset + rows.length;
273
+ const nextOffset = offset + rows.length;
274
+ return { rows, total, nextOffset, hasMore: nextOffset < total };
275
+ }
276
+
277
+ const baseState: S = derive({
278
+ status: "loading",
279
+ query: "",
280
+ selectedCategoryId: "",
281
+ categories: [{ id: "", label: "All" }],
282
+ selectedCategoryIds: [""],
283
+ hideCategories: true,
284
+ pinnedUnavailable: false,
285
+ allPosts: [],
286
+ posts: [],
287
+ offset: 0,
288
+ total: 0,
289
+ hasMore: false,
290
+ noMore: true,
291
+ nextCursor: "",
292
+ generation: 0,
293
+ emptyText: "",
294
+ errorText: "",
295
+ isLoading: true,
296
+ notLoading: false,
297
+ errored: false,
298
+ notErrored: true,
299
+ isEmpty: false,
300
+ noMatchHidden: true,
301
+ noPostsHidden: true,
302
+ noEmpty: true,
303
+ resultSummary: "",
304
+ });
305
+
306
+ /** The site's pinned posts, whatever page they would fall on by date: they lead the feed. */
307
+ async function loadPinned(categoryMap: Map<string, string>): Promise<PostRow[]> {
308
+ const result = await queryPosts({ query: { filter: { pinned: true }, paging: { limit: PAGE_SIZE } }, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest);
309
+ // Only rows that say they are pinned: a source that ignores the filter cannot reorder the feed.
310
+ return withAuthors((result.posts ?? []).map((post) => normalize(post, categoryMap)).filter((row) => row.pinned));
311
+ }
312
+
313
+ /** `rows` without the posts `kept` already holds (a pinned post also arrives on its date's page). */
314
+ function withoutKnown(rows: PostRow[], kept: PostRow[]): PostRow[] {
315
+ const known = new Set(kept.map((row) => row.id));
316
+ return rows.filter((row) => !known.has(row.id));
317
+ }
318
+
319
+ async function loadFeedState(s: S): Promise<S> {
320
+ // 1) Instant paint from the on-device cache (offline-safe; empty on first-ever run).
321
+ const cached = await readCachedPosts();
322
+ const base = cached.length
323
+ ? applyFilters({ ...s, status: "ready", allPosts: cached, posts: cached, errorText: "" })
324
+ : s;
325
+ // 2) Revalidate from Wix and refresh the cache.
326
+ try {
327
+ const read = await loadCategories();
328
+ // A failed categories read keeps the chips already known (and so the selection): only a
329
+ // category the site answered without is gone, and cannot stay selected.
330
+ const categories = read.failed && s.categories.length > 1 ? { rows: s.categories, map: labelsOf(s) } : read;
331
+ const selectedCategoryId = categories.rows.some((row) => row.id === s.selectedCategoryId) ? s.selectedCategoryId : "";
332
+ const page = await loadPosts(0, categories.map, selectedCategoryId);
333
+ // A failed pinned read is recorded, not taken for "no pinned posts". Pinned posts lead All;
334
+ // a category shows its own posts in date order.
335
+ let pinned: PostRow[] = [];
336
+ let pinnedUnavailable = false;
337
+ if (!selectedCategoryId) {
338
+ try { pinned = await loadPinned(categories.map); } catch { pinnedUnavailable = true; }
339
+ }
340
+ const rows = [...pinned, ...withoutKnown(page.rows, pinned)];
341
+ await writeCachedPosts(rows);
342
+ return applyFilters({
343
+ ...base,
344
+ status: "ready",
345
+ categories: categories.rows,
346
+ selectedCategoryId,
347
+ pinnedUnavailable,
348
+ allPosts: rows,
349
+ posts: rows,
350
+ offset: page.nextOffset,
351
+ total: page.total,
352
+ hasMore: page.hasMore,
353
+ errorText: "",
354
+ });
355
+ } catch {
356
+ // Offline / fetch failure: keep the cached rows instead of a blank error state. No paging
357
+ // from them: the offset belongs to whatever list was read before (another chip, maybe), so a
358
+ // later page would skip this list's first posts. Retry or pull-to-refresh reads page 1.
359
+ return cached.length
360
+ ? derive({ ...base, hasMore: false })
361
+ : derive({ ...s, status: "error", hasMore: false, errorText: copyParam("blog.errorText", "Blog posts are unavailable. Try again.") });
362
+ }
363
+ }
364
+
365
+ // The reads are async and the runtime keeps whichever result resolves LAST, so a slower answer to
366
+ // an earlier tap (chip A, then chip B; a chip, then a search) would put the older choice back.
367
+ // Every action that changes which posts are READ (load, retry, chip, clear) takes a new version;
368
+ // an async result whose version is no longer current is dropped (undefined keeps the state the
369
+ // newer action set). Search only filters what is loaded, so it does not drop a read in flight
370
+ // (a first load would then never land): the reader's latest search text is applied to the
371
+ // result instead.
372
+ // `shownVersion` is the version of the list on screen: while a newer read is in flight the two
373
+ // differ, and loadMore waits (a page of the old list would land on top of the new one). A chip tap
374
+ // is compared with the latest tap (`wantedCategoryId`), not with the chip on screen, so tapping
375
+ // back to it while another chip's read is in flight still wins.
376
+ let feedVersion = 0;
377
+ let shownVersion = 0;
378
+ let searchText = "";
379
+ let wantedCategoryId = "";
380
+ async function current(version: number, next: Promise<S>): Promise<S | undefined> {
381
+ const s = await next;
382
+ if (version !== feedVersion) return undefined;
383
+ shownVersion = version;
384
+ wantedCategoryId = s.selectedCategoryId;
385
+ return applyFilters({ ...s, query: searchText, generation: s.generation + 1 });
386
+ }
387
+
388
+ const svc = defineService<S, {
389
+ load: (s: S, arg?: unknown) => Promise<S | undefined>;
390
+ retry: (s: S) => Promise<S | undefined>;
391
+ search: (s: S, arg?: unknown) => S;
392
+ /** A chip: that category's posts, read on the server (from the first page). */
393
+ selectCategory: (s: S, arg?: unknown) => Promise<S | undefined>;
394
+ clearFilters: (s: S) => Promise<S | undefined>;
395
+ loadMore: (s: S) => Promise<S | undefined>;
396
+ }>("himiBlogFeed", {
397
+ state: baseState,
398
+ actions: {
399
+ // Both read the last chip tapped, not the one on screen: a tap whose read is still in flight is kept.
400
+ load: (s, arg) => { stashCopy(arg); return current(++feedVersion, loadFeedState({ ...s, selectedCategoryId: wantedCategoryId })); },
401
+ retry: (s) => current(++feedVersion, loadFeedState({ ...s, selectedCategoryId: wantedCategoryId, status: "loading", errorText: "" })),
402
+ search: (s, arg) => { searchText = strOf(arg); return applyFilters({ ...s, query: searchText }); },
403
+ selectCategory: (s, arg) => {
404
+ const selectedCategoryId = categoryIdOf(arg);
405
+ if (selectedCategoryId === wantedCategoryId) return Promise.resolve(s);
406
+ wantedCategoryId = selectedCategoryId;
407
+ return current(++feedVersion, loadFeedState(applyFilters({ ...s, selectedCategoryId })));
408
+ },
409
+ clearFilters: (s) => { searchText = ""; wantedCategoryId = ""; return current(++feedVersion, loadFeedState(applyFilters({ ...s, query: "", selectedCategoryId: "" }))); },
410
+ loadMore: async (s) => {
411
+ // Not while a newer read is in flight: s is the old list, and its next page would replace
412
+ // the new one when it lands.
413
+ if (!s.hasMore || s.status === "loading" || shownVersion !== feedVersion) return s;
414
+ // A page that lands after a newer chip or reload belongs to the old list: dropped. A search
415
+ // made while it loaded is applied to it.
416
+ const version = feedVersion;
417
+ try {
418
+ const page = await loadPosts(s.offset, labelsOf(s), s.selectedCategoryId);
419
+ if (version !== feedVersion) return undefined;
420
+ const allPosts = [...s.allPosts, ...withoutKnown(page.rows, s.allPosts)];
421
+ await writeCachedPosts(allPosts);
422
+ // Again after the cache write: a chip or reload that landed during it is newer.
423
+ if (version !== feedVersion) return undefined;
424
+ return applyFilters({
425
+ ...s,
426
+ query: searchText,
427
+ status: "ready",
428
+ allPosts,
429
+ offset: page.nextOffset,
430
+ total: page.total,
431
+ hasMore: page.hasMore,
432
+ errorText: "",
433
+ });
434
+ } catch {
435
+ if (version !== feedVersion) return undefined;
436
+ // A search typed while the page loaded stays applied.
437
+ return applyFilters({ ...s, query: searchText, errorText: copyParam("blog.loadMoreErrorText", "More posts could not load.") });
438
+ }
439
+ },
440
+ },
441
+ });
442
+
443
+ svc.load();
444
+ export { svc };