@wix/himalaya-cli 0.2045.0 → 0.2047.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 (305) hide show
  1. package/dist/cli.mjs +0 -2
  2. package/package.json +2 -2
  3. package/templates/beauty-salon/l10n/ar.json +5 -0
  4. package/templates/beauty-salon/l10n/cs.json +5 -0
  5. package/templates/beauty-salon/l10n/da.json +5 -0
  6. package/templates/beauty-salon/l10n/de.json +5 -0
  7. package/templates/beauty-salon/l10n/el.json +5 -0
  8. package/templates/beauty-salon/l10n/es.json +5 -0
  9. package/templates/beauty-salon/l10n/fi.json +5 -0
  10. package/templates/beauty-salon/l10n/fr.json +5 -0
  11. package/templates/beauty-salon/l10n/he.json +4 -0
  12. package/templates/beauty-salon/l10n/hu.json +5 -0
  13. package/templates/beauty-salon/l10n/id.json +5 -0
  14. package/templates/beauty-salon/l10n/it.json +5 -0
  15. package/templates/beauty-salon/l10n/ja.json +5 -0
  16. package/templates/beauty-salon/l10n/ko.json +5 -0
  17. package/templates/beauty-salon/l10n/lt.json +5 -0
  18. package/templates/beauty-salon/l10n/nl.json +5 -0
  19. package/templates/beauty-salon/l10n/no.json +5 -0
  20. package/templates/beauty-salon/l10n/pl.json +5 -0
  21. package/templates/beauty-salon/l10n/pt.json +5 -0
  22. package/templates/beauty-salon/l10n/ru.json +5 -0
  23. package/templates/beauty-salon/l10n/sv.json +5 -0
  24. package/templates/beauty-salon/l10n/th.json +5 -0
  25. package/templates/beauty-salon/l10n/tr.json +5 -0
  26. package/templates/beauty-salon/l10n/uk.json +5 -0
  27. package/templates/beauty-salon/l10n/vi.json +5 -0
  28. package/templates/beauty-salon/l10n/zh.json +5 -0
  29. package/templates/beauty-salon/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  30. package/templates/branded-lite/l10n/ar.json +5 -0
  31. package/templates/branded-lite/l10n/cs.json +5 -0
  32. package/templates/branded-lite/l10n/da.json +5 -0
  33. package/templates/branded-lite/l10n/de.json +5 -0
  34. package/templates/branded-lite/l10n/el.json +5 -0
  35. package/templates/branded-lite/l10n/es.json +5 -0
  36. package/templates/branded-lite/l10n/fi.json +5 -0
  37. package/templates/branded-lite/l10n/fr.json +5 -0
  38. package/templates/branded-lite/l10n/he.json +4 -0
  39. package/templates/branded-lite/l10n/hu.json +5 -0
  40. package/templates/branded-lite/l10n/id.json +5 -0
  41. package/templates/branded-lite/l10n/it.json +5 -0
  42. package/templates/branded-lite/l10n/ja.json +5 -0
  43. package/templates/branded-lite/l10n/ko.json +5 -0
  44. package/templates/branded-lite/l10n/lt.json +5 -0
  45. package/templates/branded-lite/l10n/nl.json +5 -0
  46. package/templates/branded-lite/l10n/no.json +5 -0
  47. package/templates/branded-lite/l10n/pl.json +5 -0
  48. package/templates/branded-lite/l10n/pt.json +5 -0
  49. package/templates/branded-lite/l10n/ru.json +5 -0
  50. package/templates/branded-lite/l10n/sv.json +5 -0
  51. package/templates/branded-lite/l10n/th.json +5 -0
  52. package/templates/branded-lite/l10n/tr.json +5 -0
  53. package/templates/branded-lite/l10n/uk.json +5 -0
  54. package/templates/branded-lite/l10n/vi.json +5 -0
  55. package/templates/branded-lite/l10n/zh.json +5 -0
  56. package/templates/branded-lite/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  57. package/templates/brandy/config.ts +1 -0
  58. package/templates/brandy/dev/member-screens.ts +1619 -411
  59. package/templates/brandy/tier5-src/_shared/empty-flags.ts +33 -0
  60. package/templates/brandy/tier5-src/_shared/push-permission.ts +75 -0
  61. package/templates/brandy/tier5-src/himi-branded-lite-notifsettings/index.ts +455 -0
  62. package/templates/community-club/l10n/ar.json +5 -0
  63. package/templates/community-club/l10n/cs.json +5 -0
  64. package/templates/community-club/l10n/da.json +5 -0
  65. package/templates/community-club/l10n/de.json +5 -0
  66. package/templates/community-club/l10n/el.json +5 -0
  67. package/templates/community-club/l10n/es.json +5 -0
  68. package/templates/community-club/l10n/fi.json +5 -0
  69. package/templates/community-club/l10n/fr.json +5 -0
  70. package/templates/community-club/l10n/he.json +4 -0
  71. package/templates/community-club/l10n/hu.json +5 -0
  72. package/templates/community-club/l10n/id.json +5 -0
  73. package/templates/community-club/l10n/it.json +5 -0
  74. package/templates/community-club/l10n/ja.json +5 -0
  75. package/templates/community-club/l10n/ko.json +5 -0
  76. package/templates/community-club/l10n/lt.json +5 -0
  77. package/templates/community-club/l10n/nl.json +5 -0
  78. package/templates/community-club/l10n/no.json +5 -0
  79. package/templates/community-club/l10n/pl.json +5 -0
  80. package/templates/community-club/l10n/pt.json +5 -0
  81. package/templates/community-club/l10n/ru.json +5 -0
  82. package/templates/community-club/l10n/sv.json +5 -0
  83. package/templates/community-club/l10n/th.json +5 -0
  84. package/templates/community-club/l10n/tr.json +5 -0
  85. package/templates/community-club/l10n/uk.json +5 -0
  86. package/templates/community-club/l10n/vi.json +5 -0
  87. package/templates/community-club/l10n/zh.json +5 -0
  88. package/templates/community-club/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  89. package/templates/events-meetups/l10n/ar.json +5 -0
  90. package/templates/events-meetups/l10n/cs.json +5 -0
  91. package/templates/events-meetups/l10n/da.json +5 -0
  92. package/templates/events-meetups/l10n/de.json +5 -0
  93. package/templates/events-meetups/l10n/el.json +5 -0
  94. package/templates/events-meetups/l10n/es.json +5 -0
  95. package/templates/events-meetups/l10n/fi.json +5 -0
  96. package/templates/events-meetups/l10n/fr.json +5 -0
  97. package/templates/events-meetups/l10n/he.json +4 -0
  98. package/templates/events-meetups/l10n/hu.json +5 -0
  99. package/templates/events-meetups/l10n/id.json +5 -0
  100. package/templates/events-meetups/l10n/it.json +5 -0
  101. package/templates/events-meetups/l10n/ja.json +5 -0
  102. package/templates/events-meetups/l10n/ko.json +5 -0
  103. package/templates/events-meetups/l10n/lt.json +5 -0
  104. package/templates/events-meetups/l10n/nl.json +5 -0
  105. package/templates/events-meetups/l10n/no.json +5 -0
  106. package/templates/events-meetups/l10n/pl.json +5 -0
  107. package/templates/events-meetups/l10n/pt.json +5 -0
  108. package/templates/events-meetups/l10n/ru.json +5 -0
  109. package/templates/events-meetups/l10n/sv.json +5 -0
  110. package/templates/events-meetups/l10n/th.json +5 -0
  111. package/templates/events-meetups/l10n/tr.json +5 -0
  112. package/templates/events-meetups/l10n/uk.json +5 -0
  113. package/templates/events-meetups/l10n/vi.json +5 -0
  114. package/templates/events-meetups/l10n/zh.json +5 -0
  115. package/templates/events-meetups/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  116. package/templates/gym-fitness/l10n/ar.json +5 -0
  117. package/templates/gym-fitness/l10n/cs.json +5 -0
  118. package/templates/gym-fitness/l10n/da.json +5 -0
  119. package/templates/gym-fitness/l10n/de.json +5 -0
  120. package/templates/gym-fitness/l10n/el.json +5 -0
  121. package/templates/gym-fitness/l10n/es.json +5 -0
  122. package/templates/gym-fitness/l10n/fi.json +5 -0
  123. package/templates/gym-fitness/l10n/fr.json +5 -0
  124. package/templates/gym-fitness/l10n/he.json +4 -0
  125. package/templates/gym-fitness/l10n/hu.json +5 -0
  126. package/templates/gym-fitness/l10n/id.json +5 -0
  127. package/templates/gym-fitness/l10n/it.json +5 -0
  128. package/templates/gym-fitness/l10n/ja.json +5 -0
  129. package/templates/gym-fitness/l10n/ko.json +5 -0
  130. package/templates/gym-fitness/l10n/lt.json +5 -0
  131. package/templates/gym-fitness/l10n/nl.json +5 -0
  132. package/templates/gym-fitness/l10n/no.json +5 -0
  133. package/templates/gym-fitness/l10n/pl.json +5 -0
  134. package/templates/gym-fitness/l10n/pt.json +5 -0
  135. package/templates/gym-fitness/l10n/ru.json +5 -0
  136. package/templates/gym-fitness/l10n/sv.json +5 -0
  137. package/templates/gym-fitness/l10n/th.json +5 -0
  138. package/templates/gym-fitness/l10n/tr.json +5 -0
  139. package/templates/gym-fitness/l10n/uk.json +5 -0
  140. package/templates/gym-fitness/l10n/vi.json +5 -0
  141. package/templates/gym-fitness/l10n/zh.json +5 -0
  142. package/templates/gym-fitness/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  143. package/templates/nonprofit-cause/l10n/ar.json +5 -0
  144. package/templates/nonprofit-cause/l10n/cs.json +5 -0
  145. package/templates/nonprofit-cause/l10n/da.json +5 -0
  146. package/templates/nonprofit-cause/l10n/de.json +5 -0
  147. package/templates/nonprofit-cause/l10n/el.json +5 -0
  148. package/templates/nonprofit-cause/l10n/es.json +5 -0
  149. package/templates/nonprofit-cause/l10n/fi.json +5 -0
  150. package/templates/nonprofit-cause/l10n/fr.json +5 -0
  151. package/templates/nonprofit-cause/l10n/he.json +4 -0
  152. package/templates/nonprofit-cause/l10n/hu.json +5 -0
  153. package/templates/nonprofit-cause/l10n/id.json +5 -0
  154. package/templates/nonprofit-cause/l10n/it.json +5 -0
  155. package/templates/nonprofit-cause/l10n/ja.json +5 -0
  156. package/templates/nonprofit-cause/l10n/ko.json +5 -0
  157. package/templates/nonprofit-cause/l10n/lt.json +5 -0
  158. package/templates/nonprofit-cause/l10n/nl.json +5 -0
  159. package/templates/nonprofit-cause/l10n/no.json +5 -0
  160. package/templates/nonprofit-cause/l10n/pl.json +5 -0
  161. package/templates/nonprofit-cause/l10n/pt.json +5 -0
  162. package/templates/nonprofit-cause/l10n/ru.json +5 -0
  163. package/templates/nonprofit-cause/l10n/sv.json +5 -0
  164. package/templates/nonprofit-cause/l10n/th.json +5 -0
  165. package/templates/nonprofit-cause/l10n/tr.json +5 -0
  166. package/templates/nonprofit-cause/l10n/uk.json +5 -0
  167. package/templates/nonprofit-cause/l10n/vi.json +5 -0
  168. package/templates/nonprofit-cause/l10n/zh.json +5 -0
  169. package/templates/nonprofit-cause/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  170. package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  171. package/templates/podcast-creator/l10n/ar.json +5 -0
  172. package/templates/podcast-creator/l10n/cs.json +5 -0
  173. package/templates/podcast-creator/l10n/da.json +5 -0
  174. package/templates/podcast-creator/l10n/de.json +5 -0
  175. package/templates/podcast-creator/l10n/el.json +5 -0
  176. package/templates/podcast-creator/l10n/es.json +5 -0
  177. package/templates/podcast-creator/l10n/fi.json +5 -0
  178. package/templates/podcast-creator/l10n/fr.json +5 -0
  179. package/templates/podcast-creator/l10n/he.json +4 -0
  180. package/templates/podcast-creator/l10n/hu.json +5 -0
  181. package/templates/podcast-creator/l10n/id.json +5 -0
  182. package/templates/podcast-creator/l10n/it.json +5 -0
  183. package/templates/podcast-creator/l10n/ja.json +5 -0
  184. package/templates/podcast-creator/l10n/ko.json +5 -0
  185. package/templates/podcast-creator/l10n/lt.json +5 -0
  186. package/templates/podcast-creator/l10n/nl.json +5 -0
  187. package/templates/podcast-creator/l10n/no.json +5 -0
  188. package/templates/podcast-creator/l10n/pl.json +5 -0
  189. package/templates/podcast-creator/l10n/pt.json +5 -0
  190. package/templates/podcast-creator/l10n/ru.json +5 -0
  191. package/templates/podcast-creator/l10n/sv.json +5 -0
  192. package/templates/podcast-creator/l10n/th.json +5 -0
  193. package/templates/podcast-creator/l10n/tr.json +5 -0
  194. package/templates/podcast-creator/l10n/uk.json +5 -0
  195. package/templates/podcast-creator/l10n/vi.json +5 -0
  196. package/templates/podcast-creator/l10n/zh.json +5 -0
  197. package/templates/podcast-creator/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  198. package/templates/portfolio-creative/l10n/ar.json +5 -0
  199. package/templates/portfolio-creative/l10n/cs.json +5 -0
  200. package/templates/portfolio-creative/l10n/da.json +5 -0
  201. package/templates/portfolio-creative/l10n/de.json +5 -0
  202. package/templates/portfolio-creative/l10n/el.json +5 -0
  203. package/templates/portfolio-creative/l10n/es.json +5 -0
  204. package/templates/portfolio-creative/l10n/fi.json +5 -0
  205. package/templates/portfolio-creative/l10n/fr.json +5 -0
  206. package/templates/portfolio-creative/l10n/he.json +4 -0
  207. package/templates/portfolio-creative/l10n/hu.json +5 -0
  208. package/templates/portfolio-creative/l10n/id.json +5 -0
  209. package/templates/portfolio-creative/l10n/it.json +5 -0
  210. package/templates/portfolio-creative/l10n/ja.json +5 -0
  211. package/templates/portfolio-creative/l10n/ko.json +5 -0
  212. package/templates/portfolio-creative/l10n/lt.json +5 -0
  213. package/templates/portfolio-creative/l10n/nl.json +5 -0
  214. package/templates/portfolio-creative/l10n/no.json +5 -0
  215. package/templates/portfolio-creative/l10n/pl.json +5 -0
  216. package/templates/portfolio-creative/l10n/pt.json +5 -0
  217. package/templates/portfolio-creative/l10n/ru.json +5 -0
  218. package/templates/portfolio-creative/l10n/sv.json +5 -0
  219. package/templates/portfolio-creative/l10n/th.json +5 -0
  220. package/templates/portfolio-creative/l10n/tr.json +5 -0
  221. package/templates/portfolio-creative/l10n/uk.json +5 -0
  222. package/templates/portfolio-creative/l10n/vi.json +5 -0
  223. package/templates/portfolio-creative/l10n/zh.json +5 -0
  224. package/templates/portfolio-creative/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  225. package/templates/restaurant/l10n/ar.json +5 -0
  226. package/templates/restaurant/l10n/cs.json +5 -0
  227. package/templates/restaurant/l10n/da.json +5 -0
  228. package/templates/restaurant/l10n/de.json +5 -0
  229. package/templates/restaurant/l10n/el.json +5 -0
  230. package/templates/restaurant/l10n/es.json +5 -0
  231. package/templates/restaurant/l10n/fi.json +5 -0
  232. package/templates/restaurant/l10n/fr.json +5 -0
  233. package/templates/restaurant/l10n/he.json +4 -0
  234. package/templates/restaurant/l10n/hu.json +5 -0
  235. package/templates/restaurant/l10n/id.json +5 -0
  236. package/templates/restaurant/l10n/it.json +5 -0
  237. package/templates/restaurant/l10n/ja.json +5 -0
  238. package/templates/restaurant/l10n/ko.json +5 -0
  239. package/templates/restaurant/l10n/lt.json +5 -0
  240. package/templates/restaurant/l10n/nl.json +5 -0
  241. package/templates/restaurant/l10n/no.json +5 -0
  242. package/templates/restaurant/l10n/pl.json +5 -0
  243. package/templates/restaurant/l10n/pt.json +5 -0
  244. package/templates/restaurant/l10n/ru.json +5 -0
  245. package/templates/restaurant/l10n/sv.json +5 -0
  246. package/templates/restaurant/l10n/th.json +5 -0
  247. package/templates/restaurant/l10n/tr.json +5 -0
  248. package/templates/restaurant/l10n/uk.json +5 -0
  249. package/templates/restaurant/l10n/vi.json +5 -0
  250. package/templates/restaurant/l10n/zh.json +5 -0
  251. package/templates/restaurant/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  252. package/templates/retail-store/l10n/ar.json +5 -0
  253. package/templates/retail-store/l10n/cs.json +5 -0
  254. package/templates/retail-store/l10n/da.json +5 -0
  255. package/templates/retail-store/l10n/de.json +5 -0
  256. package/templates/retail-store/l10n/el.json +5 -0
  257. package/templates/retail-store/l10n/es.json +5 -0
  258. package/templates/retail-store/l10n/fi.json +5 -0
  259. package/templates/retail-store/l10n/fr.json +5 -0
  260. package/templates/retail-store/l10n/he.json +4 -0
  261. package/templates/retail-store/l10n/hu.json +5 -0
  262. package/templates/retail-store/l10n/id.json +5 -0
  263. package/templates/retail-store/l10n/it.json +5 -0
  264. package/templates/retail-store/l10n/ja.json +5 -0
  265. package/templates/retail-store/l10n/ko.json +5 -0
  266. package/templates/retail-store/l10n/lt.json +5 -0
  267. package/templates/retail-store/l10n/nl.json +5 -0
  268. package/templates/retail-store/l10n/no.json +5 -0
  269. package/templates/retail-store/l10n/pl.json +5 -0
  270. package/templates/retail-store/l10n/pt.json +5 -0
  271. package/templates/retail-store/l10n/ru.json +5 -0
  272. package/templates/retail-store/l10n/sv.json +5 -0
  273. package/templates/retail-store/l10n/th.json +5 -0
  274. package/templates/retail-store/l10n/tr.json +5 -0
  275. package/templates/retail-store/l10n/uk.json +5 -0
  276. package/templates/retail-store/l10n/vi.json +5 -0
  277. package/templates/retail-store/l10n/zh.json +5 -0
  278. package/templates/retail-store/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
  279. package/templates/yoga-studio/l10n/ar.json +5 -0
  280. package/templates/yoga-studio/l10n/cs.json +5 -0
  281. package/templates/yoga-studio/l10n/da.json +5 -0
  282. package/templates/yoga-studio/l10n/de.json +5 -0
  283. package/templates/yoga-studio/l10n/el.json +5 -0
  284. package/templates/yoga-studio/l10n/es.json +5 -0
  285. package/templates/yoga-studio/l10n/fi.json +5 -0
  286. package/templates/yoga-studio/l10n/fr.json +5 -0
  287. package/templates/yoga-studio/l10n/he.json +4 -0
  288. package/templates/yoga-studio/l10n/hu.json +5 -0
  289. package/templates/yoga-studio/l10n/id.json +5 -0
  290. package/templates/yoga-studio/l10n/it.json +5 -0
  291. package/templates/yoga-studio/l10n/ja.json +5 -0
  292. package/templates/yoga-studio/l10n/ko.json +5 -0
  293. package/templates/yoga-studio/l10n/lt.json +5 -0
  294. package/templates/yoga-studio/l10n/nl.json +5 -0
  295. package/templates/yoga-studio/l10n/no.json +5 -0
  296. package/templates/yoga-studio/l10n/pl.json +5 -0
  297. package/templates/yoga-studio/l10n/pt.json +5 -0
  298. package/templates/yoga-studio/l10n/ru.json +5 -0
  299. package/templates/yoga-studio/l10n/sv.json +5 -0
  300. package/templates/yoga-studio/l10n/th.json +5 -0
  301. package/templates/yoga-studio/l10n/tr.json +5 -0
  302. package/templates/yoga-studio/l10n/uk.json +5 -0
  303. package/templates/yoga-studio/l10n/vi.json +5 -0
  304. package/templates/yoga-studio/l10n/zh.json +5 -0
  305. package/templates/yoga-studio/tier5-src/himi-branded-lite-notifsettings/index.ts +225 -45
