@wix/himalaya-cli 0.1871.0 → 0.1873.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 (184) 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/browser-plane/assets.json +5 -5
  4. package/dist/browser-plane/preview-deferred/{ab91dfb9c348c8c78f942a5b88ba90df456c5b436e135d97791d5dd95d6a40dc.bin → a9d34f09c807f1cde9ab000737f0f7b849670c37908aa47cb77889b7e01d34cb.bin} +1 -1
  5. package/dist/browser-plane/sw.js +9 -9
  6. package/dist/cli.mjs +506 -323
  7. package/dist/preview-assets.generated.bin +0 -0
  8. package/fixtures/wix-canned.json +8 -0
  9. package/guides/release-notes.md +18 -0
  10. package/guides/sdk-reference.json +8 -1
  11. package/package.json +2 -2
  12. package/template-icons/professional-services.png +0 -0
  13. package/templates/bare-fashion/config.ts +37 -2
  14. package/templates/bare-fashion/dev/index.ts +4006 -48
  15. package/templates/bare-fashion/himalaya.content.json +15 -0
  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/branded-lite/dev/index.ts +2 -1
  24. package/templates/branded-lite/tier5-src/_shared/portfolio-details.ts +70 -0
  25. package/templates/branded-lite/tier5-src/himi-branded-lite-coupons/index.ts +13 -2
  26. package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
  27. package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
  28. package/templates/branded-lite/tier5-src/himi-events-list/index.ts +5 -1
  29. package/templates/community-club/tier5-src/himi-events-list/index.ts +5 -1
  30. package/templates/conference/config.ts +43 -1
  31. package/templates/conference/dev/index.ts +4127 -0
  32. package/templates/conference/himalaya.content.json +18 -0
  33. package/templates/conference/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  34. package/templates/conference/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  35. package/templates/conference/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  36. package/templates/conference/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  37. package/templates/conference/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  38. package/templates/conference/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  39. package/templates/conference/tier5-src/himi-events-list/index.ts +5 -1
  40. package/templates/conference/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  41. package/templates/events-meetups/tier5-src/himi-events-list/index.ts +5 -1
  42. package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +5 -1
  43. package/templates/medical-services/config.ts +42 -0
  44. package/templates/medical-services/dev/index.ts +4136 -0
  45. package/templates/medical-services/himalaya.content.json +18 -0
  46. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  47. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  48. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  49. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  50. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  51. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  52. package/templates/medical-services/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  53. package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +5 -1
  54. package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +5 -1
  55. package/templates/portfolio-creative/dev/index.ts +2 -1
  56. package/templates/portfolio-creative/tier5-src/_shared/portfolio-details.ts +70 -0
  57. package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
  58. package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
  59. package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +5 -1
  60. package/templates/professional-services/README.md +55 -0
  61. package/templates/professional-services/config.ts +436 -0
  62. package/templates/professional-services/dev/index.ts +44772 -0
  63. package/templates/professional-services/himalaya.content.json +100 -0
  64. package/templates/professional-services/himalaya.template.json +16 -0
  65. package/templates/professional-services/icon.png +0 -0
  66. package/templates/professional-services/platforms.json +1 -0
  67. package/templates/professional-services/tier5-src/_shared/app-locale.ts +70 -0
  68. package/templates/professional-services/tier5-src/_shared/booking-location.ts +147 -0
  69. package/templates/professional-services/tier5-src/_shared/booking-session.ts +224 -0
  70. package/templates/professional-services/tier5-src/_shared/branded-lite-hosted.ts +282 -0
  71. package/templates/professional-services/tier5-src/_shared/branded-load-state.ts +109 -0
  72. package/templates/professional-services/tier5-src/_shared/business-chat-copy.ts +40 -0
  73. package/templates/professional-services/tier5-src/_shared/business-chat-history.ts +51 -0
  74. package/templates/professional-services/tier5-src/_shared/business-chat-message-model.ts +177 -0
  75. package/templates/professional-services/tier5-src/_shared/business-chat-model.ts +56 -0
  76. package/templates/professional-services/tier5-src/_shared/business-chat-presenter.ts +587 -0
  77. package/templates/professional-services/tier5-src/_shared/business-chat-transport.ts +164 -0
  78. package/templates/professional-services/tier5-src/_shared/chat-live.ts +242 -0
  79. package/templates/professional-services/tier5-src/_shared/collection-contract.ts +232 -0
  80. package/templates/professional-services/tier5-src/_shared/collection-query.ts +201 -0
  81. package/templates/professional-services/tier5-src/_shared/collection-service.ts +429 -0
  82. package/templates/professional-services/tier5-src/_shared/detail-presence.ts +51 -0
  83. package/templates/professional-services/tier5-src/_shared/engine-intl.ts +538 -0
  84. package/templates/professional-services/tier5-src/_shared/event-registration.ts +86 -0
  85. package/templates/professional-services/tier5-src/_shared/events-inline-options.ts +77 -0
  86. package/templates/professional-services/tier5-src/_shared/faq-list.ts +405 -0
  87. package/templates/professional-services/tier5-src/_shared/featured-event.ts +63 -0
  88. package/templates/professional-services/tier5-src/_shared/group-member-count.ts +15 -0
  89. package/templates/professional-services/tier5-src/_shared/group-privacy.ts +14 -0
  90. package/templates/professional-services/tier5-src/_shared/guest-sign-in.ts +36 -0
  91. package/templates/professional-services/tier5-src/_shared/himi-account.ts +222 -0
  92. package/templates/professional-services/tier5-src/_shared/himi-blog-hidden.ts +66 -0
  93. package/templates/professional-services/tier5-src/_shared/himi-blog-post-row.ts +214 -0
  94. package/templates/professional-services/tier5-src/_shared/himi-blog-saved.ts +64 -0
  95. package/templates/professional-services/tier5-src/_shared/himi-booking-saved.ts +88 -0
  96. package/templates/professional-services/tier5-src/_shared/himi-bookings.ts +318 -0
  97. package/templates/professional-services/tier5-src/_shared/himi-copy.ts +123 -0
  98. package/templates/professional-services/tier5-src/_shared/himi-events.ts +92 -0
  99. package/templates/professional-services/tier5-src/_shared/himi-media.ts +33 -0
  100. package/templates/professional-services/tier5-src/_shared/himi-store.ts +7 -0
  101. package/templates/professional-services/tier5-src/_shared/himi-text.ts +24 -0
  102. package/templates/professional-services/tier5-src/_shared/host-events.ts +66 -0
  103. package/templates/professional-services/tier5-src/_shared/hosted-checkout.ts +70 -0
  104. package/templates/professional-services/tier5-src/_shared/iap-attendance-form.ts +106 -0
  105. package/templates/professional-services/tier5-src/_shared/iap-attendance-purchase.ts +235 -0
  106. package/templates/professional-services/tier5-src/_shared/iap-attendance.ts +38 -0
  107. package/templates/professional-services/tier5-src/_shared/iap-worker.ts +127 -0
  108. package/templates/professional-services/tier5-src/_shared/inbox-rooms.ts +163 -0
  109. package/templates/professional-services/tier5-src/_shared/local-preferences.ts +38 -0
  110. package/templates/professional-services/tier5-src/_shared/member-access.ts +63 -0
  111. package/templates/professional-services/tier5-src/_shared/member-account-routes.ts +56 -0
  112. package/templates/professional-services/tier5-src/_shared/member-avatar.ts +76 -0
  113. package/templates/professional-services/tier5-src/_shared/member-bookings.ts +107 -0
  114. package/templates/professional-services/tier5-src/_shared/member-read.ts +82 -0
  115. package/templates/professional-services/tier5-src/_shared/member-screen.ts +99 -0
  116. package/templates/professional-services/tier5-src/_shared/notification-target.ts +141 -0
  117. package/templates/professional-services/tier5-src/_shared/offset-page.ts +10 -0
  118. package/templates/professional-services/tier5-src/_shared/online-actions.ts +76 -0
  119. package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +348 -0
  120. package/templates/professional-services/tier5-src/_shared/payment-setup.ts +6 -0
  121. package/templates/professional-services/tier5-src/_shared/portfolio-details.ts +70 -0
  122. package/templates/professional-services/tier5-src/_shared/pricing-plan-display.ts +64 -0
  123. package/templates/professional-services/tier5-src/_shared/relative-time.ts +21 -0
  124. package/templates/professional-services/tier5-src/_shared/result-snackbar.ts +26 -0
  125. package/templates/professional-services/tier5-src/_shared/rich-body.ts +78 -0
  126. package/templates/professional-services/tier5-src/_shared/rich-content-link.ts +34 -0
  127. package/templates/professional-services/tier5-src/_shared/sign-in-sheet.ts +18 -0
  128. package/templates/professional-services/tier5-src/_shared/staff-name.ts +18 -0
  129. package/templates/professional-services/tier5-src/_shared/weekly-goal.ts +111 -0
  130. package/templates/professional-services/tier5-src/_shared/wix-bi.ts +85 -0
  131. package/templates/professional-services/tier5-src/_shared/wix-member-links.ts +114 -0
  132. package/templates/professional-services/tier5-src/_shared/wix-service-price.ts +146 -0
  133. package/templates/professional-services/tier5-src/business-chat/index.ts +797 -0
  134. package/templates/professional-services/tier5-src/business-contact/index.ts +6 -0
  135. package/templates/professional-services/tier5-src/himi-blog-feed/index.ts +444 -0
  136. package/templates/professional-services/tier5-src/himi-blog-post/index.ts +1239 -0
  137. package/templates/professional-services/tier5-src/himi-booking-account/index.ts +278 -0
  138. package/templates/professional-services/tier5-src/himi-booking-bookings/index.ts +475 -0
  139. package/templates/professional-services/tier5-src/himi-booking-service/index.ts +1197 -0
  140. package/templates/professional-services/tier5-src/himi-booking-services/index.ts +795 -0
  141. package/templates/professional-services/tier5-src/himi-booking-time/index.ts +1840 -0
  142. package/templates/professional-services/tier5-src/himi-branded-lite-coupons/index.ts +96 -0
  143. package/templates/professional-services/tier5-src/himi-branded-lite-faq/index.ts +6 -0
  144. package/templates/professional-services/tier5-src/himi-branded-lite-file-share/index.ts +12 -0
  145. package/templates/professional-services/tier5-src/himi-branded-lite-group/index.ts +310 -0
  146. package/templates/professional-services/tier5-src/himi-branded-lite-group-about/index.ts +240 -0
  147. package/templates/professional-services/tier5-src/himi-branded-lite-my-groups/index.ts +237 -0
  148. package/templates/professional-services/tier5-src/himi-branded-lite-notifications/index.ts +263 -0
  149. package/templates/professional-services/tier5-src/himi-branded-lite-plans/index.ts +498 -0
  150. package/templates/professional-services/tier5-src/himi-branded-lite-portfolio/index.ts +136 -0
  151. package/templates/professional-services/tier5-src/himi-branded-lite-portfolio-project/index.ts +198 -0
  152. package/templates/professional-services/tier5-src/himi-events-detail/index.ts +1306 -0
  153. package/templates/professional-services/tier5-src/himi-events-list/index.ts +171 -0
  154. package/templates/professional-services/tier5-src/himi-events-my-events/index.ts +227 -0
  155. package/templates/professional-services/tier5-src/himi-events-rsvp/index.ts +230 -0
  156. package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts +318 -0
  157. package/templates/professional-services/tier5-src/himi-professional-services-home/index.ts +772 -0
  158. package/templates/professional-services/tier5-src/himi-store-account/index.ts +1514 -0
  159. package/templates/professional-services/tier5-src/wix-spaces-coupon-detail/index.ts +43 -0
  160. package/templates/professional-services/tier5-src/wix-spaces-my-subscriptions/index.ts +89 -0
  161. package/templates/professional-services/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
  162. package/templates/professional-services/tokens.json +456 -0
  163. package/templates/restaurant/tier5-src/himi-events-list/index.ts +5 -1
  164. package/templates/salon-spa/config.ts +42 -0
  165. package/templates/salon-spa/dev/index.ts +4136 -0
  166. package/templates/salon-spa/himalaya.content.json +18 -0
  167. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  168. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  169. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  170. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  171. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  172. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  173. package/templates/salon-spa/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  174. package/templates/wholesale-store/config.ts +43 -1
  175. package/templates/wholesale-store/dev/index.ts +4136 -0
  176. package/templates/wholesale-store/himalaya.content.json +18 -0
  177. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  178. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  179. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  180. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  181. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  182. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  183. package/templates/wholesale-store/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  184. package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +5 -1
