@wix/himalaya-cli 0.1871.0 → 0.1872.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-module.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/portfolio/src/index.d.ts +19 -0
- package/dist/cli.mjs +89 -39
- package/fixtures/wix-canned.json +8 -0
- package/guides/release-notes.md +18 -0
- package/guides/sdk-reference.json +8 -1
- package/package.json +2 -2
- package/template-icons/professional-services.png +0 -0
- package/templates/bare-fashion/config.ts +37 -2
- package/templates/bare-fashion/dev/index.ts +4006 -48
- package/templates/bare-fashion/himalaya.content.json +15 -0
- package/templates/bare-fashion/tier5-src/_shared/member-account-routes.ts +56 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/branded-lite/dev/index.ts +2 -1
- package/templates/branded-lite/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-coupons/index.ts +13 -2
- package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
- package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/community-club/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/conference/config.ts +43 -1
- package/templates/conference/dev/index.ts +4127 -0
- package/templates/conference/himalaya.content.json +18 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/conference/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/conference/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/events-meetups/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/medical-services/config.ts +42 -0
- package/templates/medical-services/dev/index.ts +4136 -0
- package/templates/medical-services/himalaya.content.json +18 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/medical-services/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/portfolio-creative/dev/index.ts +2 -1
- package/templates/portfolio-creative/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
- package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/professional-services/README.md +55 -0
- package/templates/professional-services/config.ts +436 -0
- package/templates/professional-services/dev/index.ts +44772 -0
- package/templates/professional-services/himalaya.content.json +100 -0
- package/templates/professional-services/himalaya.template.json +16 -0
- package/templates/professional-services/icon.png +0 -0
- package/templates/professional-services/platforms.json +1 -0
- package/templates/professional-services/tier5-src/_shared/app-locale.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/booking-location.ts +147 -0
- package/templates/professional-services/tier5-src/_shared/booking-session.ts +224 -0
- package/templates/professional-services/tier5-src/_shared/branded-lite-hosted.ts +282 -0
- package/templates/professional-services/tier5-src/_shared/branded-load-state.ts +109 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-copy.ts +40 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-history.ts +51 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-message-model.ts +177 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-model.ts +56 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-presenter.ts +587 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-transport.ts +164 -0
- package/templates/professional-services/tier5-src/_shared/chat-live.ts +242 -0
- package/templates/professional-services/tier5-src/_shared/collection-contract.ts +232 -0
- package/templates/professional-services/tier5-src/_shared/collection-query.ts +201 -0
- package/templates/professional-services/tier5-src/_shared/collection-service.ts +429 -0
- package/templates/professional-services/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/professional-services/tier5-src/_shared/engine-intl.ts +538 -0
- package/templates/professional-services/tier5-src/_shared/event-registration.ts +86 -0
- package/templates/professional-services/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/professional-services/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/professional-services/tier5-src/_shared/featured-event.ts +63 -0
- package/templates/professional-services/tier5-src/_shared/group-member-count.ts +15 -0
- package/templates/professional-services/tier5-src/_shared/group-privacy.ts +14 -0
- package/templates/professional-services/tier5-src/_shared/guest-sign-in.ts +36 -0
- package/templates/professional-services/tier5-src/_shared/himi-account.ts +222 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-hidden.ts +66 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-post-row.ts +214 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-saved.ts +64 -0
- package/templates/professional-services/tier5-src/_shared/himi-booking-saved.ts +88 -0
- package/templates/professional-services/tier5-src/_shared/himi-bookings.ts +318 -0
- package/templates/professional-services/tier5-src/_shared/himi-copy.ts +123 -0
- package/templates/professional-services/tier5-src/_shared/himi-events.ts +92 -0
- package/templates/professional-services/tier5-src/_shared/himi-media.ts +33 -0
- package/templates/professional-services/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/professional-services/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/professional-services/tier5-src/_shared/host-events.ts +66 -0
- package/templates/professional-services/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance-form.ts +106 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance-purchase.ts +235 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance.ts +38 -0
- package/templates/professional-services/tier5-src/_shared/iap-worker.ts +127 -0
- package/templates/professional-services/tier5-src/_shared/inbox-rooms.ts +163 -0
- package/templates/professional-services/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/professional-services/tier5-src/_shared/member-access.ts +63 -0
- package/templates/professional-services/tier5-src/_shared/member-account-routes.ts +56 -0
- package/templates/professional-services/tier5-src/_shared/member-avatar.ts +76 -0
- package/templates/professional-services/tier5-src/_shared/member-bookings.ts +107 -0
- package/templates/professional-services/tier5-src/_shared/member-read.ts +82 -0
- package/templates/professional-services/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/professional-services/tier5-src/_shared/notification-target.ts +141 -0
- package/templates/professional-services/tier5-src/_shared/offset-page.ts +10 -0
- package/templates/professional-services/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/professional-services/tier5-src/_shared/payment-setup.ts +6 -0
- package/templates/professional-services/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/professional-services/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/professional-services/tier5-src/_shared/result-snackbar.ts +26 -0
- package/templates/professional-services/tier5-src/_shared/rich-body.ts +78 -0
- package/templates/professional-services/tier5-src/_shared/rich-content-link.ts +34 -0
- package/templates/professional-services/tier5-src/_shared/sign-in-sheet.ts +18 -0
- package/templates/professional-services/tier5-src/_shared/staff-name.ts +18 -0
- package/templates/professional-services/tier5-src/_shared/weekly-goal.ts +111 -0
- package/templates/professional-services/tier5-src/_shared/wix-bi.ts +85 -0
- package/templates/professional-services/tier5-src/_shared/wix-member-links.ts +114 -0
- package/templates/professional-services/tier5-src/_shared/wix-service-price.ts +146 -0
- package/templates/professional-services/tier5-src/business-chat/index.ts +797 -0
- package/templates/professional-services/tier5-src/business-contact/index.ts +6 -0
- package/templates/professional-services/tier5-src/himi-blog-feed/index.ts +444 -0
- package/templates/professional-services/tier5-src/himi-blog-post/index.ts +1239 -0
- package/templates/professional-services/tier5-src/himi-booking-account/index.ts +278 -0
- package/templates/professional-services/tier5-src/himi-booking-bookings/index.ts +475 -0
- package/templates/professional-services/tier5-src/himi-booking-service/index.ts +1197 -0
- package/templates/professional-services/tier5-src/himi-booking-services/index.ts +795 -0
- package/templates/professional-services/tier5-src/himi-booking-time/index.ts +1840 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-coupons/index.ts +96 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-faq/index.ts +6 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-file-share/index.ts +12 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-group/index.ts +310 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-group-about/index.ts +240 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-my-groups/index.ts +237 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-notifications/index.ts +263 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-plans/index.ts +498 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-portfolio/index.ts +136 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-portfolio-project/index.ts +198 -0
- package/templates/professional-services/tier5-src/himi-events-detail/index.ts +1306 -0
- package/templates/professional-services/tier5-src/himi-events-list/index.ts +171 -0
- package/templates/professional-services/tier5-src/himi-events-my-events/index.ts +227 -0
- package/templates/professional-services/tier5-src/himi-events-rsvp/index.ts +230 -0
- package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts +318 -0
- package/templates/professional-services/tier5-src/himi-professional-services-home/index.ts +772 -0
- package/templates/professional-services/tier5-src/himi-store-account/index.ts +1514 -0
- package/templates/professional-services/tier5-src/wix-spaces-coupon-detail/index.ts +43 -0
- package/templates/professional-services/tier5-src/wix-spaces-my-subscriptions/index.ts +89 -0
- package/templates/professional-services/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
- package/templates/professional-services/tokens.json +456 -0
- package/templates/restaurant/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/salon-spa/config.ts +42 -0
- package/templates/salon-spa/dev/index.ts +4136 -0
- package/templates/salon-spa/himalaya.content.json +18 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/salon-spa/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/wholesale-store/config.ts +43 -1
- package/templates/wholesale-store/dev/index.ts +4136 -0
- package/templates/wholesale-store/himalaya.content.json +18 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/wholesale-store/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +5 -1
|
@@ -0,0 +1,1514 @@
|
|
|
1
|
+
import { authFailure, authMessage, identityErrors, type AuthOperation } from "@himalaya/auth";
|
|
2
|
+
// Tier-5 bundle: himi-store — visitor/member account state.
|
|
3
|
+
//
|
|
4
|
+
// SINGLE-SITE BY DESIGN. A Branded Lite build talks to exactly one Wix site, and the
|
|
5
|
+
// binding is the baked Headless `clientId` itself:
|
|
6
|
+
// there is no metaSiteId to move and Wix will not route a consumer token minted for one
|
|
7
|
+
// client at another site. This worker therefore has no site picker — Profile used to carry
|
|
8
|
+
// a "Your sites" list that dispatched `branded_lite.select_site`, which changed the
|
|
9
|
+
// `wix-site-id` header and nothing else, so every read stayed on the baked site while the
|
|
10
|
+
// UI claimed otherwise. Managing several businesses is Owner Lite's job (account auth, a
|
|
11
|
+
// real Sites List, and per-call site scope via `site.forSite`).
|
|
12
|
+
import { defineService, navigate } from "@himalaya/state";
|
|
13
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
14
|
+
import { get as getAppInfo } from "@himalaya/app-info";
|
|
15
|
+
import { getCurrentCart, searchOrders, type WixOrder } from "@himalaya/wix-ecom";
|
|
16
|
+
import { guestProfile, loadMemberProfile, memberIdentity, signedInEmail, strOf, fmtDate, titleCase, type AccountActivityRow, type AccountProfile, type MemberIdentity } from "../_shared/himi-account";
|
|
17
|
+
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
18
|
+
import { signInPageStyle, signInSheetStyle } from "../_shared/sign-in-sheet.js";
|
|
19
|
+
import { atLeast, memberAccountRoutes } from "../_shared/member-account-routes.js";
|
|
20
|
+
import { CONTINUATION_BUDGET_MS, memberScreenTarget, within } from "../_shared/member-screen.js";
|
|
21
|
+
import { createIapCommerce, onlineProgramOrders, pricingPlanOrders, storesProductOrders } from "@himalaya/iap-checkout";
|
|
22
|
+
import { IAP_RESTORE_KEYS, NO_IAP_RESTORE, createIapRestore, resetUnhydratedKeysOnOlderRuntime, type IapRestoreFields } from "../_shared/iap-worker.js";
|
|
23
|
+
|
|
24
|
+
interface AuthRouteInput {
|
|
25
|
+
authContinuation?: string;
|
|
26
|
+
/** Standalone sign-in only: `register` opens the form on Create account. */
|
|
27
|
+
mode?: string;
|
|
28
|
+
intent?: string;
|
|
29
|
+
contextName?: string;
|
|
30
|
+
returnScreenId?: string;
|
|
31
|
+
returnId?: string;
|
|
32
|
+
returnChannelId?: string;
|
|
33
|
+
/** Standalone sign-in only: "1" when it was opened as a modal (sheet / cover). */
|
|
34
|
+
modal?: string;
|
|
35
|
+
/** Modal only: the tab whose stack the return screen opens on once the modal closes. */
|
|
36
|
+
returnTab?: string;
|
|
37
|
+
/** Passed to the return screen as `doneTab` (a booking returns to that tab once confirmed). */
|
|
38
|
+
returnDoneTab?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The screen's boot input survives refresh; consuming it must survive too.
|
|
42
|
+
let routeInputConsumed = false;
|
|
43
|
+
// The form's heading has its copy: a copy pack was stashed, a probe (not the boot load)
|
|
44
|
+
// finished without one, or the visitor switched mode — the form is in use by then.
|
|
45
|
+
let headingReady = false;
|
|
46
|
+
|
|
47
|
+
/** Mid-flow open params land on `himalaya.input` (paramKeys on himi_account). */
|
|
48
|
+
function routeInput(): AuthRouteInput {
|
|
49
|
+
const input = (globalThis as { himalaya?: { input?: AuthRouteInput } }).himalaya?.input;
|
|
50
|
+
return input && typeof input === "object" ? input : {};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The route opened the standalone form on Create account. Read once, before any probe. */
|
|
54
|
+
const ROUTE_ASKS_REGISTER = routeInput().mode === "register";
|
|
55
|
+
|
|
56
|
+
function strField(arg: unknown, key: string): string {
|
|
57
|
+
if (!arg || typeof arg !== "object") return "";
|
|
58
|
+
const raw = (arg as Record<string, unknown>)[key];
|
|
59
|
+
return typeof raw === "string" ? raw.trim() : "";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Mid-flow auth (UX F3): intent + return path from himi.open / himalaya.input. */
|
|
63
|
+
function authIntentFromArg(arg: unknown, prev: Pick<S, "authIntent" | "authContextName" | "returnScreenId" | "returnId" | "returnChannelId">): Pick<S, "authIntent" | "authContextName" | "returnScreenId" | "returnId" | "returnChannelId"> {
|
|
64
|
+
const route = routeInputConsumed ? {} : routeInput();
|
|
65
|
+
return {
|
|
66
|
+
authIntent: strField(arg, "intent") || route.intent || prev.authIntent || "",
|
|
67
|
+
authContextName: strField(arg, "contextName") || route.contextName || prev.authContextName || "",
|
|
68
|
+
returnScreenId: strField(arg, "returnScreenId") || route.returnScreenId || prev.returnScreenId || "",
|
|
69
|
+
returnId: strField(arg, "returnId") || route.returnId || prev.returnId || "",
|
|
70
|
+
returnChannelId: strField(arg, "returnChannelId") || route.returnChannelId || prev.returnChannelId || "",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** How the standalone form leaves. A modal is closed: on web `back` pops the tab's stack,
|
|
75
|
+
* not the modal. A pushed form goes back. */
|
|
76
|
+
function leaveNav(): "dismiss" | "back" {
|
|
77
|
+
return routeInput().modal === "1" ? "dismiss" : "back";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Where a successful sign-in returns to, or null. Never Account itself — that would
|
|
81
|
+
* only push a second copy of the screen the member is already on. */
|
|
82
|
+
function resumeTarget(s: Pick<S, "returnScreenId" | "returnId" | "returnChannelId">): { screenId: string; args?: Record<string, string> } | null {
|
|
83
|
+
if (!s.returnScreenId || s.returnScreenId === "himi_account") return null;
|
|
84
|
+
const doneTab = routeDoneTab();
|
|
85
|
+
return s.returnId || s.returnChannelId || doneTab ? {
|
|
86
|
+
screenId: s.returnScreenId,
|
|
87
|
+
args: { ...(s.returnId ? { id: s.returnId } : {}), ...(s.returnChannelId ? { channelId: s.returnChannelId } : {}), ...(doneTab ? { doneTab } : {}) },
|
|
88
|
+
} : { screenId: s.returnScreenId };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The opener's `returnDoneTab` (a route param): the resumed screen gets it as `doneTab`, so a
|
|
92
|
+
* booking started before sign-in still returns to the tab it began in. Empty when not sent. */
|
|
93
|
+
function routeDoneTab(): string {
|
|
94
|
+
const tab = routeInput().returnDoneTab ?? "";
|
|
95
|
+
return /^[A-Za-z0-9_-]{1,64}$/.test(tab) ? tab : "";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Resume the member-only screen that sent the visitor here, once. The return path is
|
|
99
|
+
* consumed so a later refresh cannot fire it again; the host opens the target only if
|
|
100
|
+
* it is linkable, the same check an authored `himi.open` gets.
|
|
101
|
+
*
|
|
102
|
+
* On the standalone sign-in screen the target is pushed, not a `replace`: on iOS and
|
|
103
|
+
* Android `replace` resets the stack to its root, which would drop the screens the
|
|
104
|
+
* visitor came through. Back from the target shows the form again, and the form sends a
|
|
105
|
+
* member back on appear (settle). With no target the form goes back.
|
|
106
|
+
*
|
|
107
|
+
* A modal form closes. A target pushed from here would open inside the modal (iOS, Android)
|
|
108
|
+
* or under it (web), so a modal that names a `returnTab` hands the target to that tab: the
|
|
109
|
+
* host closes the modal, then pushes it on that tab's stack (Account's member rows). A host
|
|
110
|
+
* showing no such tab (a drawer, a narrow Mac window) drops that request whole, modal and
|
|
111
|
+
* all, so the modal is also dismissed directly: it always closes, and the row opens where
|
|
112
|
+
* the tab exists. With no `returnTab` it only closes, and the screen under it loads again —
|
|
113
|
+
* the screen that opened the modal is the return target. */
|
|
114
|
+
async function resumeAfterAuth(next: S): Promise<S> {
|
|
115
|
+
const target = resumeTarget(next);
|
|
116
|
+
if (!next.isMember) return next;
|
|
117
|
+
const tab = routeInput().modal === "1" ? routeInput().returnTab ?? "" : "";
|
|
118
|
+
if (target && tab && next.standalone) {
|
|
119
|
+
routeInputConsumed = true;
|
|
120
|
+
// The opener's continuation is spent first, so a later form replacement cannot resume it too.
|
|
121
|
+
// "refused" means another form already spent it, or it expired. A host may replace this form
|
|
122
|
+
// when the account changes yet let this sign-in finish (Android Himi Player parks the old
|
|
123
|
+
// worker alive): the replacement opened the screen, so this form only closes. A continuation
|
|
124
|
+
// lives 5 min from the tap, and a guest can take longer (Forgot your password?): a form shown
|
|
125
|
+
// about that long resumes, so an expiry never costs them the screen.
|
|
126
|
+
if (routeInput().authContinuation) {
|
|
127
|
+
const answer = await within(consumeContinuation(target.screenId), CONTINUATION_BUDGET_MS, "unsupported" as const);
|
|
128
|
+
if (answer === "refused" && Date.now() - formShownAt < CONTINUATION_LIFETIME_MS - CONTINUATION_MARGIN_MS) {
|
|
129
|
+
return navigate(derive({ ...next, ...NO_VISIT }), { presentation: leaveNav() });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
void dispatch("himi.open", { presentation: "dismiss" });
|
|
133
|
+
const cleared = derive({ ...next, authIntent: "", authContextName: "", returnScreenId: "", returnId: "", returnChannelId: "" });
|
|
134
|
+
return navigate(cleared, target.args ? { tab, screenId: target.screenId, args: target.args } : { tab, screenId: target.screenId });
|
|
135
|
+
}
|
|
136
|
+
if (!target || routeInput().modal === "1") return next.standalone ? navigate(next, { presentation: leaveNav() }) : next;
|
|
137
|
+
routeInputConsumed = true;
|
|
138
|
+
const cleared = derive({ ...next, authIntent: "", authContextName: "", returnScreenId: "", returnId: "", returnChannelId: "" });
|
|
139
|
+
return navigate(cleared, target);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** How long a host keeps a continuation: 300 s in all three (web authContinuation.ts, iOS and Android
|
|
143
|
+
* AuthProvider). A form shown that long has outlived the one it was opened with. The margin covers
|
|
144
|
+
* the time between the tap and the form's appear. */
|
|
145
|
+
const CONTINUATION_LIFETIME_MS = 300_000;
|
|
146
|
+
const CONTINUATION_MARGIN_MS = 15_000;
|
|
147
|
+
/** When this visit's form appeared (`appearConfig`), for the continuation's lifetime above. */
|
|
148
|
+
let formShownAt = Date.now();
|
|
149
|
+
|
|
150
|
+
/** Spend the host-held continuation an opener began for `screenId` (_shared/member-screen.ts).
|
|
151
|
+
* "confirmed" once, and only after a sign-in made on this form confirmed it for the member signed
|
|
152
|
+
* in now; "refused" otherwise (spent, cancelled, expired, forged); "unsupported" on a host without
|
|
153
|
+
* the contract. */
|
|
154
|
+
async function consumeContinuation(screenId: string): Promise<"confirmed" | "refused" | "unsupported"> {
|
|
155
|
+
try {
|
|
156
|
+
const value = await dispatch("himi.wix.authContinuation", { operation: "consume", target: memberScreenTarget(screenId) }) as
|
|
157
|
+
{ supported?: unknown; confirmed?: unknown; payload?: { supported?: unknown; confirmed?: unknown } } | null;
|
|
158
|
+
const fields = value?.payload ?? value;
|
|
159
|
+
if (fields?.supported !== true) return "unsupported";
|
|
160
|
+
return fields.confirmed === true ? "confirmed" : "refused";
|
|
161
|
+
} catch {
|
|
162
|
+
return "unsupported";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** A modal form whose sign-in replaced this worker. On Android the account change of a sign-in
|
|
167
|
+
* boots a new worker for the open form before `authenticate` returns, so resumeAfterAuth never
|
|
168
|
+
* runs, and this worker sees only a member on the form, which settle sends back. The return
|
|
169
|
+
* path resumes here only with the opener's continuation, which the sign-in on this form
|
|
170
|
+
* confirmed and the host spends once; a route alone never opens it (see settle). */
|
|
171
|
+
async function resumeFromContinuation(next: S, arg: unknown): Promise<S | null> {
|
|
172
|
+
const route = routeInput();
|
|
173
|
+
// Not gated on `routeInputConsumed`: the replacement's boot load settles first and marks the
|
|
174
|
+
// route used. The host's consume is the one-shot authority.
|
|
175
|
+
if (!next.standalone || !next.isMember || strField(arg, "standalone") !== "1") return null;
|
|
176
|
+
if (route.modal !== "1" || !route.returnTab || !route.authContinuation) return null;
|
|
177
|
+
const returnPath = { returnScreenId: route.returnScreenId ?? "", returnId: route.returnId ?? "", returnChannelId: route.returnChannelId ?? "" };
|
|
178
|
+
const target = resumeTarget(returnPath);
|
|
179
|
+
if (!target || await within(consumeContinuation(target.screenId), CONTINUATION_BUDGET_MS, "unsupported" as const) !== "confirmed") return null;
|
|
180
|
+
routeInputConsumed = true;
|
|
181
|
+
void dispatch("himi.open", { presentation: "dismiss" });
|
|
182
|
+
const cleared = derive({ ...next, ...NO_VISIT });
|
|
183
|
+
return navigate(cleared, target.args ? { tab: route.returnTab, screenId: target.screenId, args: target.args } : { tab: route.returnTab, screenId: target.screenId });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** After a probe: a form a sign-in replaced resumes its return path; anything else settles. */
|
|
187
|
+
async function afterProbe(r: { next: S; latest: boolean } | { kept: S; latest: boolean }, arg: unknown): Promise<S> {
|
|
188
|
+
if ("next" in r && r.latest) {
|
|
189
|
+
const resumed = await resumeFromContinuation(r.next, arg);
|
|
190
|
+
if (resumed) return resumed;
|
|
191
|
+
}
|
|
192
|
+
return "next" in r ? settle(r.next, arg, r.latest) : r.latest ? settle(r.kept, arg, true) : r.kept;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Account with a standalone sign-in screen (`signInScreen` appear param): a guest who
|
|
196
|
+
* arrives with a sign-in intent or a return path — a member gate, an old deep link — is
|
|
197
|
+
* sent on to that screen with the same params, once. */
|
|
198
|
+
function forwardToSignIn(next: S): S {
|
|
199
|
+
if (!next.signInScreen || next.isMember || routeInputConsumed) return next;
|
|
200
|
+
if (!next.authIntent && !next.returnScreenId) return next;
|
|
201
|
+
routeInputConsumed = true;
|
|
202
|
+
const args: Record<string, string> = { mode: "signin" };
|
|
203
|
+
for (const key of ["authIntent", "authContextName"] as const) {
|
|
204
|
+
if (next[key]) args[key === "authIntent" ? "intent" : "contextName"] = next[key];
|
|
205
|
+
}
|
|
206
|
+
return openSignIn(derive({ ...next, authIntent: "", authContextName: "", returnScreenId: "", returnId: "", returnChannelId: "" }),
|
|
207
|
+
args, resumeTarget(next));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Account sends a guest to the standalone sign-in screen, with `after`, the member screen to
|
|
211
|
+
* open once signed in. With a `signInPresentation` appear param it opens as that modal, and
|
|
212
|
+
* `after` goes on Account's own tab (`signInReturnTab`) when the modal closes; pushed, the form
|
|
213
|
+
* pushes `after` itself (resumeAfterAuth). */
|
|
214
|
+
function openSignIn(next: S, args: Record<string, string>, after: { screenId: string; args?: Record<string, string> } | null): S {
|
|
215
|
+
const screenId = next.signInScreen || "himi_sign_in";
|
|
216
|
+
const presentation = signInPresentationRequested;
|
|
217
|
+
const back: Record<string, string> = {};
|
|
218
|
+
if (after) {
|
|
219
|
+
back.returnScreenId = after.screenId;
|
|
220
|
+
if (after.args?.id) back.returnId = after.args.id;
|
|
221
|
+
if (after.args?.channelId) back.returnChannelId = after.args.channelId;
|
|
222
|
+
if (after.args?.doneTab) back.returnDoneTab = after.args.doneTab;
|
|
223
|
+
}
|
|
224
|
+
if (!presentation) return navigate(next, { screenId, args: { ...args, ...back } });
|
|
225
|
+
const modalArgs: Record<string, string> = { ...args, modal: "1", ...signInSheetStyle(presentation, signInStyleRequested) };
|
|
226
|
+
// With no tab to open it on, a modal has no way to the member screen: it only closes.
|
|
227
|
+
if (after && signInReturnTabRequested) Object.assign(modalArgs, back, { returnTab: signInReturnTabRequested });
|
|
228
|
+
return navigate(next, { screenId, presentation, args: modalArgs });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** After a load: the standalone sign-in screen sends a member back (a stale link, or a
|
|
232
|
+
* sign-in finished elsewhere); Account forwards a guest with a sign-in intent.
|
|
233
|
+
*
|
|
234
|
+
* The member goes back WITHOUT the return path: only a sign-in made on this form resumes
|
|
235
|
+
* it (authenticate → resumeAfterAuth). The screen is public, so honouring a route's
|
|
236
|
+
* return path here would let a bare link open a member-only screen with no tap. */
|
|
237
|
+
function stashScreenCopy(arg: unknown): void {
|
|
238
|
+
stashCopy(arg);
|
|
239
|
+
if (strField(arg, "copy")) headingReady = true;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function settle(next: S, arg: unknown, latest = true): S {
|
|
243
|
+
// A member on the form goes back. Coming back to the form after the pushed
|
|
244
|
+
// target, iOS re-runs only `load()` with no params and DISCARDS its result, so the move is
|
|
245
|
+
// a dispatch, not `_nav`. Never from the boot load: the appear refresh of the same visit
|
|
246
|
+
// sends it.
|
|
247
|
+
if (next.standalone && next.isMember) {
|
|
248
|
+
routeInputConsumed = true;
|
|
249
|
+
// The form is on its way out: it shows nothing, and "You're signed in" only if it is still
|
|
250
|
+
// here after SIGNED_IN_FALLBACK_MS (a form no refresh sends back).
|
|
251
|
+
// A form already closing after its own sign-in keeps its busy form until it is gone.
|
|
252
|
+
const closing = !!next.leaving;
|
|
253
|
+
// A closing form also keeps its visit: Create account must not turn into Sign in, nor a gate lose its heading.
|
|
254
|
+
const cleared = derive({ ...next, ...(closing ? {} : NO_VISIT), leaving: closing, authBusy: closing || (authInFlight && next.authBusy),
|
|
255
|
+
...(next.signedInFallback ? {} : armSignedInFallback()) });
|
|
256
|
+
// Only the newest probe moves: web re-shows a form with an arg-less load AND the appear
|
|
257
|
+
// refresh, and both may land, any time apart. The boot load never moves.
|
|
258
|
+
if (!latest || strField(arg, "boot") === "1") return cleared;
|
|
259
|
+
// The appear refresh returns `_nav`, which every host applies — binaries from before
|
|
260
|
+
// worker nav dispatch included. Only an arg-less load, whose result iOS
|
|
261
|
+
// discards, dispatches.
|
|
262
|
+
if (strField(arg, "standalone") === "1") return navigate(cleared, { presentation: leaveNav() });
|
|
263
|
+
// Not from a modal: nothing pushed over it comes back to it, and on iOS the closing modal's
|
|
264
|
+
// own screen reloads here once, after it has asked to close — a late dismiss would close
|
|
265
|
+
// whatever modal is open by then.
|
|
266
|
+
if (routeInput().modal !== "1") void dispatch("himi.open", { presentation: leaveNav() });
|
|
267
|
+
return cleared;
|
|
268
|
+
}
|
|
269
|
+
// Account forwards only on an appear refresh: the boot `load()` has no params and its
|
|
270
|
+
// navigation is dropped, so a forward there was lost and used up the one forward.
|
|
271
|
+
if (!strField(arg, "signInScreen")) return next;
|
|
272
|
+
const forwarded = forwardToSignIn(next);
|
|
273
|
+
return forwarded === next ? offerSignIn(next, arg) : forwarded;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Profile (appear param `signInOnAppear: "1"`, set by an app whose top bar leads with the profile avatar): a guest who opens it is
|
|
277
|
+
* offered the standalone sign-in as a sheet, once. The sheet closes by itself or by the guest: either way this screen is under it, so
|
|
278
|
+
* a guest who only closes it stays on the guest Profile. A reload that follows is not a second offer; a member resets it. */
|
|
279
|
+
let signInOffered = false;
|
|
280
|
+
function offerSignIn(next: S, arg: unknown): S {
|
|
281
|
+
if (next.isMember) { signInOffered = false; return next; }
|
|
282
|
+
if (strField(arg, "signInOnAppear") !== "1" || signInOffered || next.standalone) return next;
|
|
283
|
+
signInOffered = true;
|
|
284
|
+
return openSignIn(next, { mode: "signin" }, null);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Reveal "You're signed in" with Continue if a member is still on the form a moment from now: a
|
|
288
|
+
* one-shot host `_poll` (worker timers are not on every host; the Android WebView worker has none).
|
|
289
|
+
* The visit it was armed for is remembered, so a later visit's form is never revealed by it. */
|
|
290
|
+
const SIGNED_IN_POLL_ID = "himi-sign-in-fallback";
|
|
291
|
+
let fallbackVisit = -1;
|
|
292
|
+
function armSignedInFallback(): Partial<S> {
|
|
293
|
+
fallbackVisit = visitSeq;
|
|
294
|
+
return { _poll: { id: SIGNED_IN_POLL_ID, intervalMs: SIGNED_IN_FALLBACK_MS, action: "himiStoreAccount.revealSignedIn", immediate: false } } as Partial<S>;
|
|
295
|
+
}
|
|
296
|
+
const STOP_SIGNED_IN_POLL = { _poll: { id: SIGNED_IN_POLL_ID, stop: true } } as Partial<S>;
|
|
297
|
+
|
|
298
|
+
// A tick reads only the session. The profile is read again only when the signed-in email
|
|
299
|
+
// changes, so an idle tick costs no profile read and no re-render. Account opts in
|
|
300
|
+
// (`pollIdentity`): a sign-in on the standalone screen changes the session while Account
|
|
301
|
+
// stays mounted, and not every host re-runs `load` when it comes back.
|
|
302
|
+
const IDENTITY_POLL = { id: "himi-account-identity", intervalMs: 1500, action: "himiStoreAccount.sync" };
|
|
303
|
+
|
|
304
|
+
/** "Hey, <name>" wants a first name. A profile with no display name carries the email. */
|
|
305
|
+
function greetingName(memberName: string): string {
|
|
306
|
+
const name = memberName.trim();
|
|
307
|
+
const bare = name.includes("@") ? name.slice(0, name.indexOf("@")) : name;
|
|
308
|
+
return bare.split(/\s+/)[0] ?? "";
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Applied once per worker: the standalone screen opens on the mode its route asked for.
|
|
312
|
+
let routeModeApplied = false;
|
|
313
|
+
|
|
314
|
+
/** One visit's form mode and mid-flow return path. Never restored from a snapshot: the
|
|
315
|
+
* snapshot is keyed by screen, not by the route that opened it. */
|
|
316
|
+
const NO_VISIT = {
|
|
317
|
+
isRegistering: false, isRecovering: false,
|
|
318
|
+
authIntent: "", authContextName: "", returnScreenId: "", returnId: "", returnChannelId: "",
|
|
319
|
+
};
|
|
320
|
+
const VISIT_KEYS = Object.keys(NO_VISIT) as (keyof typeof NO_VISIT)[];
|
|
321
|
+
/** The form's own view of this worker session (never restored: a snapshot's would show a form, or a
|
|
322
|
+
* signed-in view, that this worker has not confirmed). */
|
|
323
|
+
const FORM_VIEW_KEYS = ["leaving", "signedInFallback", "hideSignInForm", "hideSignedIn", "hideFormSkeleton", "credentialError", "errorMessage", "noticeMessage", "pendingApproval", "hidePendingApproval", "pendingTitle", "pendingBody"] as const;
|
|
324
|
+
/** What derive() computes from the visit keys. Hydration copies keys without re-deriving,
|
|
325
|
+
* so these stay out of the snapshot with them, or the first paint mixes two visits. */
|
|
326
|
+
const VISIT_DERIVED_KEYS = ["notRegistering", "notRecovering", "hideSignInChoices", "hideShowRegister", "hideShowRecovery", "authTitle", "authBody",
|
|
327
|
+
"hasReturnPath", "noReturnPath", "returnCta"] as const;
|
|
328
|
+
|
|
329
|
+
// Actions are not serialized: two quick Sign in taps both run against the pre-tap
|
|
330
|
+
// state, so without this both would submit credentials and both would resume.
|
|
331
|
+
let authInFlight = false;
|
|
332
|
+
// The sign-in form shows only once a probe of THIS worker has found a guest. Android boots a new
|
|
333
|
+
// worker for the open form when a sign-in changes the account; that worker's first states are a
|
|
334
|
+
// member's, and painting the form for them showed an empty form just before the sheet closed.
|
|
335
|
+
let guestSeen = false;
|
|
336
|
+
// Bumped by every visit to the form, so a fallback timer an earlier visit armed never fires on this one.
|
|
337
|
+
let visitSeq = 0;
|
|
338
|
+
/** How long a member may sit on the form before it says "You're signed in" with Continue. A form
|
|
339
|
+
* that closes by itself (every sign-in made on it, every appear refresh) is gone well before. */
|
|
340
|
+
const SIGNED_IN_FALLBACK_MS = 1500;
|
|
341
|
+
// Never projected or persisted. The renderer retains its own masked draft for retry.
|
|
342
|
+
let passwordDraft = "";
|
|
343
|
+
let editRevision = 0;
|
|
344
|
+
// load, refresh and sync each run a whole probe and replace the whole state. Only the newest
|
|
345
|
+
// one to start may land: a boot `load()` that resolves after the appear refresh would put
|
|
346
|
+
// back a state without the appear params, and a sync that resolves after a Sign out would
|
|
347
|
+
// put the member back.
|
|
348
|
+
let probeSeq = 0;
|
|
349
|
+
let appliedSeq = 0;
|
|
350
|
+
// The appear params belong to the worker session too, like the two flags above: a probe
|
|
351
|
+
// dropped because the visitor typed must not take them with it.
|
|
352
|
+
let signInScreenRequested = "";
|
|
353
|
+
/** Account only: how it opens the standalone sign-in screen ("" = push). */
|
|
354
|
+
let signInPresentationRequested: "" | "sheet" | "full_screen" = "";
|
|
355
|
+
/** Account only: `signInSheetStyle`, "page" when the app opens that sheet as a full page. */
|
|
356
|
+
let signInStyleRequested: "page" | "" = "";
|
|
357
|
+
/** Account only: its tab, where a member screen opens after a modal sign-in. */
|
|
358
|
+
let signInReturnTabRequested = "";
|
|
359
|
+
/** Bumped by Dismiss (before and after the host forgets): a probe that was in flight across a Dismiss
|
|
360
|
+
* read the notice before it was dismissed and must not bring it back. A probe started after it reads
|
|
361
|
+
* the host, which has forgotten, so nothing here outlives that one race. */
|
|
362
|
+
let sessionEndedDismissals = 0;
|
|
363
|
+
/** Bumped by every email edit: a value typed back to what it was is still an edit. */
|
|
364
|
+
let emailEdits = 0;
|
|
365
|
+
let standaloneRequested = false;
|
|
366
|
+
let pollIdentityRequested = false;
|
|
367
|
+
// iOS can start the arg-less boot load after the appear refresh that asks for the row; the
|
|
368
|
+
// newer boot probe must not land, or be kept, without it.
|
|
369
|
+
let restorePurchasesRequested = false;
|
|
370
|
+
/** Profile's "Pages" group (appear param `showPages: "1"`): set on the screen's load by whoever knows the app's top bar
|
|
371
|
+
* leads with the profile avatar, so the drawer's pages stay reachable. Off, the group is hidden. */
|
|
372
|
+
let showPagesRequested = false;
|
|
373
|
+
/** An app's sign-in form that carries the ended-session notice (appear param `sessionEndedNotice: "1"`).
|
|
374
|
+
* Only that form gets the signed-out headline, whose copy only that app's pack translates, and the ended
|
|
375
|
+
* session's address, which only its email field shows, so no form submits it unseen. */
|
|
376
|
+
let sessionEndedNoticeRequested = false;
|
|
377
|
+
// Bumped by every mode switch, so a dropped probe never puts back a mode the visitor left.
|
|
378
|
+
let modeSwitches = 0;
|
|
379
|
+
|
|
380
|
+
interface AppearConfig { mode: Partial<S>; visit: Partial<S> }
|
|
381
|
+
|
|
382
|
+
/** The appear params the worker session has seen so far — read when a state is built, so a
|
|
383
|
+
* probe that started before an appear refresh still carries what that refresh asked for. */
|
|
384
|
+
function appearBase(): Partial<S> {
|
|
385
|
+
return {
|
|
386
|
+
signInScreen: signInScreenRequested,
|
|
387
|
+
standalone: standaloneRequested,
|
|
388
|
+
pollIdentity: pollIdentityRequested,
|
|
389
|
+
restorePurchases: restorePurchasesRequested,
|
|
390
|
+
showPages: showPagesRequested,
|
|
391
|
+
// One `_poll` per state: Account polls identity and never shows the social block.
|
|
392
|
+
...(pollIdentityRequested ? { _poll: { ...IDENTITY_POLL } } : socialRetriesLeft > 0 || flowsRetriesLeft > 0 ? { _poll: { ...SOCIAL_POLL } } : {}),
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** What the appear params ask for. Read before the probe awaits anything. */
|
|
397
|
+
function appearConfig(s: S, arg: unknown): AppearConfig {
|
|
398
|
+
const appearing = strField(arg, "standalone") === "1";
|
|
399
|
+
// Each visit to the form reads its own route again. A pooled worker comes back for a
|
|
400
|
+
// later visit with the same params, after an earlier visit consumed the route.
|
|
401
|
+
if (appearing) {
|
|
402
|
+
routeInputConsumed = false;
|
|
403
|
+
formShownAt = Date.now();
|
|
404
|
+
visitSeq++;
|
|
405
|
+
// A pooled worker serves the next visitor too: the fields mount empty, so the last
|
|
406
|
+
// visit's draft must not be what Sign in submits.
|
|
407
|
+
passwordDraft = "";
|
|
408
|
+
}
|
|
409
|
+
signInScreenRequested ||= strField(arg, "signInScreen") || s.signInScreen;
|
|
410
|
+
const presentation = strField(arg, "signInPresentation");
|
|
411
|
+
if (presentation === "sheet" || presentation === "full_screen") {
|
|
412
|
+
signInPresentationRequested = presentation;
|
|
413
|
+
signInStyleRequested = signInPageStyle(strField(arg, "signInSheetStyle"));
|
|
414
|
+
}
|
|
415
|
+
signInReturnTabRequested ||= strField(arg, "signInReturnTab");
|
|
416
|
+
// Only the sign-in screen's route carries `mode`, so it marks the form from the boot load on.
|
|
417
|
+
standaloneRequested ||= s.standalone || appearing || (!routeInputConsumed && !!routeInput().mode);
|
|
418
|
+
pollIdentityRequested ||= s.pollIdentity || strField(arg, "pollIdentity") === "1";
|
|
419
|
+
restorePurchasesRequested ||= s.restorePurchases || strField(arg, "restorePurchases") === "1";
|
|
420
|
+
showPagesRequested ||= s.showPages || strField(arg, "showPages") === "1";
|
|
421
|
+
sessionEndedNoticeRequested ||= strField(arg, "sessionEndedNotice") === "1";
|
|
422
|
+
// The form opens on the mode its route asked for each time it appears, sign-in by
|
|
423
|
+
// default: a pooled worker reopened with the same params must not open on the mode the
|
|
424
|
+
// last visit toggled to.
|
|
425
|
+
let mode: Partial<S> = {};
|
|
426
|
+
if (standaloneRequested && (!routeModeApplied || appearing)) {
|
|
427
|
+
routeModeApplied = true;
|
|
428
|
+
const asked = strField(arg, "mode") || (routeInputConsumed ? "" : routeInput().mode ?? "");
|
|
429
|
+
const isRegistering = asked === "register";
|
|
430
|
+
if (isRegistering !== !!s.isRegistering || s.isRecovering) {
|
|
431
|
+
mode = { isRegistering, isRecovering: false, ...NO_FOCUS_MODE_SWITCH };
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const visit: Partial<S> = appearing
|
|
435
|
+
// The route's own intent and return path too: a dropped probe must not keep the last
|
|
436
|
+
// visit's (an abandoned gate) for the next Sign in to resume.
|
|
437
|
+
? { email: "", emailTyped: false, firstName: "", lastName: "", password: "", emailError: "", passwordError: "", credentialError: false, message: "", lastNameFocus: "", emailFocus: "", passwordFocus: "",
|
|
438
|
+
leaving: false, signedInFallback: false, pendingApproval: false, ...(authInFlight ? {} : { authBusy: false }), ...authIntentFromArg(arg, NO_VISIT) }
|
|
439
|
+
: {};
|
|
440
|
+
return { mode, visit };
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** The probe's state, or — when it must not land — the appear params alone, on the
|
|
444
|
+
* current state. */
|
|
445
|
+
// Bumped when an appear refresh's visit reset lands. A probe that started before it read the
|
|
446
|
+
// last visit's state, so it must not land over the reset (iOS can start the arg-less load
|
|
447
|
+
// after the appear refresh, from the same pre-reset state).
|
|
448
|
+
let visitsApplied = 0;
|
|
449
|
+
|
|
450
|
+
async function freshProbe(s: S, arg?: unknown): Promise<{ next: S; latest: boolean } | { kept: S; latest: boolean }> {
|
|
451
|
+
const seq = ++probeSeq;
|
|
452
|
+
const revision = editRevision;
|
|
453
|
+
const switches = modeSwitches;
|
|
454
|
+
const visits = visitsApplied;
|
|
455
|
+
const emailsAtStart = emailEdits;
|
|
456
|
+
const config = appearConfig(s, arg);
|
|
457
|
+
const next = await probe(s, arg, config);
|
|
458
|
+
if (authInFlight || revision !== editRevision || seq < appliedSeq || visits !== visitsApplied) {
|
|
459
|
+
const current = svc.getState();
|
|
460
|
+
const mode = authInFlight || switches !== modeSwitches ? {} : config.mode;
|
|
461
|
+
// The new visit's clean form, except for what the visitor typed since it appeared.
|
|
462
|
+
// The email field and its `emailTyped` marker stay as they are after any edit during this probe,
|
|
463
|
+
// even one that typed the same address back.
|
|
464
|
+
const untouched = (key: keyof S) => current[key] === s[key] && (key !== "email" && key !== "emailTyped" || emailsAtStart === emailEdits);
|
|
465
|
+
const visit = Object.fromEntries(Object.entries(config.visit).filter(([key]) => untouched(key as keyof S)));
|
|
466
|
+
// Dropped only because a visit reset landed meanwhile: this is still the newest probe, so
|
|
467
|
+
// it may still move a member off the form (the reset's own probe was not the newest).
|
|
468
|
+
const latest = !authInFlight && revision === editRevision && seq >= appliedSeq && seq === probeSeq;
|
|
469
|
+
// The newest probe's ended-session read still counts when an edit dropped it: the signed-out
|
|
470
|
+
// headline, and the pre-fill for an email the reset empties. An older probe's read never does.
|
|
471
|
+
if (seq === probeSeq) {
|
|
472
|
+
Object.assign(visit, { sessionEnded: next.sessionEnded });
|
|
473
|
+
// The pre-fill lands on an email nobody edited during this probe that is (or is being reset to) empty.
|
|
474
|
+
const emptyUntouched = emailsAtStart === emailEdits && ("email" in visit || !current.email);
|
|
475
|
+
if (next.sessionEnded && next.email && emptyUntouched) Object.assign(visit, { email: next.email, emailTyped: next.emailTyped });
|
|
476
|
+
}
|
|
477
|
+
const kept = derive({ ...current, ...appearBase(), ...mode, ...visit });
|
|
478
|
+
// The reset still landed even though its probe was dropped. Invalidate arg-less loads
|
|
479
|
+
// that started from the previous visit's state before they can restore its return path.
|
|
480
|
+
if (strField(arg, "standalone") === "1") visitsApplied++;
|
|
481
|
+
return { kept, latest };
|
|
482
|
+
}
|
|
483
|
+
appliedSeq = seq;
|
|
484
|
+
if (strField(arg, "standalone") === "1") visitsApplied++;
|
|
485
|
+
// A newer probe is still on its way: this one may land, but must not navigate.
|
|
486
|
+
return { next, latest: seq === probeSeq };
|
|
487
|
+
}
|
|
488
|
+
// Descriptor configuration belongs to the worker session. Keep it even when a
|
|
489
|
+
// delayed profile probe is discarded because the user edited the form.
|
|
490
|
+
let memberAccountLinksRequested = false;
|
|
491
|
+
let cartCountRequested = false;
|
|
492
|
+
const translated = (key: string) => copyParam(key, authMessage(key));
|
|
493
|
+
|
|
494
|
+
// Member Apple / Google sign-in (the host's `himi.wix.socialProviders` / `signInWithSocial`).
|
|
495
|
+
// Module state, like the probe's appear params: a dropped probe must not take the buttons with it.
|
|
496
|
+
const SOCIAL_PROVIDERS = ["apple", "google"] as const;
|
|
497
|
+
type SocialProvider = typeof SOCIAL_PROVIDERS[number];
|
|
498
|
+
let socialProviders: SocialProvider[] = [];
|
|
499
|
+
/** The first runtime that draws the Button style `appleSignIn`. Below it an Apple-platform host draws an
|
|
500
|
+
* unknown style as bare text, so the screen shows its older outlined Apple button there. */
|
|
501
|
+
export const APPLE_SIGN_IN_STYLE_MIN_BINARY = "1.10.0";
|
|
502
|
+
let appleButtonLegacy = false;
|
|
503
|
+
let hostInfo: Awaited<ReturnType<typeof getAppInfo>> | undefined;
|
|
504
|
+
|
|
505
|
+
/** `answered`: the host listed a provider, even one this screen then hides; only a host that listed
|
|
506
|
+
* none may still be booting its auth, so only that one is polled again. */
|
|
507
|
+
type SocialProvidersRead = { ok: true; providers: SocialProvider[]; appleButtonLegacy: boolean; answered: boolean } | { ok: false };
|
|
508
|
+
|
|
509
|
+
/** The providers the host offers: site enables it, binary configured, platform supports it. */
|
|
510
|
+
async function readSocialProviders(): Promise<SocialProvidersRead> {
|
|
511
|
+
try {
|
|
512
|
+
const raw = await dispatch("himi.wix.socialProviders") as { payload?: { providers?: unknown; answered?: unknown }; providers?: unknown; answered?: unknown } | null;
|
|
513
|
+
const listed = raw?.payload?.providers ?? raw?.providers;
|
|
514
|
+
// iOS says the site answered even when its App Review rule left nothing to show; such a [] is final.
|
|
515
|
+
const hostAnswered = (raw?.payload?.answered ?? raw?.answered) === true;
|
|
516
|
+
const providers = Array.isArray(listed) ? SOCIAL_PROVIDERS.filter((p) => listed.includes(p)) : [];
|
|
517
|
+
const read = providers.length ? await getAppInfo().catch(() => undefined) : undefined;
|
|
518
|
+
// A host's platform and runtime do not change: once named, a later failed lookup keeps them.
|
|
519
|
+
if (read && read.platform !== "unknown") hostInfo = read;
|
|
520
|
+
const info = read && read.platform !== "unknown" ? read : hostInfo ?? read;
|
|
521
|
+
const platform = info?.platform;
|
|
522
|
+
// App Review 4.8: on iOS, Google only beside Apple. A current iOS host already answers so; an installed
|
|
523
|
+
// older one still gets this screen over the air and can answer Google alone. Fails closed: only a
|
|
524
|
+
// host that says it is Android or web (neither reviewed by Apple) keeps Google alone, since one that
|
|
525
|
+
// refuses app_info could be iOS. macOS stays covered: App Review applies to Mac apps too.
|
|
526
|
+
if (providers.includes("google") && !providers.includes("apple") && platform !== "android" && platform !== "web") {
|
|
527
|
+
// A lookup that failed outright may be transient: hide Google now, and ask again on the poll.
|
|
528
|
+
return { ok: true, providers: [], appleButtonLegacy: false, answered: info !== undefined };
|
|
529
|
+
}
|
|
530
|
+
// Apple's button only where the host is known to draw it: Android and web always do, an Apple
|
|
531
|
+
// platform from APPLE_SIGN_IN_STYLE_MIN_BINARY; a host that does not say gets the older button.
|
|
532
|
+
const drawsAppleStyle = platform === "android" || platform === "web"
|
|
533
|
+
|| ((platform === "ios" || platform === "macos") && atLeast(info?.binaryVersion ?? "", APPLE_SIGN_IN_STYLE_MIN_BINARY));
|
|
534
|
+
const legacy = !drawsAppleStyle;
|
|
535
|
+
// Listed providers whose platform lookup failed are polled again, so a current host is not left on the older button.
|
|
536
|
+
return { ok: true, providers, appleButtonLegacy: legacy, answered: providers.length > 0 ? info !== undefined : hostAnswered };
|
|
537
|
+
} catch {
|
|
538
|
+
return { ok: false };
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** A failed read keeps what the last read showed: a blip must not take the buttons away. A host
|
|
543
|
+
* without the action (web, an older binary) never answers, so it never shows any. */
|
|
544
|
+
function applySocialProviders(read: SocialProvidersRead): void {
|
|
545
|
+
if (read.ok) { socialProviders = read.providers; appleButtonLegacy = read.appleButtonLegacy; }
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// Which member flows this binding can run (the host's `himi.wix.memberFlows`). A One App binding with no Headless OAuth client
|
|
549
|
+
// signs members in with email and password only, so Create account and Forgot password would fail: the form hides them. Module
|
|
550
|
+
// state like the providers above. A host without the action (web, an older binary) never answers, and the form keeps both,
|
|
551
|
+
// exactly what it showed before.
|
|
552
|
+
let signUpAvailable = true;
|
|
553
|
+
let passwordResetAvailable = true;
|
|
554
|
+
|
|
555
|
+
/** `notReady`: the host said `unavailable` (its auth boot has not wired the provider yet), so the answer is worth asking for again. */
|
|
556
|
+
type MemberFlowsRead = { ok: true; signUp: boolean; passwordReset: boolean } | { ok: false; notReady: boolean };
|
|
557
|
+
|
|
558
|
+
async function readMemberFlows(): Promise<MemberFlowsRead> {
|
|
559
|
+
try {
|
|
560
|
+
const raw = await dispatch("himi.wix.memberFlows") as { status?: unknown; payload?: Record<string, unknown>; signUp?: unknown; passwordReset?: unknown } | null;
|
|
561
|
+
const answer = raw?.payload ?? raw;
|
|
562
|
+
return typeof answer?.signUp === "boolean" && typeof answer?.passwordReset === "boolean"
|
|
563
|
+
? { ok: true, signUp: answer.signUp, passwordReset: answer.passwordReset }
|
|
564
|
+
: { ok: false, notReady: raw?.status === "unavailable" };
|
|
565
|
+
} catch {
|
|
566
|
+
return { ok: false, notReady: false };
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/** A failed or missing read keeps what the last read showed (both flows until a host says otherwise). */
|
|
571
|
+
function applyMemberFlows(read: MemberFlowsRead): void {
|
|
572
|
+
if (read.ok) { signUpAvailable = read.signUp; passwordResetAvailable = read.passwordReset; }
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// An empty list is also what the host answers before its auth boot has wired the provider (a
|
|
576
|
+
// cold launch straight onto the form), so it is re-read on a short poll; a site with no social
|
|
577
|
+
// login stops after a few reads.
|
|
578
|
+
const SOCIAL_POLL = { id: "himi-account-social", intervalMs: 1500, action: "himiStoreAccount.refreshSocial" };
|
|
579
|
+
const SOCIAL_RETRIES = 4;
|
|
580
|
+
let socialRetriesLeft = 0;
|
|
581
|
+
// The member flows are read on the same short poll: before the host's auth boot has wired the provider (a cold launch straight
|
|
582
|
+
// onto the gate screen) it answers `unavailable` and is asked again; a host that does not know the verb (web, an older binary) is not.
|
|
583
|
+
let flowsRetriesLeft = 0;
|
|
584
|
+
|
|
585
|
+
function armFlowsRetry(read: MemberFlowsRead): void {
|
|
586
|
+
flowsRetriesLeft = !read.ok && read.notReady ? SOCIAL_RETRIES : 0;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function armSocialRetry(read: SocialProvidersRead): void {
|
|
590
|
+
if (read.ok) socialRetriesLeft = read.answered ? 0 : SOCIAL_RETRIES;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
async function refreshSocial(): Promise<S> {
|
|
594
|
+
if (socialRetriesLeft > 0) {
|
|
595
|
+
socialRetriesLeft -= 1;
|
|
596
|
+
const read = await readSocialProviders();
|
|
597
|
+
applySocialProviders(read);
|
|
598
|
+
if (read.ok && read.answered) socialRetriesLeft = 0;
|
|
599
|
+
}
|
|
600
|
+
if (flowsRetriesLeft > 0) {
|
|
601
|
+
flowsRetriesLeft -= 1;
|
|
602
|
+
const flows = await readMemberFlows();
|
|
603
|
+
applyMemberFlows(flows);
|
|
604
|
+
if (flows.ok || !flows.notReady) flowsRetriesLeft = 0;
|
|
605
|
+
}
|
|
606
|
+
const ended = await lateSessionEnded();
|
|
607
|
+
const current = svc.getState();
|
|
608
|
+
return derive({ ...current, ...ended(current), ...(socialRetriesLeft > 0 || flowsRetriesLeft > 0 ? {} : { _poll: { id: SOCIAL_POLL.id, stop: true } }) });
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/** This poll runs while the host's auth is not wired yet (a cold launch straight into the form), so the
|
|
612
|
+
* form's own identity reads may have seen no ended session: ask again until it is. */
|
|
613
|
+
async function lateSessionEnded(): Promise<(s: S) => Partial<S>> {
|
|
614
|
+
const before = svc.getState();
|
|
615
|
+
if (!standaloneRequested || before.isMember || before.sessionEnded) return () => ({});
|
|
616
|
+
const dismissals = sessionEndedDismissals;
|
|
617
|
+
const identity = await memberIdentity();
|
|
618
|
+
return (s) => {
|
|
619
|
+
if (identity.signedIn || !identity.sessionEnded || dismissals !== sessionEndedDismissals || s.isMember) return {};
|
|
620
|
+
return { sessionEnded: true, ...(s.email || s.emailTyped ? {} : endedSessionEmail(true, false, identity.lastEmail)) };
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function socialCancelled(raw: unknown): boolean {
|
|
625
|
+
const value = raw as { code?: unknown; error?: unknown; payload?: { code?: unknown; error?: unknown } } | null;
|
|
626
|
+
return [value?.code, value?.error, value?.payload?.code, value?.payload?.error].includes("cancelled");
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/** The host refused because another provider's sheet is up (iOS `socialSignInBlocked`), as a result or a throw. That attempt
|
|
630
|
+
* carries on and reports itself, so this tap says nothing. iOS rejects with the Swift error's
|
|
631
|
+
* description, which has no structured form to parse, hence the string match. */
|
|
632
|
+
function socialBusy(error: unknown): boolean {
|
|
633
|
+
const value = error as { code?: unknown; error?: unknown; message?: unknown; payload?: { code?: unknown; error?: unknown } } | null;
|
|
634
|
+
return [value?.code, value?.error, value?.payload?.code, value?.payload?.error].includes("busy")
|
|
635
|
+
|| String(value?.message ?? "").includes('IdentityFailure(code: "busy")');
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** One generic line. The email path's credential copy ("wrong password") never fits a social failure. */
|
|
639
|
+
function socialFailureMessage(error: unknown): string {
|
|
640
|
+
const failure = authFailure(error, "signIn", translated);
|
|
641
|
+
return failure.code === "invalid_credentials" ? authFailure({ code: "unknown" }, "signIn", translated).reason : failure.reason;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
async function signInWithSocial(arg: unknown): Promise<S | undefined> {
|
|
645
|
+
const provider = socialProviders.find((p) => p === strField(arg, "provider"));
|
|
646
|
+
if (authInFlight || !provider) return undefined;
|
|
647
|
+
authInFlight = true;
|
|
648
|
+
try {
|
|
649
|
+
await svc.beginAuth();
|
|
650
|
+
const raw = await dispatch("himi.wix.signInWithSocial", {
|
|
651
|
+
provider,
|
|
652
|
+
...(routeInput().authContinuation ? { authContinuation: routeInput().authContinuation } : {}),
|
|
653
|
+
});
|
|
654
|
+
// Before rejectResult, which would turn either into a generic failure.
|
|
655
|
+
if (socialCancelled(raw) || socialBusy(raw)) return derive({ ...svc.getState(), authBusy: false });
|
|
656
|
+
rejectResult(raw, "signIn");
|
|
657
|
+
const next = await probe(svc.getState());
|
|
658
|
+
if (!next.isMember) throw { code: "unknown" };
|
|
659
|
+
passwordDraft = "";
|
|
660
|
+
return await resumeAfterAuth(completedAuth(next));
|
|
661
|
+
} catch (error) {
|
|
662
|
+
const quiet = socialCancelled(error) || socialBusy(error);
|
|
663
|
+
// A member waiting for the owner's approval gets the Pending approval panel, as on the email path.
|
|
664
|
+
const pending = !quiet && authFailure(error, "signIn", translated).code === "pending_approval";
|
|
665
|
+
return derive({ ...svc.getState(), authBusy: false, message: quiet ? "" : socialFailureMessage(error), ...(pending ? { pendingApproval: true } : {}) });
|
|
666
|
+
} finally { authInFlight = false; }
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function validateAuth(s: S, operation: AuthOperation): S {
|
|
670
|
+
const errors = identityErrors({ email: s.email, password: passwordDraft }, operation);
|
|
671
|
+
return derive({ ...s, emailError: errors.email ? translated(errors.email) : "",
|
|
672
|
+
passwordError: errors.password ? translated(errors.password) : "",
|
|
673
|
+
emailFocus: errors.email ? bumpToken(s.emailFocus) : s.emailFocus,
|
|
674
|
+
passwordFocus: !errors.email && errors.password ? bumpToken(s.passwordFocus) : s.passwordFocus,
|
|
675
|
+
credentialError: false, message: "" });
|
|
676
|
+
}
|
|
677
|
+
function rejectResult(raw: unknown, operation: AuthOperation) {
|
|
678
|
+
const value = raw as { status?: string; error?: unknown; payload?: { error?: unknown } } | null;
|
|
679
|
+
if (value?.status === "error" || value?.error || value?.payload?.error) throw authFailure(raw, operation, translated);
|
|
680
|
+
}
|
|
681
|
+
async function authenticate(s: S, operation: "signIn" | "register"): Promise<S | undefined> {
|
|
682
|
+
if (authInFlight) return undefined;
|
|
683
|
+
const checked = validateAuth(s, operation);
|
|
684
|
+
if (checked.emailError || checked.passwordError) return checked;
|
|
685
|
+
authInFlight = true;
|
|
686
|
+
const revision = editRevision;
|
|
687
|
+
const password = passwordDraft;
|
|
688
|
+
try {
|
|
689
|
+
await svc.beginAuth(); // publish busy before waiting for the network
|
|
690
|
+
const raw = await dispatch(operation === "signIn" ? "himi.wix.signInDirect" : "himi.wix.registerDirect", {
|
|
691
|
+
email: s.email.trim(), password,
|
|
692
|
+
// An opaque host-issued token, never a return route. Native commits it before the
|
|
693
|
+
// account change can destroy this worker; the replacement does not need this promise.
|
|
694
|
+
...(routeInput().authContinuation ? { authContinuation: routeInput().authContinuation } : {}),
|
|
695
|
+
...(operation === "register" ? { firstName: s.firstName, lastName: s.lastName } : {}),
|
|
696
|
+
});
|
|
697
|
+
rejectResult(raw, operation);
|
|
698
|
+
// The host has signed the member in: an edit typed meanwhile cannot undo that, so the form
|
|
699
|
+
// completes. (Android keeps this worker across the account change, so nothing else would.)
|
|
700
|
+
const next = await probe(svc.getState());
|
|
701
|
+
if (!next.isMember) {
|
|
702
|
+
if (revision !== editRevision) return derive({ ...svc.getState(), authBusy: false });
|
|
703
|
+
throw { code: "unknown" };
|
|
704
|
+
}
|
|
705
|
+
passwordDraft = "";
|
|
706
|
+
return await resumeAfterAuth(completedAuth(next));
|
|
707
|
+
} catch (error) {
|
|
708
|
+
const current = svc.getState();
|
|
709
|
+
if (revision !== editRevision) return derive({ ...current, authBusy: false, message: "" });
|
|
710
|
+
return failedAuth(current, authFailure(error, operation, translated));
|
|
711
|
+
} finally { authInFlight = false; }
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/** A failure goes where the visitor fixes it, as the Wix branded app routes it: a wrong password
|
|
715
|
+
* under Password (focused, to retype); a taken email, or one with no account, under Email; a
|
|
716
|
+
* member waiting for the owner's approval to the "Pending approval" panel; a password Wix reset
|
|
717
|
+
* to Reset password, with the email kept; anything else (network, too many attempts) above the
|
|
718
|
+
* buttons. */
|
|
719
|
+
function failedAuth(s: S, failure: { code: string; reason: string }): S {
|
|
720
|
+
const base = { ...s, authBusy: false, leaving: false, message: "", credentialError: false };
|
|
721
|
+
if (failure.code === "invalid_credentials") {
|
|
722
|
+
return derive({ ...base, passwordError: failure.reason, credentialError: true, passwordFocus: bumpToken(s.passwordFocus) });
|
|
723
|
+
}
|
|
724
|
+
if (failure.code === "email_in_use" || failure.code === "account_not_found") {
|
|
725
|
+
return derive({ ...base, emailError: failure.reason, emailFocus: bumpToken(s.emailFocus) });
|
|
726
|
+
}
|
|
727
|
+
if (failure.code === "pending_approval") {
|
|
728
|
+
passwordDraft = "";
|
|
729
|
+
// The sheet's panel says it; a form with no panel (Account's inline login) shows the line.
|
|
730
|
+
return derive({ ...base, password: "", pendingApproval: true, message: failure.reason });
|
|
731
|
+
}
|
|
732
|
+
if (failure.code === "password_reset_required") {
|
|
733
|
+
editRevision++; modeSwitches++; passwordDraft = "";
|
|
734
|
+
return derive({ ...base, isRegistering: false, isRecovering: true, password: "", passwordError: "", emailError: "",
|
|
735
|
+
resetSent: false, message: failure.reason, ...NO_FOCUS_MODE_SWITCH });
|
|
736
|
+
}
|
|
737
|
+
return derive({ ...base, message: failure.reason });
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// Next value of a focus token: never empty once requested, and never a value this worker
|
|
741
|
+
// issued before — one counter for every token, not "previous + 1". A visit reset puts a
|
|
742
|
+
// token back to "" while a pooled form's field may still be mounted; "previous + 1" would
|
|
743
|
+
// then republish a value that field already acted on, and it would ignore the request.
|
|
744
|
+
// A counter rather than Date.now() — deterministic under test, and immune to two focus
|
|
745
|
+
// requests landing inside the same millisecond.
|
|
746
|
+
let focusSeq = 0;
|
|
747
|
+
function bumpToken(_previous: string): string {
|
|
748
|
+
return String(++focusSeq);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// A token may be cleared ONLY by a transition that unmounts the field it targets, so
|
|
752
|
+
// the two transitions here clear different sets — the whole rule in two constants.
|
|
753
|
+
//
|
|
754
|
+
// A mode switch re-lays-out the card: the name fields (gated on notRegistering) go
|
|
755
|
+
// away, but Email is rendered in ALL three modes and stays mounted. Clearing
|
|
756
|
+
// `emailFocus` here would be a reset-while-mounted: Email's renderer-side "last token
|
|
757
|
+
// I acted on" survives, so the next bump would republish a value it has already seen
|
|
758
|
+
// and ignores — the Last name → Email chain would silently die after one round-trip.
|
|
759
|
+
const NO_FOCUS_MODE_SWITCH = { lastNameFocus: "" };
|
|
760
|
+
|
|
761
|
+
// Sign-out hides the entire login card (it is gated on isMember), Email included, so
|
|
762
|
+
// here both tokens must go or the re-mounted card auto-focuses Email on logout.
|
|
763
|
+
const NO_FOCUS_ALL = { lastNameFocus: "", emailFocus: "" };
|
|
764
|
+
|
|
765
|
+
// Every focus token, cleared once the visitor types (see setEmail).
|
|
766
|
+
const TYPED = { ...NO_FOCUS_ALL, passwordFocus: "" };
|
|
767
|
+
|
|
768
|
+
function authHeadline(s: S, isRegistering: boolean, isRecovering: boolean): { authTitle: string; authBody: string } {
|
|
769
|
+
if (isRecovering) {
|
|
770
|
+
return {
|
|
771
|
+
authTitle: copyParam("storeAccount.authTitleRecovery", "Reset password"),
|
|
772
|
+
authBody: copyParam("storeAccount.authBodyRecovery", "Enter your member email and we will send a reset link."),
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
if (isRegistering) {
|
|
776
|
+
return {
|
|
777
|
+
authTitle: copyParam("storeAccount.authTitleRegister", "Create account"),
|
|
778
|
+
authBody: copyParam("storeAccount.authBodyRegister", "Create a member account to continue — cart, bookings, RSVPs, and memberships stay with you."),
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
const contextual = intentHeadline(s);
|
|
782
|
+
if (s.sessionEnded && sessionEndedNoticeRequested) {
|
|
783
|
+
// A gate's own title stays ("Sign in to book"); the body says why they are signing in again.
|
|
784
|
+
return contextual
|
|
785
|
+
? { authTitle: contextual.authTitle, authBody: copyParam("storeAccount.sessionEndedBodyContext", "You've been signed out. Sign in again, then we’ll bring you back.") }
|
|
786
|
+
: sessionEndedHeadline();
|
|
787
|
+
}
|
|
788
|
+
return contextual ?? {
|
|
789
|
+
authTitle: copyParam("storeAccount.authTitle", "Welcome"),
|
|
790
|
+
authBody: copyParam("storeAccount.authBody", "Sign in to continue — cart, bookings, RSVPs, and memberships stay with you."),
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/** A mid-flow gate's headline (`authIntent`), or null for a plain sign-in. */
|
|
795
|
+
function intentHeadline(s: S): { authTitle: string; authBody: string } | null {
|
|
796
|
+
switch (s.authIntent) {
|
|
797
|
+
case "join_group":
|
|
798
|
+
return {
|
|
799
|
+
authTitle: copyParam("storeAccount.authTitleJoinGroup", "Sign in to join"),
|
|
800
|
+
authBody: s.authContextName
|
|
801
|
+
? copyTemplate("storeAccount.authBodyJoinGroupNamed", "Sign in to join {name}, then we’ll bring you back.", { name: s.authContextName })
|
|
802
|
+
: copyParam("storeAccount.authBodyJoinGroup", "Sign in to join this group, then we’ll bring you back."),
|
|
803
|
+
};
|
|
804
|
+
case "rsvp":
|
|
805
|
+
return {
|
|
806
|
+
authTitle: copyParam("storeAccount.authTitleRsvp", "Sign in to RSVP"),
|
|
807
|
+
authBody: copyParam("storeAccount.authBodyRsvp", "Sign in to RSVP, then we’ll bring you back."),
|
|
808
|
+
};
|
|
809
|
+
case "book":
|
|
810
|
+
return {
|
|
811
|
+
authTitle: copyParam("storeAccount.authTitleBook", "Sign in to book"),
|
|
812
|
+
authBody: copyParam("storeAccount.authBodyBook", "Sign in to book this time, then we’ll bring you back."),
|
|
813
|
+
};
|
|
814
|
+
case "post":
|
|
815
|
+
return {
|
|
816
|
+
authTitle: copyParam("storeAccount.authTitlePost", "Sign in to post"),
|
|
817
|
+
authBody: copyParam("storeAccount.authBodyPost", "Sign in to join the conversation, then we’ll bring you back."),
|
|
818
|
+
};
|
|
819
|
+
default:
|
|
820
|
+
return null;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/** The member's session ended on its own: the form says why they are signing in again. */
|
|
825
|
+
function sessionEndedHeadline(): { authTitle: string; authBody: string } {
|
|
826
|
+
return {
|
|
827
|
+
authTitle: copyParam("storeAccount.sessionEndedTitle", "You've been signed out"),
|
|
828
|
+
authBody: copyParam("storeAccount.sessionEndedBody", "Sign in again to get back to your cart, orders, and bookings."),
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
interface S extends IapRestoreFields {
|
|
833
|
+
status: "loading" | "ready";
|
|
834
|
+
isMember: boolean;
|
|
835
|
+
notMember: boolean;
|
|
836
|
+
identityLine: string;
|
|
837
|
+
detailLine: string;
|
|
838
|
+
memberName: string;
|
|
839
|
+
memberEmail: string;
|
|
840
|
+
memberImage: string;
|
|
841
|
+
memberInitials: string;
|
|
842
|
+
hasMemberImage: boolean;
|
|
843
|
+
noMemberImage: boolean;
|
|
844
|
+
authTitle: string;
|
|
845
|
+
authBody: string;
|
|
846
|
+
/** The plain sign-in heading this form last showed with the app's copy. Kept across runs: a form
|
|
847
|
+
* opened again shows it until this visit's copy arrives, instead of a form with no title. */
|
|
848
|
+
signInTitle: string;
|
|
849
|
+
signInBody: string;
|
|
850
|
+
/** Mid-flow gate intent (`join_group` | `rsvp` | `book` | `post` | ""). */
|
|
851
|
+
authIntent: string;
|
|
852
|
+
authContextName: string;
|
|
853
|
+
returnScreenId: string;
|
|
854
|
+
returnId: string;
|
|
855
|
+
returnChannelId: string;
|
|
856
|
+
/** Show Continue when an already-signed-in member opens Account with a return path.
|
|
857
|
+
* A sign-in made here resumes on its own (resumeAfterAuth). */
|
|
858
|
+
hasReturnPath: boolean;
|
|
859
|
+
noReturnPath: boolean;
|
|
860
|
+
returnCta: string;
|
|
861
|
+
email: string;
|
|
862
|
+
/** Legacy snapshot slot, always empty. The active form keeps its password in
|
|
863
|
+
* transient memory for retry; hydration never restores a persisted secret. */
|
|
864
|
+
password: string;
|
|
865
|
+
authBusy: boolean;
|
|
866
|
+
/** Legacy binding, always empty: the busy button's spinner says it, not a "Please wait…" line. */
|
|
867
|
+
busyMessage?: string;
|
|
868
|
+
/** A sign-in made on this form succeeded and the form is closing: it stays on screen as it was,
|
|
869
|
+
* its button busy, instead of switching to a signed-in view for the length of the close. */
|
|
870
|
+
leaving: boolean;
|
|
871
|
+
/** A member is still on the form SIGNED_IN_FALLBACK_MS later: show "You're signed in" + Continue. */
|
|
872
|
+
signedInFallback: boolean;
|
|
873
|
+
/** The form: hidden until this worker has seen a guest, and for a member unless leaving. */
|
|
874
|
+
hideSignInForm: boolean;
|
|
875
|
+
/** "You're signed in" + Continue: only the late fallback. */
|
|
876
|
+
hideSignedIn: boolean;
|
|
877
|
+
/** The form's skeleton: shown until this worker knows a guest (form) or a member (nothing) is here. */
|
|
878
|
+
hideFormSkeleton: boolean;
|
|
879
|
+
/** `passwordError` holds "wrong email or password", which an edit to the email clears too. */
|
|
880
|
+
credentialError: boolean;
|
|
881
|
+
/** `message` when it is a failure, for the error line (danger color). */
|
|
882
|
+
errorMessage: string;
|
|
883
|
+
/** `message` when it is good news (reset link sent), for the notice line. */
|
|
884
|
+
noticeMessage: string;
|
|
885
|
+
/** The site approves its members, and this one's request waits for the owner: the form gives way
|
|
886
|
+
* to a "Pending approval" panel, as the Wix branded app's screen of that name does. */
|
|
887
|
+
pendingApproval: boolean;
|
|
888
|
+
hidePendingApproval: boolean;
|
|
889
|
+
pendingTitle: string;
|
|
890
|
+
pendingBody: string;
|
|
891
|
+
emailError: string;
|
|
892
|
+
passwordError: string;
|
|
893
|
+
passwordFocus: string;
|
|
894
|
+
firstName: string;
|
|
895
|
+
lastName: string;
|
|
896
|
+
// Focus TOKENS (`TextFieldProps.focus_path`), not flags: the bound field focuses
|
|
897
|
+
// whenever the token becomes a new non-empty value, so a monotonic counter is the
|
|
898
|
+
// shape — a latched boolean cannot request focus a second time. Every other
|
|
899
|
+
// transition here goes through derive({...s}), which carries them, and they are
|
|
900
|
+
// deliberately never reset: re-publishing a token the renderer has already seen
|
|
901
|
+
// is ignored, which would make the Next key go dead.
|
|
902
|
+
lastNameFocus: string;
|
|
903
|
+
emailFocus: string;
|
|
904
|
+
message: string;
|
|
905
|
+
hideMessage: boolean;
|
|
906
|
+
/** "none" when there is no line, so a slot keyed on it draws nothing on a paint from the saved state. */
|
|
907
|
+
messageKind: "error" | "success" | "none";
|
|
908
|
+
resetSent: boolean;
|
|
909
|
+
isLoading: boolean;
|
|
910
|
+
notLoading: boolean;
|
|
911
|
+
isRegistering: boolean;
|
|
912
|
+
notRegistering: boolean;
|
|
913
|
+
isRecovering: boolean;
|
|
914
|
+
notRecovering: boolean;
|
|
915
|
+
hideSignInChoices: boolean;
|
|
916
|
+
/** The form's Create account / Forgot password links: hidden while registering or recovering, and when the binding
|
|
917
|
+
* cannot run the flow (`himi.wix.memberFlows`). */
|
|
918
|
+
hideShowRegister: boolean;
|
|
919
|
+
hideShowRecovery: boolean;
|
|
920
|
+
hideAppleSignIn: boolean;
|
|
921
|
+
/** Apple's appleSignIn button: hidden without Apple, or on a runtime that cannot draw it. */
|
|
922
|
+
hideAppleSystemButton: boolean;
|
|
923
|
+
/** The older outlined Apple button, shown only on such a runtime. */
|
|
924
|
+
hideAppleLegacyButton: boolean;
|
|
925
|
+
hideGoogleSignIn: boolean;
|
|
926
|
+
/** The social block and its "or" divider: no provider to show, or resetting a password. */
|
|
927
|
+
hideSocialSignIn: boolean;
|
|
928
|
+
activityTitle: string;
|
|
929
|
+
activitySummary: string;
|
|
930
|
+
activityRows: AccountActivityRow[];
|
|
931
|
+
activityEmptyText: string;
|
|
932
|
+
hasActivity: boolean;
|
|
933
|
+
noActivity: boolean;
|
|
934
|
+
/** Set once a descriptor asks for the member-account links (appear param
|
|
935
|
+
* `memberAccountLinks: "1"`). Only then does the probe read app_info, so a descriptor
|
|
936
|
+
* that renders no such link need not declare that capability. */
|
|
937
|
+
memberAccountLinks: boolean;
|
|
938
|
+
/** Hides My Addresses where this runtime cannot reach the address book. */
|
|
939
|
+
noMemberAddresses: boolean;
|
|
940
|
+
/** Hides My Wallet where this runtime cannot reach saved cards. */
|
|
941
|
+
noMemberWallet: boolean;
|
|
942
|
+
/** Set once a descriptor asks for the Restore purchases row (appear param
|
|
943
|
+
* `restorePurchases: "1"`). Only then does the worker reach the App Store layer, so a
|
|
944
|
+
* descriptor that renders no such row need not declare `iap`. */
|
|
945
|
+
restorePurchases: boolean;
|
|
946
|
+
/** Set once a descriptor asks for Profile's "Pages" group (appear param `showPages: "1"`). */
|
|
947
|
+
showPages: boolean;
|
|
948
|
+
/** Hides Profile's "Pages" group until then. */
|
|
949
|
+
hidePages: boolean;
|
|
950
|
+
/** Top-bar cart badge, read only once a descriptor asks for it (appear param
|
|
951
|
+
* `cartCount: "1"`), so an app with no store never reads a cart. A guest has a
|
|
952
|
+
* visitor cart too, so this is read for members and guests alike. */
|
|
953
|
+
cartCount: number;
|
|
954
|
+
/** "Hey, guest" / "Hey, <first name>". */
|
|
955
|
+
greeting: string;
|
|
956
|
+
/** The member's first name alone. Account puts it after its own translated "Hey,":
|
|
957
|
+
* the server translates descriptor copy, never worker copy. */
|
|
958
|
+
greetingFirstName: string;
|
|
959
|
+
/** Guest header: hidden for a member and while the first session check runs. */
|
|
960
|
+
hideGuest: boolean;
|
|
961
|
+
/** Member header and the Sign out footer: hidden for a guest and while loading. */
|
|
962
|
+
hideMember: boolean;
|
|
963
|
+
/** Account only (appear param): the standalone sign-in screen a guest is sent to. */
|
|
964
|
+
signInScreen: string;
|
|
965
|
+
/** The standalone sign-in screen itself (appear param `standalone: "1"`). */
|
|
966
|
+
standalone: boolean;
|
|
967
|
+
/** Account only (appear param `pollIdentity: "1"`): re-read the session on a timer. */
|
|
968
|
+
pollIdentity: boolean;
|
|
969
|
+
/** The host says this visitor's member session ended on its own (`himi.wix.memberIdentity`'s
|
|
970
|
+
* `sessionEnded`): never after their own sign-out, gone once they sign in or dismiss it. */
|
|
971
|
+
sessionEnded: boolean;
|
|
972
|
+
/** Account's "You've been signed out" notice: hidden for a member, while loading, and with no ended session. */
|
|
973
|
+
hideSessionEnded: boolean;
|
|
974
|
+
/** The visitor edited the email field in this visit (a clear included): no pre-fill replaces it. */
|
|
975
|
+
emailTyped?: boolean;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// Restore purchases (App Review 3.1.1) for every vertical the app sells through the App Store. The
|
|
979
|
+
// row shows once purchasing is ready on this host (a bound iOS binary with managed StoreKit), to a
|
|
980
|
+
// guest too: the restore itself asks them to sign in.
|
|
981
|
+
const commerce = createIapCommerce({
|
|
982
|
+
adapters: [onlineProgramOrders, pricingPlanOrders, storesProductOrders],
|
|
983
|
+
onChange: () => { void svc.restorePublish(); },
|
|
984
|
+
});
|
|
985
|
+
const restore = createIapRestore(commerce, { prefix: "storeAccount", repaint: () => { void svc.restorePublish(); } });
|
|
986
|
+
let commerceEntered = false;
|
|
987
|
+
|
|
988
|
+
/** The first entry reads readiness and recovers held purchases; later ones reconcile, as on any
|
|
989
|
+
* screen that sells. */
|
|
990
|
+
function enterCommerce(): void {
|
|
991
|
+
void (commerceEntered ? commerce.reconcile() : commerce.start());
|
|
992
|
+
commerceEntered = true;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
function derive(s: S): S {
|
|
996
|
+
const isRegistering = !!s.isRegistering;
|
|
997
|
+
const isRecovering = !!s.isRecovering;
|
|
998
|
+
const hasActivity = s.activityRows.length > 0;
|
|
999
|
+
// Until the screen's copy pack (or a probe) arrives: the boot state is built before any copy, and
|
|
1000
|
+
// its English default would paint first in a translated app. A plain sign-in shows the heading
|
|
1001
|
+
// this form last showed with the copy; anything else shows none.
|
|
1002
|
+
const signInMode = !isRegistering && !isRecovering && !s.authIntent;
|
|
1003
|
+
const headline = headingReady ? authHeadline(s, isRegistering, isRecovering)
|
|
1004
|
+
: signInMode ? { authTitle: s.signInTitle ?? "", authBody: s.signInBody ?? "" } : { authTitle: "", authBody: "" };
|
|
1005
|
+
// The heading saved for the next visit: never the ended-session one ("You've been signed out").
|
|
1006
|
+
const savesHeading = headingReady && signInMode && !s.sessionEnded;
|
|
1007
|
+
const hasReturnPath = !!s.isMember && !!s.returnScreenId;
|
|
1008
|
+
const loading = s.status === "loading";
|
|
1009
|
+
const name = s.isMember ? greetingName(s.memberName) : "";
|
|
1010
|
+
return {
|
|
1011
|
+
...s,
|
|
1012
|
+
hideMessage: !s.message,
|
|
1013
|
+
messageKind: !s.message ? "none" : s.resetSent ? "success" : "error",
|
|
1014
|
+
resetSent: !!s.message && !!s.resetSent,
|
|
1015
|
+
greeting: name
|
|
1016
|
+
? copyTemplate("storeAccount.greetingMember", "Hey, {name}", { name })
|
|
1017
|
+
: copyParam("storeAccount.greetingGuest", "Hey, guest"),
|
|
1018
|
+
greetingFirstName: name,
|
|
1019
|
+
hideGuest: loading || !!s.isMember,
|
|
1020
|
+
hideMember: loading || !s.isMember,
|
|
1021
|
+
hideSessionEnded: loading || !!s.isMember || !s.sessionEnded,
|
|
1022
|
+
hidePages: !s.showPages,
|
|
1023
|
+
password: "",
|
|
1024
|
+
busyMessage: "",
|
|
1025
|
+
leaving: !!s.leaving,
|
|
1026
|
+
signedInFallback: !!s.signedInFallback,
|
|
1027
|
+
credentialError: !!s.credentialError,
|
|
1028
|
+
pendingApproval: !!s.pendingApproval && !s.isMember,
|
|
1029
|
+
hidePendingApproval: !s.pendingApproval || !!s.isMember,
|
|
1030
|
+
pendingTitle: s.pendingApproval ? translated("auth.gate.pendingApproval.title") : "",
|
|
1031
|
+
pendingBody: s.pendingApproval ? translated("auth.feedback.pending_approval") : "",
|
|
1032
|
+
hideSignInForm: !guestSeen || (!!s.isMember && !s.leaving) || (!!s.pendingApproval && !s.isMember),
|
|
1033
|
+
hideSignedIn: !s.isMember || !!s.leaving || !s.signedInFallback,
|
|
1034
|
+
hideFormSkeleton: guestSeen || !!s.isMember,
|
|
1035
|
+
errorMessage: s.message && !s.resetSent ? s.message : "",
|
|
1036
|
+
noticeMessage: s.message && s.resetSent ? s.message : "",
|
|
1037
|
+
isLoading: s.status === "loading",
|
|
1038
|
+
notLoading: s.status !== "loading",
|
|
1039
|
+
notMember: !s.isMember,
|
|
1040
|
+
isRegistering,
|
|
1041
|
+
notRegistering: !isRegistering,
|
|
1042
|
+
isRecovering,
|
|
1043
|
+
notRecovering: !isRecovering,
|
|
1044
|
+
hideSignInChoices: isRegistering || isRecovering,
|
|
1045
|
+
hideShowRegister: isRegistering || isRecovering || !signUpAvailable,
|
|
1046
|
+
hideShowRecovery: isRegistering || isRecovering || !passwordResetAvailable,
|
|
1047
|
+
hideAppleSignIn: !socialProviders.includes("apple"),
|
|
1048
|
+
hideAppleSystemButton: !socialProviders.includes("apple") || appleButtonLegacy,
|
|
1049
|
+
hideAppleLegacyButton: !socialProviders.includes("apple") || !appleButtonLegacy,
|
|
1050
|
+
hideGoogleSignIn: !socialProviders.includes("google"),
|
|
1051
|
+
hideSocialSignIn: isRecovering || socialProviders.length === 0,
|
|
1052
|
+
hasActivity,
|
|
1053
|
+
noActivity: !hasActivity,
|
|
1054
|
+
...restore.fields(s.restorePurchases && commerce.readiness().status === "ready"),
|
|
1055
|
+
authTitle: headline.authTitle,
|
|
1056
|
+
authBody: headline.authBody,
|
|
1057
|
+
signInTitle: savesHeading ? headline.authTitle : s.signInTitle ?? "",
|
|
1058
|
+
signInBody: savesHeading ? headline.authBody : s.signInBody ?? "",
|
|
1059
|
+
hasReturnPath,
|
|
1060
|
+
noReturnPath: !hasReturnPath,
|
|
1061
|
+
returnCta: s.authIntent === "join_group"
|
|
1062
|
+
? copyParam("storeAccount.returnJoinGroupCta", "Back to group")
|
|
1063
|
+
: s.authIntent === "rsvp"
|
|
1064
|
+
? copyParam("storeAccount.returnRsvpCta", "Back to event")
|
|
1065
|
+
: s.authIntent === "post"
|
|
1066
|
+
? copyParam("storeAccount.returnPostCta", "Back to feed")
|
|
1067
|
+
: copyParam("storeAccount.returnCta", "Continue"),
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
function orderEmail(order: WixOrder): string {
|
|
1072
|
+
return (order.buyerInfo?.email || "").toLowerCase();
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
function itemCount(order: WixOrder): string {
|
|
1076
|
+
const total = (order.lineItems ?? []).reduce((sum, item) => sum + (item.quantity || 1), 0);
|
|
1077
|
+
if (!total) return "";
|
|
1078
|
+
return `${total} ${total === 1 ? "item" : "items"}`;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function orderRow(order: WixOrder): AccountActivityRow {
|
|
1082
|
+
const total = order.priceSummary?.total?.formattedAmount || "";
|
|
1083
|
+
const meta = [fmtDate(order.createdDate), itemCount(order)].filter(Boolean).join(" · ");
|
|
1084
|
+
return {
|
|
1085
|
+
id: order.id || order.number || "order",
|
|
1086
|
+
title: `Order #${order.number || order.id || ""}`.trim(),
|
|
1087
|
+
subtitle: total || "Order total unavailable",
|
|
1088
|
+
meta,
|
|
1089
|
+
status: titleCase(order.fulfillmentStatus || order.paymentStatus) || "Order",
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
async function orderRows(memberEmail: string): Promise<AccountActivityRow[]> {
|
|
1094
|
+
if (!memberEmail) return [];
|
|
1095
|
+
const res = await searchOrders({
|
|
1096
|
+
search: {
|
|
1097
|
+
cursorPaging: { limit: 30 },
|
|
1098
|
+
sort: [{ fieldName: "createdDate", order: "DESC" }],
|
|
1099
|
+
},
|
|
1100
|
+
});
|
|
1101
|
+
return (res.orders ?? [])
|
|
1102
|
+
.filter((order) => orderEmail(order) === memberEmail.toLowerCase())
|
|
1103
|
+
.slice(0, 3)
|
|
1104
|
+
.map(orderRow);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/** A failed read keeps the count the badge last showed (`known`): an unreachable cart
|
|
1108
|
+
* must not read as an emptied one. Before any read succeeds, that is 0 — no badge. */
|
|
1109
|
+
async function cartItemCount(known: number): Promise<number> {
|
|
1110
|
+
try {
|
|
1111
|
+
const cart = await getCurrentCart();
|
|
1112
|
+
return (cart.lineItems ?? []).reduce((n, li) => n + (li.quantity ?? 1), 0);
|
|
1113
|
+
} catch {
|
|
1114
|
+
return known;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
async function probe(s: S, arg?: unknown, config: AppearConfig = appearConfig(s, arg)): Promise<S> {
|
|
1119
|
+
const dismissalsAtStart = sessionEndedDismissals;
|
|
1120
|
+
memberAccountLinksRequested ||= s.memberAccountLinks || strField(arg, "memberAccountLinks") === "1";
|
|
1121
|
+
// A new visit to the form reads its intent and return path from its own route only: the
|
|
1122
|
+
// last visit's (an abandoned gate) must not be resumed by a plain sign-in.
|
|
1123
|
+
const intent = authIntentFromArg(arg, strField(arg, "standalone") === "1" ? NO_VISIT : s);
|
|
1124
|
+
cartCountRequested ||= strField(arg, "cartCount") === "1";
|
|
1125
|
+
// Beside the profile, not after it: the badge must not add a round trip to the paint.
|
|
1126
|
+
// Not asked for (yet — the boot load runs before the appear params): keep the count the
|
|
1127
|
+
// snapshot restored, not a 0 that would empty the badge until the appear refresh lands.
|
|
1128
|
+
const cartCountRead = cartCountRequested ? cartItemCount(s.cartCount ?? 0) : Promise.resolve(s.cartCount ?? 0);
|
|
1129
|
+
const socialRead: Promise<SocialProvidersRead> = standaloneRequested ? readSocialProviders() : Promise.resolve({ ok: false });
|
|
1130
|
+
const flowsRead: Promise<MemberFlowsRead> = standaloneRequested ? readMemberFlows() : Promise.resolve({ ok: false, notReady: false });
|
|
1131
|
+
const identity = await memberIdentity();
|
|
1132
|
+
const guestLine = copyParam("storeAccount.guestDetail", "Sign in to keep your cart and orders connected.");
|
|
1133
|
+
// The sign-in form only needs to know whether someone is signed in: a member is sent on at once.
|
|
1134
|
+
// The member's profile and orders are Account's, two network reads the form would make a member
|
|
1135
|
+
// wait for (a sign-in on the form, or the form Android re-boots for the new account).
|
|
1136
|
+
const profile = standaloneRequested ? sessionProfile(guestLine, identity) : await loadMemberProfile(guestLine, identity);
|
|
1137
|
+
if (!profile.isMember) guestSeen = true;
|
|
1138
|
+
const social = await socialRead;
|
|
1139
|
+
applySocialProviders(social);
|
|
1140
|
+
const flows = await flowsRead;
|
|
1141
|
+
applyMemberFlows(flows);
|
|
1142
|
+
armFlowsRetry(flows);
|
|
1143
|
+
armSocialRetry(social);
|
|
1144
|
+
// Not the boot load: it never carries the copy, and the appear refresh that does is coming.
|
|
1145
|
+
if (strField(arg, "boot") !== "1") headingReady = true;
|
|
1146
|
+
const memberAccountLinks = memberAccountLinksRequested;
|
|
1147
|
+
if (restorePurchasesRequested) enterCommerce();
|
|
1148
|
+
const routes = memberAccountLinks ? await memberAccountRoutes() : { addresses: false, wallet: false };
|
|
1149
|
+
let activityRows: AccountActivityRow[] = [];
|
|
1150
|
+
if (profile.isMember && !standaloneRequested) {
|
|
1151
|
+
try {
|
|
1152
|
+
activityRows = await orderRows(profile.memberEmail);
|
|
1153
|
+
} catch {
|
|
1154
|
+
activityRows = [];
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
const cartCount = await cartCountRead;
|
|
1158
|
+
// After every await: a Dismiss that landed meanwhile wins over this probe's earlier read.
|
|
1159
|
+
const sessionEnded = !profile.isMember && identity.sessionEnded && dismissalsAtStart === sessionEndedDismissals;
|
|
1160
|
+
return derive({
|
|
1161
|
+
...s,
|
|
1162
|
+
...intent,
|
|
1163
|
+
status: "ready",
|
|
1164
|
+
cartCount,
|
|
1165
|
+
isMember: profile.isMember,
|
|
1166
|
+
identityLine: profile.identityLine,
|
|
1167
|
+
detailLine: profile.detailLine,
|
|
1168
|
+
memberName: profile.memberName,
|
|
1169
|
+
memberEmail: profile.memberEmail,
|
|
1170
|
+
memberImage: profile.memberImage,
|
|
1171
|
+
memberInitials: profile.memberInitials,
|
|
1172
|
+
hasMemberImage: profile.hasMemberImage,
|
|
1173
|
+
noMemberImage: profile.noMemberImage,
|
|
1174
|
+
email: profile.memberEmail || s.email,
|
|
1175
|
+
sessionEnded,
|
|
1176
|
+
message: "",
|
|
1177
|
+
memberAccountLinks,
|
|
1178
|
+
...appearBase(),
|
|
1179
|
+
...config.mode,
|
|
1180
|
+
...config.visit,
|
|
1181
|
+
// After the visit reset: the ended session's email fills an empty or still-pre-filled field,
|
|
1182
|
+
// never what was typed.
|
|
1183
|
+
...endedSessionEmail(sessionEnded, config.visit.email === "" ? false : !!s.emailTyped, identity.lastEmail),
|
|
1184
|
+
noMemberAddresses: !routes.addresses,
|
|
1185
|
+
noMemberWallet: !routes.wallet,
|
|
1186
|
+
activityRows,
|
|
1187
|
+
activityTitle: copyParam("storeAccount.activityTitle", "Previous orders"),
|
|
1188
|
+
activitySummary: activityRows.length
|
|
1189
|
+
? `${activityRows.length} recent ${activityRows.length === 1 ? "order" : "orders"}`
|
|
1190
|
+
: copyParam("storeAccount.activityHint", "Orders are loaded from the store."),
|
|
1191
|
+
activityEmptyText: profile.isMember
|
|
1192
|
+
? copyParam("storeAccount.activityEmptyMember", "No previous orders for this member yet.")
|
|
1193
|
+
: copyParam("storeAccount.activityEmptyGuest", "Sign in to see orders."),
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/** The session alone (`himi.wix.memberIdentity`, answered by the host with no network read). */
|
|
1198
|
+
function sessionProfile(guestLine: string, identity: MemberIdentity): AccountProfile {
|
|
1199
|
+
if (!identity.signedIn) return guestProfile(guestLine);
|
|
1200
|
+
return { ...guestProfile(guestLine), isMember: true, identityLine: "", detailLine: identity.email,
|
|
1201
|
+
memberName: identity.email, memberEmail: identity.email };
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/** An ended session's email fills the field until the visitor edits it in this visit (`setEmail`, a
|
|
1205
|
+
* clear included); state, so a discarded probe changes nothing. */
|
|
1206
|
+
function endedSessionEmail(sessionEnded: boolean, typed: boolean, lastEmail: string): Partial<S> {
|
|
1207
|
+
return sessionEnded && !typed && sessionEndedNoticeRequested ? { email: lastEmail } : {};
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
function completedAuth(s: S): S {
|
|
1211
|
+
// The standalone form closes next (resumeAfterAuth): it keeps the form and its busy button on
|
|
1212
|
+
// screen while it does. If it is somehow still here a moment later, the fallback says so.
|
|
1213
|
+
const leaving = !!s.standalone;
|
|
1214
|
+
return derive({
|
|
1215
|
+
...s,
|
|
1216
|
+
...(leaving ? armSignedInFallback() : {}),
|
|
1217
|
+
password: "",
|
|
1218
|
+
authBusy: leaving, leaving, signedInFallback: false,
|
|
1219
|
+
emailError: "", passwordError: "", passwordFocus: "", credentialError: false,
|
|
1220
|
+
firstName: "",
|
|
1221
|
+
lastName: "",
|
|
1222
|
+
// A form that is closing keeps its mode: Create account must not turn into Sign in on the way out.
|
|
1223
|
+
isRegistering: leaving ? !!s.isRegistering : false,
|
|
1224
|
+
isRecovering: false,
|
|
1225
|
+
message: "",
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
const svc = defineService<S, {
|
|
1230
|
+
beginAuth: (s: S) => S;
|
|
1231
|
+
submit: (s: S) => Promise<S | undefined>;
|
|
1232
|
+
load: (s: S, arg?: unknown) => Promise<S>;
|
|
1233
|
+
refresh: (s: S, arg?: unknown) => Promise<S>;
|
|
1234
|
+
clearFormEmail: (s: S) => S;
|
|
1235
|
+
setEmail: (s: S, arg?: unknown) => S;
|
|
1236
|
+
setPassword: (s: S, arg?: unknown) => S;
|
|
1237
|
+
setFirstName: (s: S, arg?: unknown) => S;
|
|
1238
|
+
setLastName: (s: S, arg?: unknown) => S;
|
|
1239
|
+
focusLastName: (s: S) => S;
|
|
1240
|
+
focusEmail: (s: S) => S;
|
|
1241
|
+
showRegister: (s: S) => S;
|
|
1242
|
+
showSignIn: (s: S) => S;
|
|
1243
|
+
showRecovery: (s: S) => S;
|
|
1244
|
+
resetPassword: (s: S) => Promise<S>;
|
|
1245
|
+
signIn: (s: S) => Promise<S | undefined>;
|
|
1246
|
+
register: (s: S) => Promise<S | undefined>;
|
|
1247
|
+
signInWithSocial: (s: S, arg?: unknown) => Promise<S | undefined>;
|
|
1248
|
+
refreshSocial: (s: S) => Promise<S>;
|
|
1249
|
+
signOut: (s: S) => Promise<S>;
|
|
1250
|
+
dismissSessionEnded: (s: S) => Promise<S>;
|
|
1251
|
+
sync: (s: S) => Promise<S | undefined>;
|
|
1252
|
+
openMember: (s: S, arg?: unknown) => Promise<S>;
|
|
1253
|
+
leave: (s: S) => S;
|
|
1254
|
+
restorePublish: (s: S) => S;
|
|
1255
|
+
revealSignedIn: (s: S) => S;
|
|
1256
|
+
closePendingApproval: (s: S) => S;
|
|
1257
|
+
iapRestore: (s: S) => Promise<undefined>;
|
|
1258
|
+
}>("himiStoreAccount", {
|
|
1259
|
+
// The form's email is never stored: after an ended session it is the former member's address, and a
|
|
1260
|
+
// visitor's snapshot is the shared `default` account's.
|
|
1261
|
+
// Nor the headline: a stored "You've been signed out" would paint again after a dismissal.
|
|
1262
|
+
// Nor the lines: "We sent a reset link to <address>" names what the visitor typed.
|
|
1263
|
+
// Nor a visit's field errors: a reopened sheet must not paint the last visit's "Wrong password".
|
|
1264
|
+
// (The view keys that hide or show a part stay stored: unstored, every part would paint at once,
|
|
1265
|
+
// since a node's hiddenPath fails open while unbound.)
|
|
1266
|
+
notPersisted: ["email", "emailTyped", "authTitle", "authBody", "message", "messageKind", "errorMessage", "noticeMessage", "emailError", "passwordError", "credentialError"],
|
|
1267
|
+
notHydrated: ["sessionEnded", "hideSessionEnded", "email", "emailTyped", "message", "hideMessage", "messageKind", "resetSent", "password", "authBusy", ...FORM_VIEW_KEYS, "hideAppleSignIn", "hideAppleSystemButton", "hideAppleLegacyButton", "hideGoogleSignIn", "hideSocialSignIn", "emailError", "passwordError", "passwordFocus", "lastNameFocus", "emailFocus", ...VISIT_KEYS, ...VISIT_DERIVED_KEYS, ...IAP_RESTORE_KEYS],
|
|
1268
|
+
state: derive({
|
|
1269
|
+
status: "loading",
|
|
1270
|
+
isMember: false,
|
|
1271
|
+
notMember: true,
|
|
1272
|
+
identityLine: "",
|
|
1273
|
+
detailLine: "",
|
|
1274
|
+
memberName: "",
|
|
1275
|
+
memberEmail: "",
|
|
1276
|
+
memberImage: "",
|
|
1277
|
+
memberInitials: "M",
|
|
1278
|
+
hasMemberImage: false,
|
|
1279
|
+
noMemberImage: true,
|
|
1280
|
+
authTitle: "Welcome",
|
|
1281
|
+
authBody: "Sign in to continue — cart, bookings, RSVPs, and memberships stay with you.",
|
|
1282
|
+
signInTitle: "",
|
|
1283
|
+
signInBody: "",
|
|
1284
|
+
authIntent: "",
|
|
1285
|
+
authContextName: "",
|
|
1286
|
+
returnScreenId: "",
|
|
1287
|
+
returnId: "",
|
|
1288
|
+
returnChannelId: "",
|
|
1289
|
+
hasReturnPath: false,
|
|
1290
|
+
noReturnPath: true,
|
|
1291
|
+
returnCta: "Continue",
|
|
1292
|
+
email: "",
|
|
1293
|
+
password: "",
|
|
1294
|
+
authBusy: false, emailError: "", passwordError: "", passwordFocus: "",
|
|
1295
|
+
leaving: false, signedInFallback: false, hideSignInForm: true, hideSignedIn: true, hideFormSkeleton: false,
|
|
1296
|
+
credentialError: false, errorMessage: "", noticeMessage: "",
|
|
1297
|
+
pendingApproval: false, hidePendingApproval: true, pendingTitle: "", pendingBody: "",
|
|
1298
|
+
firstName: "",
|
|
1299
|
+
lastName: "",
|
|
1300
|
+
lastNameFocus: "",
|
|
1301
|
+
emailFocus: "",
|
|
1302
|
+
message: "",
|
|
1303
|
+
hideMessage: true,
|
|
1304
|
+
messageKind: "error",
|
|
1305
|
+
resetSent: false,
|
|
1306
|
+
isLoading: true,
|
|
1307
|
+
notLoading: false,
|
|
1308
|
+
// The form's first paint is already on its route's mode: only sign-in's route has `mode`.
|
|
1309
|
+
isRegistering: ROUTE_ASKS_REGISTER,
|
|
1310
|
+
notRegistering: true,
|
|
1311
|
+
isRecovering: false,
|
|
1312
|
+
notRecovering: true,
|
|
1313
|
+
hideSignInChoices: false,
|
|
1314
|
+
hideShowRegister: false,
|
|
1315
|
+
hideShowRecovery: false,
|
|
1316
|
+
hideAppleSignIn: true,
|
|
1317
|
+
hideAppleSystemButton: true,
|
|
1318
|
+
hideAppleLegacyButton: true,
|
|
1319
|
+
hideGoogleSignIn: true,
|
|
1320
|
+
hideSocialSignIn: true,
|
|
1321
|
+
activityTitle: "Previous orders",
|
|
1322
|
+
activitySummary: "",
|
|
1323
|
+
activityRows: [],
|
|
1324
|
+
activityEmptyText: "No previous orders for this member yet.",
|
|
1325
|
+
hasActivity: false,
|
|
1326
|
+
noActivity: true,
|
|
1327
|
+
memberAccountLinks: false,
|
|
1328
|
+
noMemberAddresses: true,
|
|
1329
|
+
noMemberWallet: true,
|
|
1330
|
+
restorePurchases: false,
|
|
1331
|
+
showPages: false,
|
|
1332
|
+
hidePages: true,
|
|
1333
|
+
cartCount: 0,
|
|
1334
|
+
greeting: "Hey, guest",
|
|
1335
|
+
greetingFirstName: "",
|
|
1336
|
+
hideGuest: true,
|
|
1337
|
+
hideMember: true,
|
|
1338
|
+
signInScreen: "",
|
|
1339
|
+
standalone: false,
|
|
1340
|
+
pollIdentity: false,
|
|
1341
|
+
sessionEnded: false,
|
|
1342
|
+
hideSessionEnded: true,
|
|
1343
|
+
...NO_IAP_RESTORE,
|
|
1344
|
+
}),
|
|
1345
|
+
actions: {
|
|
1346
|
+
submit: (s): Promise<S | undefined> => s.isRecovering ? svc.resetPassword() : authenticate(s, s.isRegistering ? "register" : "signIn"),
|
|
1347
|
+
beginAuth: (s) => derive({ ...s, authBusy: true, message: "", emailError: "", passwordError: "" }),
|
|
1348
|
+
load: async (s, arg): Promise<S> => { stashScreenCopy(arg); return afterProbe(await freshProbe(s, arg), arg); },
|
|
1349
|
+
refresh: async (s, arg): Promise<S> => {
|
|
1350
|
+
stashScreenCopy(arg);
|
|
1351
|
+
// A new visit to the form: its bound email field must not show the last visitor's address, nor its
|
|
1352
|
+
// headline the last visit's notice, while this visit's identity read is still on its way.
|
|
1353
|
+
const reopened = strField(arg, "standalone") === "1" && (!!s.email || !!s.emailTyped || !!s.sessionEnded);
|
|
1354
|
+
if (reopened) await svc.clearFormEmail();
|
|
1355
|
+
const start = reopened ? svc.getState() : s;
|
|
1356
|
+
return afterProbe(await freshProbe(start, arg), arg);
|
|
1357
|
+
},
|
|
1358
|
+
// Also drops any probe still in flight: it started before this visit and would put the old address back.
|
|
1359
|
+
// And the last visit's notice: this visit's read says whether the session ended (it may have been dismissed).
|
|
1360
|
+
clearFormEmail: (s) => { visitsApplied++; return derive({ ...s, email: "", emailTyped: false, sessionEnded: false }); },
|
|
1361
|
+
// Idle ticks return undefined, so an unchanged session costs no re-render.
|
|
1362
|
+
sync: async (s): Promise<S | undefined> => {
|
|
1363
|
+
if (authInFlight) return undefined;
|
|
1364
|
+
const identity = await memberIdentity();
|
|
1365
|
+
const email = identity.email.toLowerCase();
|
|
1366
|
+
// An empty read during a poll is a failed read as often as a sign-out (a network blip,
|
|
1367
|
+
// a 5xx): it never turns a member into a guest. Account's own Sign out, and the next
|
|
1368
|
+
// appear refresh, handle a real sign-out. A host that says the session ENDED is not a
|
|
1369
|
+
// failed read: the member is a visitor now and is told so.
|
|
1370
|
+
if (!email && s.isMember && !identity.sessionEnded) return undefined;
|
|
1371
|
+
// A notice that arrived after the last paint (the provider was wired after Account first read
|
|
1372
|
+
// identity) is a change too.
|
|
1373
|
+
if (email === s.memberEmail.toLowerCase() && !!email === s.isMember && identity.sessionEnded === !!s.sessionEnded) return undefined;
|
|
1374
|
+
const r = await freshProbe(s);
|
|
1375
|
+
return "next" in r ? r.next : undefined;
|
|
1376
|
+
},
|
|
1377
|
+
// A row to a member-only screen shows to a guest too. A member opens it; a guest signs
|
|
1378
|
+
// in first, and the sign-in screen then opens the row's screen — as a modal, by closing
|
|
1379
|
+
// and pushing it on this tab (openSignIn) — so Back returns here either way.
|
|
1380
|
+
openMember: async (s, arg): Promise<S> => {
|
|
1381
|
+
const screenId = strField(arg, "screenId");
|
|
1382
|
+
if (!screenId) return s;
|
|
1383
|
+
const member = s.isMember || !!await signedInEmail();
|
|
1384
|
+
// From the state as it is now: a probe may have landed during the identity read.
|
|
1385
|
+
const now = svc.getState();
|
|
1386
|
+
if (member) return navigate(now, { screenId });
|
|
1387
|
+
return openSignIn(now, { mode: "signin" }, { screenId });
|
|
1388
|
+
},
|
|
1389
|
+
// The standalone form's Continue: leaves the form the way it was opened.
|
|
1390
|
+
leave: (s) => navigate(s, { presentation: leaveNav() }),
|
|
1391
|
+
// Typing means any focus request was delivered: clear the tokens (safe while mounted, since
|
|
1392
|
+
// bumpToken never repeats), so a visit rarely ends — and a pooled form rarely reopens —
|
|
1393
|
+
// holding one.
|
|
1394
|
+
// A setter given the value it already has is not an edit: a hidden form's secure field
|
|
1395
|
+
// clears itself on unmount (setPassword("")), and counting that would drop the probe
|
|
1396
|
+
// that is about to move a member off the form.
|
|
1397
|
+
setEmail: (s, arg) => { if (strOf(arg).trim() === s.email) return s; editRevision++; const next = { ...s, ...TYPED, email: strOf(arg).trim(), emailTyped: true, message: "", ...(s.credentialError ? { passwordError: "", credentialError: false } : {}) }; emailEdits++; return derive({ ...next, emailError: s.emailError ? (identityErrors({ email: next.email }, "reset").email ? translated(identityErrors({ email: next.email }, "reset").email!) : "") : "" }); },
|
|
1398
|
+
setPassword: (s, arg) => { if (strOf(arg) === passwordDraft) return s; editRevision++; passwordDraft = strOf(arg); return derive({ ...s, ...TYPED, message: "", credentialError: false, passwordError: s.passwordError && !passwordDraft ? translated("auth.validation.passwordRequired") : "" }); },
|
|
1399
|
+
setFirstName: (s, arg) => { if (strOf(arg) === s.firstName) return s; editRevision++; return derive({ ...s, ...TYPED, firstName: strOf(arg), message: "" }); },
|
|
1400
|
+
setLastName: (s, arg) => { if (strOf(arg) === s.lastName) return s; editRevision++; return derive({ ...s, ...TYPED, lastName: strOf(arg), message: "" }); },
|
|
1401
|
+
// The register form's Next keys. Only first/last name carry one: they share a
|
|
1402
|
+
// single visibility gate (notRegistering) so their target is always on screen.
|
|
1403
|
+
// Email deliberately does NOT chain to password — see the comment on the
|
|
1404
|
+
// descriptor: password is hidden while recovering, and submitLabel is static.
|
|
1405
|
+
focusLastName: (s) => derive({ ...s, lastNameFocus: bumpToken(s.lastNameFocus) }),
|
|
1406
|
+
focusEmail: (s) => derive({ ...s, emailFocus: bumpToken(s.emailFocus) }),
|
|
1407
|
+
// A mode switch RE-LAYS-OUT this card, mounting and unmounting fields behind
|
|
1408
|
+
// `hiddenWhen`. A re-mounted field treats its first seed as "focus me on open", so
|
|
1409
|
+
// a carried-over token would drop the user into the MIDDLE of the form — leaving
|
|
1410
|
+
// register and coming back would open focused on Last name, skipping First name.
|
|
1411
|
+
// Only the tokens whose fields actually unmount here are cleared: see
|
|
1412
|
+
// NO_FOCUS_MODE_SWITCH for why Email's is deliberately NOT among them.
|
|
1413
|
+
showRegister: (s) => { if (authInFlight) return s; editRevision++; modeSwitches++; headingReady = true; return derive({ ...s, isRegistering: true, isRecovering: false, message: "", emailError: "", passwordError: "", ...NO_FOCUS_MODE_SWITCH }) },
|
|
1414
|
+
showSignIn: (s) => { if (authInFlight) return s; editRevision++; modeSwitches++; headingReady = true; return derive({ ...s, isRegistering: false, isRecovering: false, message: "", emailError: "", passwordError: "", ...NO_FOCUS_MODE_SWITCH }) },
|
|
1415
|
+
showRecovery: (s) => { if (authInFlight) return s; editRevision++; modeSwitches++; headingReady = true; return derive({ ...s, isRegistering: false, isRecovering: true, password: "", message: "", emailError: "", passwordError: "", ...NO_FOCUS_MODE_SWITCH }) },
|
|
1416
|
+
resetPassword: async (s): Promise<S> => {
|
|
1417
|
+
if (authInFlight) return s;
|
|
1418
|
+
const checked = validateAuth(s, "reset");
|
|
1419
|
+
if (checked.emailError) return checked;
|
|
1420
|
+
authInFlight = true;
|
|
1421
|
+
const revision = editRevision;
|
|
1422
|
+
try {
|
|
1423
|
+
await svc.beginAuth();
|
|
1424
|
+
const raw = await dispatch("himi.wix.resetPassword", { email: s.email.trim() });
|
|
1425
|
+
rejectResult(raw, "reset");
|
|
1426
|
+
if (revision !== editRevision) return derive({ ...svc.getState(), authBusy: false });
|
|
1427
|
+
return derive({ ...svc.getState(), authBusy: false, isRecovering: false,
|
|
1428
|
+
resetSent: true, message: copyTemplate("storeAccount.resetSentTo", "We sent a reset link to {email}. Check your inbox.", { email: s.email.trim() }) });
|
|
1429
|
+
} catch (error) {
|
|
1430
|
+
if (revision !== editRevision) return derive({ ...svc.getState(), authBusy: false, resetSent: false, message: "" });
|
|
1431
|
+
const failure = authFailure(error, "reset", translated);
|
|
1432
|
+
const current = svc.getState();
|
|
1433
|
+
// No account for this email: said under Email, as at sign in.
|
|
1434
|
+
if (failure.code === "account_not_found") {
|
|
1435
|
+
return derive({ ...current, authBusy: false, resetSent: false, message: "", emailError: failure.reason, emailFocus: bumpToken(current.emailFocus) });
|
|
1436
|
+
}
|
|
1437
|
+
return derive({ ...current, authBusy: false, resetSent: false, message: failure.reason });
|
|
1438
|
+
} finally { authInFlight = false; }
|
|
1439
|
+
},
|
|
1440
|
+
/** "Back to sign in" on the Pending approval panel. */
|
|
1441
|
+
closePendingApproval: (s) => { editRevision++; modeSwitches++; return derive({ ...s, pendingApproval: false, isRegistering: false, isRecovering: false, message: "", emailError: "", passwordError: "", ...NO_FOCUS_MODE_SWITCH }) },
|
|
1442
|
+
signIn: (s) => authenticate(s, "signIn"),
|
|
1443
|
+
register: (s) => authenticate(s, "register"),
|
|
1444
|
+
signInWithSocial: (_s, arg) => signInWithSocial(arg),
|
|
1445
|
+
refreshSocial: () => refreshSocial(),
|
|
1446
|
+
signOut: async (s): Promise<S> => {
|
|
1447
|
+
if (authInFlight) return svc.getState();
|
|
1448
|
+
passwordDraft = ""; editRevision++;
|
|
1449
|
+
routeInputConsumed = true;
|
|
1450
|
+
try { await dispatch("himi.wix.signOut"); } catch { /* ignore */ }
|
|
1451
|
+
// Do NOT re-probe via getMyData after logout — visitor-scoped my-data can
|
|
1452
|
+
// still return a site nickname and resurrect isMember (BUG-3). Trust the
|
|
1453
|
+
// cleared session and paint the guest form immediately.
|
|
1454
|
+
const guest = guestProfile(copyParam("storeAccount.guestDetail", "Sign in to keep your cart and orders connected."));
|
|
1455
|
+
guestSeen = true;
|
|
1456
|
+
const cleared = {
|
|
1457
|
+
...s,
|
|
1458
|
+
...guest,
|
|
1459
|
+
status: "ready" as const,
|
|
1460
|
+
isMember: false,
|
|
1461
|
+
sessionEnded: false,
|
|
1462
|
+
isRegistering: false,
|
|
1463
|
+
isRecovering: false,
|
|
1464
|
+
message: "",
|
|
1465
|
+
password: "",
|
|
1466
|
+
// Signing out re-mounts the whole login card (it hides behind isMember), so a
|
|
1467
|
+
// carried token would auto-focus Email and pop the keyboard the instant the
|
|
1468
|
+
// user logs out. This is the one transition that unmounts Email too, so unlike
|
|
1469
|
+
// the mode switches it clears BOTH tokens.
|
|
1470
|
+
...NO_FOCUS_ALL,
|
|
1471
|
+
activityRows: [] as AccountActivityRow[],
|
|
1472
|
+
activityEmptyText: copyParam("storeAccount.activityEmptyGuest", "Sign in to see orders."),
|
|
1473
|
+
authIntent: "",
|
|
1474
|
+
authContextName: "",
|
|
1475
|
+
returnScreenId: "",
|
|
1476
|
+
returnId: "",
|
|
1477
|
+
returnChannelId: "",
|
|
1478
|
+
// The member's cart stays with the member; the new visitor session has its own.
|
|
1479
|
+
cartCount: cartCountRequested ? await cartItemCount(0) : 0,
|
|
1480
|
+
...(s.pollIdentity ? { _poll: { ...IDENTITY_POLL } } : {}),
|
|
1481
|
+
};
|
|
1482
|
+
return derive(cleared);
|
|
1483
|
+
},
|
|
1484
|
+
// The notice's dismiss: hidden at once, and the host forgets it (an older host has no such verb).
|
|
1485
|
+
dismissSessionEnded: async (): Promise<S> => {
|
|
1486
|
+
sessionEndedDismissals++;
|
|
1487
|
+
try { await dispatch("himi.wix.dismissSessionEnded"); } catch { /* ignore */ }
|
|
1488
|
+
sessionEndedDismissals++;
|
|
1489
|
+
return derive({ ...svc.getState(), sessionEnded: false });
|
|
1490
|
+
},
|
|
1491
|
+
restorePublish: (s) => derive(s),
|
|
1492
|
+
// The fallback timer (armSignedInFallback): a member the form did not send back gets Continue.
|
|
1493
|
+
revealSignedIn: (s) => fallbackVisit === visitSeq && s.standalone && s.isMember && !s.signedInFallback
|
|
1494
|
+
? derive({ ...s, ...STOP_SIGNED_IN_POLL, signedInFallback: true, leaving: false, authBusy: false })
|
|
1495
|
+
: derive({ ...s, ...STOP_SIGNED_IN_POLL }),
|
|
1496
|
+
iapRestore: async () => { await restore.run(); return undefined; },
|
|
1497
|
+
},
|
|
1498
|
+
});
|
|
1499
|
+
|
|
1500
|
+
resetUnhydratedKeysOnOlderRuntime(svc, derive({ ...svc.getState(), ...NO_IAP_RESTORE, ...NO_VISIT, ...NO_FOCUS_ALL, message: "", resetSent: false, passwordFocus: "", leaving: false, signedInFallback: false, credentialError: false, pendingApproval: false, isRegistering: ROUTE_ASKS_REGISTER, sessionEnded: false }), ["sessionEnded", "hideSessionEnded", "message", "hideMessage", "messageKind", "resetSent", ...FORM_VIEW_KEYS, "hideAppleSignIn", "hideAppleSystemButton", "hideAppleLegacyButton", "hideGoogleSignIn", "hideSocialSignIn", ...IAP_RESTORE_KEYS, ...VISIT_KEYS, ...VISIT_DERIVED_KEYS, "lastNameFocus", "emailFocus", "passwordFocus"]);
|
|
1501
|
+
// The host paints this form from the last run's saved state (a guest's form) before this worker
|
|
1502
|
+
// boots. Starting from the skeleton would replace that form and then paint it again: the form, a
|
|
1503
|
+
// skeleton, a form with no title, the title. A guest seen in that run is a guest here until the
|
|
1504
|
+
// probe says otherwise, and the form keeps its last plain heading (`signInTitle`).
|
|
1505
|
+
const booted = svc.getState();
|
|
1506
|
+
if (booted && booted.status === "ready" && !booted.isMember) {
|
|
1507
|
+
guestSeen = true;
|
|
1508
|
+
// This visit's route intent first: a sheet a gate opened ("Sign in to join") never shows the plain heading.
|
|
1509
|
+
Object.assign(booted, derive({ ...booted, ...authIntentFromArg(undefined, NO_VISIT) }));
|
|
1510
|
+
}
|
|
1511
|
+
// `boot` tells settle this is not a visit: the host drops this call's navigation, and the
|
|
1512
|
+
// appear refresh does the visit's moves.
|
|
1513
|
+
svc.load({ boot: "1" });
|
|
1514
|
+
export { svc };
|