@wix/himalaya-cli 0.1870.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 (497) 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 +90 -39
  4. package/fixtures/wix-canned.json +8 -0
  5. package/guides/android-ux.md +3 -2
  6. package/guides/designing-himi-screens.md +10 -4
  7. package/guides/ios-ux.md +3 -2
  8. package/guides/release-notes.md +18 -0
  9. package/guides/sdk-reference.json +8 -1
  10. package/package.json +2 -2
  11. package/template-icons/professional-services.png +0 -0
  12. package/templates/bare-fashion/config.ts +37 -2
  13. package/templates/bare-fashion/dev/index.ts +4006 -48
  14. package/templates/bare-fashion/himalaya.content.json +15 -0
  15. package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +6 -1
  16. package/templates/bare-fashion/tier5-src/_shared/member-account-routes.ts +56 -0
  17. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  18. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  19. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  20. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  21. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  22. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  23. package/templates/beauty-salon/tier5-src/_shared/collection-contract.ts +6 -1
  24. package/templates/beauty-salon/tier5-src/_shared/himi-events.ts +27 -0
  25. package/templates/beauty-salon-owner/tier5-src/_shared/collection-contract.ts +6 -1
  26. package/templates/beauty-salon-owner/tier5-src/_shared/himi-events.ts +27 -0
  27. package/templates/branded-lite/dev/index.ts +22 -1
  28. package/templates/branded-lite/l10n/ar.json +10 -0
  29. package/templates/branded-lite/l10n/cs.json +10 -0
  30. package/templates/branded-lite/l10n/da.json +10 -0
  31. package/templates/branded-lite/l10n/de.json +10 -0
  32. package/templates/branded-lite/l10n/el.json +10 -0
  33. package/templates/branded-lite/l10n/es.json +10 -0
  34. package/templates/branded-lite/l10n/fi.json +10 -0
  35. package/templates/branded-lite/l10n/fr.json +10 -0
  36. package/templates/branded-lite/l10n/he.json +8 -0
  37. package/templates/branded-lite/l10n/hu.json +10 -0
  38. package/templates/branded-lite/l10n/id.json +10 -0
  39. package/templates/branded-lite/l10n/it.json +10 -0
  40. package/templates/branded-lite/l10n/ja.json +10 -0
  41. package/templates/branded-lite/l10n/ko.json +10 -0
  42. package/templates/branded-lite/l10n/lt.json +10 -0
  43. package/templates/branded-lite/l10n/nl.json +10 -0
  44. package/templates/branded-lite/l10n/no.json +10 -0
  45. package/templates/branded-lite/l10n/pl.json +10 -0
  46. package/templates/branded-lite/l10n/pt.json +10 -0
  47. package/templates/branded-lite/l10n/ru.json +10 -0
  48. package/templates/branded-lite/l10n/sv.json +10 -0
  49. package/templates/branded-lite/l10n/th.json +10 -0
  50. package/templates/branded-lite/l10n/tr.json +10 -0
  51. package/templates/branded-lite/l10n/uk.json +10 -0
  52. package/templates/branded-lite/l10n/vi.json +10 -0
  53. package/templates/branded-lite/l10n/zh.json +10 -0
  54. package/templates/branded-lite/tier5-src/_shared/collection-contract.ts +6 -1
  55. package/templates/branded-lite/tier5-src/_shared/himi-events.ts +27 -0
  56. package/templates/branded-lite/tier5-src/_shared/portfolio-details.ts +70 -0
  57. package/templates/branded-lite/tier5-src/himi-branded-lite-coupons/index.ts +13 -2
  58. package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
  59. package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
  60. package/templates/branded-lite/tier5-src/himi-events-detail/index.ts +3 -1
  61. package/templates/branded-lite/tier5-src/himi-events-list/index.ts +38 -8
  62. package/templates/branded-lite/tier5-src/himi-events-my-events/index.ts +4 -2
  63. package/templates/brandy/tier5-src/_shared/collection-contract.ts +6 -1
  64. package/templates/community-club/dev/index.ts +20 -0
  65. package/templates/community-club/l10n/ar.json +10 -0
  66. package/templates/community-club/l10n/cs.json +10 -0
  67. package/templates/community-club/l10n/da.json +10 -0
  68. package/templates/community-club/l10n/de.json +10 -0
  69. package/templates/community-club/l10n/el.json +10 -0
  70. package/templates/community-club/l10n/es.json +10 -0
  71. package/templates/community-club/l10n/fi.json +10 -0
  72. package/templates/community-club/l10n/fr.json +10 -0
  73. package/templates/community-club/l10n/he.json +8 -0
  74. package/templates/community-club/l10n/hu.json +10 -0
  75. package/templates/community-club/l10n/id.json +10 -0
  76. package/templates/community-club/l10n/it.json +10 -0
  77. package/templates/community-club/l10n/ja.json +10 -0
  78. package/templates/community-club/l10n/ko.json +10 -0
  79. package/templates/community-club/l10n/lt.json +10 -0
  80. package/templates/community-club/l10n/nl.json +10 -0
  81. package/templates/community-club/l10n/no.json +10 -0
  82. package/templates/community-club/l10n/pl.json +10 -0
  83. package/templates/community-club/l10n/pt.json +10 -0
  84. package/templates/community-club/l10n/ru.json +10 -0
  85. package/templates/community-club/l10n/sv.json +10 -0
  86. package/templates/community-club/l10n/th.json +10 -0
  87. package/templates/community-club/l10n/tr.json +10 -0
  88. package/templates/community-club/l10n/uk.json +10 -0
  89. package/templates/community-club/l10n/vi.json +10 -0
  90. package/templates/community-club/l10n/zh.json +10 -0
  91. package/templates/community-club/tier5-src/_shared/collection-contract.ts +6 -1
  92. package/templates/community-club/tier5-src/_shared/himi-events.ts +27 -0
  93. package/templates/community-club/tier5-src/himi-events-detail/index.ts +3 -1
  94. package/templates/community-club/tier5-src/himi-events-list/index.ts +38 -8
  95. package/templates/community-club/tier5-src/himi-events-my-events/index.ts +4 -2
  96. package/templates/community-club-owner/tier5-src/_shared/collection-contract.ts +6 -1
  97. package/templates/community-club-owner/tier5-src/_shared/himi-events.ts +27 -0
  98. package/templates/conference/config.ts +43 -1
  99. package/templates/conference/dev/index.ts +4147 -0
  100. package/templates/conference/himalaya.content.json +18 -0
  101. package/templates/conference/tier5-src/_shared/collection-contract.ts +6 -1
  102. package/templates/conference/tier5-src/_shared/himi-events.ts +27 -0
  103. package/templates/conference/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  104. package/templates/conference/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  105. package/templates/conference/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  106. package/templates/conference/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  107. package/templates/conference/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  108. package/templates/conference/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  109. package/templates/conference/tier5-src/himi-events-detail/index.ts +3 -1
  110. package/templates/conference/tier5-src/himi-events-list/index.ts +38 -8
  111. package/templates/conference/tier5-src/himi-events-my-events/index.ts +4 -2
  112. package/templates/conference/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  113. package/templates/events-meetups/dev/index.ts +20 -0
  114. package/templates/events-meetups/l10n/ar.json +10 -0
  115. package/templates/events-meetups/l10n/cs.json +10 -0
  116. package/templates/events-meetups/l10n/da.json +10 -0
  117. package/templates/events-meetups/l10n/de.json +10 -0
  118. package/templates/events-meetups/l10n/el.json +10 -0
  119. package/templates/events-meetups/l10n/es.json +10 -0
  120. package/templates/events-meetups/l10n/fi.json +10 -0
  121. package/templates/events-meetups/l10n/fr.json +10 -0
  122. package/templates/events-meetups/l10n/he.json +8 -0
  123. package/templates/events-meetups/l10n/hu.json +10 -0
  124. package/templates/events-meetups/l10n/id.json +10 -0
  125. package/templates/events-meetups/l10n/it.json +10 -0
  126. package/templates/events-meetups/l10n/ja.json +10 -0
  127. package/templates/events-meetups/l10n/ko.json +10 -0
  128. package/templates/events-meetups/l10n/lt.json +10 -0
  129. package/templates/events-meetups/l10n/nl.json +10 -0
  130. package/templates/events-meetups/l10n/no.json +10 -0
  131. package/templates/events-meetups/l10n/pl.json +10 -0
  132. package/templates/events-meetups/l10n/pt.json +10 -0
  133. package/templates/events-meetups/l10n/ru.json +10 -0
  134. package/templates/events-meetups/l10n/sv.json +10 -0
  135. package/templates/events-meetups/l10n/th.json +10 -0
  136. package/templates/events-meetups/l10n/tr.json +10 -0
  137. package/templates/events-meetups/l10n/uk.json +10 -0
  138. package/templates/events-meetups/l10n/vi.json +10 -0
  139. package/templates/events-meetups/l10n/zh.json +10 -0
  140. package/templates/events-meetups/tier5-src/_shared/collection-contract.ts +6 -1
  141. package/templates/events-meetups/tier5-src/_shared/himi-events.ts +27 -0
  142. package/templates/events-meetups/tier5-src/himi-events-detail/index.ts +3 -1
  143. package/templates/events-meetups/tier5-src/himi-events-list/index.ts +38 -8
  144. package/templates/events-meetups/tier5-src/himi-events-my-events/index.ts +4 -2
  145. package/templates/events-meetups-owner/tier5-src/_shared/collection-contract.ts +6 -1
  146. package/templates/events-meetups-owner/tier5-src/_shared/himi-events.ts +27 -0
  147. package/templates/fitness-gym/tier5-src/_shared/collection-contract.ts +6 -1
  148. package/templates/gym-fitness/dev/index.ts +20 -0
  149. package/templates/gym-fitness/l10n/ar.json +10 -0
  150. package/templates/gym-fitness/l10n/cs.json +10 -0
  151. package/templates/gym-fitness/l10n/da.json +10 -0
  152. package/templates/gym-fitness/l10n/de.json +10 -0
  153. package/templates/gym-fitness/l10n/el.json +10 -0
  154. package/templates/gym-fitness/l10n/es.json +10 -0
  155. package/templates/gym-fitness/l10n/fi.json +10 -0
  156. package/templates/gym-fitness/l10n/fr.json +10 -0
  157. package/templates/gym-fitness/l10n/he.json +8 -0
  158. package/templates/gym-fitness/l10n/hu.json +10 -0
  159. package/templates/gym-fitness/l10n/id.json +10 -0
  160. package/templates/gym-fitness/l10n/it.json +10 -0
  161. package/templates/gym-fitness/l10n/ja.json +10 -0
  162. package/templates/gym-fitness/l10n/ko.json +10 -0
  163. package/templates/gym-fitness/l10n/lt.json +10 -0
  164. package/templates/gym-fitness/l10n/nl.json +10 -0
  165. package/templates/gym-fitness/l10n/no.json +10 -0
  166. package/templates/gym-fitness/l10n/pl.json +10 -0
  167. package/templates/gym-fitness/l10n/pt.json +10 -0
  168. package/templates/gym-fitness/l10n/ru.json +10 -0
  169. package/templates/gym-fitness/l10n/sv.json +10 -0
  170. package/templates/gym-fitness/l10n/th.json +10 -0
  171. package/templates/gym-fitness/l10n/tr.json +10 -0
  172. package/templates/gym-fitness/l10n/uk.json +10 -0
  173. package/templates/gym-fitness/l10n/vi.json +10 -0
  174. package/templates/gym-fitness/l10n/zh.json +10 -0
  175. package/templates/gym-fitness/tier5-src/_shared/collection-contract.ts +6 -1
  176. package/templates/gym-fitness/tier5-src/_shared/himi-events.ts +27 -0
  177. package/templates/gym-fitness/tier5-src/himi-events-detail/index.ts +3 -1
  178. package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +38 -8
  179. package/templates/gym-fitness/tier5-src/himi-events-my-events/index.ts +4 -2
  180. package/templates/gym-fitness-owner/tier5-src/_shared/collection-contract.ts +6 -1
  181. package/templates/gym-fitness-owner/tier5-src/_shared/himi-events.ts +27 -0
  182. package/templates/medical-services/config.ts +42 -0
  183. package/templates/medical-services/dev/index.ts +4136 -0
  184. package/templates/medical-services/himalaya.content.json +18 -0
  185. package/templates/medical-services/tier5-src/_shared/collection-contract.ts +6 -1
  186. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  187. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  188. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  189. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  190. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  191. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  192. package/templates/medical-services/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  193. package/templates/nonprofit-cause/dev/index.ts +20 -0
  194. package/templates/nonprofit-cause/l10n/ar.json +10 -0
  195. package/templates/nonprofit-cause/l10n/cs.json +10 -0
  196. package/templates/nonprofit-cause/l10n/da.json +10 -0
  197. package/templates/nonprofit-cause/l10n/de.json +10 -0
  198. package/templates/nonprofit-cause/l10n/el.json +10 -0
  199. package/templates/nonprofit-cause/l10n/es.json +10 -0
  200. package/templates/nonprofit-cause/l10n/fi.json +10 -0
  201. package/templates/nonprofit-cause/l10n/fr.json +10 -0
  202. package/templates/nonprofit-cause/l10n/he.json +8 -0
  203. package/templates/nonprofit-cause/l10n/hu.json +10 -0
  204. package/templates/nonprofit-cause/l10n/id.json +10 -0
  205. package/templates/nonprofit-cause/l10n/it.json +10 -0
  206. package/templates/nonprofit-cause/l10n/ja.json +10 -0
  207. package/templates/nonprofit-cause/l10n/ko.json +10 -0
  208. package/templates/nonprofit-cause/l10n/lt.json +10 -0
  209. package/templates/nonprofit-cause/l10n/nl.json +10 -0
  210. package/templates/nonprofit-cause/l10n/no.json +10 -0
  211. package/templates/nonprofit-cause/l10n/pl.json +10 -0
  212. package/templates/nonprofit-cause/l10n/pt.json +10 -0
  213. package/templates/nonprofit-cause/l10n/ru.json +10 -0
  214. package/templates/nonprofit-cause/l10n/sv.json +10 -0
  215. package/templates/nonprofit-cause/l10n/th.json +10 -0
  216. package/templates/nonprofit-cause/l10n/tr.json +10 -0
  217. package/templates/nonprofit-cause/l10n/uk.json +10 -0
  218. package/templates/nonprofit-cause/l10n/vi.json +10 -0
  219. package/templates/nonprofit-cause/l10n/zh.json +10 -0
  220. package/templates/nonprofit-cause/tier5-src/_shared/collection-contract.ts +6 -1
  221. package/templates/nonprofit-cause/tier5-src/_shared/himi-events.ts +27 -0
  222. package/templates/nonprofit-cause/tier5-src/himi-events-detail/index.ts +3 -1
  223. package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +38 -8
  224. package/templates/nonprofit-cause/tier5-src/himi-events-my-events/index.ts +4 -2
  225. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-contract.ts +6 -1
  226. package/templates/nonprofit-cause-owner/tier5-src/_shared/himi-events.ts +27 -0
  227. package/templates/owner-lite/tier5-src/_shared/collection-contract.ts +6 -1
  228. package/templates/owner-lite/tier5-src/_shared/himi-events.ts +27 -0
  229. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-contract.ts +6 -1
  230. package/templates/podcast-creator/dev/index.ts +20 -0
  231. package/templates/podcast-creator/l10n/ar.json +10 -0
  232. package/templates/podcast-creator/l10n/cs.json +10 -0
  233. package/templates/podcast-creator/l10n/da.json +10 -0
  234. package/templates/podcast-creator/l10n/de.json +10 -0
  235. package/templates/podcast-creator/l10n/el.json +10 -0
  236. package/templates/podcast-creator/l10n/es.json +10 -0
  237. package/templates/podcast-creator/l10n/fi.json +10 -0
  238. package/templates/podcast-creator/l10n/fr.json +10 -0
  239. package/templates/podcast-creator/l10n/he.json +8 -0
  240. package/templates/podcast-creator/l10n/hu.json +10 -0
  241. package/templates/podcast-creator/l10n/id.json +10 -0
  242. package/templates/podcast-creator/l10n/it.json +10 -0
  243. package/templates/podcast-creator/l10n/ja.json +10 -0
  244. package/templates/podcast-creator/l10n/ko.json +10 -0
  245. package/templates/podcast-creator/l10n/lt.json +10 -0
  246. package/templates/podcast-creator/l10n/nl.json +10 -0
  247. package/templates/podcast-creator/l10n/no.json +10 -0
  248. package/templates/podcast-creator/l10n/pl.json +10 -0
  249. package/templates/podcast-creator/l10n/pt.json +10 -0
  250. package/templates/podcast-creator/l10n/ru.json +10 -0
  251. package/templates/podcast-creator/l10n/sv.json +10 -0
  252. package/templates/podcast-creator/l10n/th.json +10 -0
  253. package/templates/podcast-creator/l10n/tr.json +10 -0
  254. package/templates/podcast-creator/l10n/uk.json +10 -0
  255. package/templates/podcast-creator/l10n/vi.json +10 -0
  256. package/templates/podcast-creator/l10n/zh.json +10 -0
  257. package/templates/podcast-creator/tier5-src/_shared/collection-contract.ts +6 -1
  258. package/templates/podcast-creator/tier5-src/_shared/himi-events.ts +27 -0
  259. package/templates/podcast-creator/tier5-src/himi-events-detail/index.ts +3 -1
  260. package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +38 -8
  261. package/templates/podcast-creator/tier5-src/himi-events-my-events/index.ts +4 -2
  262. package/templates/podcast-creator-owner/tier5-src/_shared/collection-contract.ts +6 -1
  263. package/templates/podcast-creator-owner/tier5-src/_shared/himi-events.ts +27 -0
  264. package/templates/portfolio-creative/dev/index.ts +22 -1
  265. package/templates/portfolio-creative/l10n/ar.json +10 -0
  266. package/templates/portfolio-creative/l10n/cs.json +10 -0
  267. package/templates/portfolio-creative/l10n/da.json +10 -0
  268. package/templates/portfolio-creative/l10n/de.json +10 -0
  269. package/templates/portfolio-creative/l10n/el.json +10 -0
  270. package/templates/portfolio-creative/l10n/es.json +10 -0
  271. package/templates/portfolio-creative/l10n/fi.json +10 -0
  272. package/templates/portfolio-creative/l10n/fr.json +10 -0
  273. package/templates/portfolio-creative/l10n/he.json +8 -0
  274. package/templates/portfolio-creative/l10n/hu.json +10 -0
  275. package/templates/portfolio-creative/l10n/id.json +10 -0
  276. package/templates/portfolio-creative/l10n/it.json +10 -0
  277. package/templates/portfolio-creative/l10n/ja.json +10 -0
  278. package/templates/portfolio-creative/l10n/ko.json +10 -0
  279. package/templates/portfolio-creative/l10n/lt.json +10 -0
  280. package/templates/portfolio-creative/l10n/nl.json +10 -0
  281. package/templates/portfolio-creative/l10n/no.json +10 -0
  282. package/templates/portfolio-creative/l10n/pl.json +10 -0
  283. package/templates/portfolio-creative/l10n/pt.json +10 -0
  284. package/templates/portfolio-creative/l10n/ru.json +10 -0
  285. package/templates/portfolio-creative/l10n/sv.json +10 -0
  286. package/templates/portfolio-creative/l10n/th.json +10 -0
  287. package/templates/portfolio-creative/l10n/tr.json +10 -0
  288. package/templates/portfolio-creative/l10n/uk.json +10 -0
  289. package/templates/portfolio-creative/l10n/vi.json +10 -0
  290. package/templates/portfolio-creative/l10n/zh.json +10 -0
  291. package/templates/portfolio-creative/tier5-src/_shared/collection-contract.ts +6 -1
  292. package/templates/portfolio-creative/tier5-src/_shared/himi-events.ts +27 -0
  293. package/templates/portfolio-creative/tier5-src/_shared/portfolio-details.ts +70 -0
  294. package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
  295. package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
  296. package/templates/portfolio-creative/tier5-src/himi-events-detail/index.ts +3 -1
  297. package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +38 -8
  298. package/templates/portfolio-creative/tier5-src/himi-events-my-events/index.ts +4 -2
  299. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-contract.ts +6 -1
  300. package/templates/portfolio-creative-owner/tier5-src/_shared/himi-events.ts +27 -0
  301. package/templates/professional-services/README.md +55 -0
  302. package/templates/professional-services/config.ts +436 -0
  303. package/templates/professional-services/dev/index.ts +44772 -0
  304. package/templates/professional-services/himalaya.content.json +100 -0
  305. package/templates/professional-services/himalaya.template.json +16 -0
  306. package/templates/professional-services/icon.png +0 -0
  307. package/templates/professional-services/platforms.json +1 -0
  308. package/templates/professional-services/tier5-src/_shared/app-locale.ts +70 -0
  309. package/templates/professional-services/tier5-src/_shared/booking-location.ts +147 -0
  310. package/templates/professional-services/tier5-src/_shared/booking-session.ts +224 -0
  311. package/templates/professional-services/tier5-src/_shared/branded-lite-hosted.ts +282 -0
  312. package/templates/professional-services/tier5-src/_shared/branded-load-state.ts +109 -0
  313. package/templates/professional-services/tier5-src/_shared/business-chat-copy.ts +40 -0
  314. package/templates/professional-services/tier5-src/_shared/business-chat-history.ts +51 -0
  315. package/templates/professional-services/tier5-src/_shared/business-chat-message-model.ts +177 -0
  316. package/templates/professional-services/tier5-src/_shared/business-chat-model.ts +56 -0
  317. package/templates/professional-services/tier5-src/_shared/business-chat-presenter.ts +587 -0
  318. package/templates/professional-services/tier5-src/_shared/business-chat-transport.ts +164 -0
  319. package/templates/professional-services/tier5-src/_shared/chat-live.ts +242 -0
  320. package/templates/professional-services/tier5-src/_shared/collection-contract.ts +232 -0
  321. package/templates/professional-services/tier5-src/_shared/collection-query.ts +201 -0
  322. package/templates/professional-services/tier5-src/_shared/collection-service.ts +429 -0
  323. package/templates/professional-services/tier5-src/_shared/detail-presence.ts +51 -0
  324. package/templates/professional-services/tier5-src/_shared/engine-intl.ts +538 -0
  325. package/templates/professional-services/tier5-src/_shared/event-registration.ts +86 -0
  326. package/templates/professional-services/tier5-src/_shared/events-inline-options.ts +77 -0
  327. package/templates/professional-services/tier5-src/_shared/faq-list.ts +405 -0
  328. package/templates/professional-services/tier5-src/_shared/featured-event.ts +63 -0
  329. package/templates/professional-services/tier5-src/_shared/group-member-count.ts +15 -0
  330. package/templates/professional-services/tier5-src/_shared/group-privacy.ts +14 -0
  331. package/templates/professional-services/tier5-src/_shared/guest-sign-in.ts +36 -0
  332. package/templates/professional-services/tier5-src/_shared/himi-account.ts +222 -0
  333. package/templates/professional-services/tier5-src/_shared/himi-blog-hidden.ts +66 -0
  334. package/templates/professional-services/tier5-src/_shared/himi-blog-post-row.ts +214 -0
  335. package/templates/professional-services/tier5-src/_shared/himi-blog-saved.ts +64 -0
  336. package/templates/professional-services/tier5-src/_shared/himi-booking-saved.ts +88 -0
  337. package/templates/professional-services/tier5-src/_shared/himi-bookings.ts +318 -0
  338. package/templates/professional-services/tier5-src/_shared/himi-copy.ts +123 -0
  339. package/templates/professional-services/tier5-src/_shared/himi-events.ts +92 -0
  340. package/templates/professional-services/tier5-src/_shared/himi-media.ts +33 -0
  341. package/templates/professional-services/tier5-src/_shared/himi-store.ts +7 -0
  342. package/templates/professional-services/tier5-src/_shared/himi-text.ts +24 -0
  343. package/templates/professional-services/tier5-src/_shared/host-events.ts +66 -0
  344. package/templates/professional-services/tier5-src/_shared/hosted-checkout.ts +70 -0
  345. package/templates/professional-services/tier5-src/_shared/iap-attendance-form.ts +106 -0
  346. package/templates/professional-services/tier5-src/_shared/iap-attendance-purchase.ts +235 -0
  347. package/templates/professional-services/tier5-src/_shared/iap-attendance.ts +38 -0
  348. package/templates/professional-services/tier5-src/_shared/iap-worker.ts +127 -0
  349. package/templates/professional-services/tier5-src/_shared/inbox-rooms.ts +163 -0
  350. package/templates/professional-services/tier5-src/_shared/local-preferences.ts +38 -0
  351. package/templates/professional-services/tier5-src/_shared/member-access.ts +63 -0
  352. package/templates/professional-services/tier5-src/_shared/member-account-routes.ts +56 -0
  353. package/templates/professional-services/tier5-src/_shared/member-avatar.ts +76 -0
  354. package/templates/professional-services/tier5-src/_shared/member-bookings.ts +107 -0
  355. package/templates/professional-services/tier5-src/_shared/member-read.ts +82 -0
  356. package/templates/professional-services/tier5-src/_shared/member-screen.ts +99 -0
  357. package/templates/professional-services/tier5-src/_shared/notification-target.ts +141 -0
  358. package/templates/professional-services/tier5-src/_shared/offset-page.ts +10 -0
  359. package/templates/professional-services/tier5-src/_shared/online-actions.ts +76 -0
  360. package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +348 -0
  361. package/templates/professional-services/tier5-src/_shared/payment-setup.ts +6 -0
  362. package/templates/professional-services/tier5-src/_shared/portfolio-details.ts +70 -0
  363. package/templates/professional-services/tier5-src/_shared/pricing-plan-display.ts +64 -0
  364. package/templates/professional-services/tier5-src/_shared/relative-time.ts +21 -0
  365. package/templates/professional-services/tier5-src/_shared/result-snackbar.ts +26 -0
  366. package/templates/professional-services/tier5-src/_shared/rich-body.ts +78 -0
  367. package/templates/professional-services/tier5-src/_shared/rich-content-link.ts +34 -0
  368. package/templates/professional-services/tier5-src/_shared/sign-in-sheet.ts +18 -0
  369. package/templates/professional-services/tier5-src/_shared/staff-name.ts +18 -0
  370. package/templates/professional-services/tier5-src/_shared/weekly-goal.ts +111 -0
  371. package/templates/professional-services/tier5-src/_shared/wix-bi.ts +85 -0
  372. package/templates/professional-services/tier5-src/_shared/wix-member-links.ts +114 -0
  373. package/templates/professional-services/tier5-src/_shared/wix-service-price.ts +146 -0
  374. package/templates/professional-services/tier5-src/business-chat/index.ts +797 -0
  375. package/templates/professional-services/tier5-src/business-contact/index.ts +6 -0
  376. package/templates/professional-services/tier5-src/himi-blog-feed/index.ts +444 -0
  377. package/templates/professional-services/tier5-src/himi-blog-post/index.ts +1239 -0
  378. package/templates/professional-services/tier5-src/himi-booking-account/index.ts +278 -0
  379. package/templates/professional-services/tier5-src/himi-booking-bookings/index.ts +475 -0
  380. package/templates/professional-services/tier5-src/himi-booking-service/index.ts +1197 -0
  381. package/templates/professional-services/tier5-src/himi-booking-services/index.ts +795 -0
  382. package/templates/professional-services/tier5-src/himi-booking-time/index.ts +1840 -0
  383. package/templates/professional-services/tier5-src/himi-branded-lite-coupons/index.ts +96 -0
  384. package/templates/professional-services/tier5-src/himi-branded-lite-faq/index.ts +6 -0
  385. package/templates/professional-services/tier5-src/himi-branded-lite-file-share/index.ts +12 -0
  386. package/templates/professional-services/tier5-src/himi-branded-lite-group/index.ts +310 -0
  387. package/templates/professional-services/tier5-src/himi-branded-lite-group-about/index.ts +240 -0
  388. package/templates/professional-services/tier5-src/himi-branded-lite-my-groups/index.ts +237 -0
  389. package/templates/professional-services/tier5-src/himi-branded-lite-notifications/index.ts +263 -0
  390. package/templates/professional-services/tier5-src/himi-branded-lite-plans/index.ts +498 -0
  391. package/templates/professional-services/tier5-src/himi-branded-lite-portfolio/index.ts +136 -0
  392. package/templates/professional-services/tier5-src/himi-branded-lite-portfolio-project/index.ts +198 -0
  393. package/templates/professional-services/tier5-src/himi-events-detail/index.ts +1306 -0
  394. package/templates/professional-services/tier5-src/himi-events-list/index.ts +171 -0
  395. package/templates/professional-services/tier5-src/himi-events-my-events/index.ts +227 -0
  396. package/templates/professional-services/tier5-src/himi-events-rsvp/index.ts +230 -0
  397. package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts +318 -0
  398. package/templates/professional-services/tier5-src/himi-professional-services-home/index.ts +772 -0
  399. package/templates/professional-services/tier5-src/himi-store-account/index.ts +1514 -0
  400. package/templates/professional-services/tier5-src/wix-spaces-coupon-detail/index.ts +43 -0
  401. package/templates/professional-services/tier5-src/wix-spaces-my-subscriptions/index.ts +89 -0
  402. package/templates/professional-services/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
  403. package/templates/professional-services/tokens.json +456 -0
  404. package/templates/restaurant/dev/index.ts +20 -0
  405. package/templates/restaurant/l10n/ar.json +10 -0
  406. package/templates/restaurant/l10n/cs.json +10 -0
  407. package/templates/restaurant/l10n/da.json +10 -0
  408. package/templates/restaurant/l10n/de.json +10 -0
  409. package/templates/restaurant/l10n/el.json +10 -0
  410. package/templates/restaurant/l10n/es.json +10 -0
  411. package/templates/restaurant/l10n/fi.json +10 -0
  412. package/templates/restaurant/l10n/fr.json +10 -0
  413. package/templates/restaurant/l10n/he.json +8 -0
  414. package/templates/restaurant/l10n/hu.json +10 -0
  415. package/templates/restaurant/l10n/id.json +10 -0
  416. package/templates/restaurant/l10n/it.json +10 -0
  417. package/templates/restaurant/l10n/ja.json +10 -0
  418. package/templates/restaurant/l10n/ko.json +10 -0
  419. package/templates/restaurant/l10n/lt.json +10 -0
  420. package/templates/restaurant/l10n/nl.json +10 -0
  421. package/templates/restaurant/l10n/no.json +10 -0
  422. package/templates/restaurant/l10n/pl.json +10 -0
  423. package/templates/restaurant/l10n/pt.json +10 -0
  424. package/templates/restaurant/l10n/ru.json +10 -0
  425. package/templates/restaurant/l10n/sv.json +10 -0
  426. package/templates/restaurant/l10n/th.json +10 -0
  427. package/templates/restaurant/l10n/tr.json +10 -0
  428. package/templates/restaurant/l10n/uk.json +10 -0
  429. package/templates/restaurant/l10n/vi.json +10 -0
  430. package/templates/restaurant/l10n/zh.json +10 -0
  431. package/templates/restaurant/tier5-src/_shared/collection-contract.ts +6 -1
  432. package/templates/restaurant/tier5-src/_shared/himi-events.ts +27 -0
  433. package/templates/restaurant/tier5-src/himi-events-detail/index.ts +3 -1
  434. package/templates/restaurant/tier5-src/himi-events-list/index.ts +38 -8
  435. package/templates/restaurant/tier5-src/himi-events-my-events/index.ts +4 -2
  436. package/templates/restaurant-owner/tier5-src/_shared/collection-contract.ts +6 -1
  437. package/templates/restaurant-owner/tier5-src/_shared/himi-events.ts +27 -0
  438. package/templates/retail-store/tier5-src/_shared/collection-contract.ts +6 -1
  439. package/templates/retail-store/tier5-src/_shared/himi-events.ts +27 -0
  440. package/templates/retail-store-owner/tier5-src/_shared/collection-contract.ts +6 -1
  441. package/templates/retail-store-owner/tier5-src/_shared/himi-events.ts +27 -0
  442. package/templates/salon-spa/config.ts +42 -0
  443. package/templates/salon-spa/dev/index.ts +4136 -0
  444. package/templates/salon-spa/himalaya.content.json +18 -0
  445. package/templates/salon-spa/tier5-src/_shared/collection-contract.ts +6 -1
  446. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  447. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  448. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  449. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  450. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  451. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  452. package/templates/salon-spa/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  453. package/templates/wholesale-store/config.ts +43 -1
  454. package/templates/wholesale-store/dev/index.ts +4136 -0
  455. package/templates/wholesale-store/himalaya.content.json +18 -0
  456. package/templates/wholesale-store/tier5-src/_shared/collection-contract.ts +6 -1
  457. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  458. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  459. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  460. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  461. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  462. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  463. package/templates/wholesale-store/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  464. package/templates/yoga-studio/dev/index.ts +20 -0
  465. package/templates/yoga-studio/l10n/ar.json +10 -0
  466. package/templates/yoga-studio/l10n/cs.json +10 -0
  467. package/templates/yoga-studio/l10n/da.json +10 -0
  468. package/templates/yoga-studio/l10n/de.json +10 -0
  469. package/templates/yoga-studio/l10n/el.json +10 -0
  470. package/templates/yoga-studio/l10n/es.json +10 -0
  471. package/templates/yoga-studio/l10n/fi.json +10 -0
  472. package/templates/yoga-studio/l10n/fr.json +10 -0
  473. package/templates/yoga-studio/l10n/he.json +8 -0
  474. package/templates/yoga-studio/l10n/hu.json +10 -0
  475. package/templates/yoga-studio/l10n/id.json +10 -0
  476. package/templates/yoga-studio/l10n/it.json +10 -0
  477. package/templates/yoga-studio/l10n/ja.json +10 -0
  478. package/templates/yoga-studio/l10n/ko.json +10 -0
  479. package/templates/yoga-studio/l10n/lt.json +10 -0
  480. package/templates/yoga-studio/l10n/nl.json +10 -0
  481. package/templates/yoga-studio/l10n/no.json +10 -0
  482. package/templates/yoga-studio/l10n/pl.json +10 -0
  483. package/templates/yoga-studio/l10n/pt.json +10 -0
  484. package/templates/yoga-studio/l10n/ru.json +10 -0
  485. package/templates/yoga-studio/l10n/sv.json +10 -0
  486. package/templates/yoga-studio/l10n/th.json +10 -0
  487. package/templates/yoga-studio/l10n/tr.json +10 -0
  488. package/templates/yoga-studio/l10n/uk.json +10 -0
  489. package/templates/yoga-studio/l10n/vi.json +10 -0
  490. package/templates/yoga-studio/l10n/zh.json +10 -0
  491. package/templates/yoga-studio/tier5-src/_shared/collection-contract.ts +6 -1
  492. package/templates/yoga-studio/tier5-src/_shared/himi-events.ts +27 -0
  493. package/templates/yoga-studio/tier5-src/himi-events-detail/index.ts +3 -1
  494. package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +38 -8
  495. package/templates/yoga-studio/tier5-src/himi-events-my-events/index.ts +4 -2
  496. package/templates/yoga-studio-owner/tier5-src/_shared/collection-contract.ts +6 -1
  497. package/templates/yoga-studio-owner/tier5-src/_shared/himi-events.ts +27 -0
