@wix/himalaya-cli 0.1750.0 → 0.1752.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-config.d.ts +1 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-module.d.ts +3 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +3 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/define-app.d.ts +16 -1
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/himi-package.d.ts +478 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/host-compatibility.d.ts +56 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/icon-catalog.generated.d.ts +1 -1
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +4 -0
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-shell.d.ts +154 -7
  10. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/validator.d.ts +3 -0
  11. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/auth-providers/wix/src/index.d.ts +1 -1
  12. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/auth-providers/wix/src/native-engine.d.ts +49 -3
  13. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/auth/src/copy.generated.d.ts +16 -1
  14. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/auth/src/feedback.d.ts +1 -1
  15. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/index.d.ts +2 -0
  16. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/podcast-service.d.ts +105 -0
  17. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/podcast.d.ts +116 -0
  18. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/auth.mjs +27 -2
  19. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +326 -13
  20. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +757 -83
  21. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +156 -0
  22. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-auth/worker.mjs +133 -13
  23. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-auth.mjs +139 -13
  24. package/dist/browser-plane/assets.json +5 -5
  25. package/dist/browser-plane/preview-deferred/{b40ea5d0d6251898ff5617139fde8be008dd11e99a70b14c1052093685401700.bin → 2671d1cadb15daa5e59440f4c924e30c221ab3d405e8a56a0ab1cdbe4764af3d.bin} +1 -1
  26. package/dist/browser-plane/sw.js +7 -7
  27. package/dist/cli.mjs +37219 -33014
  28. package/dist/preview-assets.generated.bin +0 -0
  29. package/guides/app-config.md +1 -1
  30. package/guides/component-reference.json +1 -1
  31. package/guides/component-reference.md +4 -0
  32. package/guides/designing-himi-screens.md +7 -0
  33. package/guides/getting-started.md +2 -0
  34. package/guides/headless-loop.md +1 -1
  35. package/guides/himi-json-output.md +25 -3
  36. package/guides/himi-skill.md +2 -0
  37. package/guides/index.json +6 -0
  38. package/guides/push-cli-onboarding.md +13 -0
  39. package/guides/qa-builds.md +15 -2
  40. package/guides/recipe-podcast.md +149 -0
  41. package/guides/releasing-with-himi-serve.md +51 -0
  42. package/guides/store-submission.md +46 -1
  43. package/guides/tier-5-add-a-screen.md +16 -2
  44. package/guides/wix-business-context.md +29 -0
  45. package/guides/wix-platform-usage.md +7 -2
  46. package/package.json +10 -10
  47. package/template-icons/fitness-gym.png +0 -0
  48. package/templates/beauty-salon/dev/index.ts +1 -1
  49. package/templates/beauty-salon/l10n/en.json +1 -1
  50. package/templates/beauty-salon/tier5-src/_shared/program-fields.ts +16 -0
  51. package/templates/beauty-salon/tier5-src/_shared/programs-section.ts +5 -8
  52. package/templates/beauty-salon/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  53. package/templates/branded-lite/dev/index.ts +101 -1
  54. package/templates/branded-lite/l10n/en.json +22 -1
  55. package/templates/branded-lite/l10n/es.json +22 -0
  56. package/templates/branded-lite/l10n/fr.json +18 -0
  57. package/templates/branded-lite/l10n/he.json +15 -0
  58. package/templates/branded-lite/tier5-src/_shared/program-fields.ts +16 -0
  59. package/templates/branded-lite/tier5-src/_shared/programs-section.ts +5 -8
  60. package/templates/branded-lite/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  61. package/templates/branded-lite/tier5-src/himi-branded-lite-podcasts/index.ts +14 -234
  62. package/templates/brandy/README.md +33 -0
  63. package/templates/brandy/config.ts +51 -7
  64. package/templates/brandy/dev/index.ts +23 -9
  65. package/templates/community-club/l10n/en.json +1 -1
  66. package/templates/community-club/tier5-src/_shared/program-fields.ts +16 -0
  67. package/templates/community-club/tier5-src/_shared/programs-section.ts +5 -8
  68. package/templates/events-meetups/l10n/en.json +1 -1
  69. package/templates/events-meetups/tier5-src/_shared/program-fields.ts +16 -0
  70. package/templates/events-meetups/tier5-src/_shared/programs-section.ts +5 -8
  71. package/templates/fitness-gym/README.md +53 -0
  72. package/templates/fitness-gym/config.ts +560 -0
  73. package/templates/fitness-gym/dev/index.ts +25787 -0
  74. package/templates/fitness-gym/himalaya.content.json +64 -0
  75. package/templates/fitness-gym/himalaya.template.json +15 -0
  76. package/templates/fitness-gym/icon.png +0 -0
  77. package/templates/fitness-gym/platforms.json +1 -0
  78. package/templates/fitness-gym/tier5-src/_shared/app-locale.ts +61 -0
  79. package/templates/fitness-gym/tier5-src/_shared/booking-location.ts +147 -0
  80. package/templates/fitness-gym/tier5-src/_shared/booking-session.ts +224 -0
  81. package/templates/fitness-gym/tier5-src/_shared/branded-lite-hosted.ts +280 -0
  82. package/templates/fitness-gym/tier5-src/_shared/branded-load-state.ts +109 -0
  83. package/templates/fitness-gym/tier5-src/_shared/business-chat-copy.ts +40 -0
  84. package/templates/fitness-gym/tier5-src/_shared/business-chat-history.ts +51 -0
  85. package/templates/fitness-gym/tier5-src/_shared/business-chat-message-model.ts +177 -0
  86. package/templates/fitness-gym/tier5-src/_shared/business-chat-model.ts +56 -0
  87. package/templates/fitness-gym/tier5-src/_shared/business-chat-presenter.ts +576 -0
  88. package/templates/fitness-gym/tier5-src/_shared/business-chat-transport.ts +148 -0
  89. package/templates/fitness-gym/tier5-src/_shared/collection-contract.ts +228 -0
  90. package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +193 -0
  91. package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +400 -0
  92. package/templates/fitness-gym/tier5-src/_shared/detail-presence.ts +51 -0
  93. package/templates/fitness-gym/tier5-src/_shared/engine-intl.ts +523 -0
  94. package/templates/fitness-gym/tier5-src/_shared/himi-account.ts +194 -0
  95. package/templates/fitness-gym/tier5-src/_shared/himi-booking-saved.ts +88 -0
  96. package/templates/fitness-gym/tier5-src/_shared/himi-bookings.ts +318 -0
  97. package/templates/fitness-gym/tier5-src/_shared/himi-copy.ts +116 -0
  98. package/templates/fitness-gym/tier5-src/_shared/himi-media.ts +29 -0
  99. package/templates/fitness-gym/tier5-src/_shared/himi-store.ts +7 -0
  100. package/templates/fitness-gym/tier5-src/_shared/himi-text.ts +24 -0
  101. package/templates/fitness-gym/tier5-src/_shared/host-events.ts +66 -0
  102. package/templates/fitness-gym/tier5-src/_shared/hosted-checkout.ts +70 -0
  103. package/templates/fitness-gym/tier5-src/_shared/iap-attendance-form.ts +106 -0
  104. package/templates/fitness-gym/tier5-src/_shared/iap-attendance-purchase.ts +216 -0
  105. package/templates/fitness-gym/tier5-src/_shared/iap-attendance.ts +38 -0
  106. package/templates/fitness-gym/tier5-src/_shared/iap-worker.ts +127 -0
  107. package/templates/fitness-gym/tier5-src/_shared/inbox-rooms.ts +68 -0
  108. package/templates/fitness-gym/tier5-src/_shared/local-preferences.ts +38 -0
  109. package/templates/fitness-gym/tier5-src/_shared/member-access.ts +63 -0
  110. package/templates/fitness-gym/tier5-src/_shared/member-account-routes.ts +52 -0
  111. package/templates/fitness-gym/tier5-src/_shared/member-bookings.ts +107 -0
  112. package/templates/fitness-gym/tier5-src/_shared/member-screen.ts +99 -0
  113. package/templates/fitness-gym/tier5-src/_shared/notification-target.ts +141 -0
  114. package/templates/fitness-gym/tier5-src/_shared/offset-page.ts +10 -0
  115. package/templates/fitness-gym/tier5-src/_shared/online-actions.ts +76 -0
  116. package/templates/fitness-gym/tier5-src/_shared/owner-load-error.ts +348 -0
  117. package/templates/fitness-gym/tier5-src/_shared/payment-setup.ts +6 -0
  118. package/templates/fitness-gym/tier5-src/_shared/pricing-plan-display.ts +64 -0
  119. package/templates/fitness-gym/tier5-src/_shared/program-description.ts +11 -0
  120. package/templates/fitness-gym/tier5-src/_shared/program-fields.ts +16 -0
  121. package/templates/fitness-gym/tier5-src/_shared/program-standing.ts +46 -0
  122. package/templates/fitness-gym/tier5-src/_shared/rich-body.ts +78 -0
  123. package/templates/fitness-gym/tier5-src/_shared/rich-content-link.ts +34 -0
  124. package/templates/fitness-gym/tier5-src/_shared/sign-in-sheet.ts +18 -0
  125. package/templates/fitness-gym/tier5-src/_shared/staff-name.ts +18 -0
  126. package/templates/fitness-gym/tier5-src/_shared/weekly-goal.ts +107 -0
  127. package/templates/fitness-gym/tier5-src/_shared/wix-bi.ts +85 -0
  128. package/templates/fitness-gym/tier5-src/_shared/wix-member-links.ts +114 -0
  129. package/templates/fitness-gym/tier5-src/_shared/wix-service-price.ts +146 -0
  130. package/templates/fitness-gym/tier5-src/business-chat/index.ts +732 -0
  131. package/templates/fitness-gym/tier5-src/business-contact/index.ts +6 -0
  132. package/templates/fitness-gym/tier5-src/himi-booking-account/index.ts +267 -0
  133. package/templates/fitness-gym/tier5-src/himi-booking-bookings/index.ts +468 -0
  134. package/templates/fitness-gym/tier5-src/himi-booking-service/index.ts +1190 -0
  135. package/templates/fitness-gym/tier5-src/himi-booking-services/index.ts +791 -0
  136. package/templates/fitness-gym/tier5-src/himi-booking-time/index.ts +1729 -0
  137. package/templates/fitness-gym/tier5-src/himi-branded-lite-agenda/index.ts +988 -0
  138. package/templates/fitness-gym/tier5-src/himi-branded-lite-member-programs/index.ts +656 -0
  139. package/templates/fitness-gym/tier5-src/himi-branded-lite-notifications/index.ts +256 -0
  140. package/templates/fitness-gym/tier5-src/himi-branded-lite-plans/index.ts +495 -0
  141. package/templates/fitness-gym/tier5-src/himi-branded-lite-program/facts.ts +52 -0
  142. package/templates/fitness-gym/tier5-src/himi-branded-lite-program/index.ts +845 -0
  143. package/templates/fitness-gym/tier5-src/himi-fitcoach-goal/index.ts +190 -0
  144. package/templates/fitness-gym/tier5-src/himi-fitcoach-home/index.ts +619 -0
  145. package/templates/fitness-gym/tier5-src/himi-store-account/index.ts +1007 -0
  146. package/templates/fitness-gym/tier5-src/wix-spaces-my-subscriptions/index.ts +84 -0
  147. package/templates/fitness-gym/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
  148. package/templates/fitness-gym/tokens.json +414 -0
  149. package/templates/gym-fitness/dev/index.ts +1 -1
  150. package/templates/gym-fitness/l10n/en.json +1 -1
  151. package/templates/gym-fitness/tier5-src/_shared/program-fields.ts +16 -0
  152. package/templates/gym-fitness/tier5-src/_shared/programs-section.ts +5 -8
  153. package/templates/gym-fitness/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  154. package/templates/medical-services/dev/index.ts +2 -1
  155. package/templates/medical-services/tier5-src/himi-booking-account/index.ts +16 -1
  156. package/templates/nonprofit-cause/l10n/en.json +1 -1
  157. package/templates/nonprofit-cause/tier5-src/_shared/program-fields.ts +16 -0
  158. package/templates/nonprofit-cause/tier5-src/_shared/programs-section.ts +5 -8
  159. package/templates/personal-fitness-trainer/dev/index.ts +2 -2
  160. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  161. package/templates/podcast-creator/dev/index.ts +100 -0
  162. package/templates/podcast-creator/l10n/en.json +22 -1
  163. package/templates/podcast-creator/l10n/es.json +22 -0
  164. package/templates/podcast-creator/l10n/fr.json +18 -0
  165. package/templates/podcast-creator/l10n/he.json +15 -0
  166. package/templates/podcast-creator/tier5-src/_shared/program-fields.ts +16 -0
  167. package/templates/podcast-creator/tier5-src/_shared/programs-section.ts +5 -8
  168. package/templates/podcast-creator/tier5-src/himi-branded-lite-podcasts/index.ts +14 -234
  169. package/templates/portfolio-creative/l10n/en.json +1 -1
  170. package/templates/portfolio-creative/tier5-src/_shared/program-fields.ts +16 -0
  171. package/templates/portfolio-creative/tier5-src/_shared/programs-section.ts +5 -8
  172. package/templates/restaurant/l10n/en.json +1 -1
  173. package/templates/restaurant/tier5-src/_shared/program-fields.ts +16 -0
  174. package/templates/restaurant/tier5-src/_shared/programs-section.ts +5 -8
  175. package/templates/retail-store/l10n/en.json +1 -1
  176. package/templates/retail-store/tier5-src/_shared/program-fields.ts +16 -0
  177. package/templates/retail-store/tier5-src/_shared/programs-section.ts +5 -8
  178. package/templates/salon-spa/dev/index.ts +1 -1
  179. package/templates/salon-spa/tier5-src/himi-booking-account/index.ts +16 -1
  180. package/templates/salon-spa/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
  181. package/templates/yoga-studio/dev/index.ts +1 -1
  182. package/templates/yoga-studio/l10n/en.json +1 -1
  183. package/templates/yoga-studio/tier5-src/_shared/program-fields.ts +16 -0
  184. package/templates/yoga-studio/tier5-src/_shared/programs-section.ts +5 -8
  185. package/templates/yoga-studio/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