@@ -0,0 +1,33 @@
1
+ // Empty-collection flags for descriptors.
2
+ //
3
+ // A bound Grid/LazyList with zero rows still renders a zero-height box, and a stack
4
+ // allocates its `spacing` between CHILDREN, not between painted children — so every
5
+ // empty list left a full gap of blank on the screen (the measure pass's `dead-gap`, on
6
+ // iOS and Android as much as on web). `hiddenWhen` hides on a TRUE scalar only, and an
7
+ // empty array is not one, so a descriptor cannot gate a list on its own rows.
8
+ //
9
+ // `withEmptyFlags(def, { rows: "noRows" })` derives `noRows = rows is empty` into the
10
+ // initial state and after EVERY action (sync or async), so a builder can write
11
+ // `hiddenWhen(grid(...), "$service:svc.noRows")` without each reducer remembering to.
12
+ type State = Record<string, unknown>;
13
+ type Action = (s: State, ...args: unknown[]) => unknown;
14
+
15
+ export function withEmptyFlags<D extends { state: object; actions?: object }>(def: D, flags: Record<string, string>): D {
16
+ const derive = <T>(s: T): T => {
17
+ if (!s || typeof s !== "object") return s;
18
+ const out = { ...(s as State) };
19
+ for (const [rows, flag] of Object.entries(flags)) {
20
+ const v = out[rows];
21
+ out[flag] = !Array.isArray(v) || v.length === 0;
22
+ }
23
+ return out as T;
24
+ };
25
+ const actions: Record<string, Action> = {};
26
+ for (const [name, action] of Object.entries((def.actions ?? {}) as Record<string, Action>)) {
27
+ actions[name] = (s, ...args) => {
28
+ const r = action(s, ...args);
29
+ return r && typeof (r as Promise<unknown>).then === "function" ? (r as Promise<unknown>).then(derive) : derive(r);
30
+ };
31
+ }
32
+ return { ...def, state: derive(def.state), actions } as D;
33
+ }
@@ -0,0 +1,75 @@
1
+ // The phone's notification permission, as Branded Lite's screens use it (Notification settings and
2
+ // Home's in-context ask). Every call is caught: a host without the push capability (an older binary)
3
+ // answers "error", which shows nothing rather than an offer that leads nowhere.
4
+ //
5
+ // Only a native app has a PHONE permission. A web host reports the browser's, which says nothing
6
+ // about the member's phone, so it reads as "error" too.
7
+ //
8
+ // Android reports "denied" both before its first ask and after a refusal (it has no "undetermined"
9
+ // once API 33's runtime permission exists), so only a request can tell the two apart. Below API 33
10
+ // there is no runtime dialog at all: "denied" means switched off in Settings.
11
+
12
+ import { openSettings, requestPermission, type PushPermission } from "@himalaya/push";
13
+ import { dispatch } from "@himalaya/dispatch";
14
+ import { get as getAppInfo } from "@himalaya/app-info";
15
+
16
+ export type PushStatus = PushPermission | "error";
17
+ export type PushPlatform = "ios" | "android" | "macos" | "";
18
+
19
+ export interface PhonePush {
20
+ status: PushStatus;
21
+ platform: PushPlatform;
22
+ /** A "denied" answer may still hide a first ask the system can show (Android 13+ only). */
23
+ deniedMayPrompt: boolean;
24
+ }
25
+
26
+ const NATIVE: readonly string[] = ["ios", "android", "macos"];
27
+
28
+ /** Android's major version, or 0 when the host does not say. */
29
+ function androidMajor(osVersion: string | undefined): number {
30
+ const major = Number.parseInt(String(osVersion ?? ""), 10);
31
+ return Number.isFinite(major) ? major : 0;
32
+ }
33
+
34
+ export async function readPhonePush(): Promise<PhonePush> {
35
+ const info = await getAppInfo().catch(() => undefined);
36
+ const platform = (NATIVE.includes(info?.platform ?? "") ? info!.platform : "") as PushPlatform;
37
+ if (!platform) return { status: "error", platform, deniedMayPrompt: false };
38
+ const status = await readPushStatus();
39
+ // An unknown Android version may be below 13, where no dialog exists: promise no prompt then.
40
+ return { status, platform, deniedMayPrompt: platform === "android" && androidMajor(info?.osVersion) >= 13 };
41
+ }
42
+
43
+ /** Read raw: the SDK maps every unknown answer to "undetermined", but a native host without the
44
+ * push module answers "unavailable", where a Turn on button could never prompt. */
45
+ export async function readPushStatus(): Promise<PushStatus> {
46
+ try {
47
+ const r = (await dispatch("capability.push.getPermissionStatus")) as { status?: unknown } | null;
48
+ const status = r?.status;
49
+ return status === "granted" || status === "denied" || status === "undetermined" ? status : "error";
50
+ } catch { return "error"; }
51
+ }
52
+
53
+ /** Ask the OS. Shows the system prompt only while it still can; otherwise just reads the answer.
54
+ * Once granted it also registers this session's push token (no prompt). */
55
+ export async function askForPush(): Promise<PushStatus> {
56
+ try { return await requestPermission(); } catch { return readPushStatus(); }
57
+ }
58
+
59
+ export async function openPushSettings(): Promise<boolean> {
60
+ try { return await openSettings(); } catch { return false; }
61
+ }
62
+
63
+ /** A grant made earlier (or just now, in the OS settings) still needs this launch's token:
64
+ * `requestPermission` on a granted phone registers it without a prompt. */
65
+ export async function refreshGrantedToken(status: PushStatus): Promise<void> {
66
+ if (status === "granted") await askForPush();
67
+ }
68
+
69
+ /** The same, at most once per worker run: a launch needs one token request, not one per refresh. */
70
+ let tokenRefreshedThisRun = false;
71
+ export async function refreshGrantedTokenOnce(status: PushStatus): Promise<void> {
72
+ if (status !== "granted" || tokenRefreshedThisRun) return;
73
+ tokenRefreshedThisRun = true;
74
+ await askForPush();
75
+ }
@@ -0,0 +1,455 @@
1
+ import { withOnlineWrites } from "../_shared/online-actions.js";
2
+ // himi-branded-lite-notifsettings — reads the site's notification topics + the member's preferences.
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
+ // any exist. INTERACTIVE: tapping a row toggles that topic On/Off at once; a failed
8
+ // upsertMyNotificationPreferences puts it back and says so (a no-op on sample rows).
9
+ //
10
+ // A saved preference is only half the truth: the PHONE's permission decides whether anything
11
+ // arrives. So the screen also reads it (declares "push"): denied ⇒ "off on this phone" + Open
12
+ // Settings, never asked ⇒ an offer to turn on, and either way the switches are dimmed. `load`
13
+ // arms a poll the host fires the moment the app returns to the foreground, which is the return
14
+ // from the OS settings.
15
+ import { defineService as registerService, type PollDirective } from "@himalaya/state";
16
+ import { askForPush, openPushSettings, readPhonePush, refreshGrantedToken, refreshGrantedTokenOnce, type PushStatus } from "../_shared/push-permission.js";
17
+ import { withEmptyFlags } from "../_shared/empty-flags.js";
18
+ import { copyParam, stashCopy } from "../_shared/himi-copy.js";
19
+ import { memberAccess, assertMemberAccess, type MemberAccess } from "../_shared/member-access.js";
20
+ import { LOADING, loaded, loadFailed, type LoadCopy, type LoadFlags } from "../_shared/branded-load-state.js";
21
+ import {
22
+ getNotificationTopics,
23
+ getMyNotificationPreferences,
24
+ upsertMyNotificationPreferences,
25
+ muteStatusFor,
26
+ readTopics,
27
+ readPreferences,
28
+ isDeliveredNow,
29
+ isLocked,
30
+ preferenceFor,
31
+ type NotificationTopicDefinition,
32
+ type PreferenceInfo,
33
+ type Channel,
34
+ } from "@himalaya/wix-notification-preferences";
35
+
36
+ /** The channels a member can pick (WebShell's Push / Email). Without the `channels` option the
37
+ * screen stays on push, as Branded Lite always was. One map, so a row's read and its write
38
+ * cannot drift apart. */
39
+ type ChannelId = "push" | "email";
40
+ const WIX_CHANNEL: Record<ChannelId, Channel> = { push: "MOBILE", email: "EMAIL" };
41
+
42
+ /** WebShell's options, set by the screen's load params ("1" = on). Off: Branded Lite's screen. */
43
+ const options = { channels: false, allowAll: false };
44
+ function readOptions(arg: unknown): void {
45
+ if (!arg || typeof arg !== "object" || !("channels" in arg || "allowAll" in arg)) return;
46
+ const a = arg as Record<string, unknown>;
47
+ options.channels = a.channels === "1";
48
+ options.allowAll = a.allowAll === "1";
49
+ }
50
+
51
+ /** The last read of the site's topics and the member's rows on every channel, so switching
52
+ * channel re-derives the switches without a second read. */
53
+ let definitions: NotificationTopicDefinition[] = [];
54
+ let preferences: PreferenceInfo[] = [];
55
+
56
+ /** A successful write, recorded so the other channel and back shows what was saved. The server's own row
57
+ * wins when the response carries it: its `granted` / `overridden` verdict decides whether the switch is on
58
+ * and editable, which the requested mute state alone cannot tell. */
59
+ function rememberWrites(written: PreferenceInfo[], response: unknown, seq: number): void {
60
+ const returned = readPreferences(response as Parameters<typeof readPreferences>[0]);
61
+ const same = (a: PreferenceInfo, b: PreferenceInfo) => a.topicId === b.topicId && a.channel === b.channel;
62
+ // A newer save of the same row already answered, and the server applies saves in the order sent, so
63
+ // this older answer is not its last word. A failed save marks nothing: an older success still counts.
64
+ const rows = written.filter((w) => (lastSaved.get(keyOf(w)) ?? 0) < seq).map((w) => returned.find((r) => same(r, w)) ?? w);
65
+ for (const r of rows) lastSaved.set(keyOf(r), seq);
66
+ preferences = [...preferences.filter((p) => !rows.some((r) => same(r, p))), ...rows];
67
+ }
68
+ const keyOf = (p: PreferenceInfo) => `${p.topicId}\u0000${p.channel}`;
69
+ let writeSeq = 0;
70
+ /** Per row, the send order of the newest save whose answer is in the cache. */
71
+ const lastSaved = new Map<string, number>();
72
+ /** Saves go out one at a time, in tap order: nothing else makes the server apply them in the order
73
+ * `lastSaved` assumes. A tap takes its place in the queue before its first await, so a slow member
74
+ * check cannot let a later tap send first. A tap that writes nothing gives its place up, and a failed
75
+ * save does not stop the next. A save that waited is sent only if its member is still the one signed
76
+ * in, so it never lands on another account. */
77
+ let saveQueue: Promise<unknown> = Promise.resolve();
78
+ interface SaveSlot { seq: number; send(written: PreferenceInfo[], member: MemberAccess): Promise<unknown>; cancel(): void }
79
+ function reserveSave(): SaveSlot {
80
+ const seq = ++writeSeq;
81
+ let fill!: (run: (() => Promise<unknown>) | null) => void;
82
+ const job = new Promise<(() => Promise<unknown>) | null>((resolve) => { fill = resolve; });
83
+ const sent = saveQueue.then(() => job).then((run) => (run ? run() : undefined));
84
+ saveQueue = sent.catch(() => undefined);
85
+ return {
86
+ seq,
87
+ send: (written, member) => {
88
+ fill(async () => { await assertMemberAccess(member); return upsertMyNotificationPreferences(written); });
89
+ return sent;
90
+ },
91
+ cancel: () => fill(null),
92
+ };
93
+ }
94
+
95
+ /** `note` is the line under a row's switch — only a locked topic has one. */
96
+ interface Row { id: string; name: string; subtitle: string; note: string; on: boolean; locked: boolean;
97
+ /** Inverse of `locked` (hiddenWhen hides on TRUE) and the plain On/Off a locked row shows. */
98
+ notLocked: boolean; stateLabel: string }
99
+ interface S extends LoadFlags {
100
+ preferencesMember: MemberAccess | null;
101
+ topics: Row[]; emptyText: string; actionMessage: string;
102
+ isMock: boolean; notMock: boolean; /** #2849 — hiddenWhen() hides on TRUE, so these are inverted: the empty-state banner
103
+ * shows only when the site really has none, and the unavailable one only when the
104
+ * query failed. A failed query must never render the sentence that claims the
105
+ * customer has no content. */
106
+ notMockEmpty: boolean; notMockUnavailable: boolean;
107
+ /** The phone's notification permission; "loading" until read, "error" without push. */
108
+ pushStatus: PushStatus | "loading";
109
+ /** hiddenWhen flags: the "off on this phone" card shows only when denied, the turn-on offer
110
+ * only when never asked. Both hidden while loading or without push. */
111
+ hidePushOff: boolean; hidePushAsk: boolean;
112
+ /** The off card's one button: "Open Settings" where only Settings can change it, "Turn on" on
113
+ * Android 13+, whose "denied" also means never asked (the action prompts, then falls to Settings). */
114
+ hideOffSettingsCta: boolean; hideOffTurnOnCta: boolean;
115
+ /** The topic switches' opacity: dimmed while the phone blocks notifications. */
116
+ topicsOpacity: number;
117
+ pushMessage: string;
118
+ /** The picked channel, and the hiddenWhen flag of its picker (true without the option). */
119
+ channel: ChannelId; hideChannels: boolean;
120
+ /** "Allow all": on when every changeable topic is on. One switch per channel, each with its own static
121
+ * label (a native switch draws its label as catalog text, never a `$service:` path); each is hidden
122
+ * without the option, without topics, or on the other channel. */
123
+ allOn: boolean; hideAllowAllPush: boolean; hideAllowAllEmail: boolean;
124
+ /** Transient: the runtime strips it and arms the foreground-refresh poll. */
125
+ _poll?: PollDirective;
126
+ }
127
+
128
+ const DIMMED = 0.45;
129
+
130
+ /** The push half of the view for a status. Pure, so every branch is pinned by the tests. */
131
+ type PushView = Pick<S, "pushStatus" | "hidePushOff" | "hidePushAsk" | "hideOffSettingsCta" | "hideOffTurnOnCta" | "topicsOpacity">;
132
+ export function pushView(pushStatus: S["pushStatus"], deniedMayPrompt = false): PushView {
133
+ const blocked = pushStatus === "denied" || pushStatus === "undetermined";
134
+ const off = pushStatus === "denied";
135
+ return {
136
+ pushStatus, hidePushOff: !off, hidePushAsk: pushStatus !== "undetermined",
137
+ hideOffSettingsCta: !off || deniedMayPrompt, hideOffTurnOnCta: !off || !deniedMayPrompt,
138
+ topicsOpacity: blocked ? DIMMED : 1,
139
+ };
140
+ }
141
+
142
+ /** Whether this phone's "denied" may still hide a first ask (last read; see readPhonePush). */
143
+ let deniedMayPrompt = false;
144
+ const viewOf = (status: S["pushStatus"]): PushView => pushView(status, deniedMayPrompt);
145
+
146
+ const POLL: PollDirective = { id: "himi-branded-notifsettings-push", intervalMs: 60_000, action: "himiBrandedNotifSettings.checkPush", immediate: false };
147
+ const OPEN_FAILED = () => copyParam("notifsettings.openSettingsFailed", "Change notifications for this app in your phone's settings.");
148
+
149
+ /** Whether this topic is actually being DELIVERED — not merely what the recipient
150
+ * asked for. `isDeliveredNow` prefers the server's `granted` verdict, so a topic the
151
+ * member unmuted under a channel-wide mute renders OFF instead of promising a
152
+ * notification that will never arrive. No preference row at all ⇒ the topic's default,
153
+ * which is delivery. */
154
+ function isOn(topicId: string, prefs: PreferenceInfo[], channel: Channel): boolean {
155
+ const p = preferenceFor(topicId, prefs, channel);
156
+ if (!p) return true;
157
+ return isDeliveredNow(p.stateData);
158
+ }
159
+
160
+ /** A row the server says cannot be changed here (a broader rule overrides it). */
161
+ function locked(topicId: string, prefs: PreferenceInfo[], channel: Channel): boolean {
162
+ return isLocked(preferenceFor(topicId, prefs, channel)?.stateData);
163
+ }
164
+
165
+ /** Row subtitle doubles as an affordance: current state + how to change it. */
166
+ function subtitleFor(on: boolean): string {
167
+ return on ? "On · tap to mute" : "Off · tap to enable";
168
+ }
169
+
170
+ function withOn(r: Row, on: boolean): Row {
171
+ return { ...r, on, subtitle: subtitleFor(on), stateLabel: on ? "On" : "Off" };
172
+ }
173
+
174
+ function row(id: string, name: string, on: boolean): Row {
175
+ return { id, name, subtitle: subtitleFor(on), note: "", on, locked: false, notLocked: true, stateLabel: on ? "On" : "Off" };
176
+ }
177
+
178
+ const topicName = (t: NotificationTopicDefinition) => (t.displayName || "Notification").trim() || "Notification";
179
+ /** A row's id: the topic id, or its name when the definition has none. */
180
+ const rowId = (t: NotificationTopicDefinition) => t.topicId || topicName(t);
181
+ function norm(t: NotificationTopicDefinition, prefs: PreferenceInfo[], channel: Channel): Row {
182
+ const name = topicName(t);
183
+ const id = rowId(t);
184
+ const r = row(id, name, isOn(id, prefs, channel));
185
+ // An overridden row says so instead of offering a toggle that cannot take effect.
186
+ return locked(id, prefs, channel)
187
+ ? { ...r, locked: true, notLocked: false, subtitle: "Managed by your channel settings", note: "Managed by your channel settings" }
188
+ : r;
189
+ }
190
+
191
+ const MOCK: Row[] = [
192
+ row("sample-orders", "Order updates", true),
193
+ row("sample-bookings", "Bookings & reminders", true),
194
+ row("sample-promos", "Promotions & offers", false),
195
+ row("sample-community", "Community activity", true),
196
+ ];
197
+
198
+ /** sample rows reach the screen ONLY in the host's explicit sample preview;
199
+ * a failed or empty query is an honest error / empty state (branded-load-state.ts). */
200
+ const COPY: LoadCopy<Row> = {
201
+ prefix: "notifsettings",
202
+ empty: "No notification topics to manage yet.",
203
+ error: "Notification settings couldn't be loaded.",
204
+ signIn: "Sign in to manage your notifications.",
205
+ sample: () => MOCK.map((r) => ({ ...r })),
206
+ };
207
+
208
+ const defineService = withOnlineWrites(registerService, ["toggle", "toggleAll"], { messageFields: ["actionMessage"] });
209
+
210
+ const SAVE_FAILED = () => copyParam("notifsettings.saveFailed", "Couldn't save your notification settings. Try again.");
211
+
212
+ /** The rows for one channel, from the last read plus every write since. */
213
+ function rowsFor(channel: ChannelId): Row[] {
214
+ return definitions.map((t) => norm(t, preferences, WIX_CHANNEL[channel]));
215
+ }
216
+ /** One topic's row, without rebuilding the others. */
217
+ function rowFor(channel: ChannelId, id: string): Row | undefined {
218
+ const t = definitions.find((d) => rowId(d) === id);
219
+ return t ? norm(t, preferences, WIX_CHANNEL[channel]) : undefined;
220
+ }
221
+
222
+ /** The channel-dependent fields, derived after every action so no reducer can leave them stale.
223
+ * Email reaches the member whatever the phone allows, so only push switches are dimmed. */
224
+ function channelView<T extends S>(s: T): T {
225
+ const channel: ChannelId = options.channels ? s.channel : "push";
226
+ const changeable = s.topics.filter((r) => !r.locked);
227
+ return {
228
+ ...s,
229
+ channel,
230
+ // No topics (loading, signed out, failed): nothing to pick a channel for.
231
+ hideChannels: !options.channels || s.topics.length === 0,
232
+ allOn: changeable.length > 0 && changeable.every((r) => r.on),
233
+ hideAllowAllPush: !options.allowAll || changeable.length === 0 || channel !== "push",
234
+ hideAllowAllEmail: !options.allowAll || changeable.length === 0 || channel !== "email",
235
+ ...(channel === "email" ? { topicsOpacity: 1 } : {}),
236
+ };
237
+ }
238
+
239
+ // Typed like `withEmptyFlags`: D passes through untouched, so each action keeps its own parameter types.
240
+ type Action = (s: S, ...args: unknown[]) => unknown;
241
+ function withChannelView<D extends { state: object; actions?: object }>(def: D): D {
242
+ const derive = (r: unknown) => (r && typeof r === "object" ? channelView(r as S) : r);
243
+ const actions: Record<string, Action> = {};
244
+ for (const [name, action] of Object.entries((def.actions ?? {}) as Record<string, Action>)) {
245
+ actions[name] = (s, ...args) => {
246
+ const r = action(s, ...args);
247
+ return r instanceof Promise ? r.then(derive) : derive(r);
248
+ };
249
+ }
250
+ return { ...def, state: channelView(def.state as S), actions } as D;
251
+ }
252
+ const CHANNEL_INITIAL = { channel: "push" as ChannelId, hideChannels: true, allOn: false, hideAllowAllPush: true, hideAllowAllEmail: true };
253
+ const CHANNEL_FIELDS = Object.keys(CHANNEL_INITIAL) as Array<keyof typeof CHANNEL_INITIAL>;
254
+ const INITIAL = { ...LOADING, topics: [] as Row[], emptyText: "", actionMessage: "", preferencesMember: null };
255
+ const PUSH_INITIAL = { ...pushView("loading"), pushMessage: "" };
256
+ const PUSH_FIELDS = ["pushStatus", "hidePushOff", "hidePushAsk", "hideOffSettingsCta", "hideOffTurnOnCta", "topicsOpacity", "pushMessage"] as const;
257
+ /** Bumped by every action that writes the permission: a load started earlier must not overwrite it. */
258
+ let pushWrites = 0;
259
+ function pushFieldsOf(state: S): Pick<S, (typeof PUSH_FIELDS)[number]> {
260
+ return Object.fromEntries(PUSH_FIELDS.map((k) => [k, state[k]])) as Pick<S, (typeof PUSH_FIELDS)[number]>;
261
+ }
262
+ const signInRequired = () => new Error("Unauthenticated: sign in to manage notifications");
263
+ let loadVersion = 0;
264
+ const svc = defineService<S, {
265
+ prepare: (s: S) => S;
266
+ load: (s: S, arg?: unknown) => Promise<S | undefined>;
267
+ toggle: (s: S, p?: { id?: string; value?: unknown }) => Promise<S | undefined>;
268
+ checkPush: (s: S) => Promise<S | undefined>;
269
+ enablePush: (s: S) => Promise<S>;
270
+ openPushSettings: (s: S) => Promise<S>;
271
+ setChannel: (s: S, arg?: unknown) => S | undefined;
272
+ toggleAll: (s: S, p?: { value?: unknown }) => Promise<S | undefined>;
273
+ showOn: (s: S, p?: { ids?: unknown; on?: unknown; channel?: unknown }) => S | undefined;
274
+ }>("himiBrandedNotifSettings", withChannelView(withEmptyFlags({
275
+ state: { ...INITIAL, ...PUSH_INITIAL, ...CHANNEL_INITIAL } as S,
276
+ // The phone's permission is read fresh each run: last run's answer may have changed in Settings.
277
+ // The channel controls too: last run's picker or Allow all must not paint over a signed-out screen.
278
+ notHydrated: [...PUSH_FIELDS, ...CHANNEL_FIELDS],
279
+ // Nor persisted: an early paint from the snapshot would show last run's card before the worker reads the OS.
280
+ notPersisted: [...PUSH_FIELDS, ...CHANNEL_FIELDS],
281
+ actions: {
282
+ // The push view too: a warm worker must not show last visit's card while this load reads the OS.
283
+ // `pushStatus` is kept: a poll comparing against it must not mistake a reload for a change.
284
+ prepare: (s) => ({ ...s, ...INITIAL, ...PUSH_INITIAL, pushStatus: s.pushStatus }),
285
+ load: async (s, arg): Promise<S | undefined> => {
286
+ stashCopy(arg);
287
+ readOptions(arg);
288
+ const version = ++loadVersion;
289
+ await svc.prepare();
290
+ // Independent of the member (a visitor's phone permission is just as real), and read HERE rather
291
+ // than by a second action, which could commit after this one with no topics.
292
+ const phoneRead = readPhonePush();
293
+ const writesAtStart = pushWrites;
294
+ const pushOf = async () => {
295
+ const phone = await phoneRead;
296
+ // A grant made (or seen) while this load waited on the topics wins over its older read.
297
+ if (pushWrites !== writesAtStart) return pushFieldsOf(current());
298
+ deniedMayPrompt = phone.deniedMayPrompt;
299
+ // A grant first seen here (e.g. turned on in Settings before this screen opened) still needs
300
+ // this session's token.
301
+ await refreshGrantedTokenOnce(phone.status);
302
+ return { ...viewOf(phone.status), pushMessage: "" };
303
+ };
304
+ try {
305
+ const member = await memberAccess();
306
+ if (!member.email) throw signInRequired();
307
+ const [topicsRes, prefsRes] = await Promise.all([
308
+ getNotificationTopics(),
309
+ getMyNotificationPreferences(),
310
+ ]);
311
+ await assertMemberAccess(member);
312
+ if (version !== loadVersion) return undefined;
313
+ preferences = readPreferences(prefsRes);
314
+ definitions = readTopics(topicsRes);
315
+ const topics = rowsFor(options.channels ? current().channel : "push");
316
+ const push = await pushOf();
317
+ return version === loadVersion ? { ...current(), ...loaded("topics", topics, COPY), ...push, preferencesMember: member, actionMessage: "", _poll: POLL } : undefined;
318
+ } catch {
319
+ const member = await memberAccess();
320
+ // An authenticated denial is not repaired by an endless sign-in loop.
321
+ const failure = member.email ? new Error(COPY.error) : signInRequired();
322
+ // Nothing of a previous member's list may be re-derived after a failed load.
323
+ if (version === loadVersion) { definitions = []; preferences = []; }
324
+ const push = await pushOf();
325
+ return version === loadVersion ? { ...current(), ...loadFailed("topics", failure, COPY), ...push, preferencesMember: null, actionMessage: "", _poll: POLL } : undefined;
326
+ }
327
+ },
328
+ // Flip one topic's On/Off. Shown at once; a failed save puts the row back and says so, so a
329
+ // member never believes a topic is muted when it is not. A no-op write on sample rows.
330
+ toggle: async (s, p): Promise<S | undefined> => {
331
+ const id = p?.id;
332
+ const target = s.topics.find((r) => r.id === id);
333
+ if (s.busy || !id || !target || target.locked) return undefined;
334
+ // A Toggle sends the NEXT state as `value` (action-payload contract); honour it so
335
+ // a repeated event can never flip the row the wrong way. A bare tap still flips.
336
+ const nextOn = typeof p?.value === "boolean" ? p.value : !target.on;
337
+ if (s.isMock || id.startsWith("sample-")) return { ...s, topics: s.topics.map((r) => (r.id === id ? withOn(r, nextOn) : r)) };
338
+ const slot = reserveSave();
339
+ try {
340
+ try {
341
+ if (!s.preferencesMember) return undefined;
342
+ await assertMemberAccess(s.preferencesMember);
343
+ if (svc.getState().preferencesMember !== s.preferencesMember) return undefined;
344
+ } catch {
345
+ await svc.load();
346
+ return undefined;
347
+ }
348
+ await svc.showOn({ ids: [id], on: nextOn, channel: s.channel });
349
+ // `stateData.state` is a SCALAR enum — the old nested `{ muteStatus }` was a
350
+ // shape this service does not have, so every write was malformed.
351
+ const written = [{ topicId: id, channel: WIX_CHANNEL[s.channel], stateData: { state: muteStatusFor(nextOn) } }];
352
+ let failed = false;
353
+ try { rememberWrites(written, await slot.send(written, s.preferencesMember), slot.seq); }
354
+ catch { failed = true; }
355
+ try { await assertMemberAccess(s.preferencesMember); }
356
+ catch { await svc.load(); return undefined; }
357
+ const now = current();
358
+ if (now.preferencesMember !== s.preferencesMember) return undefined;
359
+ // A save that worked clears an earlier failure's message, as Allow all's does.
360
+ const actionMessage = failed ? SAVE_FAILED() : "";
361
+ // Moved to the other channel while saving: its rows stay as they are (a save of its own may be out);
362
+ // the cache holds this one for when the member comes back.
363
+ if (now.channel !== s.channel) return { ...now, actionMessage };
364
+ // Only this row changes: a bulk update that landed while this save was out stays on screen.
365
+ // A failure shows what the cache holds, which includes an Allow all that landed meanwhile.
366
+ const saved = rowFor(s.channel, id) ?? (failed ? target : withOn(target, nextOn));
367
+ return { ...now, topics: now.topics.map((r) => (r.id === id ? saved : r)), actionMessage };
368
+ } finally { slot.cancel(); }
369
+ },
370
+ // A switch shown at once, before its save. Published, so that a failed save is a real change back:
371
+ // a native switch keeps its own flip until its bound value moves.
372
+ showOn: (s, p): S | undefined => {
373
+ const a = (p ?? {}) as { ids?: unknown; on?: unknown; channel?: unknown };
374
+ // The member moved to the other channel meanwhile: these rows are not the ones being saved.
375
+ if (a.channel !== s.channel) return undefined;
376
+ const ids = Array.isArray(a.ids) ? a.ids : [];
377
+ return { ...s, topics: s.topics.map((r) => (ids.includes(r.id) && !r.locked ? withOn(r, a.on === true) : r)) };
378
+ },
379
+ // onAppear's kick and every poll tick (the host fires it on return from the OS settings).
380
+ checkPush: async (s): Promise<S | undefined> => {
381
+ const phone = await readPhonePush();
382
+ deniedMayPrompt = phone.deniedMayPrompt;
383
+ const status = phone.status;
384
+ if (status === s.pushStatus) return undefined;
385
+ pushWrites++;
386
+ // Turned on in the OS settings while away: register this session's token.
387
+ await refreshGrantedToken(status);
388
+ return { ...current(), ...viewOf(status), pushMessage: "" };
389
+ },
390
+ // "Turn on notifications" (never asked): the system prompt, and nothing else. The answer is
391
+ // awaited BEFORE the state is read: topics may have loaded while the prompt was up.
392
+ enablePush: async (): Promise<S> => {
393
+ const status = await askForPush();
394
+ pushWrites++;
395
+ return { ...current(), ...viewOf(status), pushMessage: "" };
396
+ },
397
+ // "Open Settings" (denied). A request first: on Android "denied" also means never asked, and
398
+ // a request is the only way to find out. Anything but a grant goes to the OS settings.
399
+ openPushSettings: async (): Promise<S> => {
400
+ const status = await askForPush();
401
+ pushWrites++;
402
+ if (status === "granted") return { ...current(), ...viewOf(status), pushMessage: "" };
403
+ const opened = await openPushSettings();
404
+ return { ...current(), ...viewOf(status), pushMessage: opened ? "" : OPEN_FAILED() };
405
+ },
406
+ // The Push / Email picker. Sample rows are one channel's illustration, so they stay as they are.
407
+ setChannel: (s, arg): S | undefined => {
408
+ const raw = typeof arg === "string" ? arg : (arg as { selectedId?: unknown } | undefined)?.selectedId;
409
+ const channel: ChannelId = raw === "email" ? "email" : "push";
410
+ if (!options.channels || channel === s.channel) return undefined;
411
+ // Back on push, the dimming follows the phone again (email set it to full).
412
+ return { ...s, channel, topics: s.isMock || s.busy ? s.topics : rowsFor(channel), topicsOpacity: viewOf(s.pushStatus).topicsOpacity, actionMessage: "" };
413
+ },
414
+ // "Allow all": every changeable topic on this channel, in one write. Unlike a single switch, a
415
+ // failure rolls back: a master switch left On over topics that were never saved would lie.
416
+ toggleAll: async (s, p): Promise<S | undefined> => {
417
+ const changeable = s.topics.filter((r) => !r.locked);
418
+ if (!options.allowAll || s.busy || changeable.length === 0) return undefined;
419
+ const on = typeof p?.value === "boolean" ? p.value : !s.topics.every((r) => r.locked || r.on);
420
+ const flip = (r: Row): Row => (r.locked ? r : withOn(r, on));
421
+ if (s.isMock) return { ...s, topics: s.topics.map(flip) };
422
+ const slot = reserveSave();
423
+ try {
424
+ if (!s.preferencesMember) return undefined;
425
+ // As `toggle`: never write one member's list under another account.
426
+ try { await assertMemberAccess(s.preferencesMember); }
427
+ catch { await svc.load(); return undefined; }
428
+ if (current().preferencesMember !== s.preferencesMember) return undefined;
429
+ await svc.showOn({ ids: changeable.map((r) => r.id), on, channel: s.channel });
430
+ const channel = WIX_CHANNEL[s.channel];
431
+ const written = changeable.map((r) => ({ topicId: r.id, channel, stateData: { state: muteStatusFor(on) } }));
432
+ let failed = false;
433
+ try { rememberWrites(written, await slot.send(written, s.preferencesMember), slot.seq); }
434
+ catch { failed = true; }
435
+ // Signed out or switched account while saving: the next load shows that, not this member's rows.
436
+ try { await assertMemberAccess(s.preferencesMember); }
437
+ catch { await svc.load(); return undefined; }
438
+ const now = current();
439
+ if (failed) {
440
+ // Every row as the cache has it, so the master switch moves back too.
441
+ return now.preferencesMember === s.preferencesMember
442
+ ? { ...now, topics: now.channel === s.channel ? rowsFor(s.channel) : now.topics, actionMessage: SAVE_FAILED() }
443
+ : undefined;
444
+ }
445
+ // The rows as the server answered: a topic it still holds muted shows Off.
446
+ return now.preferencesMember === s.preferencesMember && now.channel === s.channel ? { ...now, topics: rowsFor(s.channel), actionMessage: "" } : undefined;
447
+ } finally { slot.cancel(); }
448
+ },
449
+ },
450
+ }, { topics: "noTopics" })));
451
+ /** The live state, typed: the actions above read it after an await (TS7022 without the annotation). */
452
+ function current(): S { return svc.getState() as S; }
453
+ svc.prepare();
454
+ svc.load();
455
+ export { svc };
@@ -2220,6 +2220,11 @@
2220
2220
  "translation": "سجّل الدخول لإدارة إشعاراتك.",
