@wix/himalaya-cli 0.1637.0 → 0.1639.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-module.d.ts +8 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +25 -0
  3. package/dist/browser-plane/assets.json +5 -5
  4. package/dist/browser-plane/preview-deferred/{289b89dc660fa050af31f8ce5f22ffd7332a60c7b80b8ffd2b141ec074fb2e22.bin → 3361f61ce6b490c8b7b252658ea67f733d88c6e9f95906d0e31eea4827141df3.bin} +1 -1
  5. package/dist/browser-plane/sw.js +8 -8
  6. package/dist/cli.mjs +1259 -914
  7. package/dist/preview-assets.generated.bin +0 -0
  8. package/guides/android-ux.md +6 -3
  9. package/guides/himi-json-output.md +40 -0
  10. package/guides/himi-test.md +8 -0
  11. package/guides/ios-ux.md +4 -2
  12. package/package.json +2 -2
  13. package/templates/beauty-salon/tier5-src/_shared/member-screen.ts +99 -0
  14. package/templates/beauty-salon/tier5-src/himi-booking-service/index.ts +10 -0
  15. package/templates/beauty-salon/tier5-src/himi-booking-time/index.ts +20 -5
  16. package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +71 -4
  17. package/templates/branded-lite/tier5-src/_shared/member-screen.ts +99 -0
  18. package/templates/branded-lite/tier5-src/himi-booking-service/index.ts +10 -0
  19. package/templates/branded-lite/tier5-src/himi-booking-time/index.ts +20 -5
  20. package/templates/branded-lite/tier5-src/himi-store-account/index.ts +71 -4
  21. package/templates/community-club/tier5-src/_shared/member-screen.ts +99 -0
  22. package/templates/community-club/tier5-src/himi-store-account/index.ts +71 -4
  23. package/templates/events-meetups/tier5-src/_shared/member-screen.ts +99 -0
  24. package/templates/events-meetups/tier5-src/himi-store-account/index.ts +71 -4
  25. package/templates/gym-fitness/tier5-src/_shared/member-screen.ts +99 -0
  26. package/templates/gym-fitness/tier5-src/himi-booking-service/index.ts +10 -0
  27. package/templates/gym-fitness/tier5-src/himi-booking-time/index.ts +20 -5
  28. package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +71 -4
  29. package/templates/nonprofit-cause/tier5-src/_shared/member-screen.ts +99 -0
  30. package/templates/nonprofit-cause/tier5-src/himi-store-account/index.ts +71 -4
  31. package/templates/podcast-creator/tier5-src/_shared/member-screen.ts +99 -0
  32. package/templates/podcast-creator/tier5-src/himi-store-account/index.ts +71 -4
  33. package/templates/portfolio-creative/tier5-src/_shared/member-screen.ts +99 -0
  34. package/templates/portfolio-creative/tier5-src/himi-store-account/index.ts +71 -4
  35. package/templates/restaurant/tier5-src/_shared/member-screen.ts +99 -0
  36. package/templates/restaurant/tier5-src/himi-store-account/index.ts +71 -4
  37. package/templates/retail-store/tier5-src/_shared/member-screen.ts +99 -0
  38. package/templates/retail-store/tier5-src/himi-store-account/index.ts +71 -4
  39. package/templates/salon-spa/dev/index.ts +16 -12
  40. package/templates/salon-spa/tier5-src/_shared/member-screen.ts +99 -0
  41. package/templates/salon-spa/tier5-src/himi-booking-account/index.ts +12 -1
  42. package/templates/salon-spa/tier5-src/himi-booking-service/index.ts +10 -0
  43. package/templates/salon-spa/tier5-src/himi-booking-time/index.ts +20 -5
  44. package/templates/salon-spa/tier5-src/himi-salon-home/index.ts +17 -27
  45. package/templates/salon-spa/tier5-src/himi-store-account/index.ts +71 -4
  46. package/templates/yoga-studio/tier5-src/_shared/member-screen.ts +99 -0
  47. package/templates/yoga-studio/tier5-src/himi-booking-service/index.ts +10 -0
  48. package/templates/yoga-studio/tier5-src/himi-booking-time/index.ts +20 -5
  49. package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +71 -4