@@ -4,6 +4,21 @@
4
4
  "himi_account": {
5
5
  "displayName": "Profile"
6
6
  },
7
+ "himi_account_change_password": {
8
+ "displayName": "Change password"
9
+ },
10
+ "himi_account_login_info": {
11
+ "displayName": "Login info"
12
+ },
13
+ "himi_account_personal_info": {
14
+ "displayName": "Personal info"
15
+ },
16
+ "himi_account_privacy": {
17
+ "displayName": "Privacy"
18
+ },
19
+ "himi_account_settings": {
20
+ "displayName": "Account settings"
21
+ },
7
22
  "himi_agenda": {
8
23
  "displayName": "Class schedule"
9
24
  },
@@ -13,6 +28,9 @@
13
28
  "himi_business_chat": {
14
29
  "displayName": "Message the salon"
15
30
  },
31
+ "himi_delete_account": {
32
+ "displayName": "Delete Account"
33
+ },
16
34
  "himi_galleries": {
17
35
  "displayName": "Our space"
18
36
  },
@@ -0,0 +1,295 @@
1
+ import { dispatch } from "@himalaya/dispatch";
2
+ import { defineService } from "@himalaya/state";
3
+ import { alert } from "@himalaya/ui";
4
+ import { getMyMember, getPublicMember, listCurrentMemberBlocking, unblockCurrentMember } from "@himalaya/wix-members";
5
+ import { getMyData } from "@himalaya/wix-users";
6
+ import { assertMemberAccess, memberAccess, type MemberAccess } from "../_shared/member-access.js";
7
+ import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
8
+
9
+ const PAGE_SIZE = 50;
10
+ const MAX_READBACK_PAGES = 20;
11
+ interface Row { memberId: string; label: string; initials: string }
12
+ interface State {
13
+ /** `idle` until the Privacy modal loads it: the other account screens boot this bundle too. */
14
+ status: "idle" | "loading" | "loaded" | "error";
15
+ identityStatus: "unresolved" | "guest" | "error" | "member";
16
+ hydrated: boolean; notIdentityResolved: boolean;
17
+ guest: boolean; notGuest: boolean; identityError: boolean; notIdentityError: boolean;
18
+ notMember: boolean; isMember: boolean; notLoading: boolean; notErrored: boolean;
19
+ hasError: boolean; errorText: string;
20
+ blockedMembers: Row[]; hasMembers: boolean; noMembers: boolean; hideEmpty: boolean;
21
+ nextCursor: string; hasMore: boolean; noMore: boolean; loadingMore: boolean;
22
+ confirmOpen: boolean; noConfirm: boolean; confirmMemberId: string; message: string;
23
+ currentMemberEmail: string; currentMemberScope: string; currentMemberId: string;
24
+ }
25
+ interface Identity extends MemberAccess { memberId: string }
26
+ interface MyMemberResponse { member?: { id?: string } }
27
+ interface Page { blockedMemberIds?: string[]; pagingMetadata?: { cursors?: { next?: string } } }
28
+
29
+ const EMPTY: State = {
30
+ status: "idle", identityStatus: "unresolved", hydrated: false, notIdentityResolved: true,
31
+ guest: false, notGuest: true, identityError: false, notIdentityError: true,
32
+ notMember: true, isMember: false, notLoading: false, notErrored: true,
33
+ hasError: false, errorText: "", blockedMembers: [], hasMembers: false, noMembers: false, hideEmpty: true,
34
+ nextCursor: "", hasMore: false, noMore: true, loadingMore: false,
35
+ confirmOpen: false, noConfirm: true, confirmMemberId: "", message: "",
36
+ currentMemberEmail: "", currentMemberScope: "", currentMemberId: "",
37
+ };
38
+
39
+ function namedError(name: string, message: string): Error {
40
+ const error = new Error(message);
41
+ error.name = name;
42
+ return error;
43
+ }
44
+ function isNamed(error: unknown, name: string): boolean {
45
+ return (error as { name?: unknown } | null)?.name === name;
46
+ }
47
+ function clean(value: unknown): string { return typeof value === "string" ? value.trim() : ""; }
48
+ function sameIdentity(a: Identity, b: Identity): boolean {
49
+ return a.email === b.email && a.scope === b.scope && a.memberId === b.memberId;
50
+ }
51
+
52
+ async function currentIdentity(): Promise<Identity | null> {
53
+ let raw: unknown;
54
+ let identityUnavailable = false;
55
+ try { raw = await dispatch("himi.wix.memberIdentity"); }
56
+ catch { identityUnavailable = true; }
57
+ const value = raw as { email?: unknown; payload?: { email?: unknown } } | null;
58
+ const emailValue = value?.email ?? value?.payload?.email;
59
+ let email = typeof emailValue === "string" ? emailValue.trim().toLowerCase() : "";
60
+ // Older native hosts predate the memberIdentity action but expose the profile through wix-users (the
61
+ // same rung memberAccess() uses). A host that fails BOTH ways is unavailable, never a guest.
62
+ if (!email && identityUnavailable) {
63
+ try {
64
+ const profile = await getMyData();
65
+ const legacy = profile.email ?? profile.contactEmail;
66
+ email = typeof legacy === "string" ? legacy.trim().toLowerCase() : "";
67
+ } catch { /* fall through to unavailable */ }
68
+ if (!email) throw namedError("IdentityUnavailable", "The current member identity could not be checked.");
69
+ }
70
+ if (!email) return null;
71
+ const access = await memberAccess();
72
+ if (!access.email || access.email !== email) throw namedError("IdentityUnavailable", "The current member identity could not be checked.");
73
+ const response = await getMyMember({ fieldsets: ["FULL"] }) as MyMemberResponse;
74
+ await assertMemberAccess(access);
75
+ const memberId = clean(response.member?.id);
76
+ if (!memberId) throw new Error("The signed-in member profile is unavailable.");
77
+ return { ...access, memberId };
78
+ }
79
+
80
+ async function assertCurrentIdentity(expected: Identity): Promise<void> {
81
+ const current = await currentIdentity();
82
+ if (!current || !sameIdentity(current, expected)) throw namedError("MemberChanged", "The signed-in member changed. Reload this section.");
83
+ }
84
+
85
+ /** Public display names by member id, for this worker's life. "" = the profile has no public name. */
86
+ const publicNames = new Map<string, string>();
87
+
88
+ /** The member-owned endpoint returns IDs only, and getMember(id) is APP-authenticated: never call
89
+ * it with a member token. The PUBLIC profile (nickname) is readable by any visitor, so the rows show
90
+ * that name; a member with no public profile shows as "Member", never as a guessed name. */
91
+ async function resolveNames(ids: string[]): Promise<void> {
92
+ const missing = [...new Set(ids.map(clean).filter((id) => id && !publicNames.has(id)))];
93
+ await Promise.all(missing.map(async (id) => {
94
+ try { publicNames.set(id, clean((await getPublicMember(id))?.member?.profile?.nickname)); }
95
+ catch { /* not cached: the next load asks again, and the row says "Member" meanwhile */ }
96
+ }));
97
+ }
98
+
99
+ function initialsOf(name: string): string {
100
+ const words = name.split(/\s+/).filter(Boolean);
101
+ return (words.length > 1 ? `${words[0][0]}${words[words.length - 1][0]}` : (words[0] ?? "").slice(0, 1)).toUpperCase();
102
+ }
103
+
104
+ function rows(ids: string[]): Row[] {
105
+ const seen = new Set<string>();
106
+ const result: Row[] = [];
107
+ for (const raw of ids) {
108
+ const memberId = clean(raw);
109
+ if (!memberId || seen.has(memberId)) continue;
110
+ seen.add(memberId);
111
+ const name = publicNames.get(memberId) ?? "";
112
+ const label = name || copyParam("accountSettings.blockedMemberLabel", "Member");
113
+ result.push({ memberId, label, initials: initialsOf(label) });
114
+ }
115
+ return result;
116
+ }
117
+
118
+ function withRows(state: State, blockedMembers: Row[], nextCursor: string): State {
119
+ return { ...state, blockedMembers, hasMembers: blockedMembers.length > 0,
120
+ noMembers: blockedMembers.length === 0,
121
+ hideEmpty: !(state.status === "loaded" && state.isMember && blockedMembers.length === 0),
122
+ nextCursor, hasMore: !!nextCursor, noMore: !nextCursor };
123
+ }
124
+
125
+ function memberState(identity: Identity): State {
126
+ return { ...EMPTY, status: "loaded", identityStatus: "member", hydrated: true, notIdentityResolved: false,
127
+ guest: false, notGuest: true, identityError: false, notIdentityError: true, notMember: false, isMember: true,
128
+ notLoading: true, notErrored: true, hasError: false, currentMemberEmail: identity.email,
129
+ currentMemberScope: identity.scope, currentMemberId: identity.memberId };
130
+ }
131
+
132
+ function failed(error: unknown): State {
133
+ const identityError = isNamed(error, "IdentityUnavailable") || isNamed(error, "MemberChanged");
134
+ const text = isNamed(error, "MemberChanged")
135
+ ? copyParam("accountSettings.blockedMembersChanged", "Your account changed. Reload your blocked members.")
136
+ : identityError
137
+ ? copyParam("accountSettings.blockedMembersIdentityError", "Your member identity could not be verified. Try again.")
138
+ : copyParam("accountSettings.blockedMembersError", "Blocked members could not be loaded. Try again.");
139
+ return { ...EMPTY, status: "error", identityStatus: identityError ? "error" : "member", hydrated: true,
140
+ notIdentityResolved: false, guest: false, notGuest: true, identityError, notIdentityError: !identityError,
141
+ notMember: false, isMember: true, notLoading: true, notErrored: false, hasError: true,
142
+ errorText: text, message: text };
143
+ }
144
+
145
+ async function readAll(identity: Identity): Promise<string[]> {
146
+ const ids: string[] = [];
147
+ const seenCursors = new Set<string>();
148
+ let cursor = "";
149
+ for (let i = 0; i < MAX_READBACK_PAGES; i += 1) {
150
+ await assertCurrentIdentity(identity);
151
+ const page = await listCurrentMemberBlocking({ cursorPaging: { limit: PAGE_SIZE, ...(cursor ? { cursor } : {}) } }) as Page;
152
+ await assertCurrentIdentity(identity);
153
+ ids.push(...(page.blockedMemberIds ?? []));
154
+ const next = clean(page.pagingMetadata?.cursors?.next);
155
+ if (!next) return [...new Set(ids.map(clean).filter(Boolean))];
156
+ if (seenCursors.has(next)) throw new Error("Blocked member paging did not advance.");
157
+ seenCursors.add(next);
158
+ cursor = next;
159
+ }
160
+ throw new Error("The blocked member list is too large to verify safely.");
161
+ }
162
+
163
+ let loadVersion = 0;
164
+ let loadInFlight = false;
165
+ let pageInFlight = false;
166
+ let unblockInFlight = false;
167
+ /** One Unblock question at a time: a second tap while an alert is open is ignored, so the alert
168
+ * the member answers is always the one about the member it names. */
169
+ let unblockAlertOpen = false;
170
+ type Actions = {
171
+ load: (state: State, arg?: unknown) => Promise<State>;
172
+ loadMore: (state: State) => Promise<State | undefined>;
173
+ showLoading: (state: State) => State;
174
+ requestUnblock: (state: State, arg?: unknown) => Promise<State>;
175
+ openConfirm: (state: State, arg?: unknown) => State;
176
+ cancelUnblock: (state: State) => State;
177
+ confirmUnblock: (state: State, arg?: unknown) => Promise<State | undefined>;
178
+ };
179
+ const svc: ReturnType<typeof defineService<State, Actions>> = defineService<State, Actions>("himiBrandedAccountBlockedMembers", {
180
+ state: { ...EMPTY },
181
+ notHydrated: ["status", "identityStatus", "hydrated", "notIdentityResolved", "guest", "notGuest", "identityError", "notIdentityError", "notMember", "isMember", "notLoading", "notErrored", "hasError", "errorText", "blockedMembers", "hasMembers", "noMembers", "hideEmpty", "nextCursor", "hasMore", "noMore", "loadingMore", "confirmOpen", "noConfirm", "confirmMemberId", "message", "currentMemberEmail", "currentMemberScope", "currentMemberId"],
182
+ actions: {
183
+ load: async (_state, arg): Promise<State> => {
184
+ if (loadInFlight) return svc.getState() as State;
185
+ loadInFlight = true;
186
+ stashCopy(arg);
187
+ // No previous member's rows while this load reads who is signed in now.
188
+ await svc.showLoading();
189
+ const version = ++loadVersion;
190
+ try {
191
+ const identity = await currentIdentity();
192
+ if (version !== loadVersion) return svc.getState() as State;
193
+ if (!identity) return { ...EMPTY, status: "loaded", identityStatus: "guest", hydrated: true,
194
+ notIdentityResolved: false, guest: true, notGuest: false, notMember: true, notLoading: true, noMembers: false };
195
+ await assertCurrentIdentity(identity);
196
+ const page = await listCurrentMemberBlocking({ cursorPaging: { limit: PAGE_SIZE } }) as Page;
197
+ await assertCurrentIdentity(identity);
198
+ await resolveNames(page.blockedMemberIds ?? []);
199
+ await assertCurrentIdentity(identity);
200
+ if (version !== loadVersion) return svc.getState() as State;
201
+ return withRows(memberState(identity), rows(page.blockedMemberIds ?? []), clean(page.pagingMetadata?.cursors?.next));
202
+ } catch (error) {
203
+ if (version !== loadVersion) return svc.getState() as State;
204
+ return failed(error);
205
+ } finally { loadInFlight = false; }
206
+ },
207
+ loadMore: async (state) => {
208
+ if (pageInFlight || state.status !== "loaded" || !state.isMember || !state.hasMore) return undefined;
209
+ pageInFlight = true;
210
+ // A newer load() supersedes this page: return undefined (commit nothing) instead of writing back
211
+ // the pre-await snapshot, which would replace the fresh list or its error state.
212
+ const version = loadVersion;
213
+ try {
214
+ const identity = await currentIdentity();
215
+ if (version !== loadVersion) return undefined;
216
+ const expected: Identity = { email: state.currentMemberEmail, scope: state.currentMemberScope, memberId: state.currentMemberId };
217
+ if (!identity || !sameIdentity(identity, expected)) return failed(namedError("MemberChanged", "The signed-in member changed. Reload this section."));
218
+ await assertCurrentIdentity(identity);
219
+ const page = await listCurrentMemberBlocking({ cursorPaging: { limit: PAGE_SIZE, cursor: state.nextCursor } }) as Page;
220
+ await assertCurrentIdentity(identity);
221
+ await resolveNames(page.blockedMemberIds ?? []);
222
+ await assertCurrentIdentity(identity);
223
+ if (version !== loadVersion) return undefined;
224
+ const combined = rows([...state.blockedMembers.map((item) => item.memberId), ...(page.blockedMemberIds ?? [])]);
225
+ return { ...withRows(state, combined, clean(page.pagingMetadata?.cursors?.next)), loadingMore: false };
226
+ } catch (error) {
227
+ if (version !== loadVersion) return undefined;
228
+ if (isNamed(error, "MemberChanged") || isNamed(error, "IdentityUnavailable")) return failed(error);
229
+ return { ...state, status: "error", notLoading: true, notErrored: false, hasError: true,
230
+ errorText: copyParam("accountSettings.blockedMembersError", "Blocked members could not be loaded. Try again."),
231
+ blockedMembers: state.blockedMembers, hasMembers: state.blockedMembers.length > 0,
232
+ noMembers: false, hideEmpty: true, nextCursor: state.nextCursor, hasMore: true, noMore: false };
233
+ } finally { pageInFlight = false; }
234
+ },
235
+ showLoading: () => ({ ...EMPTY, status: "loading" }),
236
+ // Unblock asks first, in an alert; confirming runs confirmUnblock, which removes the row.
237
+ requestUnblock: async (state, arg) => {
238
+ const memberId = clean((arg as { memberId?: unknown } | undefined)?.memberId);
239
+ const row = state.blockedMembers.find((item) => item.memberId === memberId);
240
+ if (unblockAlertOpen || unblockInFlight || state.status !== "loaded" || !state.isMember || !memberId || !row) return state;
241
+ unblockAlertOpen = true;
242
+ let confirmed = false;
243
+ try {
244
+ await svc.openConfirm({ memberId });
245
+ confirmed = (await alert({
246
+ title: copyTemplate("accountSettings.blockedUnblockTitle", "Unblock {name}?", { name: row.label }),
247
+ message: copyParam("accountSettings.blockedUnblockPrompt", "Unblock this member? They may be able to interact with your profile again."),
248
+ confirmLabel: copyParam("accountSettings.blockedUnblockCta", "Unblock"),
249
+ cancelLabel: copyParam("common.cancelCta", "Cancel"),
250
+ })).confirmed;
251
+ } catch { /* no presenter: nothing was confirmed */ }
252
+ finally { unblockAlertOpen = false; }
253
+ if (!confirmed) return { ...svc.getState(), confirmOpen: false, noConfirm: true, confirmMemberId: "" };
254
+ // The member the alert named, not whatever confirmMemberId says by now.
255
+ return await svc.confirmUnblock({ memberId }) as State;
256
+ },
257
+ openConfirm: (state, arg) => ({ ...state, confirmOpen: true, noConfirm: false, confirmMemberId: clean((arg as { memberId?: unknown } | undefined)?.memberId),
258
+ message: "", errorText: "", hasError: false, notErrored: true }),
259
+ cancelUnblock: (state) => ({ ...state, confirmOpen: false, noConfirm: true, confirmMemberId: "" }),
260
+ confirmUnblock: async (state, arg) => {
261
+ if (unblockInFlight || !state.confirmOpen || state.status !== "loaded" || !state.isMember) return undefined;
262
+ const memberId = clean((arg as { memberId?: unknown } | undefined)?.memberId) || state.confirmMemberId;
263
+ if (memberId !== state.confirmMemberId) return undefined;
264
+ if (!memberId || !state.blockedMembers.some((item) => item.memberId === memberId)) return undefined;
265
+ unblockInFlight = true;
266
+ let mutationAttempted = false;
267
+ try {
268
+ const identity = await currentIdentity();
269
+ const expected: Identity = { email: state.currentMemberEmail, scope: state.currentMemberScope, memberId: state.currentMemberId };
270
+ if (!identity || !sameIdentity(identity, expected)) return failed(namedError("MemberChanged", "The signed-in member changed. Reload this section."));
271
+ await assertCurrentIdentity(identity);
272
+ mutationAttempted = true;
273
+ loadVersion += 1; // a page requested before the unblock must not re-add the member...
274
+ await unblockCurrentMember(memberId);
275
+ await assertCurrentIdentity(identity);
276
+ const ids = await readAll(identity);
277
+ await resolveNames(ids);
278
+ await assertCurrentIdentity(identity);
279
+ loadVersion += 1; // ...nor one requested while it was in flight: this authoritative list wins
280
+ if (ids.includes(memberId)) return { ...state, confirmOpen: true, noConfirm: false, hasError: true, notErrored: false,
281
+ errorText: copyParam("accountSettings.blockedUnblockStillListed", "This member still appears blocked. Reload the list before trying again.") };
282
+ const refreshed = rows(ids);
283
+ return { ...withRows({ ...state, confirmOpen: false, noConfirm: true, confirmMemberId: "", hasError: false,
284
+ notErrored: true, errorText: "", message: copyParam("accountSettings.blockedUnblocked", "Member unblocked.") }, refreshed, "") };
285
+ } catch (error) {
286
+ if (isNamed(error, "MemberChanged") || isNamed(error, "IdentityUnavailable")) return failed(error);
287
+ if (mutationAttempted) return { ...failed(error), errorText: copyParam("accountSettings.blockedUnblockUnconfirmed", "Could not confirm the updated blocked list. Reload and try again."), message: copyParam("accountSettings.blockedUnblockUnconfirmed", "Could not confirm the updated blocked list. Reload and try again."), confirmOpen: false, noConfirm: true };
288
+ return { ...state, confirmOpen: true, noConfirm: false, hasError: true, notErrored: false,
289
+ errorText: copyParam("accountSettings.blockedUnblockError", "This member could not be unblocked. Try again.") };
290
+ } finally { unblockInFlight = false; }
291
+ },
292
+ },
293
+ });
294
+
295
+ export { svc };
@@ -0,0 +1,58 @@
1
+ // Branded-lite member Account settings: a menu of four rows (Personal info, Login info, Privacy,
2
+ // Delete account), each area in its own modal screen. Every screen boots this one bundle and loads
3
+ // what it shows itself — the menu reads only whether a member is signed in, so it has no skeleton.
4
+ //
5
+ // himiBrandedAccountSettings the menu (this file)
6
+ // himiBrandedAccountPersonal Personal info (personal-info.ts)
7
+ // himiBrandedAccountLogin Login info (login-info.ts)
8
+ // himiBrandedAccountPassword its Change password step (login-info.ts)
9
+ // himiBrandedAccountPrivacy Privacy (privacy.ts)
10
+ // himiBrandedAccountBlockedMembers Privacy's blocked members (blocked-members.ts)
11
+ import { defineService } from "@himalaya/state";
12
+ import { copyTemplate, stashCopy } from "../_shared/himi-copy.js";
13
+ import { businessNameOf, hostedBusinessName, memberIdentityState } from "./shared.js";
14
+ import { svc as blockedMembers } from "./blocked-members.js";
15
+ import { personalInfo } from "./personal-info.js";
16
+ import { changePassword, loginInfo } from "./login-info.js";
17
+ import { privacy } from "./privacy.js";
18
+
19
+ interface S {
20
+ /** `menu` until a check finds no member signed in; the rows are static, so there is no loading.
21
+ * `error`: the identity could not be read at all, which is not the same as signed out. */
22
+ phase: "menu" | "signedOut" | "error";
23
+ /** "Delete your account on {business}. You can't undo this." */
24
+ deleteBody: string;
25
+ /** The live subtitle of every Account settings modal (`topBar.subtitlePath`): the hosted site's
26
+ * name, else the business the descriptor names. "" keeps the descriptor's own subtitle. */
27
+ businessName: string;
28
+ }
29
+
30
+ const EMPTY: S = { phase: "menu", deleteBody: "", businessName: hostedBusinessName };
31
+ let loadVersion = 0;
32
+ /** The business name from the last load that carried the descriptor's params. A host reloads the
33
+ * worker without them too (Android, after a sign-in), and the Delete row must still name it. */
34
+ let businessName = hostedBusinessName;
35
+
36
+ const svc = defineService<S, {
37
+ load: (s: S, arg?: unknown) => Promise<S>;
38
+ }>("himiBrandedAccountSettings", {
39
+ state: { ...EMPTY },
40
+ notHydrated: ["phase", "businessName"],
41
+ actions: {
42
+ load: async (s, arg): Promise<S> => {
43
+ const version = ++loadVersion;
44
+ stashCopy(arg);
45
+ businessName = businessNameOf(arg) || businessName;
46
+ // Never a sentence with an empty name: without one yet, keep what the row already shows.
47
+ const deleteBody = businessName
48
+ ? copyTemplate("accountSettings.deleteRowBody", "Delete your account on {business}. You can't undo this.", { business: businessName })
49
+ : s.deleteBody;
50
+ const identity = await memberIdentityState();
51
+ const phase: S["phase"] = identity === "member" ? "menu" : identity === "guest" ? "signedOut" : "error";
52
+ if (version !== loadVersion) return svc.getState();
53
+ return { phase, deleteBody, businessName };
54
+ },
55
+ },
56
+ });
57
+
58
+ export { svc, personalInfo, loginInfo, changePassword, privacy, blockedMembers };
@@ -0,0 +1,274 @@
1
+ // Login info — the login email (read only) and the Password section — and its Change password
2
+ // step, pushed in the same page sheet. Nothing in Login info is edited in place, so it has no Save.
3
+ //
4
+ // The Password section is a row to Change password only where this app can change it (a native
5
+ // app on HimalayaCore 1.5.0 or later). Elsewhere it is a grey notice: "in preview mode" on the web
6
+ // host, "here" in every other case, with Go to website when the site has a real URL. There is no
7
+ // change-email feature: the login email is changed on the website, and this modal does not say so.
8
+ import { dispatch } from "@himalaya/dispatch";
9
+ import { open as openUrl } from "@himalaya/open-url";
10
+ import { defineService } from "@himalaya/state";
11
+ import { snackbar } from "@himalaya/ui";
12
+ import { getMyMember } from "@himalaya/wix-members";
13
+ import { memberAccess } from "../_shared/member-access.js";
14
+ import { memberAccountRoutes } from "../_shared/member-account-routes.js";
15
+ import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
16
+ import {
17
+ clean, fetchMember, isSignedOut, loadErrorVariant, passwordCase, passwordMode, rawText, sameAccess, signedOutError, siteHandoffAvailable,
18
+ type PasswordMode, type WixMemberResponse,
19
+ } from "./shared.js";
20
+
21
+ // ---- Login info ----
22
+
23
+ interface LoginState {
24
+ phase: "loading" | "ready" | "error" | "signedOut";
25
+ errorVariant: "offline" | "server";
26
+ loginEmail: string;
27
+ passwordMode: PasswordMode;
28
+ /** row | preview | preview-link | here | here-link — the case the Password section draws. */
29
+ passwordCase: string;
30
+ siteUrl: string;
31
+ }
32
+
33
+ const LOGIN_EMPTY: LoginState = { phase: "loading", errorVariant: "server", loginEmail: "", passwordMode: "notice-here", passwordCase: "here", siteUrl: "" };
34
+ let loginLoadVersion = 0;
35
+
36
+ const login = defineService<LoginState, {
37
+ load: (s: LoginState, arg?: unknown) => Promise<LoginState>;
38
+ showLoading: (s: LoginState) => LoginState;
39
+ openSite: (s: LoginState) => Promise<LoginState>;
40
+ }>("himiBrandedAccountLogin", {
41
+ state: { ...LOGIN_EMPTY },
42
+ notHydrated: Object.keys(LOGIN_EMPTY) as (keyof LoginState)[],
43
+ notPersisted: Object.keys(LOGIN_EMPTY) as (keyof LoginState)[],
44
+ actions: {
45
+ showLoading: () => ({ ...LOGIN_EMPTY }),
46
+ load: async (_s, arg): Promise<LoginState> => {
47
+ const version = ++loginLoadVersion;
48
+ stashCopy(arg);
49
+ if (login.getState().phase !== "loading") await login.showLoading();
50
+ try {
51
+ const { member, email, scope, siteUrl } = await fetchMember((arg as { siteUrl?: unknown } | undefined)?.siteUrl);
52
+ const routes = await memberAccountRoutes();
53
+ // The member read above must still be the one signed in after the routes read.
54
+ if (!(await sameAccess(email, scope))) throw signedOutError();
55
+ if (version !== loginLoadVersion) return login.getState();
56
+ const mode = passwordMode(routes);
57
+ return {
58
+ phase: "ready",
59
+ errorVariant: "server",
60
+ loginEmail: clean(member.loginEmail) || email,
61
+ passwordMode: mode,
62
+ passwordCase: passwordCase(mode, siteHandoffAvailable(siteUrl)),
63
+ siteUrl,
64
+ };
65
+ } catch (error) {
66
+ if (version !== loginLoadVersion) return login.getState();
67
+ return { ...LOGIN_EMPTY, phase: isSignedOut(error) ? "signedOut" : "error", errorVariant: loadErrorVariant(error) };
68
+ }
69
+ },
70
+ // Go to website: a missing, malformed or placeholder site URL has no handoff.
71
+ openSite: async (s): Promise<LoginState> => {
72
+ if (!siteHandoffAvailable(s.siteUrl)) return s;
73
+ try { await openUrl(s.siteUrl, "in_app_browser"); } catch { /* the handoff is best-effort */ }
74
+ return s;
75
+ },
76
+ },
77
+ });
78
+
79
+ // ---- Change password ----
80
+
81
+ interface PasswordState {
82
+ phase: "loading" | "ready" | "error" | "signedOut";
83
+ errorVariant: "offline" | "server";
84
+ memberId: string;
85
+ memberEmail: string;
86
+ memberScope: string;
87
+ loginEmail: string;
88
+ currentPassword: string;
89
+ newPassword: string;
90
+ confirmPassword: string;
91
+ dirty: boolean;
92
+ /** Save is active only when all three fields have a value. */
93
+ cannotSave: boolean;
94
+ saving: boolean;
95
+ currentError: string;
96
+ /** Wix refused the new password: the site's length or complexity rules. */
97
+ newError: string;
98
+ confirmError: string;
99
+ /** The banner at the top after a failure that is not a field's. */
100
+ saveError: string;
101
+ noSaveError: boolean;
102
+ resetSending: boolean;
103
+ /** The line under "Forgot password?": the reset link went out, or it could not. */
104
+ resetMessage: string;
105
+ noResetMessage: boolean;
106
+ resetError: string;
107
+ noResetError: boolean;
108
+ }
109
+
110
+ const PASSWORD_EMPTY: PasswordState = {
111
+ phase: "loading", errorVariant: "server", memberId: "", memberEmail: "", memberScope: "", loginEmail: "",
112
+ currentPassword: "", newPassword: "", confirmPassword: "", dirty: false, cannotSave: true, saving: false,
113
+ currentError: "", newError: "", confirmError: "", saveError: "", noSaveError: true,
114
+ resetSending: false, resetMessage: "", noResetMessage: true, resetError: "", noResetError: true,
115
+ };
116
+
117
+ function derivePassword(s: PasswordState): PasswordState {
118
+ const filled = !!s.currentPassword && !!s.newPassword && !!s.confirmPassword;
119
+ return {
120
+ ...s,
121
+ dirty: !!(s.currentPassword || s.newPassword || s.confirmPassword),
122
+ cannotSave: s.phase !== "ready" || !filled || s.saving || s.resetSending,
123
+ noSaveError: !s.saveError,
124
+ noResetMessage: !s.resetMessage,
125
+ noResetError: !s.resetError,
126
+ };
127
+ }
128
+
129
+ type PasswordResult = { status?: string; code?: string; payload?: { status?: string; code?: string; payload?: { code?: string } } } | null;
130
+ type PasswordNext = PasswordState & { _nav?: { presentation: "dismiss" } };
131
+
132
+ let passwordLoadVersion = 0;
133
+ let passwordMutationInFlight = false;
134
+ let passwordResetInFlight = false;
135
+
136
+ // A typed value always lands; Save stays off (`cannotSave`) until the step is ready.
137
+ const setSecret = (key: "currentPassword" | "newPassword" | "confirmPassword") => (s: PasswordState, arg?: unknown): PasswordState => derivePassword({
138
+ ...s,
139
+ [key]: rawText((arg as { value?: unknown } | undefined)?.value),
140
+ ...(key === "currentPassword" ? { currentError: "" } : { newError: "", confirmError: "" }),
141
+ saveError: "",
142
+ });
143
+
144
+ const password = defineService<PasswordState, {
145
+ load: (s: PasswordState, arg?: unknown) => Promise<PasswordState>;
146
+ showLoading: (s: PasswordState) => PasswordState;
147
+ begin: (s: PasswordState, patch: Partial<PasswordState>) => PasswordState;
148
+ setCurrentPassword: (s: PasswordState, arg?: unknown) => PasswordState;
149
+ setNewPassword: (s: PasswordState, arg?: unknown) => PasswordState;
150
+ setConfirmPassword: (s: PasswordState, arg?: unknown) => PasswordState;
151
+ save: (s: PasswordState) => Promise<PasswordNext | undefined>;
152
+ resetPassword: (s: PasswordState) => Promise<PasswordState | undefined>;
153
+ }>("himiBrandedAccountPassword", {
154
+ state: { ...PASSWORD_EMPTY },
155
+ // The passwords never survive the visit: not in the persisted state, not in a hydrated one.
156
+ notHydrated: Object.keys(PASSWORD_EMPTY) as (keyof PasswordState)[],
157
+ notPersisted: Object.keys(PASSWORD_EMPTY) as (keyof PasswordState)[],
158
+ actions: {
159
+ showLoading: () => ({ ...PASSWORD_EMPTY }),
160
+ begin: (s, patch) => derivePassword({ ...s, ...patch }),
161
+ load: async (_s, arg): Promise<PasswordState> => {
162
+ const version = ++passwordLoadVersion;
163
+ stashCopy(arg);
164
+ if (password.getState().phase !== "loading") await password.showLoading();
165
+ try {
166
+ const { member, email, scope } = await fetchMember();
167
+ const routes = await memberAccountRoutes();
168
+ if (!(await sameAccess(email, scope))) throw signedOutError();
169
+ if (version !== passwordLoadVersion) return password.getState();
170
+ // Only reachable from the Login info row, which shows only where the app can change it.
171
+ if (!routes.passwordCredentials) throw new Error("Password changes are not available in this app.");
172
+ return derivePassword({ ...PASSWORD_EMPTY, phase: "ready", memberId: clean(member.id), memberEmail: email, memberScope: scope, loginEmail: clean(member.loginEmail) || email });
173
+ } catch (error) {
174
+ if (version !== passwordLoadVersion) return password.getState();
175
+ return derivePassword({ ...PASSWORD_EMPTY, phase: isSignedOut(error) ? "signedOut" : "error", errorVariant: loadErrorVariant(error) });
176
+ }
177
+ },
178
+ setCurrentPassword: setSecret("currentPassword"),
179
+ setNewPassword: setSecret("newPassword"),
180
+ setConfirmPassword: setSecret("confirmPassword"),
181
+ save: async (s): Promise<PasswordNext | undefined> => {
182
+ if (s.cannotSave || passwordMutationInFlight || passwordResetInFlight) return undefined;
183
+ if (s.newPassword !== s.confirmPassword) {
184
+ return derivePassword({ ...s, confirmError: copyParam("accountSettings.passwordMismatch", "The new passwords do not match.") });
185
+ }
186
+ passwordMutationInFlight = true;
187
+ await password.begin({ saving: true, currentError: "", newError: "", confirmError: "", saveError: "" });
188
+ let code = "";
189
+ try {
190
+ if (!(await sameAccess(s.memberEmail, s.memberScope))) code = "account_changed";
191
+ else {
192
+ const result = await dispatch("himi.wix.changePassword", { currentPassword: s.currentPassword, newPassword: s.newPassword, expectedMemberId: s.memberId }) as PasswordResult;
193
+ if (!(await sameAccess(s.memberEmail, s.memberScope))) code = "account_changed";
194
+ else if (result?.status !== "ok" && result?.payload?.status !== "ok") code = result?.code ?? result?.payload?.code ?? result?.payload?.payload?.code ?? "failed";
195
+ }
196
+ } catch {
197
+ // A binary without the native handler fails closed here; never report success.
198
+ code = "unavailable";
199
+ } finally {
200
+ passwordMutationInFlight = false;
201
+ }
202
+ const latest = password.getState();
203
+ if (!code) {
204
+ void snackbar({ message: copyParam("accountSettings.savedToast", "Your changes are saved."), tone: "info" }).catch(() => undefined);
205
+ return { ...derivePassword({ ...latest, currentPassword: "", newPassword: "", confirmPassword: "", saving: false }), _nav: { presentation: "dismiss" } };
206
+ }
207
+ // A wrong current password or another member: the secrets are cleared and typed again. Any
208
+ // other failure keeps them for the banner's Try again (they live only in this visit's state).
209
+ const cleared = { ...latest, currentPassword: "", newPassword: "", confirmPassword: "", saving: false };
210
+ if (code === "reauthentication_failed") {
211
+ return derivePassword({ ...cleared, currentError: copyParam("accountSettings.passwordReauthenticationFailed", "We could not verify your current password.") });
212
+ }
213
+ if (code === "account_changed") {
214
+ return derivePassword({ ...cleared, saveError: copyParam("accountSettings.passwordAccountChanged", "Your account changed. Sign in again before changing your password.") });
215
+ }
216
+ // The current password was right; only the new one breaks the site's rules. Keep the current
217
+ // one, clear the new pair, and say so under New password.
218
+ if (code === "password_rejected") {
219
+ return derivePassword({
220
+ ...latest, newPassword: "", confirmPassword: "", saving: false,
221
+ newError: copyParam("accountSettings.passwordRequirements", "This password doesn’t meet this site’s requirements. Use a longer password with letters, numbers and symbols."),
222
+ });
223
+ }
224
+ const message = code === "unavailable"
225
+ ? copyParam("accountSettings.passwordUnavailable", "Password changes aren’t available in this session. Sign in again or use the website.")
226
+ : code === "rate_limited"
227
+ ? copyParam("accountSettings.passwordRateLimited", "Too many attempts. Wait a few minutes, then try again.")
228
+ : copyParam("accountSettings.passwordChangeFailed", "Your password was not changed. Try again.");
229
+ return derivePassword({ ...latest, saving: false, saveError: message });
230
+ },
231
+ // Forgot password?: the existing reset email, sent to the login email of the member who is
232
+ // still signed in. The result shows under the link.
233
+ resetPassword: async (s): Promise<PasswordState | undefined> => {
234
+ if (s.phase !== "ready" || s.saving || passwordMutationInFlight || passwordResetInFlight || !s.loginEmail) return undefined;
235
+ passwordResetInFlight = true;
236
+ await password.begin({ resetSending: true, resetMessage: "", resetError: "" });
237
+ let code = "";
238
+ let resetEmail = "";
239
+ try {
240
+ const before = await memberAccess();
241
+ const beforeMember = await getMyMember({ fieldsets: ["FULL"] }) as WixMemberResponse;
242
+ const afterRead = await memberAccess();
243
+ // The same login email the screen shows: loginEmail, else the signed-in email.
244
+ resetEmail = clean(beforeMember.member?.loginEmail) || s.memberEmail;
245
+ if (!before.email || before.email !== s.memberEmail || before.scope !== s.memberScope || afterRead.email !== s.memberEmail || afterRead.scope !== s.memberScope || beforeMember.member?.id !== s.memberId || !resetEmail) {
246
+ code = "account_changed";
247
+ } else {
248
+ const result = await dispatch("himi.wix.resetPassword", { email: resetEmail }) as PasswordResult;
249
+ const current = await memberAccess();
250
+ const afterMember = await getMyMember({ fieldsets: ["FULL"] }) as WixMemberResponse;
251
+ const finalAccess = await memberAccess();
252
+ if (current.email !== s.memberEmail || current.scope !== s.memberScope || finalAccess.email !== s.memberEmail || finalAccess.scope !== s.memberScope || afterMember.member?.id !== s.memberId) code = "account_changed";
253
+ else if (result?.status !== "ok" && result?.payload?.status !== "ok") code = "reset_failed";
254
+ }
255
+ } catch {
256
+ code = "reset_failed";
257
+ } finally {
258
+ passwordResetInFlight = false;
259
+ }
260
+ const latest = password.getState();
261
+ if (!code) return derivePassword({ ...latest, resetSending: false, resetMessage: copyTemplate("accountSettings.resetLinkSent", "We sent a reset link to {email}.", { email: resetEmail }), resetError: "" });
262
+ return derivePassword({
263
+ ...latest,
264
+ resetSending: false,
265
+ resetMessage: "",
266
+ resetError: code === "account_changed"
267
+ ? copyParam("accountSettings.passwordAccountChanged", "Your account changed. Sign in again before changing your password.")
268
+ : copyParam("accountSettings.passwordResetFailed", "A reset link could not be sent. Try again."),
269
+ });
270
+ },
271
+ },
272
+ });
273
+
274
+ export { login as loginInfo, password as changePassword };