2221
2221
  "origin": "machine"
2222
2222
  },
2223
+ "h_8d5f95beb674": {
2224
+ "source": "Couldn't save your notification settings. Try again.",
2225
+ "translation": "تعذّر حفظ إعدادات الإشعارات. حاول مرة أخرى.",
2226
+ "origin": "machine"
2227
+ },
2223
2228
  "h_75f527181b57": {
2224
2229
  "source": "Free",
2225
2230
  "translation": "مجانًا",
@@ -2220,6 +2220,11 @@
2220
2220
  "translation": "Pro správu oznámení se přihlaste.",
2221
2221
  "origin": "machine"
2222
2222
  },
2223
+ "h_8d5f95beb674": {
2224
+ "source": "Couldn't save your notification settings. Try again.",
2225
+ "translation": "Nastavení oznámení se nepodařilo uložit. Zkuste to znovu.",
2226
+ "origin": "machine"
2227
+ },
2223
2228
  "h_75f527181b57": {
2224
2229
  "source": "Free",
2225
2230
  "translation": "Zdarma",
@@ -2220,6 +2220,11 @@
2220
2220
  "translation": "Log ind for at administrere dine notifikationer.",
2221
2221
  "origin": "machine"
2222
2222
  },
2223
+ "h_8d5f95beb674": {
2224
+ "source": "Couldn't save your notification settings. Try again.",
2225
+ "translation": "Notifikationsindstillingerne kunne ikke gemmes. Prøv igen.",
2226
+ "origin": "machine"
2227
+ },
2223
2228
  "h_75f527181b57": {
2224
2229
  "source": "Free",
2225
2230
  "translation": "Gratis",
@@ -2220,6 +2220,11 @@
2220
2220
  "translation": "Melde dich an, um deine Benachrichtigungen zu verwalten.",
2221
2221
  "origin": "machine"
2222
2222
  },