Binary file
@@ -16,12 +16,15 @@ Material 3. Three things are native without any work from you, and you should no
16
16
  segmented button, `Picker`/`DatePicker`/`Menu`/`BottomSheet`/`AlertDialog` the Material ones.
17
17
  - **Your type scale:** typography tokens are emitted in `sp` and follow the user's font scale.
18
18
 
19
- One thing it **cannot** do: give Android a different layout from iPhone. Lists, cards and inset
20
- sections draw the same on every renderer. Choose one structure and say so
19
+ One thing it **cannot** do: give Android a different layout from iPhone. Lists and cards draw the
20
+ same on every renderer, and a `Section` keeps its structure. Only its look follows the platform:
21
+ on Android the header is a sentence-case subheader in the primary colour and an `inset` group is
22
+ a tonal Material 3 Expressive container with no outline, as Android 16 Settings draws one. Write
23
+ the `header` in sentence case; iPhone uppercases it. Choose one structure and say so
21
24
  in `MOBILE-UX.md`. Per-platform *look* — type face, corner radius, spacing — is the
22
25
  `material` token overlay (see **Idiom overlay** in `himi docs ios-ux`), not a second screen.
23
26
  The overlay may change type face, radius and spacing; it may not change a brand colour.
24
- `himi render --platform android` changes the switch, the segmented button, and the type face.
27
+ `himi render --platform android` changes the switch, the segmented button, the section look, and the type face.
25
28
  A list or a grid looks the same in the iPhone PNG. That is one descriptor, not a failed render.
26
29
 
27
30
  ## Patterns
@@ -14,6 +14,12 @@ require those fields. Existing error-only push refusals now also carry `ok: fals
14
14
  Output channels and process exit codes are unchanged. Read JSON failures on both
15
15
  stdout and stderr; progress/warnings are not failure envelopes.
16
16
 
17
+ ## `himi login --wix` codes
18
+
19
+ | Code | Meaning |
20
+ | --- | --- |
21
+ | `wix_cli_missing` | No held token or API key is available and the `wix` CLI is missing from PATH. Install `@wix/cli` and run `wix login`, or use a token, `--browser`, or `--dpx`. Exit 1. |
22
+
17
23
  ## `himi login --device` codes
18
24
 
19
25
  | Code | Meaning |
@@ -139,6 +145,13 @@ is a positional screen ID; use `--deep=<value>` to diagnose a nonnumeric depth.
139
145
 
140
146
  ## Push codes
141
147
 
148
+ The three attestation refusals also carry a stable top-level `error` key (additive; `code`,
149
+ `errors`, `hint` and `attestation` are unchanged): `attestation_missing` (code `attestation_stale`),
150
+ `attestation_history_corrupt` (same as its code) and `attestation_failed` (code `headless_run_failed`,
151
+ with the `attestation` summary). `attestation_missing` adds `driftingWorkers: string[]` when
152
+ nondeterministic workers mean re-attesting cannot clear the refusal; each entry names the
153
+ worker's bundle. These names are stable.
154
+
142
155
  | Code | Meaning |
143
156
  | --- | --- |
144
157
  | `attestation_history_corrupt` | Retained attestation history failed integrity checks. Takes precedence if stale runs are also present. |
@@ -154,6 +167,7 @@ is a positional screen ID; use `--deep=<value>` to diagnose a nonnumeric depth.
154
167
  | `lint_errors` | Build/lint validation found errors. |
155
168
  | `depth_budget_exceeded` | A screen or a bound list/grid row template nests deeper, or has more components, than the depth budget (`depth-budget` validator pass), or any of its JSON — props, modifiers, `input`, action `args` — nests past the raw-JSON ceiling of 256 levels. Each `issues[]` entry with `pass: "depth-budget"` carries the JSON `path` of the deepest node (the tree root for a node count, the first value past the ceiling for raw JSON), the `limit` and the `actual` value. Takes precedence over `lint_errors`, and `--force` does not override it: content over the budget overflows the renderer's stack on devices already in the field. Flatten the layout and push again. `himi patch screen` refuses an over-deep raw descriptor with the same code, before any network request, and `himi pack` / `himi template publish` refuse with it even under `--force`. |
156
169
  | `placeholder_site_binding` | The app declares `wix_api` and uses the `wix-consumer` auth provider, but its resolved auth still has the scaffold placeholder `clientId` (`YOUR_WIX_CLIENT_ID`) or `siteUrl` (`https://your-site.example.com`), and it is not bound to a source site through the One App identity. Nothing is published: every Wix call would fail. Bind the site (`himi one-app provision` for a One App migration; otherwise a real clientId and siteUrl). `--force` does not override it. |
