@wix/himalaya-cli 0.1929.0 → 0.1931.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/builder.d.ts +2 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/icon-catalog.generated.d.ts +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +7 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/chat-web/src/index.d.ts +12 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +77 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +6 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-chat-web.mjs +19 -9
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{95a3ae045bad903e458ea7a5800e60e1044f0f754a65d7127de66ba62e897068.bin → eff56fd2ab5972c0c1053a214225f9d2858768f8e24845a6b99e17a2bf244fd4.bin} +1 -1
- package/dist/browser-plane/sw.js +9 -9
- package/dist/cli.mjs +332 -73
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/component-index.md +1 -1
- package/guides/component-reference.json +1 -1
- package/guides/component-reference.md +7 -0
- package/guides/headless-loop.md +1 -1
- package/guides/sdk-reference.json +2 -2
- package/package.json +2 -2
- package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/beauty-salon/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/beauty-salon-owner/dev/index.ts +169 -139
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/beauty-salon-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/branded-lite/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/brandy/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/community-club/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/community-club-owner/dev/index.ts +167 -132
- package/templates/community-club-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/community-club-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/community-club-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/community-club-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/community-club-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/community-club-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/community-club-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/conference/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/events-meetups/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/events-meetups-owner/dev/index.ts +165 -125
- package/templates/events-meetups-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/events-meetups-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/events-meetups-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/fitness-gym/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/gym-fitness/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/gym-fitness-owner/dev/index.ts +169 -139
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/gym-fitness-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/himi-chat/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/medical-services/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/nonprofit-cause/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/nonprofit-cause-owner/dev/index.ts +167 -132
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/nonprofit-cause-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/owner-lite/dev/index.ts +171 -141
- package/templates/owner-lite/himalaya.content.json +1 -1
- package/templates/owner-lite/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/owner-lite/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/owner-lite/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/owner-lite/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/owner-lite/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/owner-lite/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/owner-lite/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/owner-lite/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/personal-fitness-trainer/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/podcast-creator/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/podcast-creator-owner/dev/index.ts +167 -132
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/portfolio-creative-owner/dev/index.ts +169 -139
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/portfolio-creative-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/restaurant/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/restaurant-owner/dev/index.ts +169 -139
- package/templates/restaurant-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/restaurant-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/restaurant-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/restaurant-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/retail-store/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/retail-store-owner/dev/index.ts +167 -132
- package/templates/retail-store-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/retail-store-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/retail-store-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/salon-spa/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/wholesale-store/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/yoga-studio/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/yoga-studio-owner/dev/index.ts +167 -132
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/yoga-studio-owner/tier5-src/wix-owner-booking/index.ts +4 -1
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
// when the record changes while it stays on screen, so the button can lag one visit behind the tab.
|
|
13
13
|
// Shown too long, it opens the Maestro screen, which says so itself when Maestro is unavailable.
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { navigate, type NavDirective } from "@himalaya/state";
|
|
16
|
+
import { currentBusinessId } from "./owner-selected-site.js";
|
|
16
17
|
|
|
17
18
|
type StorageLike = { getItem(key: string): string | null; setItem(key: string, value: string): void };
|
|
18
|
-
type Host = { storage?: StorageLike
|
|
19
|
+
type Host = { storage?: StorageLike };
|
|
19
20
|
const host = (): Host | undefined => (globalThis as { himalaya?: Host }).himalaya;
|
|
20
21
|
|
|
21
22
|
const KEY = "himi.ownerLite.maestroTab.v1";
|
|
@@ -36,7 +37,82 @@ export function maestroTabIsFor(site: string): boolean {
|
|
|
36
37
|
* Maestro for the business on screen. The business is the one the host scoped, else the one
|
|
37
38
|
* picked on Sites, as the Maestro screen reads it. */
|
|
38
39
|
export function askMaestroHidden(): "true" | "false" {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
return maestroTabIsFor(currentBusinessId()) ? "false" : "true";
|
|
41
|
+
}
|
|
42
|
+
// ── "Ask Maestro" from a detail screen ─────────────────────────────────────────────────────
|
|
43
|
+
// The detail screen's worker leaves the item here and switches to the Maestro tab; the Maestro
|
|
44
|
+
// screen's worker reads it when the tab appears. A screen param cannot carry it: a tab switch
|
|
45
|
+
// takes none. The request names the business it was left for, and is good for half a minute:
|
|
46
|
+
// the Maestro worker acts on each stamp once, for that business only, and a request the tab
|
|
47
|
+
// never picked up (the switch was dropped, or a turn was streaming there) is then ignored.
|
|
48
|
+
// It is dropped as soon as its chat is used (a first turn) or left (New chat), and when the
|
|
49
|
+
// owner changes. Not on the read itself: the Maestro screen loads twice as it opens, and both
|
|
50
|
+
// loads must find it.
|
|
51
|
+
|
|
52
|
+
const ASK_KEY = "himi.ownerLite.maestroAsk.v1";
|
|
53
|
+
const ASK_REQUEST_TTL_MS = 30_000;
|
|
54
|
+
|
|
55
|
+
export type AskMaestroKind = "order" | "booking" | "contact";
|
|
56
|
+
export interface AskMaestroRequest { kind: AskMaestroKind; id: string; subject: string; site: string; n: number }
|
|
57
|
+
|
|
58
|
+
export const isAskMaestroKind = (v: unknown): v is AskMaestroKind => v === "order" || v === "booking" || v === "contact";
|
|
59
|
+
|
|
60
|
+
/** Leave "ask Maestro about this item" for the Maestro tab. False when it could not be left
|
|
61
|
+
* (no id, no business, or a host without storage): the caller then opens the Maestro screen
|
|
62
|
+
* with params. */
|
|
63
|
+
export function requestAskMaestro(kind: unknown, id: unknown, subject: unknown, now: number): boolean {
|
|
64
|
+
const item = typeof id === "string" ? id.trim() : "";
|
|
65
|
+
const site = currentBusinessId();
|
|
66
|
+
if (!isAskMaestroKind(kind) || !item || !site) return false;
|
|
67
|
+
const storage = host()?.storage;
|
|
68
|
+
if (!storage) return false;
|
|
69
|
+
try {
|
|
70
|
+
storage.setItem(ASK_KEY, JSON.stringify({ kind, id: item, subject: typeof subject === "string" ? subject.trim() : "", site, n: now }));
|
|
71
|
+
return true;
|
|
72
|
+
} catch { return false; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The request a detail screen left for `site`, while it is recent. */
|
|
76
|
+
export function pendingAskRequest(now: number, site: string): AskMaestroRequest | null {
|
|
77
|
+
try {
|
|
78
|
+
const raw = host()?.storage?.getItem(ASK_KEY);
|
|
79
|
+
if (!raw) return null;
|
|
80
|
+
const v = JSON.parse(raw) as Partial<AskMaestroRequest> | null;
|
|
81
|
+
if (!v || !isAskMaestroKind(v.kind) || typeof v.id !== "string" || !v.id || typeof v.n !== "number") return null;
|
|
82
|
+
// An item of another business is never asked about here: the owner switched in between.
|
|
83
|
+
if (!site || v.site !== site) return null;
|
|
84
|
+
if (now < v.n || now - v.n > ASK_REQUEST_TTL_MS) return null;
|
|
85
|
+
return { kind: v.kind, id: v.id, subject: typeof v.subject === "string" ? v.subject : "", site, n: v.n };
|
|
86
|
+
} catch { return null; }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Drop the request: its chat was used or left (`stamp`: only the request with that stamp, so a
|
|
90
|
+
* newer one a detail screen left meanwhile stays), or the owner changed (no stamp: whatever is
|
|
91
|
+
* there). Never throws. */
|
|
92
|
+
export function clearAskRequest(stamp?: number): void {
|
|
93
|
+
try {
|
|
94
|
+
const storage = host()?.storage;
|
|
95
|
+
if (!storage) return;
|
|
96
|
+
if (stamp !== undefined) {
|
|
97
|
+
const raw = storage.getItem(ASK_KEY);
|
|
98
|
+
if (!raw || (JSON.parse(raw) as { n?: unknown } | null)?.n !== stamp) return;
|
|
99
|
+
}
|
|
100
|
+
storage.setItem(ASK_KEY, "");
|
|
101
|
+
} catch { /* no storage on this host, or nothing readable there: nothing to drop */ }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A detail worker's `askMaestro` action: leave the item, then switch to the Maestro tab at its
|
|
105
|
+
* root: a tab left on History or on a past chat would otherwise show that, and the root is
|
|
106
|
+
* what reads the request. Every binary that can show the Maestro tab knows `{ tab, reset }`:
|
|
107
|
+
* the form shipped on 2026-10-27, and the tab needs the NDJSON stream of 2026-11-25.
|
|
108
|
+
* On a host where the item cannot be left, open the Maestro screen about it instead. */
|
|
109
|
+
export function askMaestroNav<S extends object>(state: S, arg: unknown): S & { _nav: NavDirective } {
|
|
110
|
+
const a = (arg && typeof arg === "object" ? arg : {}) as { kind?: unknown; id?: unknown; subject?: unknown };
|
|
111
|
+
if (requestAskMaestro(a.kind, a.id, a.subject, Date.now())) return navigate(state, { tab: "maestro", reset: true });
|
|
112
|
+
const args: Record<string, string> = {};
|
|
113
|
+
for (const key of ["kind", "id", "subject"] as const) {
|
|
114
|
+
const value = a[key];
|
|
115
|
+
if (typeof value === "string" && value) args[key] = value;
|
|
116
|
+
}
|
|
117
|
+
return navigate(state, { screenId: "himi_owner_lite_maestro", args });
|
|
42
118
|
}
|
|
@@ -107,3 +107,18 @@ export function fallbackNameFrom(arg: unknown, current = ""): string {
|
|
|
107
107
|
const v = (arg as { businessName?: unknown } | undefined)?.businessName;
|
|
108
108
|
return typeof v === "string" && v.trim() ? v.trim() : current;
|
|
109
109
|
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The business the owner is working in, as an id for a call that must name it ("" = none known).
|
|
113
|
+
*
|
|
114
|
+
* The picked one first: the Sites pick records it at the moment of the switch, for every worker.
|
|
115
|
+
* The host's own scope (`__himiPreferenceBusiness`) is the fallback, not the first choice: a tab
|
|
116
|
+
* kept alive across a switch keeps the scope it was opened with (measured live 2026-11-28: after
|
|
117
|
+
* a switch the Inbox tab went on reading the first business, while Home read the new one).
|
|
118
|
+
*/
|
|
119
|
+
export function currentBusinessId(): string {
|
|
120
|
+
const picked = readSelectedSite()?.id?.trim();
|
|
121
|
+
if (picked) return picked;
|
|
122
|
+
const scoped = (globalThis as { himalaya?: { input?: Record<string, unknown> } }).himalaya?.input?.__himiPreferenceBusiness;
|
|
123
|
+
return typeof scoped === "string" ? scoped.trim() : "";
|
|
124
|
+
}
|
|
@@ -21,3 +21,10 @@ export function isSectionUnavailable(e: unknown): boolean {
|
|
|
21
21
|
const text = String((e as Error)?.message ?? e);
|
|
22
22
|
return /^HTTP (?:403|404|428)\b/.test(text) || /^HTTP \d{3} \[(?:FAILED_PRECONDITION|PERMISSION_DENIED)\]/.test(text);
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
/** The business has not set this area up: its app is not installed on the site, which Wix
|
|
26
|
+
* answers with 428. Narrower than `isSectionUnavailable`: a 403 or a 404 may be a mistake
|
|
27
|
+
* worth showing, while this one is simply "nothing here". Read from the leading status only. */
|
|
28
|
+
export function isNotInstalled(e: unknown): boolean {
|
|
29
|
+
return /^HTTP 428\b/.test(String((e as Error)?.message ?? e));
|
|
30
|
+
}
|
|
@@ -19,10 +19,11 @@ import { getSiteAnalytics, getSiteTimeZone, localDateRange, localDateOf, localMi
|
|
|
19
19
|
// `text(...)` and never matched on — the RAW reason is kept beside it in
|
|
20
20
|
// `<part>Reason` for anything that needs it — so the display-only reduction is
|
|
21
21
|
// both safe here and the reason a 428 reason code stopped reaching the owner.
|
|
22
|
-
import { ownerDisplayError, isOwnerPreviewDemo, ownerDemoFallback } from "../_shared/owner-load-error.js";
|
|
22
|
+
import { ownerDisplayError, isOwnerPreviewDemo, ownerDemoFallback, SITE_CONTEXT_CODES } from "../_shared/owner-load-error.js";
|
|
23
|
+
import { isNotInstalled } from "../_shared/owner-widget-reads.js";
|
|
23
24
|
import { DEMO_DASHBOARD, DEMO_NOTE, DEMO_TODAY } from "../_shared/owner-preview-demo.js";
|
|
24
25
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
25
|
-
import { fallbackNameFrom, selectedSiteName } from "../_shared/owner-selected-site.js";
|
|
26
|
+
import { currentBusinessId, fallbackNameFrom, selectedSiteName } from "../_shared/owner-selected-site.js";
|
|
26
27
|
import { settleBusinessSwitch } from "../_shared/owner-site-pick.js";
|
|
27
28
|
import { formatCurrency } from "../_shared/engine-intl.js";
|
|
28
29
|
import {
|
|
@@ -566,6 +567,14 @@ async function loadSourcePart(source: HomeSourceId, part: SourcePart): Promise<S
|
|
|
566
567
|
}
|
|
567
568
|
}
|
|
568
569
|
|
|
570
|
+
/** Wix refusing a read because the call names no business the session may read: a 403, or one
|
|
571
|
+
* of the "no site in this request" codes. Read from the leading status only. */
|
|
572
|
+
function isSiteRefusal(reason: unknown): boolean {
|
|
573
|
+
const text = String((reason as Error)?.message ?? reason);
|
|
574
|
+
const coded = /^HTTP \d{3} \[([A-Z0-9_]+)\]/.exec(text);
|
|
575
|
+
return /^HTTP 403\b/.test(text) || (!!coded && SITE_CONTEXT_CODES.includes(coded[1]));
|
|
576
|
+
}
|
|
577
|
+
|
|
569
578
|
async function loadSource(source: HomeSourceId, parts = sourceParts(source)): Promise<SourceResult> {
|
|
570
579
|
const settled = await Promise.allSettled(parts.map(async (part) => ({ part, payload: await loadSourcePart(source, part) })));
|
|
571
580
|
const result: SourceResult = {};
|
|
@@ -662,20 +671,24 @@ function composeState(): HomeState {
|
|
|
662
671
|
const now = Date.now();
|
|
663
672
|
const sourceStates: SourceState[] = activeSources.map((id) => {
|
|
664
673
|
const result = sourceResults.get(id);
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
674
|
+
// An area the business has not set up (Wix answers 428: its app is not on the site) has
|
|
675
|
+
// nothing to show and nothing to retry. It reads as empty, not as a failed card: a Space
|
|
676
|
+
// website with no store, events, reviews or reservations used to open on four red cards.
|
|
677
|
+
const absent = (part: SourcePart): boolean => result?.[`${part}Reason`] !== undefined && isNotInstalled(result[`${part}Reason`]);
|
|
678
|
+
const primaryError = absent("primary") ? "" : result?.primaryError ?? "";
|
|
679
|
+
const activityError = absent("activity") ? "" : result?.activityError ?? "";
|
|
680
|
+
const metricsError = absent("metrics") ? "" : result?.metricsError ?? "";
|
|
668
681
|
const status: SourceStatus = primaryError ? "unavailable" : result?.primary
|
|
669
682
|
? (sourceIsEmpty(id, result) ? "empty" : "ready")
|
|
670
|
-
: "loading";
|
|
683
|
+
: absent("primary") ? "empty" : "loading";
|
|
671
684
|
const activityStatus: SourceState["activityStatus"] = !ACTIVITY_SOURCES.has(id) ? "not_applicable"
|
|
672
685
|
: activityError ? "unavailable"
|
|
673
686
|
: result?.activity ? (rowsFor(id, result.activity).length ? "ready" : "empty")
|
|
674
|
-
: "loading";
|
|
687
|
+
: absent("activity") ? "empty" : "loading";
|
|
675
688
|
const metricsStatus: SourceState["metricsStatus"] = id !== "orders" ? "not_applicable"
|
|
676
689
|
: metricsError ? "unavailable"
|
|
677
690
|
: result?.metrics ? (rowsFor(id, result.metrics).length ? "ready" : "empty")
|
|
678
|
-
: "loading";
|
|
691
|
+
: absent("metrics") ? "empty" : "loading";
|
|
679
692
|
const failedParts = [primaryError && "primary", metricsError && "metrics", activityError && "activity"].filter(Boolean);
|
|
680
693
|
const retryLabel = failedParts.length === 1 && failedParts[0] !== "primary"
|
|
681
694
|
? `Retry ${SOURCE_LABELS[id]} ${failedParts[0]}`
|
|
@@ -802,6 +815,15 @@ async function loadDashboard(s: HomeState, sources: HomeSourceId[]): Promise<Hom
|
|
|
802
815
|
for (const result of results) sourceResults.set(result.source, result.value);
|
|
803
816
|
const successfulParts = results.flatMap(({ value }) => [value.primary, value.metrics, value.activity]).filter(Boolean);
|
|
804
817
|
const failedReasons = results.flatMap(({ value }) => [value.primaryReason, value.metricsReason, value.activityReason]).filter((reason) => reason !== undefined);
|
|
818
|
+
// No business was ever picked, and Wix refused every read of one (the account's own site
|
|
819
|
+
// count aside): the session is at the account, not at a business. One line saying so replaces
|
|
820
|
+
// a card per area, each blaming a business (named after the app's own provisioning) that the
|
|
821
|
+
// owner never chose. A host that reads a business without naming one is left alone.
|
|
822
|
+
const readABusiness = results.some(({ source, value }) => source !== "sites" && (value.primary || value.metrics || value.activity));
|
|
823
|
+
if (!currentBusinessId() && !readABusiness && failedReasons.length > 0 && failedReasons.every(isSiteRefusal)) {
|
|
824
|
+
currentBusinessName = copyParam("ownerHome.noBusiness", "No business chosen");
|
|
825
|
+
return shape({ status: "error", error: copyParam("ownerHome.chooseBusiness", "Choose a business to see its day here. Tap Switch business.") });
|
|
826
|
+
}
|
|
805
827
|
if (successfulParts.length === 0) {
|
|
806
828
|
if (failedReasons.length > 0 && failedReasons.every((reason) => ownerDemoFallback(reason))) {
|
|
807
829
|
return demoDashboard(shape({ ...s, sourceStates: [], sourceFailures: [] }));
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import { defineService, type PollDirective } from "@himalaya/state";
|
|
25
25
|
import { listChatrooms, archiveChatroom, markChatroomUnread, type Chatroom } from "@himalaya/wix-chat-web";
|
|
26
|
+
import { currentBusinessId, readSelectedSite } from "../_shared/owner-selected-site.js";
|
|
26
27
|
import { formatMonthDay } from "../_shared/engine-intl.js";
|
|
27
28
|
import { ownerLoadError, ownerWriteError } from "../_shared/owner-load-error.js";
|
|
28
29
|
import { stashCopy, copyParam } from "../_shared/himi-copy.js";
|
|
@@ -93,13 +94,38 @@ function relTime(ms?: number): string {
|
|
|
93
94
|
return formatMonthDay(d);
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
/** The business a conversation belongs to, as the owner knows it ("" when Wix does not say). */
|
|
98
|
+
const businessOf = (c: Chatroom): string => (c.businessContext?.name || "").trim();
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether each row must say which business it belongs to.
|
|
102
|
+
*
|
|
103
|
+
* Wix answers an owner with ONE inbox for the whole account: the same conversations whichever
|
|
104
|
+
* business the call names (measured live 2026-11-28, the calls addressed to two different
|
|
105
|
+
* businesses, the rows identical; each row carries its own `businessContext`). A row's business
|
|
106
|
+
* is not a site id, so the list cannot be cut down to the picked business. Without a label the
|
|
107
|
+
* owner reads another business's conversations as this one's. Rows are labelled when they come
|
|
108
|
+
* from more than one business, or from one that is not the business on screen. When the name of
|
|
109
|
+
* the business on screen is not known (a host that scoped it without a pick), there is nothing
|
|
110
|
+
* to compare with, so a business Wix names is always shown.
|
|
111
|
+
*/
|
|
112
|
+
export function labelsBusiness(rooms: Chatroom[], pickedName: string): boolean {
|
|
113
|
+
const names = new Set(rooms.map(businessOf).filter(Boolean));
|
|
114
|
+
if (names.size > 1) return true;
|
|
115
|
+
const [only] = [...names];
|
|
116
|
+
if (!only) return false;
|
|
117
|
+
return !pickedName.trim() || only.toLowerCase() !== pickedName.trim().toLowerCase();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function rowOf(c: Chatroom, withBusiness = false): InboxRow {
|
|
97
121
|
const fallback = copyParam("ownerInbox.untitled", "Conversation");
|
|
98
122
|
const display = (c.displayData?.name || c.lastMessage?.senderDisplayData?.name || "").trim() || fallback;
|
|
99
123
|
const image = c.displayData?.image?.url || c.lastMessage?.senderDisplayData?.image?.url || "";
|
|
100
124
|
const unread = Math.max(0, c.unreadCount ?? 0);
|
|
101
125
|
const unreadText = unread > 0 ? (unread > 99 ? "99+" : String(unread)) : "";
|
|
102
|
-
const
|
|
126
|
+
const preview = (c.lastMessage?.summary || "").trim().slice(0, 120);
|
|
127
|
+
const business = withBusiness ? businessOf(c) : "";
|
|
128
|
+
const subtitle = [business, preview].filter(Boolean).join(" · ");
|
|
103
129
|
const unreadLabel = unread === 0 ? "" : unread === 1
|
|
104
130
|
? copyParam("ownerInbox.oneUnread", "1 unread message")
|
|
105
131
|
: `${unreadText} ${copyParam("ownerInbox.manyUnread", "unread messages")}`;
|
|
@@ -209,6 +235,8 @@ const archivedAt = new Map<string, number>();
|
|
|
209
235
|
const unreadAt = new Map<string, { at: number; until: number }>();
|
|
210
236
|
const UNREAD_GRACE_MS = 3000;
|
|
211
237
|
let readGeneration = 0;
|
|
238
|
+
/** The business the last read was for. */
|
|
239
|
+
let readSite = "";
|
|
212
240
|
/** The newest read whose answer reached the screen. Reads are not ordered — a `load` on
|
|
213
241
|
* return can start a read while a poll tick's is still in flight — so an OLDER read that
|
|
214
242
|
* finishes after a newer one is dropped instead of painting the past over it. */
|
|
@@ -222,8 +250,19 @@ let appliedGeneration = 0;
|
|
|
222
250
|
*/
|
|
223
251
|
async function read(): Promise<InboxState> {
|
|
224
252
|
const generation = ++readGeneration;
|
|
253
|
+
// Every call names the business: this tab is kept alive across a business switch, and its
|
|
254
|
+
// Wix connection stays on the business it was opened for. A switch also ends what was
|
|
255
|
+
// learnt about the last business's rows.
|
|
256
|
+
const site = currentBusinessId();
|
|
257
|
+
if (site !== readSite) {
|
|
258
|
+
readSite = site;
|
|
259
|
+
archivedAt.clear();
|
|
260
|
+
unreadAt.clear();
|
|
261
|
+
}
|
|
225
262
|
try {
|
|
226
|
-
const rooms = await listChatrooms(PAGE_SIZE);
|
|
263
|
+
const rooms = await listChatrooms(PAGE_SIZE, { siteId: site });
|
|
264
|
+
// The owner switched business while this was read: its rows are the last business's.
|
|
265
|
+
if (site !== currentBusinessId()) return liveState();
|
|
227
266
|
// Stale first: a read older than one already painted changes nothing — not the screen,
|
|
228
267
|
// and not the fences either.
|
|
229
268
|
if (generation < appliedGeneration) return liveState();
|
|
@@ -231,9 +270,9 @@ async function read(): Promise<InboxState> {
|
|
|
231
270
|
for (const [id, at] of archivedAt) if (at < generation && !rooms.some((c) => c?.id === id)) archivedAt.delete(id);
|
|
232
271
|
const clock = Date.now();
|
|
233
272
|
for (const [id, fence] of unreadAt) if (fence.at < generation && clock >= fence.until) unreadAt.delete(id);
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
273
|
+
const listed = rooms.filter((c) => c?.id && !c.isArchived && !archivedAt.has(c.id));
|
|
274
|
+
const withBusiness = labelsBusiness(listed, readSelectedSite()?.name ?? "");
|
|
275
|
+
const all = listed.map((c) => rowOf(unreadAt.has(c.id) ? { ...c, unreadCount: Math.max(1, c.unreadCount ?? 0) } : c, withBusiness));
|
|
237
276
|
const now = liveState();
|
|
238
277
|
return shape({ status: "ready", all, filter: now.filter, query: now.query });
|
|
239
278
|
} catch (e) {
|
|
@@ -274,7 +313,7 @@ const svc = defineService<InboxState, {
|
|
|
274
313
|
const id = idOf(arg);
|
|
275
314
|
if (!id) return s;
|
|
276
315
|
try {
|
|
277
|
-
await archiveChatroom(id, true);
|
|
316
|
+
await archiveChatroom(id, true, { siteId: currentBusinessId() });
|
|
278
317
|
} catch (e) {
|
|
279
318
|
return { ...liveState(), actionError: ownerWriteError(e) };
|
|
280
319
|
}
|
|
@@ -287,7 +326,7 @@ const svc = defineService<InboxState, {
|
|
|
287
326
|
const id = idOf(arg);
|
|
288
327
|
if (!id) return s;
|
|
289
328
|
try {
|
|
290
|
-
await markChatroomUnread(id);
|
|
329
|
+
await markChatroomUnread(id, undefined, { siteId: currentBusinessId() });
|
|
291
330
|
} catch (e) {
|
|
292
331
|
return { ...liveState(), actionError: ownerWriteError(e) };
|
|
293
332
|
}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { defineService, navigate, type NavDirective, type PollDirective, type StreamDirective } from "@himalaya/state";
|
|
22
22
|
import { getMessages, sendChatMessage, listChatrooms, markChatroomRead, getChatToken, type ChatMessage } from "@himalaya/wix-chat-web";
|
|
23
|
+
import { currentBusinessId } from "../_shared/owner-selected-site.js";
|
|
23
24
|
import { formatMonthDayTime } from "../_shared/engine-intl.js";
|
|
24
25
|
import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
|
|
25
26
|
import { isOfflineFailure, ownerLoadError, ownerWriteError, writeMayHaveLanded } from "../_shared/owner-load-error.js";
|
|
@@ -106,7 +107,7 @@ function headerOf(msgs: ChatMessage[], fallback: string): string {
|
|
|
106
107
|
|
|
107
108
|
/** The conversation a contact is in, or "" when the owner's recent conversations have none. */
|
|
108
109
|
async function chatroomForContact(contactId: string): Promise<{ id: string; name: string }> {
|
|
109
|
-
const rooms = await listChatrooms(LOOKUP_SIZE);
|
|
110
|
+
const rooms = await listChatrooms(LOOKUP_SIZE, { siteId: threadSite });
|
|
110
111
|
const room = rooms.find((r) => r?.id && r.participantId === contactId);
|
|
111
112
|
return room ? { id: room.id, name: (room.displayData?.name || "").trim() } : { id: "", name: "" };
|
|
112
113
|
}
|
|
@@ -114,15 +115,20 @@ async function chatroomForContact(contactId: string): Promise<{ id: string; name
|
|
|
114
115
|
// The conversation the gate re-reads. Module state, not worker state: a re-read must use
|
|
115
116
|
// the conversation this screen opened even if an older state object is in flight.
|
|
116
117
|
let current = "";
|
|
118
|
+
// The business this thread was opened in. Read once per open, with the visit token: a thread
|
|
119
|
+
// belongs to one business, and a switch while it is on screen must not send its calls (or a
|
|
120
|
+
// token minted for the first business) to the other one.
|
|
121
|
+
let threadSite = "";
|
|
117
122
|
let realtime: ChatRealtimeConfig | null = null;
|
|
118
123
|
|
|
119
124
|
// ONE chatToken per visit (`_shared/chat-live.ts`): a 4 s re-read would otherwise mint a
|
|
120
125
|
// token every 4 s on top of its GET. Reset on every open.
|
|
121
|
-
|
|
126
|
+
// Every call names the business the thread was opened in (`threadSite`), as the Inbox list names its own.
|
|
127
|
+
const visitToken = createVisitToken(() => getChatToken({ siteId: threadSite }).then((t) => t.chatToken));
|
|
122
128
|
async function readThread(): Promise<ChatMessage[]> {
|
|
123
129
|
const token = visitToken.get();
|
|
124
130
|
try {
|
|
125
|
-
return await getMessages(current, PAGE_SIZE, { chatToken: await token });
|
|
131
|
+
return await getMessages(current, PAGE_SIZE, { chatToken: await token, siteId: threadSite });
|
|
126
132
|
} catch (e) {
|
|
127
133
|
visitToken.drop(token);
|
|
128
134
|
throw e;
|
|
@@ -135,7 +141,7 @@ const intents = createSendIntents();
|
|
|
135
141
|
/** Post once per intent: a retried tap of the same text reuses its message id. */
|
|
136
142
|
async function postOnce(chatroomId: string, text: string): Promise<void> {
|
|
137
143
|
const messageId = intents.idFor(chatroomId, text);
|
|
138
|
-
await postWithVisitToken(visitToken, (chatToken) => sendChatMessage(chatroomId, text, { chatToken, messageId }));
|
|
144
|
+
await postWithVisitToken(visitToken, (chatToken) => sendChatMessage(chatroomId, text, { chatToken, messageId, siteId: threadSite }));
|
|
139
145
|
intents.settle(chatroomId, text);
|
|
140
146
|
}
|
|
141
147
|
|
|
@@ -154,7 +160,7 @@ function markRead(chatroomId: string, msgs: ChatMessage[]): void {
|
|
|
154
160
|
if (seq === undefined || seq <= (markedUpTo.get(chatroomId) ?? -1)) return;
|
|
155
161
|
markedUpTo.set(chatroomId, seq);
|
|
156
162
|
void visitToken.get()
|
|
157
|
-
.then((t) => markChatroomRead(chatroomId, seq, { chatToken: t }))
|
|
163
|
+
.then((t) => markChatroomRead(chatroomId, seq, { chatToken: t, siteId: threadSite }))
|
|
158
164
|
.catch(() => {
|
|
159
165
|
if (markedUpTo.get(chatroomId) === seq) markedUpTo.delete(chatroomId);
|
|
160
166
|
});
|
|
@@ -229,6 +235,7 @@ const svc = defineService<ThreadState, {
|
|
|
229
235
|
const { id, kind } = input();
|
|
230
236
|
if (!id) return { ...s, ...presence("missing"), status: "ready", phase: "ready", messages: [], hideEmpty: true, live: "off" };
|
|
231
237
|
visitToken.reset();
|
|
238
|
+
threadSite = currentBusinessId();
|
|
232
239
|
|
|
233
240
|
let chatroomId = id;
|
|
234
241
|
let headerName = s.headerName;
|