2223
+ "h_8d5f95beb674": {
2224
+ "source": "Couldn't save your notification settings. Try again.",
2225
+ "translation": "Deine Benachrichtigungseinstellungen konnten nicht gespeichert werden. Versuch es noch einmal.",
2226
+ "origin": "machine"
2227
+ },
2223
2228
  "h_75f527181b57": {
2224
2229
  "source": "Free",
2225
2230
  "translation": "Kostenlos",
@@ -2220,6 +2220,11 @@
2220
2220
  "translation": "Συνδεθείτε για να διαχειριστείτε τις ειδοποιήσεις σας.",
2221
2221
  "origin": "machine"
2222
2222
  },
2223
+ "h_8d5f95beb674": {
2224
+ "source": "Couldn't save your notification settings. Try again.",
2225
+ "translation": "Δεν ήταν δυνατή η αποθήκευση των ρυθμίσεων ειδοποιήσεων. Δοκίμασε ξανά.",
2226
+ "origin": "machine"
2227
+ },
2223
2228
  "h_75f527181b57": {
2224
2229
  "source": "Free",
2225
2230
  "translation": "Δωρεάν",
@@ -2220,6 +2220,11 @@
2220
2220
  "translation": "Inicia sesión para administrar tus notificaciones.",
2221
2221
  "origin": "machine"
2222
2222
  },
2223
+ "h_8d5f95beb674": {
2224
+ "source": "Couldn't save your notification settings. Try again.",
2225
+ "translation": "No se pudo guardar la configuración de notificaciones. Inténtalo de nuevo.",
2226
+ "origin": "machine"
2227
+ },
2223
2228
  "h_75f527181b57": {
2224
2229
  "source": "Free",
2225
2230
  "translation": "Gratis",
@@ -2220,6 +2220,11 @@
2220
2220
  "translation": "Kirjaudu sisään hallitaksesi ilmoituksiasi.",
2221
2221
  "origin": "machine"
2222
2222
  },
2223
+ "h_8d5f95beb674": {
2224
+ "source": "Couldn't save your notification settings. Try again.",
2225
+ "translation": "Ilmoitusasetuksia ei voitu tallentaa. Yritä uudelleen.",
2226
+ "origin": "machine"
2227
+ },
2223
2228
  "h_75f527181b57": {
2224
2229
  "source": "Free",
2225
2230
  "translation": "Ilmainen",