@@ -0,0 +1,256 @@
1
+ import { withOnlineWrites } from "../_shared/online-actions.js";
2
+ // himi-branded-lite-notifications — reads the member's notifications via Members Feed Viewer (queryNotifications).
3
+ // a failed query is an error with Retry (or Sign in when Wix refuses the
4
+ // visitor) and an empty one is a real empty state — never sample rows presented as
5
+ // the customer's own. Samples appear only in the host's explicit sample preview
6
+ // (_shared/branded-load-state.ts).
7
+ // mark-one-read / mark-all-read stay wired: they update state optimistically and
8
+ // best-effort the real write (a no-op on sample rows).
9
+ import { defineService as registerService } from "../_shared/collection-service.js";
10
+ import { LOADING, loaded, loadFailed, type LoadCopy, type LoadFlags } from "../_shared/branded-load-state.js";
11
+ import { queryNotifications, markRead, markAllRead, type MfvNotification } from "@himalaya/wix-members-feed-viewer";
12
+ import { assertMemberAccess, memberAccess, type MemberAccess } from "../_shared/member-access.js";
13
+ import { navigate } from "@himalaya/state";
14
+ import { notificationOpen, urlHost, type NotificationOpen } from "../_shared/notification-target.js";
15
+ import { openRichLink } from "../_shared/rich-content-link.js";
16
+ import { copyParam, copyTemplate } from "../_shared/himi-copy.js";
17
+
18
+ interface Row {
19
+ id: string;
20
+ name: string;
21
+ subtitle: string;
22
+ unread: boolean;
23
+ /** "●" when unread, "" when read — bound to an accent dot that collapses when
24
+ * empty (per-item render is parity-safe; item-scoped hiddenWhen is not). */
25
+ unreadDot: string;
26
+ photo: string;
27
+ initial: string;
28
+ dest: string;
29
+ /** What a tap does (a screen, a web link or nothing). Absent on the preview samples, which open nothing. */
30
+ open?: NotificationOpen;
31
+ }
32
+ interface S extends LoadFlags {
33
+ items: Row[]; emptyText: string; actionMessage: string;
34
+ /** The web link the last tap named and is waiting for a second tap to open (see `open`). */
35
+ pendingUrl: string;
36
+ /** Ownership travels with the rows, including a state captured by an async write. */
37
+ inboxMember: MemberAccess | null;
38
+ isMock: boolean; notMock: boolean;
39
+ /** #2849 — hiddenWhen() hides on TRUE, so these are inverted: the empty-state banner
40
+ * shows only when the site really has none, and the unavailable one only when the
41
+ * query failed. A failed query must never render the sentence that claims the
42
+ * customer has no content. */
43
+ notMockEmpty: boolean; notMockUnavailable: boolean;
44
+ }
45
+
46
+ /** Human "2h ago" / "Yesterday" from an ISO date. */
47
+ function relativeTime(iso?: string): string {
48
+ if (!iso) return "";
49
+ const then = Date.parse(iso);
50
+ if (isNaN(then)) return "";
51
+ const diff = Date.now() - then;
52
+ if (diff < 0) return "Just now";
53
+ const min = Math.floor(diff / 60000);
54
+ if (min < 1) return "Just now";
55
+ if (min < 60) return `${min}m ago`;
56
+ const hr = Math.floor(min / 60);
57
+ if (hr < 24) return `${hr}h ago`;
58
+ const day = Math.floor(hr / 24);
59
+ if (day === 1) return "Yesterday";
60
+ if (day < 7) return `${day}d ago`;
61
+ const wk = Math.floor(day / 7);
62
+ if (wk < 5) return `${wk}w ago`;
63
+ return new Date(then).toLocaleDateString();
64
+ }
65
+
66
+ function isUnread(status?: string): boolean {
67
+ return status === "UNSEEN" || status === "SEEN_BUT_UNREAD";
68
+ }
69
+
70
+ function dest(n: MfvNotification): string {
71
+ return n.deeplink?.mobileData?.data || n.deeplink?.webUrlData?.webUrl || "";
72
+ }
73
+
74
+ function photo(n: MfvNotification): string {
75
+ return n.icon?.personAvatarData?.data || n.icon?.webUrlData?.webUrl || "";
76
+ }
77
+
78
+ /** The screens the Notifications screen says its app serves, or undefined when it did not say. */
79
+ function servedScreens(arg: unknown): ReadonlySet<string> | undefined {
80
+ const served = (arg as { served?: unknown } | null | undefined)?.served;
81
+ // A Retry reaches `load` with no params (the collection layer re-dispatches the action bare), so the list the screen
82
+ // last named is kept: dropping it would let every catalog link be tried again.
83
+ if (typeof served === "string") lastServed = new Set(served.split(",").filter(Boolean));
84
+ return lastServed;
85
+ }
86
+ let lastServed: ReadonlySet<string> | undefined;
87
+
88
+ function norm(n: MfvNotification, served?: ReadonlySet<string>): Row {
89
+ const name = (n.title || n.message || "Notification").trim() || "Notification";
90
+ const rel = relativeTime(n.sentDate);
91
+ const lead = n.title && n.message ? n.message.trim() : "";
92
+ const subtitle = [lead, rel].filter(Boolean).join(" · ");
93
+ const p = photo(n);
94
+ const unread = isUnread(n.status);
95
+ return {
96
+ id: n.id || "",
97
+ name,
98
+ subtitle,
99
+ unread,
100
+ unreadDot: unread ? "●" : "",
101
+ photo: p,
102
+ initial: (name[0] || "#").toUpperCase(),
103
+ dest: dest(n),
104
+ open: notificationOpen(n.deeplink, served),
105
+ };
106
+ }
107
+
108
+ const MOCK: Row[] = [
109
+ { id: "sample-like", name: "Maya Levin liked your post", subtitle: "“Weekend pop-up” · 2h ago", unread: true, unreadDot: "●", photo: "", initial: "M", dest: "" },
110
+ { id: "sample-comment", name: "Daniel Cohen commented on your post", subtitle: "“Love this — count me in!” · 5h ago", unread: true, unreadDot: "●", photo: "", initial: "D", dest: "" },
111
+ { id: "sample-booking", name: "Booking reminder", subtitle: "Yoga Flow tomorrow at 9:00 AM · Yesterday", unread: false, unreadDot: "", photo: "", initial: "B", dest: "" },
112
+ { id: "sample-follow", name: "Noa Bar started following you", subtitle: "2d ago", unread: false, unreadDot: "", photo: "", initial: "N", dest: "" },
113
+ { id: "sample-offer", name: "New offer just for you", subtitle: "15% off your next order · 3d ago", unread: false, unreadDot: "", photo: "", initial: "%", dest: "" },
114
+ ];
115
+
116
+ /** sample rows reach the screen ONLY in the host's explicit sample preview;
117
+ * a failed or empty query is an honest error / empty state (branded-load-state.ts). */
118
+ const COPY: LoadCopy<Row> = {
119
+ prefix: "notifications",
120
+ empty: "You're all caught up — no notifications yet.",
121
+ error: "Notifications couldn't be loaded.",
122
+ signIn: "Sign in to see your notifications.",
123
+ sample: () => MOCK.map((r) => ({ ...r })),
124
+ };
125
+
126
+ const signInRequired = () => new Error("Unauthenticated: sign in to see notifications");
127
+
128
+ async function requireMember(): Promise<MemberAccess> {
129
+ const member = await memberAccess();
130
+ if (!member.email) throw signInRequired();
131
+ return member;
132
+ }
133
+
134
+ async function requireInboxMember(s: S): Promise<void> {
135
+ const member = await requireMember();
136
+ if (!s.inboxMember || member.email !== s.inboxMember.email || member.scope !== s.inboxMember.scope) {
137
+ throw new Error("Member access changed: reload notifications");
138
+ }
139
+ }
140
+
141
+ /** Each successful load owns a fresh member object. Presentation changes and
142
+ * other read marks keep it; a newer inbox replaces it even for the same member. */
143
+ function currentInbox(s: S): S | undefined {
144
+ const current: S = svc.getState();
145
+ return current.inboxMember === s.inboxMember && (s.inboxMember !== null || current.items === s.items)
146
+ ? current : undefined;
147
+ }
148
+
149
+ const defineService = withOnlineWrites(registerService, ["markOneRead","markAll"], { messageFields: ["actionMessage"] });
150
+ const INITIAL = { ...LOADING, items: [] as Row[], emptyText: "", actionMessage: "", pendingUrl: "", inboxMember: null };
151
+ const svc = defineService<S, {
152
+ prepare: (s: S) => S;
153
+ load: (s: S, arg?: unknown) => Promise<S>;
154
+ markOneRead: (s: S, id: string) => Promise<S | undefined>;
155
+ markAll: (s: S) => Promise<S | undefined>;
156
+ open: (s: S, arg?: unknown) => Promise<S | undefined>;
157
+ }>("himiBrandedNotifications", {
158
+ state: INITIAL,
159
+ actions: {
160
+ // Clear worker-restored state before this worker starts its member probe.
161
+ // Native hosts may already cold-paint their account-scoped snapshot; this
162
+ // reducer does not control that earlier host phase.
163
+ prepare: (s) => ({ ...s, ...INITIAL }),
164
+ load: async (s, arg) => {
165
+ // The screen names which of the link targets this app serves (a comma list); none given means any may be tried.
166
+ const served = servedScreens(arg);
167
+ try {
168
+ const member = await requireMember();
169
+ const items = (await queryNotifications(25)).map((n) => norm(n, served));
170
+ await assertMemberAccess(member);
171
+ return { ...s, ...loaded("items", items, COPY), inboxMember: member, actionMessage: "", pendingUrl: "" };
172
+ } catch (err) {
173
+ return { ...s, ...loadFailed("items", (await memberAccess()).email ? err : signInRequired(), COPY), inboxMember: null, actionMessage: "", pendingUrl: "" };
174
+ }
175
+ },
176
+ // Mark one read; optimistically clear its dot. Real write is best-effort and
177
+ // a no-op on sample rows.
178
+ markOneRead: async (s, id): Promise<S | undefined> => {
179
+ if (!id || s.busy) return undefined;
180
+ if (!s.isMock) {
181
+ try {
182
+ await requireInboxMember(s);
183
+ if (!currentInbox(s)) return undefined;
184
+ if (!id.startsWith("sample-")) { try { await markRead([id]); } catch { /* keep optimistic */ } }
185
+ // Embedded workers may survive a host account/tenant change while
186
+ // Wix is acknowledging the write. Recheck the live identity too.
187
+ await requireInboxMember(s);
188
+ } catch (err) {
189
+ // The read may have finished while identity was checked. An obsolete
190
+ // write must not clear the freshly published inbox with its error.
191
+ const current = currentInbox(s);
192
+ return current ? { ...current, ...loadFailed("items", err, COPY), inboxMember: null } : undefined;
193
+ }
194
+ }
195
+ // A refresh can also finish while Wix acknowledges the write.
196
+ const current = currentInbox(s);
197
+ return current ? { ...current, items: current.items.map((r) => (r.id === id ? { ...r, unread: false, unreadDot: "" } : r)) } : undefined;
198
+ },
199
+ // A tap on a row opens what the notification points at, like the One App: a Himi screen when its link names
200
+ // one of ours (see _shared/notification-target.ts), else its https link, else a visible "can't open".
201
+ // A web link is written by the site, so it needs a SECOND tap on the same row, after the first tap has
202
+ // shown where it goes. It never replaces the inbox, and an unknown link never guesses a screen.
203
+ open: async (s, arg): Promise<S | undefined> => {
204
+ const id = String((arg as { id?: unknown } | null | undefined)?.id ?? "");
205
+ const row = s.items.find((r) => r.id === id);
206
+ if (!row || s.busy) return undefined;
207
+ if (!s.isMock) {
208
+ try { await requireInboxMember(s); } catch (err) {
209
+ const current = currentInbox(s);
210
+ return current ? { ...current, ...loadFailed("items", err, COPY), inboxMember: null } : undefined;
211
+ }
212
+ }
213
+ const current = currentInbox(s);
214
+ if (!current) return undefined;
215
+ const action = row.open ?? { kind: "none" as const };
216
+ if (action.kind === "url") {
217
+ if (current.pendingUrl !== action.url) {
218
+ return { ...current, pendingUrl: action.url, actionMessage: copyTemplate("notifications.openLinkText", "Tap again to open {host}.", { host: urlHost(action.url) }) };
219
+ }
220
+ const opened = await openRichLink(action.url);
221
+ const now = currentInbox(s);
222
+ return now ? { ...now, pendingUrl: "", actionMessage: opened ? "" : copyParam("notifications.cantOpenText", "This notification can't be opened here.") } : undefined;
223
+ }
224
+ if (action.kind === "none") {
225
+ return { ...current, pendingUrl: "", actionMessage: copyParam("notifications.cantOpenText", "This notification can't be opened here.") };
226
+ }
227
+ // Read on open: the dot clears at once, the write is best effort and never holds the navigation.
228
+ if (!id.startsWith("sample-") && row.unread) markRead([id]).catch(() => undefined);
229
+ const read = { ...current, pendingUrl: "", actionMessage: "", items: current.items.map((r) => (r.id === id ? { ...r, unread: false, unreadDot: "" } : r)) };
230
+ return navigate(read, { screenId: action.target.screenId, args: action.target.args });
231
+ },
232
+ // Mark everything read; optimistically clear all dots.
233
+ markAll: async (s): Promise<S | undefined> => {
234
+ if (s.busy) return undefined;
235
+ if (!s.isMock) {
236
+ try {
237
+ await requireInboxMember(s);
238
+ if (!currentInbox(s)) return undefined;
239
+ try { await markAllRead(); } catch { /* keep optimistic */ }
240
+ await requireInboxMember(s);
241
+ } catch (err) {
242
+ // The read may have finished while identity was checked. An obsolete
243
+ // write must not clear the freshly published inbox with its error.
244
+ const current = currentInbox(s);
245
+ return current ? { ...current, ...loadFailed("items", err, COPY), inboxMember: null } : undefined;
246
+ }
247
+ }
248
+ // A refresh can also finish while Wix acknowledges the write.
249
+ const current = currentInbox(s);
250
+ return current ? { ...current, items: current.items.map((r) => (r.unread ? { ...r, unread: false, unreadDot: "" } : r)) } : undefined;
251
+ },
252
+ },
253
+ });
254
+ svc.prepare();
255
+ svc.load();
256
+ export { svc };