@@ -0,0 +1,164 @@
1
+ // The business chat's Wix calls: the member-role chat-web SDK for rooms and history, plus the calls the SDKs have
2
+ // no helper for (a typed message sent through Smart Chat, a tapped button, a private attachment's download URL).
3
+ import { getChatToken, getMessagesPage, listChatroomsPage } from "@himalaya/wix-chat-web";
4
+ import { assertMemberAccess, memberAccess } from "./member-access.js";
5
+
6
+ const MANAGE = "https://manage.wix.com";
7
+ const MEMBER = { role: "member" } as const;
8
+ type Raw = Record<string, unknown>;
9
+ type Bridge = { call(method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<unknown> };
10
+
11
+ /** Who is signed in. `userId` is empty until the host reports it; the chat then tells the business
12
+ * side apart by the room's participant id instead. */
13
+ export interface ChatIdentity { authenticated: boolean; userId: string; email: string; scope: string }
14
+ export async function chatIdentity(): Promise<ChatIdentity> {
15
+ const member = await memberAccess();
16
+ return { authenticated: !!member.email, userId: "", email: member.email, scope: member.scope };
17
+ }
18
+ export const assertChatIdentity = (identity: ChatIdentity): Promise<void> => assertMemberAccess(identity);
19
+
20
+ /** Every request is fenced: the member is re-checked before it goes out and again before its response is
21
+ * used, so a sign-out or account switch mid-request never leaks one member's data to the next. */
22
+ async function fenced<T>(identity: ChatIdentity, run: () => Promise<T>): Promise<T> {
23
+ await assertChatIdentity(identity);
24
+ const result = await run();
25
+ await assertChatIdentity(identity);
26
+ return result;
27
+ }
28
+
29
+ /** Any other member-scoped call (the AI chat's) goes through the same fence. */
30
+ export const fence = fenced;
31
+
32
+ /** A signed-out visitor's Smart Chat calls are fenced the other way: still signed out before the request goes
33
+ * out and again before its response is used, so signing in mid-request never mixes the visitor's chat into
34
+ * the member's. Fails as `MemberAccessChanged`, like the member fence, so callers handle both alike. */
35
+ async function assertStillVisitor(): Promise<void> {
36
+ if ((await memberAccess()).email) throw Object.assign(new Error("visitor_signed_in"), { name: "MemberAccessChanged" });
37
+ }
38
+ export async function visitorFence<T>(run: () => Promise<T>): Promise<T> {
39
+ await assertStillVisitor();
40
+ const result = await run();
41
+ await assertStillVisitor();
42
+ return result;
43
+ }
44
+
45
+ // Minting a chat token is a network round trip, and every chat call used to mint its own. One token
46
+ // per member is reused until the member changes or a request using it is refused.
47
+ let cachedToken: { key: string; token: string } | null = null;
48
+ const tokenKey = (identity: ChatIdentity): string => `${identity.email}|${identity.scope}`;
49
+ async function chatTokenFor(identity: ChatIdentity): Promise<string> {
50
+ const key = tokenKey(identity);
51
+ if (cachedToken?.key === key) return cachedToken.token;
52
+ const { chatToken } = await getChatToken(MEMBER);
53
+ // The host mints for whoever is signed in NOW: a token minted while the member switched belongs to the
54
+ // new member and must not be cached under the old one.
55
+ await assertChatIdentity(identity);
56
+ cachedToken = { key, token: chatToken };
57
+ return chatToken;
58
+ }
59
+ /** Runs `run` with the member's cached token; a refused request mints a fresh token and tries once more. */
60
+ export async function withToken<T>(identity: ChatIdentity, run: (chatToken: string) => Promise<T>): Promise<T> {
61
+ const reused = cachedToken?.key === tokenKey(identity);
62
+ try {
63
+ return await run(await chatTokenFor(identity));
64
+ } catch (error) {
65
+ cachedToken = null;
66
+ if (!reused || !/\b(?:401|403)\b|token/i.test(String((error as Error)?.message ?? error))) throw error;
67
+ return run(await chatTokenFor(identity));
68
+ }
69
+ }
70
+
71
+ const MAX_ROOM_PAGES = 20;
72
+ /** Every chatroom the member can see: the cursor is followed so the business room is found on any page. */
73
+ export const listRooms = (identity: ChatIdentity): Promise<{ items: Raw[]; more: boolean }> => fenced(identity, async () => {
74
+ const items: Raw[] = [];
75
+ let nextPointer: number | string | undefined;
76
+ for (let page = 0; page < MAX_ROOM_PAGES; page++) {
77
+ const result = await withToken(identity, (chatToken) => listChatroomsPage({ ...MEMBER, chatToken, pageSize: 50, ...(nextPointer !== undefined ? { nextPointer } : {}) }));
78
+ items.push(...(result.items as unknown as Raw[]));
79
+ nextPointer = result.nextPointer;
80
+ if (nextPointer === undefined) return { items, more: false };
81
+ }
82
+ return { items, more: true };
83
+ });
84
+ /** How many of the member's BUSINESS chatrooms have unread messages, as the server counts them (capped at 100).
85
+ * Not the rooms themselves: the header badge needs only the total. A response without a valid count is
86
+ * unavailable, never zero. */
87
+ export const unreadRoomCount = (identity: ChatIdentity): Promise<number> => fenced(identity, async () => {
88
+ const page = await withToken(identity, (chatToken) => listChatroomsPage({ ...MEMBER, chatToken, pageSize: 1, onlyUnread: true, participantType: "business" }));
89
+ const count = page.unreadChatroomCount;
90
+ if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0) throw new Error("unavailable unread chat count");
91
+ return count;
92
+ });
93
+ export const messagesPage = (identity: ChatIdentity, roomId: string): Promise<Raw[]> => fenced(identity, async () =>
94
+ (await withToken(identity, (chatToken) => getMessagesPage(roomId, { ...MEMBER, chatToken, pageSize: 50, ordering: "Desc" }))).items as unknown as Raw[]);
95
+
96
+ export function bridge(): Bridge {
97
+ const api = (globalThis as unknown as { himalaya?: { wixApi?: Bridge } }).himalaya?.wixApi;
98
+ if (!api) throw new Error("wix_api_bridge_unavailable");
99
+ return api;
100
+ }
101
+ /** A typed message goes through Smart Chat, exactly as the site's chat widget sends it. The Inbox then files it under
102
+ * Wix Smart Chat and the AI can answer it; a message posted straight into the room has no channel, so the AI never
103
+ * saw it and the owner's reply went out by email. Smart Chat chooses the conversation and stored message id.
104
+ * The bridge resolves once the AI has finished answering, not when the message is stored. */
105
+ export const sendMessage = (identity: ChatIdentity, text: string): Promise<string | undefined> => fenced(identity, () => postQuestion(text));
106
+ /** The same Smart Chat send for a signed-out visitor: Smart Chat accepts the anonymous visitor token. */
107
+ export const sendVisitorMessage = (text: string): Promise<string | undefined> => visitorFence(() => postQuestion(text));
108
+ async function postQuestion(text: string): Promise<string | undefined> {
109
+ const response = await bridge().call("POST", "/wix-assistant-widget/v1/messages/stream", {
110
+ message: { sender: "SITE_VISITOR", messageType: "QUESTION", body: { mainText: text } },
111
+ });
112
+ // The first stream frame names the persisted question. Keep its exact id so a send
113
+ // that moves from an old Members transcript to Smart Chat never relies on a text match.
114
+ let frames: unknown = response;
115
+ if (typeof frames === "string") {
116
+ const raw = frames;
117
+ try { frames = JSON.parse(raw); }
118
+ catch {
119
+ frames = [];
120
+ // The bridge buffers SSE verbatim. Ignore event/comment lines and decode the
121
+ // data of each frame; some hosts instead hand over NDJSON or parsed frames.
122
+ for (const block of raw.split(/\r?\n\r?\n/)) {
123
+ const lines = block.split(/\r?\n/);
124
+ const event = lines.find(line => line.startsWith('event:'))?.slice(6).trim();
125
+ const data = lines.filter(line => line.startsWith('data:')).map(line => line.slice(5).trimStart()).join('\n');
126
+ try {
127
+ const value = JSON.parse(data || block);
128
+ (frames as unknown[]).push(event === 'inputMessage' && !value?.inputMessage ? { inputMessage: value } : value);
129
+ } catch { /* Comments and other non-JSON frames carry no stored question id. */ }
130
+ }
131
+ // A buffered NDJSON response has no SSE separators.
132
+ if (!(frames as unknown[]).length) {
133
+ try { frames = [JSON.parse(raw.split('\n', 1)[0]!)]; } catch { return undefined; }
134
+ }
135
+ }
136
+ }
137
+ for (const frame of Array.isArray(frames) ? frames : [frames]) {
138
+ const input = (frame as { inputMessage?: { id?: unknown; sender?: unknown; messageType?: unknown } } | null)?.inputMessage;
139
+ if (input?.sender === "SITE_VISITOR" && input.messageType === "QUESTION" && typeof input.id === "string" && input.id) return `smart-chat:${input.id}`;
140
+ }
141
+ return undefined;
142
+ }
143
+ /** A tapped button is a silent, ephemeral message carrying the button's chat action. */
144
+ export const sendButton = (identity: ChatIdentity, roomId: string, input: { id: string; text: string; appId: string; interactionId: string }): Promise<void> => fenced(identity, async () => {
145
+ await withToken(identity, (chatToken) => bridge().call("POST", `${MANAGE}/_api/chat-web/v2/chatrooms/${encodeURIComponent(roomId)}/messages`, {
146
+ sendMessageBody: { id: input.id, messageType: "message", messageTypeVersion: 1, summary: input.text, isEphemeral: true, isSilent: true, data: [{ mimeType: "text/plain", data: { text: input.text } }] },
147
+ sendMessageOptions: { chatAction: { actionType: "BUTTON_INTERACTION", appId: input.appId, interactionId: input.interactionId } },
148
+ }, { ChatToken: chatToken }));
149
+ });
150
+
151
+ const https = (value: unknown): string => (typeof value === "string" && /^https:\/\/[^\s\\]+$/.test(value) ? value : "");
152
+ /** A fresh, authorized URL for an attachment. A private file is always fetched by its id. */
153
+ export const attachmentUrl = (identity: ChatIdentity, media: { mediaId?: string; mediaProvider?: string; url?: string; fileName?: string }): Promise<string> => fenced(identity, async () => {
154
+ if (media.mediaProvider === "WixMediaPrivate") {
155
+ if (!media.mediaId) throw new Error("attachment_has_no_media_id");
156
+ const response = await bridge().call("POST", "/communication-channels-media/v1/download-url", {
157
+ fileId: media.mediaId, ...(media.fileName ? { downloadFileName: media.fileName } : {}),
158
+ }) as Raw | null;
159
+ const url = https(response?.downloadUrl);
160
+ if (!url) throw new Error("attachment_download_url_invalid");
161
+ return url;
162
+ }
163
+ return https(media.url);
164
+ });
@@ -0,0 +1,242 @@
1
+ // How an open chat thread stays live — one helper for owner-lite's Inbox thread and
2
+ // branded-lite's member chat.
3
+ //
4
+ // Two paths, and the worker never has to choose between them by platform:
5
+ //
6
+ // 1. REALTIME. With a Wix Chat channel configured, `load` returns a `_stream` directive
7
+ // whose url is `wix-realtime://<appDefId>/<channel>?slug=<slug>&resourceId=<chatroom>`.
8
+ // The iOS and Android hosts open a Wix Duplexer channel for it and
9
+ // dispatch `onEvent` for each matching message.
10
+ // 2. FALLBACK. With no channel, or once the stream fails (`onError` — which is also what
11
+ // the web host answers, since it refuses `wix-realtime://`), a `_poll` directive asks
12
+ // the host to re-read the thread every 4 s.
13
+ //
14
+ // The fallback is a HOST timer, not a worker one: the worker sandbox has no
15
+ // `setInterval`. That is also what keeps it to the
16
+ // foreground — every host suspends a poll when the app is backgrounded or the screen is
17
+ // pooled off-view, and cancels it when the screen is torn down — so a hidden thread never
18
+ // polls. A poll has no stop verb; a thread that has its stream simply never asks for one.
19
+ //
20
+ // An event is only ever "the thread changed". Its payload is not read: its shape is
21
+ // unverified, and the host deliberately does not interpret it either. The worker re-reads
22
+ // the messages instead — one cheap call that cannot desync — and `createReloadGate`
23
+ // folds a burst of events into one read.
24
+ //
25
+ // This file is copied verbatim into every generated starter app, so it explains itself
26
+ // without pointing at anything only this repo has.
27
+
28
+ import type { PollDirective, StreamDirective } from "@himalaya/state";
29
+
30
+ /** A Wix Chat Duplexer channel: the `ns` (an app def id), the bare channel name, and the
31
+ * event slug a new message arrives under. */
32
+ export interface ChatRealtimeConfig {
33
+ appDefId: string;
34
+ channel: string;
35
+ slug: string;
36
+ }
37
+
38
+ /** The stream's id. One per screen: a new directive under the same id replaces the old
39
+ * channel instead of opening a second one. */
40
+ export const CHAT_LIVE_STREAM_ID = "chat-live";
41
+ /** The fallback poll's id. Re-arming it replaces the timer, never stacks a second one. */
42
+ export const CHAT_LIVE_POLL_ID = "chat-live-poll";
43
+ /** "A message from the other side appears within 5 s." */
44
+ export const CHAT_LIVE_POLL_MS = 4000;
45
+
46
+ /** Which path is keeping the thread live: `off` before a conversation is open, `stream`
47
+ * when a realtime channel was asked for, `poll` on the fallback. Diagnostic. */
48
+ export type ChatLiveMode = "off" | "stream" | "poll";
49
+
50
+ const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
51
+
52
+ /** A complete, well-formed channel, or null. A half-filled one would subscribe to
53
+ * nothing and never fire, which looks exactly like a quiet conversation. */
54
+ export function chatRealtimeConfig(value: unknown): ChatRealtimeConfig | null {
55
+ let v = value;
56
+ if (typeof v === "string") {
57
+ if (!v.trim()) return null;
58
+ try { v = JSON.parse(v); } catch { return null; }
59
+ }
60
+ if (!v || typeof v !== "object") return null;
61
+ const { appDefId, channel, slug } = v as Record<string, unknown>;
62
+ if (typeof appDefId !== "string" || !GUID.test(appDefId)) return null;
63
+ if (typeof channel !== "string" || !channel.trim()) return null;
64
+ if (typeof slug !== "string" || !slug.trim()) return null;
65
+ return { appDefId, channel, slug };
66
+ }
67
+
68
+ /** The `wix-realtime://` url for one conversation. */
69
+ export function chatRealtimeUrl(cfg: ChatRealtimeConfig, chatroomId: string): string {
70
+ return `wix-realtime://${cfg.appDefId}/${encodeURIComponent(cfg.channel)}?slug=${encodeURIComponent(cfg.slug)}&resourceId=${encodeURIComponent(chatroomId)}`;
71
+ }
72
+
73
+ /** The stream directive that keeps `chatroomId` live, or null when there is no channel
74
+ * (or no conversation) to open. `onEvent` / `onError` are action names of the calling
75
+ * service. */
76
+ export function liveThreadDirective(
77
+ cfg: ChatRealtimeConfig | null,
78
+ chatroomId: string,
79
+ actions: { onEvent: string; onError: string },
80
+ ): StreamDirective | null {
81
+ if (!cfg || !chatroomId) return null;
82
+ return {
83
+ id: CHAT_LIVE_STREAM_ID,
84
+ request: { method: "GET", url: chatRealtimeUrl(cfg, chatroomId) },
85
+ onEvent: actions.onEvent,
86
+ onError: actions.onError,
87
+ };
88
+ }
89
+
90
+ /** The 4 s foreground re-read. `action` is fully qualified (`"<service>.<action>"`). */
91
+ export function livePollDirective(action: string, intervalMs = CHAT_LIVE_POLL_MS): PollDirective {
92
+ return { id: CHAT_LIVE_POLL_ID, intervalMs, action, immediate: false };
93
+ }
94
+
95
+ /** What `load` returns beside its state to keep the conversation live: the stream when a
96
+ * channel is configured, else the poll. Nothing when there is no conversation. The
97
+ * service's actions must be named `onStreamEvent`, `onStreamError` and `refresh`. */
98
+ export function liveDirectives(
99
+ cfg: ChatRealtimeConfig | null,
100
+ chatroomId: string,
101
+ service: string,
102
+ ): { live: ChatLiveMode; _stream?: StreamDirective; _poll?: PollDirective } {
103
+ if (!chatroomId) return { live: "off" };
104
+ const stream = liveThreadDirective(cfg, chatroomId, { onEvent: "onStreamEvent", onError: "onStreamError" });
105
+ if (stream) return { live: "stream", _stream: stream };
106
+ return { live: "poll", _poll: livePollDirective(`${service}.refresh`) };
107
+ }
108
+
109
+ /** What `onStreamError` returns beside its state: the stream is gone, so poll. */
110
+ export function liveFallback(service: string): { live: ChatLiveMode; _poll: PollDirective } {
111
+ return { live: "poll", _poll: livePollDirective(`${service}.refresh`) };
112
+ }
113
+
114
+ /**
115
+ * Fold re-read requests so a burst costs one read.
116
+ *
117
+ * Requests made in the same tick share one read. A request made while a read is in
118
+ * flight gets ONE trailing read after it — never more than one, however many arrive —
119
+ * because the in-flight read may have left the server before the change that prompted
120
+ * the request, and returning its answer would drop that message.
121
+ */
122
+ export function createReloadGate<T>(read: () => Promise<T>): { request(): Promise<T> } {
123
+ let queued: Promise<T> | null = null;
124
+ let running: Promise<void> | null = null;
125
+ return {
126
+ request() {
127
+ if (queued) return queued;
128
+ const prior = running ?? Promise.resolve();
129
+ const next = prior.then(() => {
130
+ queued = null;
131
+ return read();
132
+ });
133
+ queued = next;
134
+ const settled = next.then(() => undefined, () => undefined);
135
+ running = settled;
136
+ void settled.then(() => {
137
+ if (running === settled) running = null;
138
+ });
139
+ return next;
140
+ },
141
+ };
142
+ }
143
+
144
+ /**
145
+ * One chat token per thread VISIT.
146
+ *
147
+ * Every chat-web call needs a token, and minting one is a request of its own — so a thread
148
+ * that re-reads every 4 s would otherwise mint every 4 s. `get()` mints on first use and
149
+ * shares that token with every read and send; `reset()` starts a new visit; `drop(p)`
150
+ * forgets a token after a call that used it failed (an expired token costs one failed call,
151
+ * and the next one mints again). `drop` only forgets THAT token: a late failure from an
152
+ * earlier visit must not throw away the token the current visit just minted.
153
+ */
154
+ export function createVisitToken(mint: () => Promise<string>): {
155
+ get(): Promise<string>;
156
+ drop(token: Promise<string> | null): void;
157
+ reset(): void;
158
+ } {
159
+ let current: Promise<string> | null = null;
160
+ const drop = (token: Promise<string> | null): void => {
161
+ if (token && current === token) current = null;
162
+ };
163
+ return {
164
+ get() {
165
+ if (!current) {
166
+ const minted = mint();
167
+ current = minted;
168
+ minted.catch(() => drop(minted));
169
+ }
170
+ return current;
171
+ },
172
+ drop,
173
+ reset() {
174
+ current = null;
175
+ },
176
+ };
177
+ }
178
+
179
+ /** Did a chat-web call fail because its token was refused? The status chat-web uses for an
180
+ * expired chatToken is NOT verified against a live session: 401 and 403 are both treated as
181
+ * "refused", and either way a retry with the same message id is the same send intent, so a
182
+ * wrong guess costs one extra request, never a second message. Any other failure may have
183
+ * posted the message, so it is not retried. */
184
+ export function isTokenRejected(e: unknown): boolean {
185
+ return /HTTP 40[13]\b/.test(String((e as Error)?.message ?? e ?? ""));
186
+ }
187
+
188
+ /** UUID v4 for a send's idempotency id (the worker realm has no crypto.randomUUID). */
189
+ export function uuidV4(): string {
190
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
191
+ const r = Math.floor(Math.random() * 16);
192
+ return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
193
+ });
194
+ }
195
+
196
+ /**
197
+ * Send ids that belong to the INTENT, not the tap.
198
+ *
199
+ * The same id on a retry is the same send to chat-web, so the server keeps one message. A
200
+ * send that failed ambiguously (a gateway timeout after the backend stored it) and is tapped
201
+ * again must reuse its id, or the business receives the message twice. An intent is the
202
+ * conversation plus the exact text; it is settled once the send succeeds, and any other text
203
+ * is a new intent.
204
+ */
205
+ export function createSendIntents(): { idFor(chatroomId: string, text: string): string; settle(chatroomId: string, text: string): void } {
206
+ const ids = new Map<string, string>();
207
+ const keyOf = (chatroomId: string, text: string) => `${chatroomId}\u0000${text}`;
208
+ return {
209
+ idFor(chatroomId, text) {
210
+ const key = keyOf(chatroomId, text);
211
+ let id = ids.get(key);
212
+ if (!id) { id = uuidV4(); ids.set(key, id); }
213
+ return id;
214
+ },
215
+ settle(chatroomId, text) {
216
+ ids.delete(keyOf(chatroomId, text));
217
+ },
218
+ };
219
+ }
220
+
221
+ /** Post with the visit's token, re-minting once if chat-web refused the token. Whichever
222
+ * token a failed attempt used is dropped, so a rejected token is never reused. */
223
+ export async function postWithVisitToken(
224
+ token: ReturnType<typeof createVisitToken>,
225
+ send: (chatToken: string) => Promise<void>,
226
+ ): Promise<void> {
227
+ const first = token.get();
228
+ try {
229
+ await send(await first);
230
+ return;
231
+ } catch (e) {
232
+ token.drop(first);
233
+ if (!isTokenRejected(e)) throw e;
234
+ }
235
+ const retry = token.get();
236
+ try {
237
+ await send(await retry);
238
+ } catch (e) {
239
+ token.drop(retry);
240
+ throw e;
241
+ }
242
+ }
@@ -0,0 +1,232 @@
1
+ import { compareText, compareIso } from "./engine-intl.js";
2
+ /** Shared OTA collection contract. No host APIs: used by workers and builders. */
3
+ export interface CollectionConfig {
4
+ rows: string;
5
+ /** Flat customer history rows, divided rather than boxed. */
6
+ rowStyle?: "flat";
7
+ instanceInput?: string;
8
+ title: string;
9
+ subtitle?: string;
10
+ image?: string;
11
+ filter?: string;
12
+ filterValues?: string[];
13
+ /** A state key holding `{ label }` rows (e.g. a worker's full category list) whose
14
+ * labels are filter choices even when no loaded row carries them yet. */
15
+ filterValuesFrom?: string;
16
+ searchPlaceholder?: string;
17
+ sortLabels?: { default: string; az: string; za: string };
18
+ metadata?: string[];
19
+ /** Numeric 0–5 row field rendered as a Rating (accessible "N out of 5") instead of
20
+ * folding a "★★★★☆" glyph string into the metadata line, so screen readers get a value. */
21
+ rating?: string;
22
+ /** Domain-provided calendar text and its unavailable flag, kept separate from media. */
23
+ dateBadge?: { text: string; hidden: string };
24
+ sectioned?: boolean;
25
+ view: 'list' | 'grid';
26
+ backendQuery?: boolean;
27
+ paged?: boolean;
28
+ defaultFilter?: string;
29
+ reviewAction?: string;
30
+ reviewSelectedAction?: string;
31
+ /** Optional comfortable grid media height for immersive visual catalogs. */
32
+ gridImageHeight?: number;
33
+ /** What the count summary counts — ["dish", "dishes"] reads "12 dishes". Default "item(s)". */
34
+ countNoun?: [string, string];
35
+ /** Phone grid columns (default 2). A card carrying a paragraph of benefits and a CTA — a
36
+ * pricing plan — is unreadable at half width, so it opts into one. */
37
+ gridColumns?: number;
38
+ /** Lines of the meta caption a comfortable row may use (default 2). */
39
+ metaMaxLines?: number;
40
+ /** The card's primary verb, shown as a visible button beside the overflow.
41
+ * `screenId` opens that screen with the row id; without it the verb reuses the
42
+ * row's own tap action (the detail screen that owns the verb). */
43
+ primaryVerb?: { label: string; screenId?: string;
44
+ /** A row field holding THIS row's verb label (Register, RSVP, Buy Tickets…); `label` stays the fallback copy. */
45
+ labelPath?: string;
46
+ /** A row boolean that hides the verb on rows that offer no action (an event with no registration). */
47
+ hiddenPath?: string };
48
+ /** The worker action that shares a row (`tier5.<service>.<name>` with `{ id }`): adds Share to the card's overflow menu. */
49
+ shareAction?: string;
50
+ /** A TIME-BOUND entity (an event, a booking, a reservation): the boolean row field the
51
+ * DOMAIN sets once the record has finished — computed by the same rule as the row's own
52
+ * "Past" label, in the same place, so the two cannot disagree. A finished
53
+ * record's `primaryVerb` (Register, Book…) is transactional and would act on something
54
+ * that is over, so it is swapped for a non-transactional "View details" that opens the
55
+ * row's own detail. Without a row tap action the verb is simply hidden. */
56
+ endedWhen?: string;
57
+ /** A catalog card whose one expected per-item action is "favorite".
58
+ * The ellipsis overflow is replaced by an always-visible heart toggle wired to
59
+ * the same `collectionSave` reducer. A dropdown `Menu` anchored inside a
60
+ * list/grid row renders clipped inside the row's own bounds, so on a product
61
+ * card the overflow's items were unreachable AND the wrong pattern: shoppers
62
+ * expect a heart, not a 3-item menu two taps deep. */
63
+ favoriteToggle?: boolean;
64
+ /** A button in the EMPTY-SOURCE state that moves the list to another view of the same source (Events: "See past
65
+ * events" when Upcoming is empty and Past is not). `labelPath` and `hiddenPath` are top-level STATE fields the domain
66
+ * sets (the label through its copy, hidden until the domain knows the other view has rows); the tap sets the list's
67
+ * filter to `filter` (`collectionCriteria`), which must be one of `filterValues`. */
68
+ emptySourceAction?: { labelPath: string; hiddenPath: string; filter: string };
69
+ /** A state field the DOMAIN narrows `rows` by (e.g. a category picker). While it is set,
70
+ * zero rows is a filtered result, not an empty source. */
71
+ narrowedBy?: string;
72
+ }
73
+ /** At or below this many records, with no query/filter narrowing them and no further
74
+ * page, the list/grid toggle, Refine, chips, search and count are noise. */
75
+ export const COLLECTION_CHROME_MIN_ITEMS = 4;
76
+ /** The accessible name of a row's overflow menu: `template` with `{title}` filled, or the
77
+ * generic `fallback` for a record with no title. */
78
+ export function collectionActionsLabel(title: string, template: string, fallback: string): string {
79
+ const t = title.trim();
80
+ return t ? template.replace('{title}', () => t) : fallback;
81
+ }
82
+
83
+ export const COLLECTIONS: Record<string, CollectionConfig> = {
84
+ himiStoreShop: { rows: 'results', title: 'name', subtitle: 'subtitle', image: 'image', view: 'grid', backendQuery: true, countNoun: ['product', 'products'], favoriteToggle: true },
85
+ himiBookingServices: { rows: 'results', title: 'name', subtitle: 'subtitle', image: 'image', filter: 'category', view: 'grid', backendQuery: true, searchPlaceholder: 'Search services', countNoun: ['service', 'services'], primaryVerb: { label: 'Book', screenId: 'himi_time' } },
86
+ himiBookingBookings: { rows: 'rows', title: 'title', subtitle: 'subtitle', metadata: ['status'], view: 'list', backendQuery: true,
87
+ defaultFilter: 'value:Upcoming', searchPlaceholder: 'Search by booking ID', countNoun: ['booking', 'bookings'], filterValues: ['Upcoming', 'Past', 'Cancelled'],
88
+ sortLabels: { default: 'Soonest', az: 'Oldest', za: 'Latest' } },
89
+ himiEvents: { rows: 'results', title: 'title', subtitle: 'dateLine', image: 'image', dateBadge: { text: 'dateBadge', hidden: 'noDateBadge' }, gridColumns: 1, view: 'grid', backendQuery: true, defaultFilter: 'value:Upcoming', searchPlaceholder: 'Search events', countNoun: ['event', 'events'], filterValues: ['Upcoming', 'Past'], sortLabels: { default: 'Date', az: 'Title A–Z', za: 'Title Z–A' }, primaryVerb: { label: 'Register', labelPath: 'actionLabel', hiddenPath: 'noAction' }, shareAction: 'share', endedWhen: 'isPast', emptySourceAction: { labelPath: 'pastEventsLabel', hiddenPath: 'noPastEvents', filter: 'value:Past' } },
90
+ himiOwnerLiteProducts: { rows: 'products', title: 'name', subtitle: 'price', image: 'image', view: 'grid', backendQuery: true, countNoun: ['product', 'products'] },
91
+ himiOwnerModules: { instanceInput: 'module', rows: 'rows', title: 'title', subtitle: 'subtitle', image: 'image', filter: 'statusLabel', view: 'list', paged: true, reviewAction: 'prepareRecord', reviewSelectedAction: 'prepareSelected' },
92
+ himiOwnerLiteServices: { rows: 'services', title: 'name', subtitle: 'subtitle', view: 'list', backendQuery: true, searchPlaceholder: 'Service name starts with…' },
93
+ himiOwnerLiteEvents: { rows: 'events', title: 'title', subtitle: 'dateLine', view: 'grid', backendQuery: true, searchPlaceholder: 'Exact event title', filterValues: ['Upcoming'], sortLabels: { default: 'Date', az: 'Title A–Z', za: 'Title Z–A' } },
94
+ himiOwnerLitePosts: { rows: 'posts', title: 'title', subtitle: 'excerpt', image: 'image', view: 'grid' },
95
+ himiOwnerLiteOrders: { rows: 'orders', title: 'buyer', subtitle: 'meta', filter: 'statusLabel', view: 'list', backendQuery: true, countNoun: ['order', 'orders'],
96
+ searchPlaceholder: 'Customer name, email or order #', sortLabels: { default: 'Newest', az: 'Customer A–Z', za: 'Customer Z–A' },
97
+ filterValues: ['Recent 7 days', 'Paid', 'Unpaid', 'Partially paid', 'Pending', 'Refunded', 'Partly refunded'] },
98
+ himiBrandedGroups: { rows: 'rows', title: 'name', subtitle: 'description', image: 'image', view: 'grid' },
99
+ himiBrandedCmsCollection: { instanceInput: 'collection', rows: 'rows', title: 'title', subtitle: 'subtitle', view: 'list' },
100
+ himiBrandedOrders: { rows: 'rows', title: 'title', subtitle: 'subtitle', image: 'image', metadata: ['status', 'meta'], rowStyle: 'flat', view: 'list', backendQuery: true,
101
+ searchPlaceholder: 'Search by order number', countNoun: ['order', 'orders'], filterValues: ['Not fulfilled', 'Partially fulfilled', 'Fulfilled'],
102
+ sortLabels: { default: 'Newest', az: 'Oldest', za: 'Order # ↓' } },
103
+ himiBrandedPlans: { rows: 'rows', title: 'name', subtitle: 'description', metadata: ['badge', 'priceLine', 'periodLine', 'trialBadge', 'perk1', 'perk2', 'perk3', 'joinNote'], view: 'grid', gridColumns: 1, metaMaxLines: 8, countNoun: ['plan', 'plans'] },
104
+ himiBrandedPrograms: { rows: 'rows', title: 'name', subtitle: 'description', image: 'image', view: 'grid' },
105
+ himiBrandedCoupons: { rows: 'coupons', title: 'name', subtitle: 'subtitle', view: 'list', primaryVerb: { label: 'Get code' } },
106
+ himiBrandedNotifications: { rows: 'items', title: 'name', subtitle: 'subtitle', image: 'photo', metadata: ['unreadDot'], view: 'list' },
107
+ himiBrandedReviews: { rows: 'reviews', title: 'title', subtitle: 'body', metadata: ['author'], rating: 'rating', view: 'list' },
108
+ himiBrandedPortfolio: { rows: 'projects', title: 'title', subtitle: 'subtitle', image: 'image', view: 'grid', gridImageHeight: 180 },
109
+ himiBrandedInvoices: { rows: 'invoices', title: 'title', subtitle: 'subtitle', view: 'list' },
110
+ himiBrandedBadges: { rows: 'badges', title: 'name', subtitle: 'description', view: 'grid' },
111
+ himiBrandedDonations: { rows: 'campaigns', title: 'name', subtitle: 'description', view: 'grid', primaryVerb: { label: 'Donate' } },
112
+ himiBrandedGiftCards: { rows: 'cards', title: 'name', subtitle: 'description', view: 'grid' },
113
+ himiBrandedVideos: { rows: 'channels', title: 'title', subtitle: 'subtitle', image: 'coverUrl', view: 'grid', searchPlaceholder: 'Search channels', countNoun: ['channel', 'channels'] },
114
+ himiBrandedPodcasts: { rows: 'episodes', title: 'title', subtitle: 'subtitle', image: 'image', metadata: ['progressLabel'], view: 'list' },
115
+ himiBrandedForms: { rows: 'forms', title: 'name', subtitle: 'description', view: 'list' },
116
+ himiBrandedGalleries: { rows: 'galleries', title: 'name', subtitle: 'description', image: 'image', view: 'grid' },
117
+ himiBrandedMenus: { rows: 'rows', title: 'name', subtitle: 'description', image: 'image', sectioned: true, filter: 'collectionCategory', metadata: ['collectionCategory', 'priceLine', 'label1', 'label2', 'label3'], view: 'grid', searchPlaceholder: 'Search the menu', countNoun: ['dish', 'dishes'] },
118
+ };
119
+ export interface CollectionPreferences {
120
+ view: 'list' | 'grid';
121
+ density: 'comfortable' | 'compact';
122
+ sort: 'default' | 'az' | 'za';
123
+ filter: string;
124
+ query: string;
125
+ savedIds: string[];
126
+ selectedIds: string[];
127
+ selecting: boolean;
128
+ savedViews: SavedCollectionView[];
129
+ }
130
+ export interface SavedCollectionView {
131
+ id: string; name: string; view: 'list' | 'grid'; density: 'comfortable' | 'compact';
132
+ sort: 'default' | 'az' | 'za'; query: string; filter: string;
133
+ }
134
+ export interface CollectionItemAction {
135
+ id: string;
136
+ label: string;
137
+ destructive: boolean;
138
+ confirmationRequired: boolean;
139
+ }
140
+ export type CollectionRow = Record<string, unknown>;
141
+ export function initialCollection(config: CollectionConfig): CollectionPreferences {
142
+ return { view: config.view, density: 'comfortable', sort: 'default', filter: config.defaultFilter ?? 'all', query: '', savedIds: [], selectedIds: [], selecting: false, savedViews: [] };
143
+ }
144
+ /** Accept only small presentation preferences from local storage. Selection is
145
+ * transient and never restored as an armed bulk operation. */
146
+ export function normalizeCollection(config: CollectionConfig, value: unknown): CollectionPreferences {
147
+ const s = value && typeof value === 'object' ? value as Partial<CollectionPreferences> : {};
148
+ const base = initialCollection(config);
149
+ return { ...base,
150
+ view: s.view === 'list' || s.view === 'grid' ? s.view : base.view,
151
+ density: s.density === 'compact' ? 'compact' : 'comfortable',
152
+ sort: s.sort === 'az' || s.sort === 'za' ? s.sort : 'default',
153
+ query: typeof s.query === 'string' ? s.query.slice(0, 256) : '',
154
+ // Flat collections no longer offer Saved. Migrate its persisted value before
155
+ // the first backend request so an invisible old filter cannot empty the list.
156
+ filter: config.rowStyle === 'flat' && s.filter === 'saved' ? 'all'
157
+ : typeof s.filter === 'string' ? s.filter.slice(0, 256) : config.defaultFilter ?? 'all',
158
+ savedIds: Array.isArray(s.savedIds) ? [...new Set(s.savedIds.filter((id): id is string => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 500) : [],
159
+ savedViews: Array.isArray(s.savedViews) ? s.savedViews.filter((v): v is SavedCollectionView => !!v && typeof v === 'object' && typeof v.name === 'string' && !!v.name.trim()).slice(0, 8).map((v, i) => ({
160
+ id: `view-${i}`, name: v.name.trim().slice(0, 40),
161
+ view: v.view === 'list' || v.view === 'grid' ? v.view : config.view,
162
+ density: v.density === 'compact' ? 'compact' : 'comfortable',
163
+ sort: v.sort === 'az' || v.sort === 'za' ? v.sort : 'default',
164
+ query: typeof v.query === 'string' ? v.query.slice(0, 256) : '',
165
+ filter: config.rowStyle === 'flat' && v.filter === 'saved' ? 'all'
166
+ : typeof v.filter === 'string' ? v.filter.slice(0, 256) : 'all',
167
+ })) : [],
168
+ };
169
+ }
170
+ const scalar = (value: unknown): string => typeof value === 'string' || typeof value === 'number' ? String(value) : '';
171
+ export function collectionId(row: CollectionRow): string { return scalar(row.id) || scalar(row._id) || scalar(row.key); }
172
+ export function collectionTitle(row: CollectionRow, config: CollectionConfig): string {
173
+ return scalar(row[config.title]) || scalar(row.title) || scalar(row.name) || scalar(row.display) || scalar(row.label);
174
+ }
175
+ /** Does not mutate domain rows, paging, or domain-derived state. */
176
+ export function projectCollection(source: CollectionRow[], config: CollectionConfig, prefs: CollectionPreferences, backendQuery = false, knownFilters: string[] = []) {
177
+ const query = prefs.query.trim().toLocaleLowerCase();
178
+ const unique = new Set<string>();
179
+ // Menu sections describe their following items; they are not actionable
180
+ // records. Carry the category onto each item before sorting or filtering.
181
+ let category = '';
182
+ const records: CollectionRow[] = config.sectioned ? source.flatMap(row => {
183
+ if (row.isHeader === true) { category = scalar(row.title); return []; }
184
+ return [{ ...row, collectionCategory: category }];
185
+ }) : source;
186
+ const rows = records.filter(row => {
187
+ const id = collectionId(row);
188
+ if (!id) return true; // render anonymous records; identity actions stay disabled
189
+ if (unique.has(id)) return false;
190
+ unique.add(id); return true;
191
+ });
192
+ const filters = config.filterValues ?? [...new Set([...knownFilters, ...rows.map(row => config.filter ? scalar(row[config.filter]) : '')].filter(Boolean))].sort();
193
+ const visible = rows.filter(row => {
194
+ if (backendQuery) return true;
195
+ if (prefs.filter === 'saved' && !prefs.savedIds.includes(collectionId(row))) return false;
196
+ if (prefs.filter.startsWith('value:') && (!config.filter || scalar(row[config.filter]) !== prefs.filter.slice(6))) return false;
197
+ return !query || Object.values(row).some(value => scalar(value).toLocaleLowerCase().includes(query));
198
+ });
199
+ if (!backendQuery && prefs.sort !== 'default') visible.sort((a, b) => {
200
+ const order = compareText(collectionTitle(a, config), collectionTitle(b, config));
201
+ return (prefs.sort === 'az' ? order : -order) || compareIso(collectionId(a), collectionId(b));
202
+ });
203
+ return {
204
+ items: visible.map(row => ({ ...row, collectionId: collectionId(row), collectionTitle: collectionTitle(row, config),
205
+ collectionMeta: [...new Set((config.metadata ?? ['total', 'statusLabel', 'price', 'priceLine', 'dateLine', 'meta']).filter(key => key !== config.subtitle).map(key => scalar(row[key])).filter(Boolean))].join(' · '),
206
+ collectionSelectLabel: prefs.selectedIds.includes(collectionId(row)) ? 'Selected' : 'Select',
207
+ // The save toggle names the action it WILL take (the service localizes it).
208
+ collectionSaveLabel: prefs.savedIds.includes(collectionId(row)) ? 'Remove from saved' : 'Save',
209
+ // The row's overflow menu, named for its record: out of context (a rotor, a voice
210
+ // command) a list of identical "Item actions" cannot be told apart.
211
+ collectionActionsLabel: collectionActionsLabel(collectionTitle(row, config), 'Actions for {title}', 'Item actions'),
212
+ collectionSubtitle: scalar(row[config.subtitle ?? '']) || scalar(row.subtitle) || scalar(row.description) || scalar(row.meta),
213
+ collectionImage: scalar(row[config.image ?? '']), collectionNoImage: !scalar(row[config.image ?? '']), collectionHasImage: !!scalar(row[config.image ?? '']),
214
+ collectionSaved: prefs.savedIds.includes(collectionId(row)), collectionNotSaved: !prefs.savedIds.includes(collectionId(row)), collectionSelected: prefs.selectedIds.includes(collectionId(row)),
215
+ collectionNoIdentity: !collectionId(row),
216
+ // Older cached EventRows predate `isPast` but already stored `statusLabel: "Past"`.
217
+ // Keep their ended state through an offline render until the row is refreshed.
218
+ ...(config.endedWhen ? (() => {
219
+ const ended = row[config.endedWhen] === true || (config.endedWhen === 'isPast' && row.statusLabel === 'Past');
220
+ return { collectionEnded: ended, collectionNotEnded: !ended };
221
+ })() : {}),
222
+ // A row restored from state saved by an older build has no badge flag. An unset hidden flag
223
+ // fails open and would paint an empty chip, so it reads as "no badge" until a refresh.
224
+ ...(config.dateBadge && typeof row[config.dateBadge.hidden] !== 'boolean'
225
+ ? { [config.dateBadge.text]: '', [config.dateBadge.hidden]: true } : {}),
226
+ // Same for a per-row verb: an unset hidden flag fails open and would show a verb with an unresolved
227
+ // label, so a row without the flag offers no action until a refresh establishes one.
228
+ ...(config.primaryVerb?.hiddenPath && typeof row[config.primaryVerb.hiddenPath] !== 'boolean'
229
+ ? { ...(config.primaryVerb.labelPath ? { [config.primaryVerb.labelPath]: '' } : {}), [config.primaryVerb.hiddenPath]: true } : {}) })),
230
+ filters, loaded: rows.length,
231
+ };
232
+ }