@wix/himalaya-cli 0.1807.0 → 0.1809.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/ts/src/site-shell.d.ts +62 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +124 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +12 -0
- package/dist/cli.mjs +13 -1
- package/package.json +2 -2
- package/templates/brandy/README.md +83 -14
- package/templates/brandy/config.ts +42 -34
- package/templates/brandy/dev/index.ts +240 -21
- package/templates/brandy/dev/member-screens.ts +2302 -0
- package/templates/brandy/himalaya.content.json +3 -0
- package/templates/brandy/himalaya.template.json +1 -1
- package/templates/brandy/provisioning.json +4 -1
- package/templates/brandy/provisioning.member.example.json +69 -7
- package/templates/brandy/tier5-src/_shared/exclusive-writes.ts +66 -0
- package/templates/brandy/tier5-src/_shared/header-badges.ts +113 -0
- package/templates/brandy/tier5-src/_shared/himi-store-saved.ts +57 -0
- package/templates/brandy/tier5-src/_shared/iap-presentation.ts +207 -0
- package/templates/brandy/tier5-src/_shared/restaurant-ordering.ts +201 -0
- package/templates/brandy/tier5-src/_shared/source-badges.ts +72 -0
- package/templates/brandy/tier5-src/himi-branded-lite-cart/index.ts +703 -0
- package/templates/brandy/tier5-src/himi-branded-lite-header-badges/index.ts +70 -0
- package/templates/brandy/tier5-src/himi-branded-lite-member-cart/flag.ts +3 -0
- package/templates/brandy/tier5-src/himi-branded-lite-member-cart/index.ts +6 -0
- package/templates/brandy/tier5-src/perks/index.ts +75 -0
- package/templates/brandy/tokens.json +5 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// Restaurants online ordering — Wix's visitor "Place an order from a custom storefront" flow,
|
|
2
|
+
// shared by the dish detail (himi-branded-lite-menu-item: add a dish to the Wix cart) and the
|
|
3
|
+
// order screen (wix-spaces-food-orders: cart → pickup/delivery → hosted checkout → history).
|
|
4
|
+
//
|
|
5
|
+
// The cart is the site's eCom CURRENT cart (Cart V2). It is the same cart the Stores cart screen
|
|
6
|
+
// reads (V1 and V2 answer the same cart id), so a restaurant line is told apart by its catalog
|
|
7
|
+
// app — Restaurants Orders — never assumed. Every call here is visitor-scope; the member's placed
|
|
8
|
+
// orders are read through the eCom orders search the member Orders screen already uses, never
|
|
9
|
+
// through the owner-capable Restaurants Orders API.
|
|
10
|
+
import {
|
|
11
|
+
getFirstAvailableTimeSlotPerFulfillmentType,
|
|
12
|
+
listFulfillmentMethods,
|
|
13
|
+
listOperations,
|
|
14
|
+
queryMenus,
|
|
15
|
+
querySections,
|
|
16
|
+
type WixFulfillmentMethod,
|
|
17
|
+
type WixFulfillmentTimeSlot,
|
|
18
|
+
type WixMenu,
|
|
19
|
+
type WixOperation,
|
|
20
|
+
type WixRestaurantsAddress,
|
|
21
|
+
type WixSection,
|
|
22
|
+
} from "@himalaya/wix-restaurants";
|
|
23
|
+
import type { WixCartV2, WixCartV2LineItem, WixCatalogReference } from "@himalaya/wix-ecom";
|
|
24
|
+
import { formatCurrency } from "../_shared/engine-intl.js";
|
|
25
|
+
|
|
26
|
+
/** Wix Restaurants Orders — the catalog app a restaurant cart line belongs to. */
|
|
27
|
+
export const RESTAURANTS_ORDERS_APP_ID = "9a5d83fd-8570-482e-81ab-cfa88942ee60";
|
|
28
|
+
|
|
29
|
+
export type FulfillmentType = "PICKUP" | "DELIVERY";
|
|
30
|
+
|
|
31
|
+
/** The operation a visitor orders from: an `ENABLED` one, the site's default first. None means
|
|
32
|
+
* online ordering is closed (`DISABLED`, `PAUSED_UNTIL`, or no operation at all). */
|
|
33
|
+
export function orderingOperation(operations: WixOperation[] | undefined, selection: { businessLocationId?: string; operationId?: string } = {}): WixOperation | undefined {
|
|
34
|
+
const open = (operations ?? []).filter((operation) => !!operation?.id && operation.onlineOrderingStatus === "ENABLED");
|
|
35
|
+
if (selection.operationId) return open.find((operation) => operation.id === selection.operationId);
|
|
36
|
+
if (selection.businessLocationId) return open.find((operation) => operation.businessLocationId === selection.businessLocationId);
|
|
37
|
+
return open.find((operation) => operation.default === true) ?? open[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function loadOrderingOperation(selection: { businessLocationId?: string; operationId?: string } = {}): Promise<WixOperation | undefined> {
|
|
41
|
+
return orderingOperation((await listOperations()).operations, selection);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The enabled pickup/delivery methods [operation] offers: the ones its `fulfillmentIds` name. An
|
|
45
|
+
* operation that names none falls back only to methods at its own business location — never to
|
|
46
|
+
* every method on the site, which on a multi-location site would offer another location's pickup. */
|
|
47
|
+
export function offeredMethods(operation: WixOperation, methods: WixFulfillmentMethod[] | undefined): WixFulfillmentMethod[] {
|
|
48
|
+
const ids = new Set(operation.fulfillmentIds ?? []);
|
|
49
|
+
const belongs = (method: WixFulfillmentMethod) => ids.size > 0
|
|
50
|
+
? ids.has(method.id)
|
|
51
|
+
: !!operation.businessLocationId && method.businessLocationId === operation.businessLocationId;
|
|
52
|
+
return (methods ?? []).filter((method) =>
|
|
53
|
+
!!method?.id && method.enabled === true && (method.type === "PICKUP" || method.type === "DELIVERY") && belongs(method));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function loadOfferedMethods(operation: WixOperation): Promise<WixFulfillmentMethod[]> {
|
|
57
|
+
const all: WixFulfillmentMethod[] = [];
|
|
58
|
+
let cursor = "";
|
|
59
|
+
// A site has a handful of methods; five pages of 100 is a bound, not an expectation.
|
|
60
|
+
for (let page = 0; page < 5; page++) {
|
|
61
|
+
const response = await listFulfillmentMethods({ limit: 100, ...(cursor ? { cursor } : {}) });
|
|
62
|
+
all.push(...(response.fulfillmentMethods ?? []));
|
|
63
|
+
cursor = response.pagingMetadata?.hasNext ? response.pagingMetadata.cursors?.next ?? "" : "";
|
|
64
|
+
if (!cursor) break;
|
|
65
|
+
}
|
|
66
|
+
return offeredMethods(operation, all);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A decimal string from Wix ("6.99", "0") as a number; anything else is 0 (a missing fee is free). */
|
|
70
|
+
export function decimal(value: unknown): number {
|
|
71
|
+
const n = typeof value === "number" ? value : Number(typeof value === "string" ? value.trim() : NaN);
|
|
72
|
+
return Number.isFinite(n) ? n : 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Cart V2 money carries no formatted string: format the decimal with the cart's currency. */
|
|
76
|
+
export function money(amount: unknown, currency: string | undefined): string {
|
|
77
|
+
return formatCurrency(decimal(amount), (currency ?? "").trim() || "USD");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function cartCurrency(cart: WixCartV2 | undefined): string {
|
|
81
|
+
return cart?.businessInfo?.currencyCode || cart?.customerInfo?.currencyCode || "";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Where a dish is ordered from. Checkout validates the line against `menuSectionId`, so it must
|
|
85
|
+
* be a visible section that lists the dish, inside a visible menu that lists the section. */
|
|
86
|
+
export interface DishPlacement {
|
|
87
|
+
menuId: string;
|
|
88
|
+
sectionId: string;
|
|
89
|
+
businessLocationId?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The section the dish was shown under wins when it qualifies; otherwise the first visible
|
|
93
|
+
* menu → section that lists it. None → the dish is on no orderable menu. */
|
|
94
|
+
export function pickPlacement(
|
|
95
|
+
dishId: string,
|
|
96
|
+
menus: WixMenu[],
|
|
97
|
+
sections: WixSection[],
|
|
98
|
+
hint: { menuId?: string; sectionId?: string } = {},
|
|
99
|
+
): DishPlacement | undefined {
|
|
100
|
+
const listing = new Map(sections
|
|
101
|
+
.filter((section) => !!section?.id && section.visible !== false && (section.itemIds ?? []).includes(dishId))
|
|
102
|
+
.map((section) => [section.id, section]));
|
|
103
|
+
const candidates: DishPlacement[] = [];
|
|
104
|
+
for (const menu of menus) {
|
|
105
|
+
if (!menu?.id || menu.visible === false) continue;
|
|
106
|
+
for (const sectionId of menu.sectionIds ?? []) {
|
|
107
|
+
if (listing.has(sectionId)) candidates.push({ menuId: menu.id, sectionId, businessLocationId: menu.businessLocationId });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return candidates.find((c) => c.sectionId === hint.sectionId && (!hint.menuId || c.menuId === hint.menuId)) ?? candidates[0];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function loadDishPlacement(dishId: string, hint: { menuId?: string; sectionId?: string }): Promise<DishPlacement | undefined> {
|
|
114
|
+
const [sections, menus] = await Promise.all([
|
|
115
|
+
querySections({ paging: { limit: 100 } }),
|
|
116
|
+
queryMenus({ paging: { limit: 50 } }),
|
|
117
|
+
]);
|
|
118
|
+
return pickPlacement(dishId, menus.menus ?? [], sections.sections ?? [], hint);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The catalog reference for one dish line. There is no `variantId` key in `options`. */
|
|
122
|
+
export function dishReference(dishId: string, operationId: string, placement: DishPlacement): WixCatalogReference {
|
|
123
|
+
return {
|
|
124
|
+
appId: RESTAURANTS_ORDERS_APP_ID,
|
|
125
|
+
catalogItemId: dishId,
|
|
126
|
+
options: {
|
|
127
|
+
operationId,
|
|
128
|
+
menuId: placement.menuId,
|
|
129
|
+
menuSectionId: placement.sectionId,
|
|
130
|
+
sectionId: placement.sectionId,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function isRestaurantLine(line: WixCartV2LineItem | undefined): boolean {
|
|
136
|
+
return line?.source?.catalogReference?.appId === RESTAURANTS_ORDERS_APP_ID;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function lineVariantId(line: WixCartV2LineItem): string {
|
|
140
|
+
const variant = (line.source?.catalogReference?.options as { priceVariant?: { id?: unknown } } | undefined)?.priceVariant;
|
|
141
|
+
return typeof variant?.id === "string" ? variant.id : "";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The cart line Wix kept for [reference] — same dish, operation, menu, section and variant — or
|
|
145
|
+
* undefined when Wix dropped it. Wix can refuse an item and still answer 200, so the returned cart
|
|
146
|
+
* is the proof. The operation and menu matter: the same dish added from two restaurant locations
|
|
147
|
+
* is two lines, and only the one just added proves this add. */
|
|
148
|
+
export function addedLine(cart: WixCartV2 | undefined, reference: WixCatalogReference): WixCartV2LineItem | undefined {
|
|
149
|
+
type PlacementOptions = { operationId?: unknown; menuId?: unknown; menuSectionId?: unknown };
|
|
150
|
+
const options = (reference.options ?? {}) as PlacementOptions & { priceVariant?: { id?: unknown } };
|
|
151
|
+
const variantId = typeof options.priceVariant?.id === "string" ? options.priceVariant.id : "";
|
|
152
|
+
return (cart?.lineItems ?? []).find((line) => {
|
|
153
|
+
const ref = line.source?.catalogReference;
|
|
154
|
+
if (!ref || ref.appId !== reference.appId || ref.catalogItemId !== reference.catalogItemId) return false;
|
|
155
|
+
const lineOptions = (ref.options ?? {}) as PlacementOptions;
|
|
156
|
+
if (lineOptions.operationId !== options.operationId || lineOptions.menuId !== options.menuId) return false;
|
|
157
|
+
if (lineOptions.menuSectionId !== options.menuSectionId) return false;
|
|
158
|
+
if (lineVariantId(line) !== variantId) return false;
|
|
159
|
+
if (line.status === "OUT_OF_STOCK" || line.status === "REMOVED_FROM_CATALOG") return false;
|
|
160
|
+
const confirmed = line.quantityInfo?.confirmedQuantity;
|
|
161
|
+
return confirmed === undefined || confirmed > 0;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function lineQuantity(line: WixCartV2LineItem): number {
|
|
166
|
+
const q = line.quantityInfo?.confirmedQuantity ?? line.quantityInfo?.requestedQuantity ?? 1;
|
|
167
|
+
return Number.isFinite(q) && q >= 0 ? Math.floor(q) : 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** How many dishes the cart holds (restaurant lines only). */
|
|
171
|
+
export function restaurantItemCount(cart: WixCartV2 | undefined): number {
|
|
172
|
+
return (cart?.lineItems ?? []).filter(isRestaurantLine).reduce((total, line) => total + lineQuantity(line), 0);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function slotFor(slots: WixFulfillmentTimeSlot[] | undefined, type: FulfillmentType): WixFulfillmentTimeSlot | undefined {
|
|
176
|
+
return (slots ?? []).find((slot) => slot?.fulfilmentType === type);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The `deliveryMethod.code` for [type]: `<TYPE>|ASAP`, or the slot's own window for a pre-order.
|
|
180
|
+
* An ASAP slot must be sent as ASAP — its start/end window is refused as `DELIVERY_METHOD_NOT_FOUND`. */
|
|
181
|
+
export function deliveryCode(type: FulfillmentType, slot?: WixFulfillmentTimeSlot): string {
|
|
182
|
+
const window = slot?.timeSlot;
|
|
183
|
+
if (window?.orderSchedulingType === "PREORDER") {
|
|
184
|
+
const start = Date.parse(window.startTime ?? ""), end = Date.parse(window.endTime ?? "");
|
|
185
|
+
if (Number.isFinite(start) && Number.isFinite(end)) return `${type}|${start}|${end}`;
|
|
186
|
+
}
|
|
187
|
+
return `${type}|ASAP`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export async function firstSlots(operationId: string, deliveryAddress?: WixRestaurantsAddress): Promise<WixFulfillmentTimeSlot[]> {
|
|
191
|
+
return (await getFirstAvailableTimeSlotPerFulfillmentType(operationId, deliveryAddress)).timeslotsPerFulfillmentType ?? [];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The pickup address the cart needs before a pickup method can be set: the restaurant's own
|
|
195
|
+
* country (and region when Wix gives one) — Wix requires an address even for pickup. */
|
|
196
|
+
export function pickupCartAddress(method: WixFulfillmentMethod | undefined, fallbackCountry = ""): WixRestaurantsAddress | undefined {
|
|
197
|
+
const address = method?.pickupOptions?.address;
|
|
198
|
+
const country = (address?.country || fallbackCountry).trim();
|
|
199
|
+
if (!country) return undefined;
|
|
200
|
+
return { country, ...(address?.subdivision ? { subdivision: address.subdivision } : {}) };
|
|
201
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The live counts behind the header buttons of a migrated One App (notifications, chat, cart), read for the
|
|
2
|
+
// app-level nav worker. `null` is "unavailable" and never a zero: a failed, offline or stale read leaves the
|
|
3
|
+
// badge off instead of claiming an empty inbox or cart. The shell shows no badge for null or 0 alike, so the
|
|
4
|
+
// two differ only in what the worker may later believe about the source.
|
|
5
|
+
import { getCurrentCart } from "@himalaya/wix-ecom";
|
|
6
|
+
import { countUnseenNotifications } from "@himalaya/wix-members-feed-viewer";
|
|
7
|
+
import { connectivity } from "@himalaya/state";
|
|
8
|
+
import { chatIdentity, unreadRoomCount } from "./business-chat-transport.js";
|
|
9
|
+
import { memberAccess } from "./member-access.js";
|
|
10
|
+
|
|
11
|
+
export type SourceBadgeKey = "notifications" | "chat" | "cart";
|
|
12
|
+
export interface SourceBadges {
|
|
13
|
+
notifications: number | null;
|
|
14
|
+
chat: number | null;
|
|
15
|
+
cart: number | null;
|
|
16
|
+
/** The counts a read was attempted for and failed: not the ones unavailable by design (a Visitor's bell and chat,
|
|
17
|
+
* offline), and not one dropped because the identity changed mid-read. */
|
|
18
|
+
failed: SourceBadgeKey[];
|
|
19
|
+
}
|
|
20
|
+
export const NO_SOURCE_BADGES: SourceBadges = { notifications: null, chat: null, cart: null, failed: [] };
|
|
21
|
+
|
|
22
|
+
/** The same item count the Shop and Account badges show: every line's quantity, a missing one counting as 1. */
|
|
23
|
+
async function cartItemCount(): Promise<number> {
|
|
24
|
+
const cart = await getCurrentCart();
|
|
25
|
+
return (cart.lineItems ?? []).reduce((total, line) => total + (line.quantity ?? 1), 0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Whether the shopper is still the one the read started for. A cart belongs to a Visitor as much as to a
|
|
29
|
+
* Member, so this compares what `memberAccess` reports rather than requiring a signed-in member. */
|
|
30
|
+
async function sameShopper(started: { email: string; scope: string }): Promise<boolean> {
|
|
31
|
+
const now = await memberAccess();
|
|
32
|
+
return now.email === started.email && now.scope === started.scope;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function unavailable<T>(read: () => Promise<T>): Promise<T | null> {
|
|
36
|
+
try { return await read(); } catch { return null; }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A read dropped because the shopper changed while it ran: expected, not a failure to report. */
|
|
40
|
+
const SHOPPER_CHANGED = new Error("shopper changed");
|
|
41
|
+
|
|
42
|
+
/** One refresh. Notifications and chat are a Member's: a Visitor has neither inbox, so both read null without
|
|
43
|
+
* a request. Notifications also need `hostMember`, the host's own session clock saying it is a signed-in member
|
|
44
|
+
* (a host with no clock, web and older binaries, stays unavailable). The worker names no site: native sends
|
|
45
|
+
* the bridge's bound site, or none in the multi-tenant Player, where the member credential fixes the business.
|
|
46
|
+
* Cart is the current shopper's.
|
|
47
|
+
* Offline reads nothing. A count that finishes after the signed-in identity changed is dropped, so one
|
|
48
|
+
* member's number never lands on the next member's header. */
|
|
49
|
+
export async function readSourceBadges(hostMember: boolean): Promise<SourceBadges> {
|
|
50
|
+
// Whatever goes wrong, the answer is "unavailable": this runs fire-and-forget at launch.
|
|
51
|
+
const read = unavailable(async (): Promise<SourceBadges> => {
|
|
52
|
+
if (!connectivity().online) return NO_SOURCE_BADGES;
|
|
53
|
+
const identity = await chatIdentity();
|
|
54
|
+
const member = identity.authenticated;
|
|
55
|
+
const stillHere = async <T>(count: Promise<T>): Promise<T> => {
|
|
56
|
+
const value = await count;
|
|
57
|
+
if (!(await sameShopper(identity))) throw SHOPPER_CHANGED;
|
|
58
|
+
return value;
|
|
59
|
+
};
|
|
60
|
+
const failed: SourceBadgeKey[] = [];
|
|
61
|
+
const attempt = async <T>(key: SourceBadgeKey, run: () => Promise<T>): Promise<T | null> => {
|
|
62
|
+
try { return await run(); } catch (error) { if (error !== SHOPPER_CHANGED) failed.push(key); return null; }
|
|
63
|
+
};
|
|
64
|
+
const [notifications, chat, cart] = await Promise.all([
|
|
65
|
+
member && hostMember ? attempt("notifications", () => stillHere(countUnseenNotifications())) : null,
|
|
66
|
+
member ? attempt("chat", () => unreadRoomCount(identity)) : null,
|
|
67
|
+
attempt("cart", () => stillHere(cartItemCount())),
|
|
68
|
+
]);
|
|
69
|
+
return { notifications, chat, cart, failed };
|
|
70
|
+
});
|
|
71
|
+
return (await read) ?? NO_SOURCE_BADGES;
|
|
72
|
+
}
|