170
+ | `auth_provider_invalid` | The app's `config.ts` `auth` entry cannot be used: missing, no `providerId`, or a `config` that is not an object. `file`, `field` and `fix` say where and what to write. Nothing is published. Exit 2. The same code comes from `himi validate`, `render` and `test` (see "`config.ts` failures" below). |
157
171
  | `one_app_readiness_failed` | Reserved legacy refusal code. One App migration readiness is now advisory: publish and promotion report structured warnings instead. Other independent release checks may still refuse a push. |
158
172
  | `control_token_expired` | The selected control token has expired. |
159
173
  | `app_source_contains_secrets` | Source archiving detected a possible credential. |
@@ -358,6 +372,32 @@ file). Other `template screens` paths, and `--add`/`--write` refusals about the
358
372
  | `invalid_input` | The `--from` file is missing, unreadable or not JSON. For `--add`/`--write` also: it is not a ScreenDescriptor object, `{ "<id>": <ScreenDescriptor> }` or the entry `--show` prints, or its key or `screenId` is not the `<id>` given; a templated route (`{ pattern, display, template }`) takes back only the text `--show` prints for it. `error` names the file. Exit 2. |
359
373
  | `upsert_refused` | The JSON is not `{ "<screenId>": <ScreenDescriptor> }`, an id or `screenId` does not match, the result would not parse as plain SCREENS entries, or a target file is a symlink. `error` names which. Exit 2. |
360
374
 
375
+ ## `himi template recommend` codes
376
+
377
+ Every refusal carries a code, on stderr, exit 2. `--book <dir>` reads a `himi site analyze` output
378
+ dir. Its verticals come from the vertical probes. A URL-only pass (no `--client-id`) skips every
379
+ probe, so recommend falls back to the book's installed Wix apps (`taxonomy.installedApps`, matched by appDefId, or by name for an unknown id) and its
380
+ crawled page roles. With no vertical found and no `--text`, it ranks on the book's own words:
381
+ business name, description, tagline and section headings. A success with `--book` says which
382
+ signals it used in `book.verticalsFrom` and `book.textFrom`.
383
+
384
+ | Code | Meaning |
385
+ |---|---|
386
+ | `invalid_usage` | No `--text`, `--verticals` or `--book` was given. |
387
+ | `book_not_found` | `--book` names a dir with no `book.json` or `provisioning.overlay.json`, directly or under `.himi/business-book`. Run `himi site analyze --url <site> --out <dir>` first. `book` echoes the flag. |
388
+ | `book_unreadable` | `book.json` or `provisioning.overlay.json` is not valid JSON. `error` names the file. Re-run `himi site analyze`. |
389
+ | `book_no_signal` | The book was read and has nothing to rank on: no installed verticals (the error says whether the probes were skipped or ran and found each vertical empty or not installed), no Wix vertical among its installed apps, no page role that names a vertical, and no business name, description, tagline or section copy. `lacked` lists each missing signal. Pass `--verticals` or `--text`, or re-run `himi site analyze` with `--client-id`. |
390
+
391
+ ## `config.ts` failures (`himi validate`, `himi render`, `himi test`, `himi push`)
392
+
393
+ The release build checks the app's `config.ts` before it builds anything. A failure is printed
394
+ on stderr as `{ ok: false, code, error, file, field, fix }`, exit 2. `file` is the config.ts path,
395
+ `field` is the field at fault, and `fix` says what to write instead.
396
+
397
+ | Code | Meaning |
398
+ |---|---|
399
+ | `auth_provider_invalid` | The `auth` entry cannot be used. `field: "auth"`: the entry is missing, or it is an array, a primitive, or a provider factory that was never called. `field: "auth.providerId"`: the entry has no `providerId`, or it is empty or not a string. `field: "auth.config"`: the entry has no `config`, or it is null, an array or not an object (write `config: {}` for a provider that takes no options). Use a provider factory (`WixConsumerAuthProvider({ … })`, `GenericOAuthProvider({ … })`), or write `auth: { providerId: "none", config: {} }` for an app with no sign-in. |
400
+
361
401
  ## `himi site member-app` codes
