@wix/himalaya-cli 0.1648.0 → 0.1650.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/sdk/ui/src/index.d.ts +4 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/ui.mjs +1 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{4ef4d326496b4d7809746936207067b4c921f5db9878ecc7030aa3a9e4d2aaeb.bin → 6ba3f2eb2ac29f4f9eeebd1294a8003820cd260274c5400149d76833b3171555.bin} +1 -1
- package/dist/browser-plane/sw.js +5 -5
- package/dist/cli.mjs +45 -40
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/sdk-reference.json +8 -1
- package/package.json +2 -2
- package/template-icons/wholesale-store.png +0 -0
- package/templates/beauty-salon/config.ts +16 -1
- package/templates/branded-lite/config.ts +16 -1
- package/templates/branded-lite/dev/index.ts +292 -305
- package/templates/branded-lite/l10n/en.json +3 -3
- package/templates/branded-lite/tier5-src/_shared/branded-form.ts +22 -4
- package/templates/branded-lite/tier5-src/himi-branded-lite-form/index.ts +250 -74
- package/templates/community-club/config.ts +16 -1
- package/templates/events-meetups/config.ts +16 -1
- package/templates/gym-fitness/config.ts +16 -1
- package/templates/nonprofit-cause/config.ts +16 -1
- package/templates/podcast-creator/config.ts +16 -1
- package/templates/portfolio-creative/config.ts +16 -1
- package/templates/restaurant/config.ts +16 -1
- package/templates/retail-store/config.ts +16 -1
- package/templates/wholesale-store/README.md +53 -0
- package/templates/wholesale-store/config.ts +247 -0
- package/templates/wholesale-store/dev/index.ts +12194 -0
- package/templates/wholesale-store/himalaya.content.json +43 -0
- package/templates/wholesale-store/himalaya.template.json +14 -0
- package/templates/wholesale-store/icon.png +0 -0
- package/templates/wholesale-store/platforms.json +1 -0
- package/templates/wholesale-store/tier5-src/_shared/app-locale.ts +61 -0
- package/templates/wholesale-store/tier5-src/_shared/branded-lite-hosted.ts +279 -0
- package/templates/wholesale-store/tier5-src/_shared/business-chat-copy.ts +40 -0
- package/templates/wholesale-store/tier5-src/_shared/business-chat-history.ts +51 -0
- package/templates/wholesale-store/tier5-src/_shared/business-chat-message-model.ts +177 -0
- package/templates/wholesale-store/tier5-src/_shared/business-chat-model.ts +56 -0
- package/templates/wholesale-store/tier5-src/_shared/business-chat-presenter.ts +576 -0
- package/templates/wholesale-store/tier5-src/_shared/business-chat-transport.ts +148 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-contract.ts +228 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +194 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +252 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +423 -0
- package/templates/wholesale-store/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/wholesale-store/tier5-src/_shared/empty-flags.ts +33 -0
- package/templates/wholesale-store/tier5-src/_shared/engine-intl.ts +508 -0
- package/templates/wholesale-store/tier5-src/_shared/exclusive-writes.ts +66 -0
- package/templates/wholesale-store/tier5-src/_shared/himi-account.ts +164 -0
- package/templates/wholesale-store/tier5-src/_shared/himi-copy.ts +89 -0
- package/templates/wholesale-store/tier5-src/_shared/himi-store-categories.ts +108 -0
- package/templates/wholesale-store/tier5-src/_shared/himi-store-collection.ts +22 -0
- package/templates/wholesale-store/tier5-src/_shared/himi-store-saved.ts +57 -0
- package/templates/wholesale-store/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/wholesale-store/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/wholesale-store/tier5-src/_shared/iap-presentation.ts +207 -0
- package/templates/wholesale-store/tier5-src/_shared/iap-worker.ts +125 -0
- package/templates/wholesale-store/tier5-src/_shared/inbox-rooms.ts +68 -0
- package/templates/wholesale-store/tier5-src/_shared/live-session.ts +172 -0
- package/templates/wholesale-store/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/wholesale-store/tier5-src/_shared/member-access.ts +52 -0
- package/templates/wholesale-store/tier5-src/_shared/member-account-routes.ts +52 -0
- package/templates/wholesale-store/tier5-src/_shared/member-orders.ts +8 -0
- package/templates/wholesale-store/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/wholesale-store/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/wholesale-store/tier5-src/_shared/owner-editor-value.ts +164 -0
- package/templates/wholesale-store/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/wholesale-store/tier5-src/_shared/payment-setup.ts +6 -0
- package/templates/wholesale-store/tier5-src/_shared/read-service.ts +255 -0
- package/templates/wholesale-store/tier5-src/_shared/restaurant-ordering.ts +201 -0
- package/templates/wholesale-store/tier5-src/_shared/rich-body.ts +78 -0
- package/templates/wholesale-store/tier5-src/_shared/rich-content-link.ts +34 -0
- package/templates/wholesale-store/tier5-src/_shared/sign-in-sheet.ts +18 -0
- package/templates/wholesale-store/tier5-src/_shared/store-order-presentation.ts +56 -0
- package/templates/wholesale-store/tier5-src/_shared/store-product-info.ts +50 -0
- package/templates/wholesale-store/tier5-src/business-chat/index.ts +724 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-cart/index.ts +602 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-order/index.ts +472 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-orders/index.ts +327 -0
- package/templates/wholesale-store/tier5-src/himi-store-account/index.ts +998 -0
- package/templates/wholesale-store/tier5-src/himi-store-product/index.ts +889 -0
- package/templates/wholesale-store/tier5-src/himi-store-saved/index.ts +68 -0
- package/templates/wholesale-store/tier5-src/himi-store-shop/index.ts +150 -0
- package/templates/wholesale-store/tier5-src/himi-wholesale-home/index.ts +507 -0
- package/templates/wholesale-store/tier5-src/wix-spaces-collection-detail/index.ts +195 -0
- package/templates/wholesale-store/tokens.json +340 -0
- package/templates/yoga-studio/config.ts +16 -1
|
@@ -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,78 @@
|
|
|
1
|
+
// [rico] #3370 — an entity's Ricos body, prepared for a RichContent component and its plain-text fallback.
|
|
2
|
+
// One rule for every worker that renders a body (the blog post and the owner post detail today; #3372's
|
|
3
|
+
// verticals next), so they cannot drift apart.
|
|
4
|
+
// Inside the platform source this import is a relative path, so node test runs resolve it; an app's copy
|
|
5
|
+
// imports "@himalaya/wix-rich-content".
|
|
6
|
+
import { encodeRichContent, parseRicosJson, ricosToPlainText } from "@himalaya/wix-rich-content";
|
|
7
|
+
|
|
8
|
+
/** What a body-rendering worker publishes: `<name>Json` for `documentJsonPath`, and the plain text. */
|
|
9
|
+
export interface RichBody {
|
|
10
|
+
/** The document as ONE JSON string (media sized, disallowed links dropped); "" when there is no document
|
|
11
|
+
* or the encoder rejected it. RichContent draws nothing for "", so a screen gates its plain text on it. */
|
|
12
|
+
bodyJson: string;
|
|
13
|
+
/** The plain text: the document's own text when it has any, else `fallback`. */
|
|
14
|
+
bodyText: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** [rico] #3372 — the media width for a document drawn in a LIST row (a feed post, a comment, a CMS item): the
|
|
18
|
+
* list-image size (WIX_LIST_IMAGE), so a scrolling list never downloads every image at detail size. */
|
|
19
|
+
export const ROW_IMAGE_WIDTH = 1000;
|
|
20
|
+
|
|
21
|
+
/** Prepares `richContent` (a Ricos document, as a Wix API returns it, or its JSON string). No document, or one
|
|
22
|
+
* that is not a document, gives `{ bodyJson: "", bodyText: fallback }`. A document past the viewer's limits
|
|
23
|
+
* gives bodyJson "" and its plain text — except one rejected as too deep, which is not walked again (the
|
|
24
|
+
* plain-text walk has no depth limit), so `fallback` stands in for it. `imageWidth` sizes its media (default
|
|
25
|
+
* the 1400 px detail budget). */
|
|
26
|
+
export function richBody(richContent: unknown, fallback = "", imageWidth = 1400): RichBody {
|
|
27
|
+
const doc = parseRicosJson(richContent);
|
|
28
|
+
if (!doc) return { bodyJson: "", bodyText: fallback };
|
|
29
|
+
// 1400 px by default — the detail-image budget, which is also the encoder's maximum; list rows pass
|
|
30
|
+
// ROW_IMAGE_WIDTH.
|
|
31
|
+
const { json, rejected } = encodeRichContent(doc, { imageWidth });
|
|
32
|
+
const text = rejected === "too_deep" ? "" : ricosToPlainText(doc);
|
|
33
|
+
return { bodyJson: json, bodyText: text || fallback };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A Wix description may be Ricos (including serialized JSON), HTML or ordinary text.
|
|
37
|
+
* Keep rich documents on the existing bounded encoder path. Non-document JSON and
|
|
38
|
+
* clearly malformed serialization use an independent fallback. Ambiguous bracketed
|
|
39
|
+
* prose stays readable; this does not attempt to repair arbitrary JSON syntax. */
|
|
40
|
+
export function descriptionBody(value: unknown, fallback = "", imageWidth = 1400): RichBody {
|
|
41
|
+
if (typeof value !== "string") return richBody(value, fallback, imageWidth);
|
|
42
|
+
const text = value.trim();
|
|
43
|
+
if (/^[{[]/.test(text)) {
|
|
44
|
+
try {
|
|
45
|
+
const parsed: unknown = JSON.parse(text);
|
|
46
|
+
// Passing the parsed value avoids parsing a valid Ricos document twice; a
|
|
47
|
+
// different JSON structure is rejected by the same existing document check.
|
|
48
|
+
if (parsed && typeof parsed === "object") return richBody(parsed, fallback, imageWidth);
|
|
49
|
+
} catch {
|
|
50
|
+
const objectLike = /^\{\s*(?:["'}]|nodes\b)/.test(text);
|
|
51
|
+
// Only reject scalar-looking malformed arrays when their syntax is clearly
|
|
52
|
+
// unfinished (or contains JS's non-JSON `undefined`). Balanced bracketed
|
|
53
|
+
// prose such as "[1,000]" and "[12:30, 13:30]" is not JSON and stays readable.
|
|
54
|
+
const arrayTokens = text.replace(/"(?:\\.|[^"\\])*"/g, "")
|
|
55
|
+
.replace(/\b(?:true|false|null|undefined)\b/g, "")
|
|
56
|
+
.replace(/-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/g, "");
|
|
57
|
+
const arrayLike = /^\[\s*[{"]/.test(text)
|
|
58
|
+
|| (text.startsWith("[") && /^[\s[\]{},:]*$/.test(arrayTokens)
|
|
59
|
+
&& (/,\s*]?$/.test(text) || /\bundefined\b/.test(text) || !text.endsWith("]")));
|
|
60
|
+
if (objectLike || arrayLike) return { bodyJson: "", bodyText: fallback };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Legacy HTML descriptions stay text. Preserve paragraph breaks and ordinary prose's
|
|
64
|
+
// bare '<' (e.g. "ages < 8"), without relying on browser-only DOM APIs in workers.
|
|
65
|
+
const plain = text
|
|
66
|
+
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, "")
|
|
67
|
+
.replace(/<br\s*\/?\s*>/gi, "\n")
|
|
68
|
+
.replace(/<\/(?:p|div|h[1-6]|li)\s*>/gi, "\n\n")
|
|
69
|
+
.replace(/<\/?[a-z][^>]*>/gi, "")
|
|
70
|
+
.replace(/&(?:nbsp|amp|lt|gt|quot|apos|#39);/gi, (entity) => ({
|
|
71
|
+
" ": " ", "&": "&", "<": "<", ">": ">", """: '"', "'": "'", "'": "'",
|
|
72
|
+
})[entity.toLowerCase()] ?? entity)
|
|
73
|
+
.replace(/[\t\r ]+/g, " ")
|
|
74
|
+
.replace(/ *\n */g, "\n")
|
|
75
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
76
|
+
.trim();
|
|
77
|
+
return { bodyJson: "", bodyText: plain || fallback };
|
|
78
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// [rico] #3370 — a RichContent `on_link` tap reaches the worker as `{ url }` (the renderers merge the tapped
|
|
2
|
+
// link into the action's args). Only http(s) with a host, mailto and tel ever reach the OS; anything
|
|
3
|
+
// else is dropped here, before any dispatch. The renderers already refuse other schemes, but the action
|
|
4
|
+
// arrives here as plain data, so the worker checks it again rather than trusting whoever sent it.
|
|
5
|
+
import { open, defaultMode } from "@himalaya/open-url";
|
|
6
|
+
|
|
7
|
+
/** The viewer's link rule, verbatim (`LINK` in @himalaya/wix-rich-content's display.ts, which the package does
|
|
8
|
+
* not export); a parity test pins this copy to the original. */
|
|
9
|
+
const LINK = /^(https?:\/\/[^\s/?#]\S*|mailto:\S+|tel:\S+)$/i;
|
|
10
|
+
/** ASCII whitespace only, as the viewer trims a link before applying the rule. */
|
|
11
|
+
const trimAscii = (s: string): string => s.replace(/^[\t\n\v\f\r ]+|[\t\n\v\f\r ]+$/g, "");
|
|
12
|
+
|
|
13
|
+
/** The url of a link tap (`{ url }`, `{ args: { url } }` or a bare string), or "" when it is missing or
|
|
14
|
+
* not an http(s), mailto or tel link. */
|
|
15
|
+
export function richLinkUrl(arg: unknown): string {
|
|
16
|
+
const a = arg as { url?: unknown; args?: { url?: unknown } } | null | undefined;
|
|
17
|
+
const raw = typeof arg === "string" ? arg
|
|
18
|
+
: typeof a?.url === "string" ? a.url
|
|
19
|
+
: typeof a?.args?.url === "string" ? a.args.url : "";
|
|
20
|
+
const url = trimAscii(raw);
|
|
21
|
+
return LINK.test(url) ? url : "";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Opens a link tap through `capability.open_url` (http(s) in the in-app browser, mailto/tel in the system
|
|
25
|
+
* handler). False when the link is blocked, nothing took it, or the host threw. */
|
|
26
|
+
export async function openRichLink(arg: unknown): Promise<boolean> {
|
|
27
|
+
const url = richLinkUrl(arg);
|
|
28
|
+
if (!url) return false;
|
|
29
|
+
try {
|
|
30
|
+
return (await open(url, defaultMode(url))).opened;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// A sign-in sheet can be a form page rather than a drawer. `sheetStyle: "page"` keeps the iOS sheet
|
|
2
|
+
// and opens a full-screen modal on Android and web, whose sheet is a bottom drawer. A host older
|
|
3
|
+
// than the param ignores it and draws its own sheet.
|
|
4
|
+
//
|
|
5
|
+
// Opt-in per app: the app passes `signInSheetStyle: "page"` beside `signInPresentation`. These
|
|
6
|
+
// workers are shared (Salon & Spa runs them too), and an app that opens its other sign-ins as a
|
|
7
|
+
// plain sheet must not get a page from some of them and a drawer from the rest.
|
|
8
|
+
|
|
9
|
+
/** The app's `signInSheetStyle` param, read beside `signInPresentation`: "page", else "". */
|
|
10
|
+
export function signInPageStyle(value: unknown): "page" | "" {
|
|
11
|
+
return value === "page" ? "page" : "";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The nav args a sign-in opened with `presentation` adds: `sheetStyle` on a sheet the app asked
|
|
15
|
+
* to open as a page, else none. */
|
|
16
|
+
export function signInSheetStyle(presentation: string | undefined, style: "page" | ""): { sheetStyle?: "page" } {
|
|
17
|
+
return presentation === "sheet" && style === "page" ? { sheetStyle: "page" } : {};
|
|
18
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Display-only fields from the ecom Order wire shape. No additional endpoints or grants.
|
|
2
|
+
// The generated minimal WixOrder intentionally omits these optional fields.
|
|
3
|
+
import type { WixOrder, WixOrderLineItem, WixOrderLineItemDescriptionLine } from "@himalaya/wix-ecom";
|
|
4
|
+
import { copyParam } from "./himi-copy.js";
|
|
5
|
+
interface Address {
|
|
6
|
+
addressLine?: string;
|
|
7
|
+
addressLine2?: string;
|
|
8
|
+
streetAddress?: { number?: string; name?: string };
|
|
9
|
+
city?: string;
|
|
10
|
+
subdivision?: string;
|
|
11
|
+
subdivisionFullname?: string;
|
|
12
|
+
postalCode?: string;
|
|
13
|
+
country?: string;
|
|
14
|
+
countryFullname?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface DisplayOrderLine extends WixOrderLineItem {
|
|
17
|
+
descriptionLines?: WixOrderLineItemDescriptionLine[];
|
|
18
|
+
}
|
|
19
|
+
export interface DisplayOrder extends WixOrder {
|
|
20
|
+
shippingInfo?: {
|
|
21
|
+
title?: string;
|
|
22
|
+
logistics?: {
|
|
23
|
+
shippingDestination?: { address?: Address; contactDetails?: { firstName?: string; lastName?: string } };
|
|
24
|
+
pickupDetails?: { address?: Address };
|
|
25
|
+
deliveryTime?: string;
|
|
26
|
+
instructions?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function orderDelivery(order: DisplayOrder): { deliveryTitle: string; deliveryLines: string; deliveryMethod: string; deliveryAddress: string } {
|
|
31
|
+
const info = order.shippingInfo;
|
|
32
|
+
const logistics = info?.logistics;
|
|
33
|
+
const pickup = logistics?.pickupDetails;
|
|
34
|
+
const destination = logistics?.shippingDestination;
|
|
35
|
+
const address = pickup?.address ?? destination?.address;
|
|
36
|
+
const name = pickup ? "" : [destination?.contactDetails?.firstName, destination?.contactDetails?.lastName].filter(Boolean).join(" ");
|
|
37
|
+
const street = address?.addressLine || [address?.streetAddress?.number, address?.streetAddress?.name].filter(Boolean).join(" ");
|
|
38
|
+
const addressLines = [name, street, address?.addressLine2,
|
|
39
|
+
[address?.city, address?.subdivisionFullname || address?.subdivision, address?.postalCode].filter(Boolean).join(", "),
|
|
40
|
+
address?.countryFullname || address?.country,
|
|
41
|
+
].filter(Boolean);
|
|
42
|
+
const methodLines = [info?.title, logistics?.deliveryTime, logistics?.instructions].filter(Boolean);
|
|
43
|
+
return {
|
|
44
|
+
deliveryTitle: pickup ? copyParam("order.pickupTitle", "Pickup") : copyParam("order.deliveryTitle", "Delivery"),
|
|
45
|
+
deliveryLines: [info?.title, ...addressLines, logistics?.deliveryTime, logistics?.instructions].filter(Boolean).join("\n"),
|
|
46
|
+
deliveryMethod: methodLines.join("\n"),
|
|
47
|
+
deliveryAddress: addressLines.join("\n"),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function orderOptions(line: DisplayOrderLine): string {
|
|
51
|
+
return (line.descriptionLines ?? []).map(option => {
|
|
52
|
+
const name = option.name?.translated || option.name?.original;
|
|
53
|
+
const value = option.plainText?.translated || option.plainText?.original;
|
|
54
|
+
return value ? [name, value].filter(Boolean).join(": ") : "";
|
|
55
|
+
}).filter(Boolean).join(" · ");
|
|
56
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { StoreProduct } from "./himi-store.js";
|
|
2
|
+
import { cleanTitle } from "./himi-text.js";
|
|
3
|
+
import { descriptionBody } from "./rich-body.js";
|
|
4
|
+
import { isEmptyDocument } from "./owner-editor-value.js";
|
|
5
|
+
|
|
6
|
+
/** V3 returns only section ids and titles for `INFO_SECTION`; the rich and HTML bodies
|
|
7
|
+
* are separate fields. `DESCRIPTION` keeps the product's own Ricos description. A V1
|
|
8
|
+
* catalog ignores all of these. */
|
|
9
|
+
export const PRODUCT_DETAIL_FIELDS = ["DESCRIPTION", "INFO_SECTION", "INFO_SECTION_DESCRIPTION", "INFO_SECTION_PLAIN_DESCRIPTION"] as const;
|
|
10
|
+
|
|
11
|
+
export interface ProductInfoSection {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
body: string;
|
|
15
|
+
bodyJson: string;
|
|
16
|
+
hasBodyJson: boolean;
|
|
17
|
+
noTitle: boolean;
|
|
18
|
+
expanded: boolean;
|
|
19
|
+
collapsed: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Keep authored order and bodies; retain expansion only where the source identity is unambiguous. */
|
|
23
|
+
export function productInfoSections(product: StoreProduct, previous: ProductInfoSection[]): ProductInfoSection[] {
|
|
24
|
+
const expanded = new Map(previous.map(section => [section.id, section.expanded]));
|
|
25
|
+
const occurrences = new Map<string, number>();
|
|
26
|
+
const sections = [...(product.infoSections ?? []), ...(product.additionalInfoSections ?? [])];
|
|
27
|
+
const titles = sections.map(section => cleanTitle(section.title));
|
|
28
|
+
const titleCounts = new Map<string, number>();
|
|
29
|
+
const previousTitleCounts = new Map<string, number>();
|
|
30
|
+
for (const title of titles) titleCounts.set(title, (titleCounts.get(title) ?? 0) + 1);
|
|
31
|
+
for (const section of previous) previousTitleCounts.set(section.title, (previousTitleCounts.get(section.title) ?? 0) + 1);
|
|
32
|
+
return sections.flatMap((section, index) => {
|
|
33
|
+
const title = titles[index];
|
|
34
|
+
const sourceId = "uniqueName" in section ? section.uniqueName?.trim() : "";
|
|
35
|
+
const key = sourceId || title;
|
|
36
|
+
const occurrence = occurrences.get(key) ?? 0;
|
|
37
|
+
occurrences.set(key, occurrence + 1);
|
|
38
|
+
const id = `info:${key}:${occurrence}`;
|
|
39
|
+
const fallback = descriptionBody("plainDescription" in section ? section.plainDescription : "").bodyText;
|
|
40
|
+
const rich = descriptionBody(section.description, fallback);
|
|
41
|
+
const body = rich.bodyText.trim() ? rich.bodyText : fallback;
|
|
42
|
+
// The bounded encoder can keep an empty paragraph. It must not hide real plain instructions.
|
|
43
|
+
const bodyJson = rich.bodyJson && !isEmptyDocument(JSON.parse(rich.bodyJson)) ? rich.bodyJson : "";
|
|
44
|
+
if (!body && !bodyJson) return [];
|
|
45
|
+
// V1 supplies no section id: duplicate titles cannot safely carry expansion through a refresh.
|
|
46
|
+
const mayKeepExpanded = !!sourceId || (titleCounts.get(title) === 1 && (previousTitleCounts.get(title) ?? 0) < 2);
|
|
47
|
+
const opened = !title || (mayKeepExpanded && (expanded.get(id) ?? false));
|
|
48
|
+
return [{ id, title, body, bodyJson, hasBodyJson: !!bodyJson, noTitle: !title, expanded: opened, collapsed: !opened }];
|
|
49
|
+
});
|
|
50
|
+
}
|