@wix/himalaya-cli 0.1637.0 → 0.1638.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 +8 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +25 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{289b89dc660fa050af31f8ce5f22ffd7332a60c7b80b8ffd2b141ec074fb2e22.bin → 3361f61ce6b490c8b7b252658ea67f733d88c6e9f95906d0e31eea4827141df3.bin} +1 -1
- package/dist/browser-plane/sw.js +8 -8
- package/dist/cli.mjs +98 -74
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/android-ux.md +6 -3
- package/guides/himi-json-output.md +7 -0
- package/guides/ios-ux.md +4 -2
- package/package.json +2 -2
- package/templates/beauty-salon/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/beauty-salon/tier5-src/himi-booking-service/index.ts +10 -0
- package/templates/beauty-salon/tier5-src/himi-booking-time/index.ts +20 -5
- package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/branded-lite/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/branded-lite/tier5-src/himi-booking-service/index.ts +10 -0
- package/templates/branded-lite/tier5-src/himi-booking-time/index.ts +20 -5
- package/templates/branded-lite/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/community-club/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/community-club/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/events-meetups/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/events-meetups/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/gym-fitness/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/gym-fitness/tier5-src/himi-booking-service/index.ts +10 -0
- package/templates/gym-fitness/tier5-src/himi-booking-time/index.ts +20 -5
- package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/nonprofit-cause/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/nonprofit-cause/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/podcast-creator/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/podcast-creator/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/portfolio-creative/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/portfolio-creative/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/restaurant/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/restaurant/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/retail-store/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/retail-store/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/salon-spa/dev/index.ts +16 -12
- package/templates/salon-spa/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/salon-spa/tier5-src/himi-booking-account/index.ts +12 -1
- package/templates/salon-spa/tier5-src/himi-booking-service/index.ts +10 -0
- package/templates/salon-spa/tier5-src/himi-booking-time/index.ts +20 -5
- package/templates/salon-spa/tier5-src/himi-salon-home/index.ts +17 -27
- package/templates/salon-spa/tier5-src/himi-store-account/index.ts +71 -4
- package/templates/yoga-studio/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/yoga-studio/tier5-src/himi-booking-service/index.ts +10 -0
- package/templates/yoga-studio/tier5-src/himi-booking-time/index.ts +20 -5
- package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +71 -4
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// "Open a member-only screen" (the business chat): a member goes there; a guest gets the app's
|
|
2
|
+
// sign-in first, never the screen's own guest prompt, and the screen opens once signed in
|
|
3
|
+
// (himi-store-account resumes `returnScreenId`). Salon & Spa offers it from Home and from the
|
|
4
|
+
// shared booking screens (a treatment that cannot be booked online, a Choose a Time with no times),
|
|
5
|
+
// so each of those workers runs the same rule.
|
|
6
|
+
//
|
|
7
|
+
// The tap's params:
|
|
8
|
+
// screenId the member screen
|
|
9
|
+
// signInScreenId the app's sign-in screen; without it the tap opens `screenId` as is
|
|
10
|
+
// signInPresentation "sheet" | "full_screen": the sign-in opens as that modal, and once signed
|
|
11
|
+
// in it closes and opens the screen on `returnTab`. Pushed (no presentation),
|
|
12
|
+
// the sign-in pushes the screen itself.
|
|
13
|
+
// returnTab the tab the screen opens on after a modal sign-in
|
|
14
|
+
//
|
|
15
|
+
// A modal sign-in also carries a host-held continuation (`authContinuation`, begun here for
|
|
16
|
+
// `memberScreenTarget(screenId)`). Where the account change of the sign-in replaces the sign-in
|
|
17
|
+
// worker before it can resume (Android), the replacement consumes it to open the screen, once.
|
|
18
|
+
// A route alone never opens a member screen; old hosts without the contract keep the plain sheet.
|
|
19
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
20
|
+
import type { NavDirective } from "@himalaya/state";
|
|
21
|
+
import { signedInEmail } from "./himi-account.js";
|
|
22
|
+
|
|
23
|
+
/** How long a continuation call may take before the worker goes on without it. Just above the web
|
|
24
|
+
* host's own 4 s identity-read deadline (identityReader.ts), which it runs before answering: a host
|
|
25
|
+
* that answers is never cut off, and one that never answers cannot hold the sheet or the form. */
|
|
26
|
+
export const CONTINUATION_BUDGET_MS = 4_500;
|
|
27
|
+
/** The whole tap (session read, then begin) waits at most this long. On the web host each call runs
|
|
28
|
+
* its own identity read, so a hung host would otherwise cost two full deadlines (~8 s) before the
|
|
29
|
+
* sheet. The session read may use the host's whole deadline; begin then gets what is left, but at
|
|
30
|
+
* least an ordinary read's 1.5 s, so a slow host (2.5 s a read) still hands out the token. */
|
|
31
|
+
const TAP_BUDGET_MS = CONTINUATION_BUDGET_MS + 1_500;
|
|
32
|
+
const MIN_BEGIN_MS = 1_500;
|
|
33
|
+
|
|
34
|
+
/** The continuation target for a member screen, shared with himi-store-account. */
|
|
35
|
+
export const memberScreenTarget = (screenId: string): string => `member_screen:${screenId}`;
|
|
36
|
+
|
|
37
|
+
/** A host-held continuation for `screenId`, or "" (an old host, or a member already). */
|
|
38
|
+
async function beginContinuation(screenId: string): Promise<string> {
|
|
39
|
+
try {
|
|
40
|
+
const value = await dispatch("himi.wix.authContinuation", { operation: "begin", target: memberScreenTarget(screenId) }) as
|
|
41
|
+
{ supported?: unknown; token?: unknown; payload?: { supported?: unknown; token?: unknown } } | null;
|
|
42
|
+
const fields = value?.payload ?? value;
|
|
43
|
+
return fields?.supported === true && typeof fields.token === "string" ? fields.token : "";
|
|
44
|
+
} catch {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const strField = (arg: unknown, key: string): string => {
|
|
50
|
+
const value = (arg as Record<string, unknown> | undefined)?.[key];
|
|
51
|
+
return typeof value === "string" ? value : "";
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** `read`, or `fallback` once `ms` pass, where the engine has a timer. A bare JSContext has no
|
|
55
|
+
* timer; there it waits, as every read does. `read` must not reject. */
|
|
56
|
+
export function within<T>(read: Promise<T>, ms: number, fallback: T): Promise<T> {
|
|
57
|
+
const host = globalThis as { setTimeout?: (fn: () => void, ms: number) => unknown; clearTimeout?: (timer: unknown) => void };
|
|
58
|
+
if (typeof host.setTimeout !== "function") return read;
|
|
59
|
+
return new Promise<T>((resolve) => {
|
|
60
|
+
const timer = host.setTimeout!(() => resolve(fallback), ms);
|
|
61
|
+
void read.then((value) => { host.clearTimeout?.(timer); resolve(value); });
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Where a tap goes, given the session's email ("" for a guest). null: no screen named. */
|
|
66
|
+
export function memberScreenNav(arg: unknown, email: string): NavDirective | null {
|
|
67
|
+
const screenId = strField(arg, "screenId"), signInScreenId = strField(arg, "signInScreenId");
|
|
68
|
+
if (!screenId) return null;
|
|
69
|
+
if (!signInScreenId || email) return { screenId };
|
|
70
|
+
const args: Record<string, string> = { mode: "signin", returnScreenId: screenId };
|
|
71
|
+
const presentation = strField(arg, "signInPresentation");
|
|
72
|
+
if (presentation !== "sheet" && presentation !== "full_screen") return { screenId: signInScreenId, args };
|
|
73
|
+
if (strField(arg, "returnTab")) args.returnTab = strField(arg, "returnTab");
|
|
74
|
+
return { screenId: signInScreenId, presentation, args: { ...args, modal: "1" } };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** One worker's opener. The session is asked at the tap, never read from the last load; a read
|
|
78
|
+
* that never answers counts as a guest, so the tap opens the sign-in rather than nothing. Only the
|
|
79
|
+
* newest tap navigates (no second sheet, no sheet over the screen): an older one answers null. */
|
|
80
|
+
// The session read has the continuation calls' budget: on the web host they all wait on the same
|
|
81
|
+
// identity read, so a shorter cutoff here would take a slow member for a guest and flash the sheet.
|
|
82
|
+
export function memberScreenOpener(readEmail: () => Promise<string> = () => within(signedInEmail(), CONTINUATION_BUDGET_MS, "")): (arg: unknown) => Promise<NavDirective | null> {
|
|
83
|
+
let taps = 0;
|
|
84
|
+
return async (arg) => {
|
|
85
|
+
if (!strField(arg, "screenId")) return null;
|
|
86
|
+
const mine = ++taps;
|
|
87
|
+
const tapped = Date.now();
|
|
88
|
+
const email = strField(arg, "signInScreenId") ? await readEmail() : "";
|
|
89
|
+
if (mine !== taps) return null;
|
|
90
|
+
const nav = memberScreenNav(arg, email);
|
|
91
|
+
if (!nav || !("presentation" in nav) || !nav.args?.modal) return nav;
|
|
92
|
+
// Bounded by what the tap has left (TAP_BUDGET_MS): a host that never answers still opens the
|
|
93
|
+
// plain sheet.
|
|
94
|
+
const left = Math.min(CONTINUATION_BUDGET_MS, Math.max(MIN_BEGIN_MS, TAP_BUDGET_MS - (Date.now() - tapped)));
|
|
95
|
+
const token = await within(beginContinuation(strField(arg, "screenId")), left, "");
|
|
96
|
+
if (mine !== taps) return null;
|
|
97
|
+
return token ? { ...nav, args: { ...nav.args, authContinuation: token } } : nav;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -16,6 +16,7 @@ import { guestProfile, loadMemberProfile, signedInEmail, strOf, fmtDate, titleCa
|
|
|
16
16
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
17
17
|
import { signInPageStyle, signInSheetStyle } from "../_shared/sign-in-sheet.js";
|
|
18
18
|
import { memberAccountRoutes } from "../_shared/member-account-routes.js";
|
|
19
|
+
import { CONTINUATION_BUDGET_MS, memberScreenTarget, within } from "../_shared/member-screen.js";
|
|
19
20
|
import { createIapCommerce, onlineProgramOrders, pricingPlanOrders, storesAppleSalesEnabled, storesProductOrders } from "@himalaya/iap-checkout";
|
|
20
21
|
import { IAP_RESTORE_KEYS, NO_IAP_RESTORE, createIapRestore, resetUnhydratedKeysOnOlderRuntime, type IapRestoreFields } from "../_shared/iap-worker.js";
|
|
21
22
|
|
|
@@ -99,12 +100,24 @@ function resumeTarget(s: Pick<S, "returnScreenId" | "returnId" | "returnChannelI
|
|
|
99
100
|
* all, so the modal is also dismissed directly: it always closes, and the row opens where
|
|
100
101
|
* the tab exists. With no `returnTab` it only closes, and the screen under it loads again —
|
|
101
102
|
* the screen that opened the modal is the return target. */
|
|
102
|
-
function resumeAfterAuth(next: S): S {
|
|
103
|
+
async function resumeAfterAuth(next: S): Promise<S> {
|
|
103
104
|
const target = resumeTarget(next);
|
|
104
105
|
if (!next.isMember) return next;
|
|
105
106
|
const tab = routeInput().modal === "1" ? routeInput().returnTab ?? "" : "";
|
|
106
107
|
if (target && tab && next.standalone) {
|
|
107
108
|
routeInputConsumed = true;
|
|
109
|
+
// The opener's continuation is spent first, so a later form replacement cannot resume it too.
|
|
110
|
+
// "refused" means another form already spent it, or it expired. A host may replace this form
|
|
111
|
+
// when the account changes yet let this sign-in finish (Android Himi Player parks the old
|
|
112
|
+
// worker alive): the replacement opened the screen, so this form only closes. A continuation
|
|
113
|
+
// lives 5 min from the tap, and a guest can take longer (Forgot your password?): a form shown
|
|
114
|
+
// about that long resumes, so an expiry never costs them the screen.
|
|
115
|
+
if (routeInput().authContinuation) {
|
|
116
|
+
const answer = await within(consumeContinuation(target.screenId), CONTINUATION_BUDGET_MS, "unsupported" as const);
|
|
117
|
+
if (answer === "refused" && Date.now() - formShownAt < CONTINUATION_LIFETIME_MS - CONTINUATION_MARGIN_MS) {
|
|
118
|
+
return navigate(derive({ ...next, ...NO_VISIT }), { presentation: leaveNav() });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
108
121
|
void dispatch("himi.open", { presentation: "dismiss" });
|
|
109
122
|
const cleared = derive({ ...next, authIntent: "", authContextName: "", returnScreenId: "", returnId: "", returnChannelId: "" });
|
|
110
123
|
return navigate(cleared, target.args ? { tab, screenId: target.screenId, args: target.args } : { tab, screenId: target.screenId });
|
|
@@ -115,6 +128,59 @@ function resumeAfterAuth(next: S): S {
|
|
|
115
128
|
return navigate(cleared, target);
|
|
116
129
|
}
|
|
117
130
|
|
|
131
|
+
/** How long a host keeps a continuation: 300 s in all three (web authContinuation.ts, iOS and Android
|
|
132
|
+
* AuthProvider). A form shown that long has outlived the one it was opened with. The margin covers
|
|
133
|
+
* the time between the tap and the form's appear. */
|
|
134
|
+
const CONTINUATION_LIFETIME_MS = 300_000;
|
|
135
|
+
const CONTINUATION_MARGIN_MS = 15_000;
|
|
136
|
+
/** When this visit's form appeared (`appearConfig`), for the continuation's lifetime above. */
|
|
137
|
+
let formShownAt = Date.now();
|
|
138
|
+
|
|
139
|
+
/** Spend the host-held continuation an opener began for `screenId` (_shared/member-screen.ts).
|
|
140
|
+
* "confirmed" once, and only after a sign-in made on this form confirmed it for the member signed
|
|
141
|
+
* in now; "refused" otherwise (spent, cancelled, expired, forged); "unsupported" on a host without
|
|
142
|
+
* the contract. */
|
|
143
|
+
async function consumeContinuation(screenId: string): Promise<"confirmed" | "refused" | "unsupported"> {
|
|
144
|
+
try {
|
|
145
|
+
const value = await dispatch("himi.wix.authContinuation", { operation: "consume", target: memberScreenTarget(screenId) }) as
|
|
146
|
+
{ supported?: unknown; confirmed?: unknown; payload?: { supported?: unknown; confirmed?: unknown } } | null;
|
|
147
|
+
const fields = value?.payload ?? value;
|
|
148
|
+
if (fields?.supported !== true) return "unsupported";
|
|
149
|
+
return fields.confirmed === true ? "confirmed" : "refused";
|
|
150
|
+
} catch {
|
|
151
|
+
return "unsupported";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A modal form whose sign-in replaced this worker. On Android the account change of a sign-in
|
|
156
|
+
* boots a new worker for the open form before `authenticate` returns, so resumeAfterAuth never
|
|
157
|
+
* runs, and this worker sees only a member on the form, which settle sends back. The return
|
|
158
|
+
* path resumes here only with the opener's continuation, which the sign-in on this form
|
|
159
|
+
* confirmed and the host spends once; a route alone never opens it (see settle). */
|
|
160
|
+
async function resumeFromContinuation(next: S, arg: unknown): Promise<S | null> {
|
|
161
|
+
const route = routeInput();
|
|
162
|
+
// Not gated on `routeInputConsumed`: the replacement's boot load settles first and marks the
|
|
163
|
+
// route used. The host's consume is the one-shot authority.
|
|
164
|
+
if (!next.standalone || !next.isMember || strField(arg, "standalone") !== "1") return null;
|
|
165
|
+
if (route.modal !== "1" || !route.returnTab || !route.authContinuation) return null;
|
|
166
|
+
const returnPath = { returnScreenId: route.returnScreenId ?? "", returnId: route.returnId ?? "", returnChannelId: route.returnChannelId ?? "" };
|
|
167
|
+
const target = resumeTarget(returnPath);
|
|
168
|
+
if (!target || await within(consumeContinuation(target.screenId), CONTINUATION_BUDGET_MS, "unsupported" as const) !== "confirmed") return null;
|
|
169
|
+
routeInputConsumed = true;
|
|
170
|
+
void dispatch("himi.open", { presentation: "dismiss" });
|
|
171
|
+
const cleared = derive({ ...next, ...NO_VISIT });
|
|
172
|
+
return navigate(cleared, target.args ? { tab: route.returnTab, screenId: target.screenId, args: target.args } : { tab: route.returnTab, screenId: target.screenId });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** After a probe: a form a sign-in replaced resumes its return path; anything else settles. */
|
|
176
|
+
async function afterProbe(r: { next: S; latest: boolean } | { kept: S; latest: boolean }, arg: unknown): Promise<S> {
|
|
177
|
+
if ("next" in r && r.latest) {
|
|
178
|
+
const resumed = await resumeFromContinuation(r.next, arg);
|
|
179
|
+
if (resumed) return resumed;
|
|
180
|
+
}
|
|
181
|
+
return "next" in r ? settle(r.next, arg, r.latest) : r.latest ? settle(r.kept, arg, true) : r.kept;
|
|
182
|
+
}
|
|
183
|
+
|
|
118
184
|
/** Account with a standalone sign-in screen (`signInScreen` appear param): a guest who
|
|
119
185
|
* arrives with a sign-in intent or a return path — a member gate, an old deep link — is
|
|
120
186
|
* sent on to that screen with the same params, once. */
|
|
@@ -265,6 +331,7 @@ function appearConfig(s: S, arg: unknown): AppearConfig {
|
|
|
265
331
|
// later visit with the same params, after an earlier visit consumed the route.
|
|
266
332
|
if (appearing) {
|
|
267
333
|
routeInputConsumed = false;
|
|
334
|
+
formShownAt = Date.now();
|
|
268
335
|
// A pooled worker serves the next visitor too: the fields mount empty, so the last
|
|
269
336
|
// visit's draft must not be what Sign in submits.
|
|
270
337
|
passwordDraft = "";
|
|
@@ -374,7 +441,7 @@ async function authenticate(s: S, operation: "signIn" | "register"): Promise<S |
|
|
|
374
441
|
if (revision !== editRevision) return derive({ ...svc.getState(), authBusy: false });
|
|
375
442
|
if (!next.isMember) throw { code: "unknown" };
|
|
376
443
|
passwordDraft = "";
|
|
377
|
-
return resumeAfterAuth(completedAuth(next));
|
|
444
|
+
return await resumeAfterAuth(completedAuth(next));
|
|
378
445
|
} catch (error) {
|
|
379
446
|
return derive({ ...svc.getState(), authBusy: false,
|
|
380
447
|
message: revision === editRevision ? authFailure(error, operation, translated).reason : "" });
|
|
@@ -810,8 +877,8 @@ const svc = defineService<S, {
|
|
|
810
877
|
actions: {
|
|
811
878
|
submit: (s): Promise<S | undefined> => s.isRecovering ? svc.resetPassword() : authenticate(s, s.isRegistering ? "register" : "signIn"),
|
|
812
879
|
beginAuth: (s) => derive({ ...s, authBusy: true, message: "", emailError: "", passwordError: "" }),
|
|
813
|
-
load: async (s, arg): Promise<S> => { stashScreenCopy(arg);
|
|
814
|
-
refresh: async (s, arg): Promise<S> => { stashScreenCopy(arg);
|
|
880
|
+
load: async (s, arg): Promise<S> => { stashScreenCopy(arg); return afterProbe(await freshProbe(s, arg), arg); },
|
|
881
|
+
refresh: async (s, arg): Promise<S> => { stashScreenCopy(arg); return afterProbe(await freshProbe(s, arg), arg); },
|
|
815
882
|
// Idle ticks return undefined, so an unchanged session costs no re-render.
|
|
816
883
|
sync: async (s): Promise<S | undefined> => {
|
|
817
884
|
if (authInFlight) return undefined;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// "Open a member-only screen" (the business chat): a member goes there; a guest gets the app's
|
|
2
|
+
// sign-in first, never the screen's own guest prompt, and the screen opens once signed in
|
|
3
|
+
// (himi-store-account resumes `returnScreenId`). Salon & Spa offers it from Home and from the
|
|
4
|
+
// shared booking screens (a treatment that cannot be booked online, a Choose a Time with no times),
|
|
5
|
+
// so each of those workers runs the same rule.
|
|
6
|
+
//
|
|
7
|
+
// The tap's params:
|
|
8
|
+
// screenId the member screen
|
|
9
|
+
// signInScreenId the app's sign-in screen; without it the tap opens `screenId` as is
|
|
10
|
+
// signInPresentation "sheet" | "full_screen": the sign-in opens as that modal, and once signed
|
|
11
|
+
// in it closes and opens the screen on `returnTab`. Pushed (no presentation),
|
|
12
|
+
// the sign-in pushes the screen itself.
|
|
13
|
+
// returnTab the tab the screen opens on after a modal sign-in
|
|
14
|
+
//
|
|
15
|
+
// A modal sign-in also carries a host-held continuation (`authContinuation`, begun here for
|
|
16
|
+
// `memberScreenTarget(screenId)`). Where the account change of the sign-in replaces the sign-in
|
|
17
|
+
// worker before it can resume (Android), the replacement consumes it to open the screen, once.
|
|
18
|
+
// A route alone never opens a member screen; old hosts without the contract keep the plain sheet.
|
|
19
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
20
|
+
import type { NavDirective } from "@himalaya/state";
|
|
21
|
+
import { signedInEmail } from "./himi-account.js";
|
|
22
|
+
|
|
23
|
+
/** How long a continuation call may take before the worker goes on without it. Just above the web
|
|
24
|
+
* host's own 4 s identity-read deadline (identityReader.ts), which it runs before answering: a host
|
|
25
|
+
* that answers is never cut off, and one that never answers cannot hold the sheet or the form. */
|
|
26
|
+
export const CONTINUATION_BUDGET_MS = 4_500;
|
|
27
|
+
/** The whole tap (session read, then begin) waits at most this long. On the web host each call runs
|
|
28
|
+
* its own identity read, so a hung host would otherwise cost two full deadlines (~8 s) before the
|
|
29
|
+
* sheet. The session read may use the host's whole deadline; begin then gets what is left, but at
|
|
30
|
+
* least an ordinary read's 1.5 s, so a slow host (2.5 s a read) still hands out the token. */
|
|
31
|
+
const TAP_BUDGET_MS = CONTINUATION_BUDGET_MS + 1_500;
|
|
32
|
+
const MIN_BEGIN_MS = 1_500;
|
|
33
|
+
|
|
34
|
+
/** The continuation target for a member screen, shared with himi-store-account. */
|
|
35
|
+
export const memberScreenTarget = (screenId: string): string => `member_screen:${screenId}`;
|
|
36
|
+
|
|
37
|
+
/** A host-held continuation for `screenId`, or "" (an old host, or a member already). */
|
|
38
|
+
async function beginContinuation(screenId: string): Promise<string> {
|
|
39
|
+
try {
|
|
40
|
+
const value = await dispatch("himi.wix.authContinuation", { operation: "begin", target: memberScreenTarget(screenId) }) as
|
|
41
|
+
{ supported?: unknown; token?: unknown; payload?: { supported?: unknown; token?: unknown } } | null;
|
|
42
|
+
const fields = value?.payload ?? value;
|
|
43
|
+
return fields?.supported === true && typeof fields.token === "string" ? fields.token : "";
|
|
44
|
+
} catch {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const strField = (arg: unknown, key: string): string => {
|
|
50
|
+
const value = (arg as Record<string, unknown> | undefined)?.[key];
|
|
51
|
+
return typeof value === "string" ? value : "";
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** `read`, or `fallback` once `ms` pass, where the engine has a timer. A bare JSContext has no
|
|
55
|
+
* timer; there it waits, as every read does. `read` must not reject. */
|
|
56
|
+
export function within<T>(read: Promise<T>, ms: number, fallback: T): Promise<T> {
|
|
57
|
+
const host = globalThis as { setTimeout?: (fn: () => void, ms: number) => unknown; clearTimeout?: (timer: unknown) => void };
|
|
58
|
+
if (typeof host.setTimeout !== "function") return read;
|
|
59
|
+
return new Promise<T>((resolve) => {
|
|
60
|
+
const timer = host.setTimeout!(() => resolve(fallback), ms);
|
|
61
|
+
void read.then((value) => { host.clearTimeout?.(timer); resolve(value); });
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Where a tap goes, given the session's email ("" for a guest). null: no screen named. */
|
|
66
|
+
export function memberScreenNav(arg: unknown, email: string): NavDirective | null {
|
|
67
|
+
const screenId = strField(arg, "screenId"), signInScreenId = strField(arg, "signInScreenId");
|
|
68
|
+
if (!screenId) return null;
|
|
69
|
+
if (!signInScreenId || email) return { screenId };
|
|
70
|
+
const args: Record<string, string> = { mode: "signin", returnScreenId: screenId };
|
|
71
|
+
const presentation = strField(arg, "signInPresentation");
|
|
72
|
+
if (presentation !== "sheet" && presentation !== "full_screen") return { screenId: signInScreenId, args };
|
|
73
|
+
if (strField(arg, "returnTab")) args.returnTab = strField(arg, "returnTab");
|
|
74
|
+
return { screenId: signInScreenId, presentation, args: { ...args, modal: "1" } };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** One worker's opener. The session is asked at the tap, never read from the last load; a read
|
|
78
|
+
* that never answers counts as a guest, so the tap opens the sign-in rather than nothing. Only the
|
|
79
|
+
* newest tap navigates (no second sheet, no sheet over the screen): an older one answers null. */
|
|
80
|
+
// The session read has the continuation calls' budget: on the web host they all wait on the same
|
|
81
|
+
// identity read, so a shorter cutoff here would take a slow member for a guest and flash the sheet.
|
|
82
|
+
export function memberScreenOpener(readEmail: () => Promise<string> = () => within(signedInEmail(), CONTINUATION_BUDGET_MS, "")): (arg: unknown) => Promise<NavDirective | null> {
|
|
83
|
+
let taps = 0;
|
|
84
|
+
return async (arg) => {
|
|
85
|
+
if (!strField(arg, "screenId")) return null;
|
|
86
|
+
const mine = ++taps;
|
|
87
|
+
const tapped = Date.now();
|
|
88
|
+
const email = strField(arg, "signInScreenId") ? await readEmail() : "";
|
|
89
|
+
if (mine !== taps) return null;
|
|
90
|
+
const nav = memberScreenNav(arg, email);
|
|
91
|
+
if (!nav || !("presentation" in nav) || !nav.args?.modal) return nav;
|
|
92
|
+
// Bounded by what the tap has left (TAP_BUDGET_MS): a host that never answers still opens the
|
|
93
|
+
// plain sheet.
|
|
94
|
+
const left = Math.min(CONTINUATION_BUDGET_MS, Math.max(MIN_BEGIN_MS, TAP_BUDGET_MS - (Date.now() - tapped)));
|
|
95
|
+
const token = await within(beginContinuation(strField(arg, "screenId")), left, "");
|
|
96
|
+
if (mine !== taps) return null;
|
|
97
|
+
return token ? { ...nav, args: { ...nav.args, authContinuation: token } } : nav;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -16,6 +16,7 @@ import { guestProfile, loadMemberProfile, signedInEmail, strOf, fmtDate, titleCa
|
|
|
16
16
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
17
17
|
import { signInPageStyle, signInSheetStyle } from "../_shared/sign-in-sheet.js";
|
|
18
18
|
import { memberAccountRoutes } from "../_shared/member-account-routes.js";
|
|
19
|
+
import { CONTINUATION_BUDGET_MS, memberScreenTarget, within } from "../_shared/member-screen.js";
|
|
19
20
|
import { createIapCommerce, onlineProgramOrders, pricingPlanOrders, storesAppleSalesEnabled, storesProductOrders } from "@himalaya/iap-checkout";
|
|
20
21
|
import { IAP_RESTORE_KEYS, NO_IAP_RESTORE, createIapRestore, resetUnhydratedKeysOnOlderRuntime, type IapRestoreFields } from "../_shared/iap-worker.js";
|
|
21
22
|
|
|
@@ -99,12 +100,24 @@ function resumeTarget(s: Pick<S, "returnScreenId" | "returnId" | "returnChannelI
|
|
|
99
100
|
* all, so the modal is also dismissed directly: it always closes, and the row opens where
|
|
100
101
|
* the tab exists. With no `returnTab` it only closes, and the screen under it loads again —
|
|
101
102
|
* the screen that opened the modal is the return target. */
|
|
102
|
-
function resumeAfterAuth(next: S): S {
|
|
103
|
+
async function resumeAfterAuth(next: S): Promise<S> {
|
|
103
104
|
const target = resumeTarget(next);
|
|
104
105
|
if (!next.isMember) return next;
|
|
105
106
|
const tab = routeInput().modal === "1" ? routeInput().returnTab ?? "" : "";
|
|
106
107
|
if (target && tab && next.standalone) {
|
|
107
108
|
routeInputConsumed = true;
|
|
109
|
+
// The opener's continuation is spent first, so a later form replacement cannot resume it too.
|
|
110
|
+
// "refused" means another form already spent it, or it expired. A host may replace this form
|
|
111
|
+
// when the account changes yet let this sign-in finish (Android Himi Player parks the old
|
|
112
|
+
// worker alive): the replacement opened the screen, so this form only closes. A continuation
|
|
113
|
+
// lives 5 min from the tap, and a guest can take longer (Forgot your password?): a form shown
|
|
114
|
+
// about that long resumes, so an expiry never costs them the screen.
|
|
115
|
+
if (routeInput().authContinuation) {
|
|
116
|
+
const answer = await within(consumeContinuation(target.screenId), CONTINUATION_BUDGET_MS, "unsupported" as const);
|
|
117
|
+
if (answer === "refused" && Date.now() - formShownAt < CONTINUATION_LIFETIME_MS - CONTINUATION_MARGIN_MS) {
|
|
118
|
+
return navigate(derive({ ...next, ...NO_VISIT }), { presentation: leaveNav() });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
108
121
|
void dispatch("himi.open", { presentation: "dismiss" });
|
|
109
122
|
const cleared = derive({ ...next, authIntent: "", authContextName: "", returnScreenId: "", returnId: "", returnChannelId: "" });
|
|
110
123
|
return navigate(cleared, target.args ? { tab, screenId: target.screenId, args: target.args } : { tab, screenId: target.screenId });
|
|
@@ -115,6 +128,59 @@ function resumeAfterAuth(next: S): S {
|
|
|
115
128
|
return navigate(cleared, target);
|
|
116
129
|
}
|
|
117
130
|
|
|
131
|
+
/** How long a host keeps a continuation: 300 s in all three (web authContinuation.ts, iOS and Android
|
|
132
|
+
* AuthProvider). A form shown that long has outlived the one it was opened with. The margin covers
|
|
133
|
+
* the time between the tap and the form's appear. */
|
|
134
|
+
const CONTINUATION_LIFETIME_MS = 300_000;
|
|
135
|
+
const CONTINUATION_MARGIN_MS = 15_000;
|
|
136
|
+
/** When this visit's form appeared (`appearConfig`), for the continuation's lifetime above. */
|
|
137
|
+
let formShownAt = Date.now();
|
|
138
|
+
|
|
139
|
+
/** Spend the host-held continuation an opener began for `screenId` (_shared/member-screen.ts).
|
|
140
|
+
* "confirmed" once, and only after a sign-in made on this form confirmed it for the member signed
|
|
141
|
+
* in now; "refused" otherwise (spent, cancelled, expired, forged); "unsupported" on a host without
|
|
142
|
+
* the contract. */
|
|
143
|
+
async function consumeContinuation(screenId: string): Promise<"confirmed" | "refused" | "unsupported"> {
|
|
144
|
+
try {
|
|
145
|
+
const value = await dispatch("himi.wix.authContinuation", { operation: "consume", target: memberScreenTarget(screenId) }) as
|
|
146
|
+
{ supported?: unknown; confirmed?: unknown; payload?: { supported?: unknown; confirmed?: unknown } } | null;
|
|
147
|
+
const fields = value?.payload ?? value;
|
|
148
|
+
if (fields?.supported !== true) return "unsupported";
|
|
149
|
+
return fields.confirmed === true ? "confirmed" : "refused";
|
|
150
|
+
} catch {
|
|
151
|
+
return "unsupported";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A modal form whose sign-in replaced this worker. On Android the account change of a sign-in
|
|
156
|
+
* boots a new worker for the open form before `authenticate` returns, so resumeAfterAuth never
|
|
157
|
+
* runs, and this worker sees only a member on the form, which settle sends back. The return
|
|
158
|
+
* path resumes here only with the opener's continuation, which the sign-in on this form
|
|
159
|
+
* confirmed and the host spends once; a route alone never opens it (see settle). */
|
|
160
|
+
async function resumeFromContinuation(next: S, arg: unknown): Promise<S | null> {
|
|
161
|
+
const route = routeInput();
|
|
162
|
+
// Not gated on `routeInputConsumed`: the replacement's boot load settles first and marks the
|
|
163
|
+
// route used. The host's consume is the one-shot authority.
|
|
164
|
+
if (!next.standalone || !next.isMember || strField(arg, "standalone") !== "1") return null;
|
|
165
|
+
if (route.modal !== "1" || !route.returnTab || !route.authContinuation) return null;
|
|
166
|
+
const returnPath = { returnScreenId: route.returnScreenId ?? "", returnId: route.returnId ?? "", returnChannelId: route.returnChannelId ?? "" };
|
|
167
|
+
const target = resumeTarget(returnPath);
|
|
168
|
+
if (!target || await within(consumeContinuation(target.screenId), CONTINUATION_BUDGET_MS, "unsupported" as const) !== "confirmed") return null;
|
|
169
|
+
routeInputConsumed = true;
|
|
170
|
+
void dispatch("himi.open", { presentation: "dismiss" });
|
|
171
|
+
const cleared = derive({ ...next, ...NO_VISIT });
|
|
172
|
+
return navigate(cleared, target.args ? { tab: route.returnTab, screenId: target.screenId, args: target.args } : { tab: route.returnTab, screenId: target.screenId });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** After a probe: a form a sign-in replaced resumes its return path; anything else settles. */
|
|
176
|
+
async function afterProbe(r: { next: S; latest: boolean } | { kept: S; latest: boolean }, arg: unknown): Promise<S> {
|
|
177
|
+
if ("next" in r && r.latest) {
|
|
178
|
+
const resumed = await resumeFromContinuation(r.next, arg);
|
|
179
|
+
if (resumed) return resumed;
|
|
180
|
+
}
|
|
181
|
+
return "next" in r ? settle(r.next, arg, r.latest) : r.latest ? settle(r.kept, arg, true) : r.kept;
|
|
182
|
+
}
|
|
183
|
+
|
|
118
184
|
/** Account with a standalone sign-in screen (`signInScreen` appear param): a guest who
|
|
119
185
|
* arrives with a sign-in intent or a return path — a member gate, an old deep link — is
|
|
120
186
|
* sent on to that screen with the same params, once. */
|
|
@@ -265,6 +331,7 @@ function appearConfig(s: S, arg: unknown): AppearConfig {
|
|
|
265
331
|
// later visit with the same params, after an earlier visit consumed the route.
|
|
266
332
|
if (appearing) {
|
|
267
333
|
routeInputConsumed = false;
|
|
334
|
+
formShownAt = Date.now();
|
|
268
335
|
// A pooled worker serves the next visitor too: the fields mount empty, so the last
|
|
269
336
|
// visit's draft must not be what Sign in submits.
|
|
270
337
|
passwordDraft = "";
|
|
@@ -374,7 +441,7 @@ async function authenticate(s: S, operation: "signIn" | "register"): Promise<S |
|
|
|
374
441
|
if (revision !== editRevision) return derive({ ...svc.getState(), authBusy: false });
|
|
375
442
|
if (!next.isMember) throw { code: "unknown" };
|
|
376
443
|
passwordDraft = "";
|
|
377
|
-
return resumeAfterAuth(completedAuth(next));
|
|
444
|
+
return await resumeAfterAuth(completedAuth(next));
|
|
378
445
|
} catch (error) {
|
|
379
446
|
return derive({ ...svc.getState(), authBusy: false,
|
|
380
447
|
message: revision === editRevision ? authFailure(error, operation, translated).reason : "" });
|
|
@@ -810,8 +877,8 @@ const svc = defineService<S, {
|
|
|
810
877
|
actions: {
|
|
811
878
|
submit: (s): Promise<S | undefined> => s.isRecovering ? svc.resetPassword() : authenticate(s, s.isRegistering ? "register" : "signIn"),
|
|
812
879
|
beginAuth: (s) => derive({ ...s, authBusy: true, message: "", emailError: "", passwordError: "" }),
|
|
813
|
-
load: async (s, arg): Promise<S> => { stashScreenCopy(arg);
|
|
814
|
-
refresh: async (s, arg): Promise<S> => { stashScreenCopy(arg);
|
|
880
|
+
load: async (s, arg): Promise<S> => { stashScreenCopy(arg); return afterProbe(await freshProbe(s, arg), arg); },
|
|
881
|
+
refresh: async (s, arg): Promise<S> => { stashScreenCopy(arg); return afterProbe(await freshProbe(s, arg), arg); },
|
|
815
882
|
// Idle ticks return undefined, so an unchanged session costs no re-render.
|
|
816
883
|
sync: async (s): Promise<S | undefined> => {
|
|
817
884
|
if (authInFlight) return undefined;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// "Open a member-only screen" (the business chat): a member goes there; a guest gets the app's
|
|
2
|
+
// sign-in first, never the screen's own guest prompt, and the screen opens once signed in
|
|
3
|
+
// (himi-store-account resumes `returnScreenId`). Salon & Spa offers it from Home and from the
|
|
4
|
+
// shared booking screens (a treatment that cannot be booked online, a Choose a Time with no times),
|
|
5
|
+
// so each of those workers runs the same rule.
|
|
6
|
+
//
|
|
7
|
+
// The tap's params:
|
|
8
|
+
// screenId the member screen
|
|
9
|
+
// signInScreenId the app's sign-in screen; without it the tap opens `screenId` as is
|
|
10
|
+
// signInPresentation "sheet" | "full_screen": the sign-in opens as that modal, and once signed
|
|
11
|
+
// in it closes and opens the screen on `returnTab`. Pushed (no presentation),
|
|
12
|
+
// the sign-in pushes the screen itself.
|
|
13
|
+
// returnTab the tab the screen opens on after a modal sign-in
|
|
14
|
+
//
|
|
15
|
+
// A modal sign-in also carries a host-held continuation (`authContinuation`, begun here for
|
|
16
|
+
// `memberScreenTarget(screenId)`). Where the account change of the sign-in replaces the sign-in
|
|
17
|
+
// worker before it can resume (Android), the replacement consumes it to open the screen, once.
|
|
18
|
+
// A route alone never opens a member screen; old hosts without the contract keep the plain sheet.
|
|
19
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
20
|
+
import type { NavDirective } from "@himalaya/state";
|
|
21
|
+
import { signedInEmail } from "./himi-account.js";
|
|
22
|
+
|
|
23
|
+
/** How long a continuation call may take before the worker goes on without it. Just above the web
|
|
24
|
+
* host's own 4 s identity-read deadline (identityReader.ts), which it runs before answering: a host
|
|
25
|
+
* that answers is never cut off, and one that never answers cannot hold the sheet or the form. */
|
|
26
|
+
export const CONTINUATION_BUDGET_MS = 4_500;
|
|
27
|
+
/** The whole tap (session read, then begin) waits at most this long. On the web host each call runs
|
|
28
|
+
* its own identity read, so a hung host would otherwise cost two full deadlines (~8 s) before the
|
|
29
|
+
* sheet. The session read may use the host's whole deadline; begin then gets what is left, but at
|
|
30
|
+
* least an ordinary read's 1.5 s, so a slow host (2.5 s a read) still hands out the token. */
|
|
31
|
+
const TAP_BUDGET_MS = CONTINUATION_BUDGET_MS + 1_500;
|
|
32
|
+
const MIN_BEGIN_MS = 1_500;
|
|
33
|
+
|
|
34
|
+
/** The continuation target for a member screen, shared with himi-store-account. */
|
|
35
|
+
export const memberScreenTarget = (screenId: string): string => `member_screen:${screenId}`;
|
|
36
|
+
|
|
37
|
+
/** A host-held continuation for `screenId`, or "" (an old host, or a member already). */
|
|
38
|
+
async function beginContinuation(screenId: string): Promise<string> {
|
|
39
|
+
try {
|
|
40
|
+
const value = await dispatch("himi.wix.authContinuation", { operation: "begin", target: memberScreenTarget(screenId) }) as
|
|
41
|
+
{ supported?: unknown; token?: unknown; payload?: { supported?: unknown; token?: unknown } } | null;
|
|
42
|
+
const fields = value?.payload ?? value;
|
|
43
|
+
return fields?.supported === true && typeof fields.token === "string" ? fields.token : "";
|
|
44
|
+
} catch {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const strField = (arg: unknown, key: string): string => {
|
|
50
|
+
const value = (arg as Record<string, unknown> | undefined)?.[key];
|
|
51
|
+
return typeof value === "string" ? value : "";
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** `read`, or `fallback` once `ms` pass, where the engine has a timer. A bare JSContext has no
|
|
55
|
+
* timer; there it waits, as every read does. `read` must not reject. */
|
|
56
|
+
export function within<T>(read: Promise<T>, ms: number, fallback: T): Promise<T> {
|
|
57
|
+
const host = globalThis as { setTimeout?: (fn: () => void, ms: number) => unknown; clearTimeout?: (timer: unknown) => void };
|
|
58
|
+
if (typeof host.setTimeout !== "function") return read;
|
|
59
|
+
return new Promise<T>((resolve) => {
|
|
60
|
+
const timer = host.setTimeout!(() => resolve(fallback), ms);
|
|
61
|
+
void read.then((value) => { host.clearTimeout?.(timer); resolve(value); });
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Where a tap goes, given the session's email ("" for a guest). null: no screen named. */
|
|
66
|
+
export function memberScreenNav(arg: unknown, email: string): NavDirective | null {
|
|
67
|
+
const screenId = strField(arg, "screenId"), signInScreenId = strField(arg, "signInScreenId");
|
|
68
|
+
if (!screenId) return null;
|
|
69
|
+
if (!signInScreenId || email) return { screenId };
|
|
70
|
+
const args: Record<string, string> = { mode: "signin", returnScreenId: screenId };
|
|
71
|
+
const presentation = strField(arg, "signInPresentation");
|
|
72
|
+
if (presentation !== "sheet" && presentation !== "full_screen") return { screenId: signInScreenId, args };
|
|
73
|
+
if (strField(arg, "returnTab")) args.returnTab = strField(arg, "returnTab");
|
|
74
|
+
return { screenId: signInScreenId, presentation, args: { ...args, modal: "1" } };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** One worker's opener. The session is asked at the tap, never read from the last load; a read
|
|
78
|
+
* that never answers counts as a guest, so the tap opens the sign-in rather than nothing. Only the
|
|
79
|
+
* newest tap navigates (no second sheet, no sheet over the screen): an older one answers null. */
|
|
80
|
+
// The session read has the continuation calls' budget: on the web host they all wait on the same
|
|
81
|
+
// identity read, so a shorter cutoff here would take a slow member for a guest and flash the sheet.
|
|
82
|
+
export function memberScreenOpener(readEmail: () => Promise<string> = () => within(signedInEmail(), CONTINUATION_BUDGET_MS, "")): (arg: unknown) => Promise<NavDirective | null> {
|
|
83
|
+
let taps = 0;
|
|
84
|
+
return async (arg) => {
|
|
85
|
+
if (!strField(arg, "screenId")) return null;
|
|
86
|
+
const mine = ++taps;
|
|
87
|
+
const tapped = Date.now();
|
|
88
|
+
const email = strField(arg, "signInScreenId") ? await readEmail() : "";
|
|
89
|
+
if (mine !== taps) return null;
|
|
90
|
+
const nav = memberScreenNav(arg, email);
|
|
91
|
+
if (!nav || !("presentation" in nav) || !nav.args?.modal) return nav;
|
|
92
|
+
// Bounded by what the tap has left (TAP_BUDGET_MS): a host that never answers still opens the
|
|
93
|
+
// plain sheet.
|
|
94
|
+
const left = Math.min(CONTINUATION_BUDGET_MS, Math.max(MIN_BEGIN_MS, TAP_BUDGET_MS - (Date.now() - tapped)));
|
|
95
|
+
const token = await within(beginContinuation(strField(arg, "screenId")), left, "");
|
|
96
|
+
if (mine !== taps) return null;
|
|
97
|
+
return token ? { ...nav, args: { ...nav.args, authContinuation: token } } : nav;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -14,6 +14,7 @@ import { getService, queryServiceAvailability, registerToWaitlist, type WixAvail
|
|
|
14
14
|
import { getMyMember } from "@himalaya/wix-members";
|
|
15
15
|
import { memberAccess, type MemberAccess } from "../_shared/member-access.js";
|
|
16
16
|
import { signInPageStyle, signInSheetStyle } from "../_shared/sign-in-sheet.js";
|
|
17
|
+
import { memberScreenOpener } from "../_shared/member-screen.js";
|
|
17
18
|
import { placesIn, sessionControl, sessionOf, type MemberPlace, type Session, type SessionControl } from "../_shared/booking-session.js";
|
|
18
19
|
import { categoryName, courseDatesText, courseReadWindows, courseSessionsAvailability, courseWindowOpen, serviceDurationText, servicePriceLine, slotStartInstant, type BookingLabel, type ServicePriceLine } from "../_shared/himi-bookings.js";
|
|
19
20
|
import { formatServiceMoney, serviceCurrency } from "../_shared/wix-service-price.js";
|
|
@@ -910,6 +911,7 @@ function tappedIndex(arg: unknown): number {
|
|
|
910
911
|
}
|
|
911
912
|
|
|
912
913
|
const id = inputId();
|
|
914
|
+
const openMemberScreen = memberScreenOpener();
|
|
913
915
|
const svc = defineService<S, {
|
|
914
916
|
load: (s: S, arg?: unknown) => Promise<S>;
|
|
915
917
|
share: (s: S) => Promise<S>;
|
|
@@ -922,6 +924,7 @@ const svc = defineService<S, {
|
|
|
922
924
|
changeTime: (s: S) => S;
|
|
923
925
|
joinWaitlist: (s: S, arg?: unknown) => Promise<S>;
|
|
924
926
|
toggleSaved: (s: S) => S;
|
|
927
|
+
openForMember: (s: S, arg?: unknown) => Promise<S>;
|
|
925
928
|
}>("himiBookingService", {
|
|
926
929
|
// A join's outcome belongs to that visit: a cold start must not replay it from saved state.
|
|
927
930
|
notHydrated: ["sessionMessage", "sessionMessageOk", "sessionMessageFailed", "noSessionMessage", "saveMessage"],
|
|
@@ -1111,6 +1114,13 @@ const svc = defineService<S, {
|
|
|
1111
1114
|
// The footer button opens the time screen for the loaded service. A worker directive,
|
|
1112
1115
|
// not a `himi.open` with a `$service:` id param: the iOS and Android sticky footers
|
|
1113
1116
|
// dispatch their taps without resolving `$service:` params, so the id never arrived.
|
|
1117
|
+
// "Contact us" on a treatment that cannot be booked online, where the app's contact screen is
|
|
1118
|
+
// for members (Salon & Spa's chat): a guest signs in first (_shared/member-screen.ts).
|
|
1119
|
+
openForMember: async (s, arg): Promise<S> => {
|
|
1120
|
+
const nav = await openMemberScreen(arg);
|
|
1121
|
+
const current: S = svc.getState?.() ?? s;
|
|
1122
|
+
return nav ? navigate(current, nav) : current;
|
|
1123
|
+
},
|
|
1114
1124
|
chooseTime: (s) => (s.id && s.hasService ? navigate(s, { screenId: "himi_time", args: { id: s.id, ...(s.isCourse ? { course: "true" } : {}) } }) : s),
|
|
1115
1125
|
// Book the session the screen opened on: Choose Time opens with it picked — the Agenda row's
|
|
1116
1126
|
// own Book (`{ id, start, sessionId }`), so the member does not choose the time again.
|