362
402
 
363
403
  `himi site member-app set|clear|show <site>` prints one envelope. A refusal from the publishing service
@@ -265,6 +265,13 @@ back/return, state carry-over or the source row's emitted navigation params; ver
265
265
  real interactions as well. A green derived crawl without such expectations does not establish
266
266
  that a detail shows the selected record.
267
267
 
268
+ A `"steps": []` journey reports `stepsExercised: 0`: it dispatched nothing, by design, and its
269
+ `expectText` is checked against the entry state booted with its `input`. The text checks read
270
+ the copy each component paints — including an `EmptyState`'s `subtitle`, and its `actionLabel`
271
+ when it has an `action` — so a not-found expectation can name any of them. Text authored in a
272
+ prop the observation set does not read is reported as `journey-unobservable` (not verified), never
273
+ as "never rendered".
274
+
268
275
  ## What it checks
269
276
 
270
277
  Only **unambiguous** defects, so a green run stays worth trusting:
@@ -288,6 +295,7 @@ Only **unambiguous** defects, so a green run stays worth trusting:
288
295
  | `token-type-invalid` | error | The package's tokens file holds a value a native `Int` field rejects — `typography.<k>.size` or `.weight`, `motions.<k>.duration` (milliseconds: `0.3` → `300`), or a `spacing` / `radius` entry — in the base document or any `idiom.<overlay>`. Both natives decode tokens.json in one strict pass, so one such value drops the WHOLE theme (iOS "Theme unavailable"; Android default palette and fonts) while the web preview looks right. Reported with `screen: "tokens.json"`, never counted as a failed screen; `himi validate` reports the same finding. |
289
296
  | `capability-undeclared` | error | A `capability.<id>.<verb>` call the screen's gate denied — reported from the gate itself, so it is raised **even when the worker catches the rejection** (which on device leaves a control that silently does nothing). Fix: declare the id on that screen's `logicBundle.declaredCapabilities` and in `config.ts` `capabilities`. One per capability per screen. See [Capabilities](#capabilities). |
290
297
  | `journey-failed` | error | A `himi-test.json` journey named an action the screen lacks, threw, or never rendered its `expectText`. |
298
+ | `journey-unobservable` | **warning** | A journey's `expectText` is authored on a node the user can see, but in a copy prop the observation set does not read (a `Banner`'s `actionLabel`, say). The assertion was **not verified**, so the journey is not `ok` and its result carries `notVerified`, but the run does not fail on it: the screen may well paint that text. Assert copy from an observed prop instead (a `Text`'s `text`, a `Button`'s `title`, an `EmptyState`'s `title`, `subtitle` or `actionLabel`), or check this one on a preview. Only copy the renderer paints in that state counts: copy on a collapsed node, in a `FragmentSlot` case the state did not select, or in a label whose handler is absent (an `actionLabel` with no `action`) is not on screen and stays `journey-failed`. |
291
299
  | `inverse-pair-diverges` | **warning** | An action and the action that undoes it do not return to the state the boot settled on — `add` then `remove` leaving a different list, or a counter it forgot to put back. |
292
300
  | `refresh-not-idempotent` | **warning** | `refresh` from a fresh boot settles somewhere other than the boot did, on identical data — usually a refresh that appends instead of replacing. |
293
301
  | `list-shrank-on-load-more` | **warning** | A "load more" returned FEWER rows than before it ran: the new page replaced the list instead of extending it. |
package/guides/ios-ux.md CHANGED
@@ -16,8 +16,10 @@ native on iPhone without any work from you, and you should not redraw them:
16
16
  control, `Picker`/`DatePicker`/`Menu`/`BottomSheet`/`AlertDialog` are the system ones.
17
17
  - **Your type scale:** typography tokens scale with Dynamic Type.
18
18
 
19
- One thing it **cannot** do: give iPhone a different layout from Android. Lists, cards and inset
20
- sections draw the same on every renderer. Choose one structure and say so
19
+ One thing it **cannot** do: give iPhone a different layout from Android. Lists and cards draw the
20
+ same on every renderer, and a `Section` keeps its structure; only its look follows the platform
21
+ (an uppercase caption over an inset group here, a Material subheader over a tonal group on
22
+ Android). Write the `header` in sentence case. Choose one structure and say so
21
23
  in `MOBILE-UX.md`; do not plan "inset grouped on iPhone, full-bleed on Android", because no Himi
22
24
  screen can deliver it. Per-platform *look* — type face, corner radius, spacing — is a token
23
25
  overlay (see **Idiom overlay** below), not a second screen. `himi render --platform ios` changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/himalaya-cli",
3
- "version": "0.1637.0",
3
+ "version": "0.1639.0",
4
4
  "type": "module",
5
5
  "description": "himi — the Himalaya authoring CLI. Build a Tier-5 content package on your own machine, push it to the production serve as a draft, preview it on web + Himi Player, and read worker logs back — the remote dev loop. Wraps @himalaya/serve-cli for transport.",
6
6
  "keywords": [
@@ -72,5 +72,5 @@
72
72
  "artifactId": "himalaya-cli"
73
73
  }
74
74
  },
75
- "falconPackageHash": "21c6c964d718871e94853190ba896eec52be97501402d21da7cdf4c9"
75
+ "falconPackageHash": "c340afe9c75f9fe0e715a9e6e98b473ad26bdb35f720d30371c3c56b"
76
76
  }
@@ -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.
@@ -18,6 +18,7 @@ import { formatServicePrice, serviceIsChargeable } from "../_shared/wix-service-
18
18
  import { stashCopy, copyParam, copyPlural, copyTemplate } from "../_shared/himi-copy.js";
19
19
  import { upsert as dbUpsert, remove as dbRemove, enqueue as dbEnqueue, type DbEntity } from "@himalaya/local-db";
20
20
  import { locationChoice, readSharedLocationResult, writeSharedLocation } from "../_shared/booking-location.js";
21
+ import { memberScreenOpener } from "../_shared/member-screen.js";
21
22
  import { isBridgeUnavailable } from "../_shared/owner-load-error.js";
22
23
  import { emitHostEvent, hostEventInstant } from "../_shared/host-events.js";
23
24
  import { availabilityBeyond, courseReadWindows, courseSessionsAvailability, courseWindowOpen, slotIdAt } from "../_shared/himi-bookings.js";
@@ -326,9 +327,11 @@ function inputId(): string {
326
327
  * not just the first, because the boot load and the screen's own `load` can overlap. */
327
328
  /** Counts the customer's picks. A load that sees it move ran while they picked a time. */
328
329
  let selectionRevision = 0;
329
- // Each guest tap that asks the session first: only the newest answers, so two quick taps whose
330
- // reads come back out of order never pick the older time or open a second sign-in.
331
- let sessionTaps = 0;
330
+ // Each guest tap that asks the session first, and each booking a member starts (a time tapped,
331
+ // Book, the in-app purchase): a guest tap still waiting for its session read answers only while
332
+ // nothing newer has started. Two quick taps whose reads come back out of order never pick the
333
+ // older time or open a second sign-in, and a sign-in never opens over a booking already under way.
334
+ let bookingActions = 0;
332
335
 
333
336
  let pendingStart = (() => {
334
337
  const start = (globalThis as { himalaya?: { input?: { start?: unknown } } }).himalaya?.input?.start;
@@ -991,6 +994,7 @@ function selectSlotIn(s: S, slotId: string): S {
991
994
  }
992
995
 
993
996
  const id = inputId();
997
+ const openMemberScreen = memberScreenOpener();
994
998
  // A member's tap on a time books it, so pickSlot needs a connection too; a guest's tap only opens
995
999
  // the sign-in screen (or the sign-in card), which works offline.
996
1000
  const defineService = withOnlineWrites(registerService, ["bookSelected", "buyApple", "signIn", "register", "pickSlot"], {
@@ -1005,6 +1009,7 @@ const svc = defineService<S, {
1005
1009
  selectDay: (s: S, arg?: unknown) => Promise<S>;
1006
1010
  selectSlot: (s: S, arg?: unknown) => S;
1007
1011
  pickSlot: (s: S, arg?: unknown) => Promise<S | undefined>;
1012
+ openForMember: (s: S, arg?: unknown) => Promise<S>;
1008
1013
  openLocations: (s: S) => S;
1009
1014
  closeLocations: (s: S) => S;
1010
1015
  selectLocation: (s: S, arg?: unknown) => Promise<S>;
@@ -1127,6 +1132,7 @@ const svc = defineService<S, {
1127
1132
  buyApple: async (s: S): Promise<S> => {
1128
1133
  const slot = slotsById.get(s.selectedSlotId);
1129
1134
  if (!slot || !s.isMember) return derive(s);
1135
+ bookingActions++;
1130
1136
  await applePurchase.buy({ key: s.selectedSlotId, slot: slot as unknown as Record<string, unknown> });
1131
1137
  return derive(svc.getState());
1132
1138
  },
@@ -1319,9 +1325,9 @@ const svc = defineService<S, {
1319
1325
  // note, as after a reload, and books on the next tap: that tap passes the booking lock and
1320
1326
  // the offline guard with the member state, which this await would let a second tap skip.
1321
1327
  if (!selected.isMember && signInScreenId && signInPresentation) {
1322
- const mine = ++sessionTaps;
1328
+ const mine = ++bookingActions;
1323
1329
  const email = await signedInEmail();
1324
- if (mine !== sessionTaps) return undefined;
1330
+ if (mine !== bookingActions) return undefined;
1325
1331
  // From the state as it is NOW: a reload may have landed during the await. The pick
1326
1332
  // stays only while that time is still bookable.
1327
1333
  const now = svc.getState?.() ?? s;
@@ -1351,12 +1357,20 @@ const svc = defineService<S, {
1351
1357
  : selected;
1352
1358
  }
1353
1359
  bookingLock = true;
1360
+ bookingActions++;
1354
1361
  try {
1355
1362
  return afterBooking(await bookSelectedIn(selected), slotId);
1356
1363
  } finally {
1357
1364
  bookingLock = false;
1358
1365
  }
1359
1366
  },
1367
+ // "Contact us" when there are no times, where the app's contact screen is for members (Salon &
1368
+ // Spa's chat): a guest signs in first (_shared/member-screen.ts).
1369
+ openForMember: async (s, arg): Promise<S> => {
1370
+ const nav = await openMemberScreen(arg);
1371
+ const current: S = svc.getState?.() ?? s;
1372
+ return nav ? navigate(current, nav) : current;
1373
+ },
1360
1374
  openLocations: (s) => derive({ ...s, locationSheetOpen: true }),
1361
1375
  closeLocations: (s) => derive({ ...s, locationSheetOpen: false }),
1362
1376
  selectLocation: async (s, arg): Promise<S> => {
@@ -1448,6 +1462,7 @@ const svc = defineService<S, {
1448
1462
  bookSelected: async (s) => {
1449
1463
  if (bookingLock) return derive(s);
1450
1464
  bookingLock = true;
1465
+ bookingActions++;
1451
1466
  try {
1452
1467
  return afterBooking(await bookSelectedIn(s), s.selectedSlotId);
1453
1468
  } finally {
@@ -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); const r = await freshProbe(s, arg); return "next" in r ? settle(r.next, arg, r.latest) : r.latest ? settle(r.kept, arg, true) : r.kept; },
814
- refresh: async (s, arg): Promise<S> => { stashScreenCopy(arg); const r = await freshProbe(s, arg); return "next" in r ? settle(r.next, arg, r.latest) : r.latest ? settle(r.kept, arg, true) : r.kept; },
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
+ }