@wix/himalaya-cli 0.1871.0 → 0.1872.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-module.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/portfolio/src/index.d.ts +19 -0
- package/dist/cli.mjs +89 -39
- package/fixtures/wix-canned.json +8 -0
- package/guides/release-notes.md +18 -0
- package/guides/sdk-reference.json +8 -1
- package/package.json +2 -2
- package/template-icons/professional-services.png +0 -0
- package/templates/bare-fashion/config.ts +37 -2
- package/templates/bare-fashion/dev/index.ts +4006 -48
- package/templates/bare-fashion/himalaya.content.json +15 -0
- package/templates/bare-fashion/tier5-src/_shared/member-account-routes.ts +56 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/branded-lite/dev/index.ts +2 -1
- package/templates/branded-lite/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-coupons/index.ts +13 -2
- package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
- package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/community-club/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/conference/config.ts +43 -1
- package/templates/conference/dev/index.ts +4127 -0
- package/templates/conference/himalaya.content.json +18 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/conference/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/conference/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/events-meetups/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/medical-services/config.ts +42 -0
- package/templates/medical-services/dev/index.ts +4136 -0
- package/templates/medical-services/himalaya.content.json +18 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/medical-services/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/portfolio-creative/dev/index.ts +2 -1
- package/templates/portfolio-creative/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
- package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/professional-services/README.md +55 -0
- package/templates/professional-services/config.ts +436 -0
- package/templates/professional-services/dev/index.ts +44772 -0
- package/templates/professional-services/himalaya.content.json +100 -0
- package/templates/professional-services/himalaya.template.json +16 -0
- package/templates/professional-services/icon.png +0 -0
- package/templates/professional-services/platforms.json +1 -0
- package/templates/professional-services/tier5-src/_shared/app-locale.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/booking-location.ts +147 -0
- package/templates/professional-services/tier5-src/_shared/booking-session.ts +224 -0
- package/templates/professional-services/tier5-src/_shared/branded-lite-hosted.ts +282 -0
- package/templates/professional-services/tier5-src/_shared/branded-load-state.ts +109 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-copy.ts +40 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-history.ts +51 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-message-model.ts +177 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-model.ts +56 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-presenter.ts +587 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-transport.ts +164 -0
- package/templates/professional-services/tier5-src/_shared/chat-live.ts +242 -0
- package/templates/professional-services/tier5-src/_shared/collection-contract.ts +232 -0
- package/templates/professional-services/tier5-src/_shared/collection-query.ts +201 -0
- package/templates/professional-services/tier5-src/_shared/collection-service.ts +429 -0
- package/templates/professional-services/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/professional-services/tier5-src/_shared/engine-intl.ts +538 -0
- package/templates/professional-services/tier5-src/_shared/event-registration.ts +86 -0
- package/templates/professional-services/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/professional-services/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/professional-services/tier5-src/_shared/featured-event.ts +63 -0
- package/templates/professional-services/tier5-src/_shared/group-member-count.ts +15 -0
- package/templates/professional-services/tier5-src/_shared/group-privacy.ts +14 -0
- package/templates/professional-services/tier5-src/_shared/guest-sign-in.ts +36 -0
- package/templates/professional-services/tier5-src/_shared/himi-account.ts +222 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-hidden.ts +66 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-post-row.ts +214 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-saved.ts +64 -0
- package/templates/professional-services/tier5-src/_shared/himi-booking-saved.ts +88 -0
- package/templates/professional-services/tier5-src/_shared/himi-bookings.ts +318 -0
- package/templates/professional-services/tier5-src/_shared/himi-copy.ts +123 -0
- package/templates/professional-services/tier5-src/_shared/himi-events.ts +92 -0
- package/templates/professional-services/tier5-src/_shared/himi-media.ts +33 -0
- package/templates/professional-services/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/professional-services/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/professional-services/tier5-src/_shared/host-events.ts +66 -0
- package/templates/professional-services/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance-form.ts +106 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance-purchase.ts +235 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance.ts +38 -0
- package/templates/professional-services/tier5-src/_shared/iap-worker.ts +127 -0
- package/templates/professional-services/tier5-src/_shared/inbox-rooms.ts +163 -0
- package/templates/professional-services/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/professional-services/tier5-src/_shared/member-access.ts +63 -0
- package/templates/professional-services/tier5-src/_shared/member-account-routes.ts +56 -0
- package/templates/professional-services/tier5-src/_shared/member-avatar.ts +76 -0
- package/templates/professional-services/tier5-src/_shared/member-bookings.ts +107 -0
- package/templates/professional-services/tier5-src/_shared/member-read.ts +82 -0
- package/templates/professional-services/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/professional-services/tier5-src/_shared/notification-target.ts +141 -0
- package/templates/professional-services/tier5-src/_shared/offset-page.ts +10 -0
- package/templates/professional-services/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/professional-services/tier5-src/_shared/payment-setup.ts +6 -0
- package/templates/professional-services/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/professional-services/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/professional-services/tier5-src/_shared/result-snackbar.ts +26 -0
- package/templates/professional-services/tier5-src/_shared/rich-body.ts +78 -0
- package/templates/professional-services/tier5-src/_shared/rich-content-link.ts +34 -0
- package/templates/professional-services/tier5-src/_shared/sign-in-sheet.ts +18 -0
- package/templates/professional-services/tier5-src/_shared/staff-name.ts +18 -0
- package/templates/professional-services/tier5-src/_shared/weekly-goal.ts +111 -0
- package/templates/professional-services/tier5-src/_shared/wix-bi.ts +85 -0
- package/templates/professional-services/tier5-src/_shared/wix-member-links.ts +114 -0
- package/templates/professional-services/tier5-src/_shared/wix-service-price.ts +146 -0
- package/templates/professional-services/tier5-src/business-chat/index.ts +797 -0
- package/templates/professional-services/tier5-src/business-contact/index.ts +6 -0
- package/templates/professional-services/tier5-src/himi-blog-feed/index.ts +444 -0
- package/templates/professional-services/tier5-src/himi-blog-post/index.ts +1239 -0
- package/templates/professional-services/tier5-src/himi-booking-account/index.ts +278 -0
- package/templates/professional-services/tier5-src/himi-booking-bookings/index.ts +475 -0
- package/templates/professional-services/tier5-src/himi-booking-service/index.ts +1197 -0
- package/templates/professional-services/tier5-src/himi-booking-services/index.ts +795 -0
- package/templates/professional-services/tier5-src/himi-booking-time/index.ts +1840 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-coupons/index.ts +96 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-faq/index.ts +6 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-file-share/index.ts +12 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-group/index.ts +310 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-group-about/index.ts +240 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-my-groups/index.ts +237 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-notifications/index.ts +263 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-plans/index.ts +498 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-portfolio/index.ts +136 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-portfolio-project/index.ts +198 -0
- package/templates/professional-services/tier5-src/himi-events-detail/index.ts +1306 -0
- package/templates/professional-services/tier5-src/himi-events-list/index.ts +171 -0
- package/templates/professional-services/tier5-src/himi-events-my-events/index.ts +227 -0
- package/templates/professional-services/tier5-src/himi-events-rsvp/index.ts +230 -0
- package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts +318 -0
- package/templates/professional-services/tier5-src/himi-professional-services-home/index.ts +772 -0
- package/templates/professional-services/tier5-src/himi-store-account/index.ts +1514 -0
- package/templates/professional-services/tier5-src/wix-spaces-coupon-detail/index.ts +43 -0
- package/templates/professional-services/tier5-src/wix-spaces-my-subscriptions/index.ts +89 -0
- package/templates/professional-services/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
- package/templates/professional-services/tokens.json +456 -0
- package/templates/restaurant/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/salon-spa/config.ts +42 -0
- package/templates/salon-spa/dev/index.ts +4136 -0
- package/templates/salon-spa/himalaya.content.json +18 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/salon-spa/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/wholesale-store/config.ts +43 -1
- package/templates/wholesale-store/dev/index.ts +4136 -0
- package/templates/wholesale-store/himalaya.content.json +18 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/wholesale-store/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +5 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Pure Events registration helpers shared by the event detail and the event list: which action an
|
|
2
|
+
// event offers, its label, and the URLs behind it. One copy, so a card and the detail screen never
|
|
3
|
+
// disagree about whether an event can be registered for.
|
|
4
|
+
import type { WixEvent } from "@himalaya/wix-events";
|
|
5
|
+
import { formatWeekdayDateTime } from "./engine-intl.js";
|
|
6
|
+
import { copyParam } from "./himi-copy.js";
|
|
7
|
+
|
|
8
|
+
function detailCopy(key: string, fallback: string): string { return copyParam(key, fallback); }
|
|
9
|
+
|
|
10
|
+
/** Registration CTA kind derived from the event's registration/eventType. */
|
|
11
|
+
export type RegistrationKind = "rsvp" | "tickets" | "external" | "none";
|
|
12
|
+
|
|
13
|
+
/** Map registration status and decoded eventType onto the CTA variant. The decoded
|
|
14
|
+
* `eventType` already folds registration.type / registration.initialType /
|
|
15
|
+
* the legacy flat `type` (decodeEvent, #478). Without a recognized type or
|
|
16
|
+
* status there is no registration action to offer. */
|
|
17
|
+
export function registrationKindOf(e: WixEvent): RegistrationKind {
|
|
18
|
+
const raw = e as unknown as { registration?: { type?: string; initialType?: string; status?: string } };
|
|
19
|
+
const value = (raw.registration?.type ?? e.eventType ?? raw.registration?.initialType ?? "").toUpperCase();
|
|
20
|
+
if (value === "NONE" || value.includes("NO_REGISTRATION")) return "none";
|
|
21
|
+
// Open statuses select the footer action, so they must also select the
|
|
22
|
+
// inventory read and action guards when type metadata is absent or stale.
|
|
23
|
+
switch (raw.registration?.status?.toUpperCase()) {
|
|
24
|
+
case "OPEN_TICKETS": return "tickets";
|
|
25
|
+
case "OPEN_EXTERNAL": return "external";
|
|
26
|
+
case "OPEN_RSVP":
|
|
27
|
+
case "OPEN_RSVP_WAITLIST_ONLY":
|
|
28
|
+
case "SCHEDULED_RSVP": return "rsvp";
|
|
29
|
+
}
|
|
30
|
+
if (value.includes("EXTERNAL")) return "external";
|
|
31
|
+
if (value.includes("TICKET")) return "tickets";
|
|
32
|
+
if (value.includes("RSVP")) return "rsvp";
|
|
33
|
+
return "none";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function eventStatus(e: WixEvent): string {
|
|
37
|
+
const raw = e as unknown as { status?: string };
|
|
38
|
+
return (raw.status ?? e.eventStatus ?? "").toUpperCase();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function registrationUi(e: WixEvent, now: number): { state: string; label: string; action: string; caption: string; notice: string } {
|
|
42
|
+
const raw = e as unknown as { registration?: { status?: string; registrationPaused?: boolean; registrationDisabled?: boolean; allowedGuestTypes?: string; rsvp?: { startDate?: string }; tickets?: { soldOut?: boolean }; external?: { url?: string } }; form?: { messages?: { registrationClosed?: { message?: string; exploreEventsActionLabel?: string }; ticketsUnavailable?: { message?: string; exploreEventsActionLabel?: string } } } };
|
|
43
|
+
const r = raw.registration ?? {};
|
|
44
|
+
const status = eventStatus(e);
|
|
45
|
+
const type = registrationKindOf(e);
|
|
46
|
+
if (status === "CANCELED") return { state: "notice", label: "", action: "", caption: "", notice: detailCopy("event.canceledNotice", "This event was canceled.") };
|
|
47
|
+
if (status === "ENDED") return { state: "notice", label: "", action: "", caption: "", notice: detailCopy("event.endedNotice", "This event has ended.") };
|
|
48
|
+
if (type === "none" || r.registrationDisabled) return { state: "none", label: "", action: "", caption: "", notice: "" };
|
|
49
|
+
const ownerClosed = raw.form?.messages?.registrationClosed?.message;
|
|
50
|
+
const ownerSold = raw.form?.messages?.ticketsUnavailable?.message;
|
|
51
|
+
if (["CLOSED_AUTOMATICALLY", "CLOSED_MANUALLY"].includes(r.status || "") || r.registrationPaused) return { state: "notice", label: "", action: "", caption: "", notice: ownerClosed || detailCopy("event.closedNotice", "Registration is closed.") };
|
|
52
|
+
if (type === "tickets" && r.tickets?.soldOut) return { state: "notice", label: "", action: "", caption: "", notice: ownerSold || detailCopy("event.soldOutNotice", "Tickets are sold out.") };
|
|
53
|
+
if (r.status === "SCHEDULED_RSVP") return { state: "scheduled", label: detailCopy("event.rsvpCta", "RSVP"), action: "", caption: detailCopy("event.opensCaption", "RSVP opens {date}.").replace("{date}", r.rsvp?.startDate ? formatWeekdayDateTime(new Date(r.rsvp.startDate)) : ""), notice: "" };
|
|
54
|
+
if (r.status === "OPEN_RSVP_WAITLIST_ONLY") return { state: "waitlist", label: detailCopy("event.waitlistCta", "Join Waitlist"), action: "himi.open", caption: detailCopy("event.fullCaption", "This event is full."), notice: "" };
|
|
55
|
+
if (r.status === "OPEN_TICKETS" || type === "tickets") return { state: "tickets", label: detailCopy("event.ticketsCta", "Buy Tickets"), action: "openTickets", caption: "", notice: "" };
|
|
56
|
+
if (r.status === "OPEN_EXTERNAL" || type === "external") return registrationUrlOf(e)
|
|
57
|
+
? { state: "external", label: detailCopy("event.externalCta", "Register"), action: "openRegistration", caption: "", notice: "" }
|
|
58
|
+
: { state: "none", label: "", action: "", caption: "", notice: "" };
|
|
59
|
+
if (type === "rsvp" && r.status === "OPEN_RSVP") return { state: "rsvp", label: detailCopy("event.rsvpCta", "RSVP"), action: "himi.open", caption: "", notice: "" };
|
|
60
|
+
if (r.status === "OPEN_RSVP" || (type === "rsvp" && !r.status)) return { state: "rsvp", label: detailCopy("event.rsvpCta", "RSVP"), action: "himi.open", caption: "", notice: "" };
|
|
61
|
+
void now;
|
|
62
|
+
return { state: "none", label: "", action: "", caption: "", notice: "" };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** External registration URL / event page URL from the raw payload ("" when absent). */
|
|
66
|
+
export function registrationUrlOf(e: WixEvent): string {
|
|
67
|
+
const raw = e as unknown as {
|
|
68
|
+
registration?: { external?: { registration?: string; url?: string } };
|
|
69
|
+
eventPageUrl?: { base?: string; path?: string } | string;
|
|
70
|
+
};
|
|
71
|
+
const external = raw.registration?.external?.registration ?? raw.registration?.external?.url;
|
|
72
|
+
if (typeof external === "string" && /^https?:\/\//i.test(external)) return external;
|
|
73
|
+
return eventPageUrlOf(e);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The event's public page URL when the payload carries one ("" otherwise). */
|
|
77
|
+
export function eventPageUrlOf(e: WixEvent): string {
|
|
78
|
+
const raw = e as unknown as { eventPageUrl?: { base?: string; path?: string } | string };
|
|
79
|
+
const page = raw.eventPageUrl;
|
|
80
|
+
if (typeof page === "string" && /^https?:\/\//i.test(page)) return page;
|
|
81
|
+
if (page && typeof page === "object" && typeof page.base === "string" && page.base) {
|
|
82
|
+
const path = typeof page.path === "string" ? page.path : "";
|
|
83
|
+
return `${page.base.replace(/\/$/, "")}${path && !path.startsWith("/") ? "/" : ""}${path}`;
|
|
84
|
+
}
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The pure options of the inline events section. No imports: Node tests read it directly, and the worker bundle shares it.
|
|
2
|
+
|
|
3
|
+
export interface EventsInlineOptions {
|
|
4
|
+
/** How many events the section shows. Clamped to 1..10; default 3. */
|
|
5
|
+
limit?: number;
|
|
6
|
+
/** Show only events in these categories (Wix event category ids). Empty or absent: every category. */
|
|
7
|
+
categoryIds?: readonly string[];
|
|
8
|
+
/** Show only these events (Wix event ids). Empty or absent: every event. */
|
|
9
|
+
eventIds?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The events a list is limited to: both lists empty is no limit. */
|
|
13
|
+
export interface EventsSelection { categoryIds: string[]; eventIds: string[] }
|
|
14
|
+
|
|
15
|
+
export const EVENTS_INLINE_DEFAULT_LIMIT = 3;
|
|
16
|
+
export const EVENTS_INLINE_MAX_LIMIT = 10;
|
|
17
|
+
/** More ids than this are dropped: a selection is a handful of categories or events, and each id rides the query. */
|
|
18
|
+
export const EVENTS_SELECTION_MAX_IDS = 50;
|
|
19
|
+
|
|
20
|
+
/** A bad or missing limit is the default, never an error: the value arrives from a generated recipe. */
|
|
21
|
+
export function eventsInlineLimit(value: unknown): number {
|
|
22
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
23
|
+
if (!Number.isFinite(n)) return EVENTS_INLINE_DEFAULT_LIMIT;
|
|
24
|
+
return Math.min(EVENTS_INLINE_MAX_LIMIT, Math.max(1, Math.trunc(n)));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Wix ids are UUIDs; anything else (a route value is user-controllable text) never becomes part of a query. */
|
|
28
|
+
const ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
29
|
+
|
|
30
|
+
/** The ids in a list, or in a comma-separated string (how a `himi.open` link carries them): valid, distinct, at most 50. */
|
|
31
|
+
export function eventsSelectionIds(value: unknown): string[] {
|
|
32
|
+
const parts = Array.isArray(value) ? value : typeof value === "string" ? value.split(",") : [];
|
|
33
|
+
const ids = parts.flatMap((part) => (typeof part === "string" && ID.test(part.trim()) ? [part.trim()] : []));
|
|
34
|
+
return [...new Set(ids)].slice(0, EVENTS_SELECTION_MAX_IDS);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function eventsSelectionOf(source: { categoryIds?: unknown; eventIds?: unknown } | undefined): EventsSelection {
|
|
38
|
+
return { categoryIds: eventsSelectionIds(source?.categoryIds), eventIds: eventsSelectionIds(source?.eventIds) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A selection as the canonical string a collection carries in its criteria (`CollectionQuery.scope`): "" for none, so no scope is set. */
|
|
42
|
+
export function eventsSelectionScope(selection: EventsSelection): string {
|
|
43
|
+
return hasEventsSelection(selection) ? JSON.stringify({ categoryIds: selection.categoryIds, eventIds: selection.eventIds }) : "";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The selection a scope string names (every id is checked again: a scope is data that crossed a cache). Anything unreadable is none. */
|
|
47
|
+
export function eventsSelectionFromScope(scope: unknown): EventsSelection {
|
|
48
|
+
if (typeof scope !== "string" || !scope) return { categoryIds: [], eventIds: [] };
|
|
49
|
+
try { return eventsSelectionOf(JSON.parse(scope) as { categoryIds?: unknown; eventIds?: unknown }); } catch { return { categoryIds: [], eventIds: [] }; }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Whether a selection limits anything. */
|
|
53
|
+
export function hasEventsSelection(selection: EventsSelection): boolean {
|
|
54
|
+
return selection.categoryIds.length > 0 || selection.eventIds.length > 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The query filter of a selection: events in any of the categories (`categories.id $hasSome`, which a visitor may query) and events
|
|
59
|
+
* among the chosen ones (`id $in`). A selection naming both narrows by both. `limitIds` further narrows the chosen events, for
|
|
60
|
+
* a list that also shows only the visitor's saved events: an id both lists agree on, so a saved event outside the selection stays out.
|
|
61
|
+
*/
|
|
62
|
+
export function eventsSelectionFilter(selection: EventsSelection, limitIds?: readonly string[]): Record<string, unknown> {
|
|
63
|
+
const ids = limitIds && selection.eventIds.length ? selection.eventIds.filter((id) => limitIds.includes(id)) : limitIds ? [...limitIds] : selection.eventIds;
|
|
64
|
+
return {
|
|
65
|
+
...(selection.categoryIds.length ? { "categories.id": { $hasSome: selection.categoryIds } } : {}),
|
|
66
|
+
...(limitIds || selection.eventIds.length ? { id: { $in: ids } } : {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Events that have not finished: not started yet, or still running (a festival on its second day is still on). Narrowed to a selection when given one. */
|
|
71
|
+
export function upcomingFilter(nowIso: string, selection?: EventsSelection): Record<string, unknown> {
|
|
72
|
+
return {
|
|
73
|
+
status: { $ne: "DRAFT" },
|
|
74
|
+
$or: [{ "dateAndTimeSettings.startDate": { $gte: nowIso } }, { "dateAndTimeSettings.endDate": { $gte: nowIso } }],
|
|
75
|
+
...(selection ? eventsSelectionFilter(selection) : {}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// The FAQ as a registrable service: one worker for the himi_faq screen and for a migrated page's FAQ section.
|
|
2
|
+
// registerFaqList(name) -> the screen: every question, search, categories (the himi_faq bundle is this call);
|
|
3
|
+
// registerFaqList(name, options) -> a section: `limit` (the source's NumberOfFAQs), `showCategories`, `firstOpen`, `oneAtATime`, `showSearch`.
|
|
4
|
+
// State and flags are the screen's own (`loadingHidden`, `errorHidden`, ...), so the faq-list recipe and the himi_faq descriptor bind the same names.
|
|
5
|
+
import { defineService } from "@himalaya/state";
|
|
6
|
+
import {
|
|
7
|
+
queryCategories,
|
|
8
|
+
queryQuestionEntries,
|
|
9
|
+
type WixCategory,
|
|
10
|
+
type WixQuestionEntry,
|
|
11
|
+
} from "@himalaya/wix-faq";
|
|
12
|
+
import { openRichLink } from "../_shared/rich-content-link.js";
|
|
13
|
+
import { richBody, ROW_IMAGE_WIDTH } from "../_shared/rich-body.js";
|
|
14
|
+
|
|
15
|
+
interface FaqQuestion {
|
|
16
|
+
id: string;
|
|
17
|
+
categoryId: string;
|
|
18
|
+
question: string;
|
|
19
|
+
/** The PLAIN_TEXT answer: the RichContent fallback, and what shows with no trusted document. */
|
|
20
|
+
answer: string;
|
|
21
|
+
/** [rico] #3372 — the RICH_CONTENT answer as ONE document string, used ONLY when its text matches the plain
|
|
22
|
+
* answer (a legacy DraftJS record converts unreliably); "" otherwise. */
|
|
23
|
+
answerJson: string;
|
|
24
|
+
/** answerJson !== "" — gates the plain answer, because RichContent draws nothing for "". */
|
|
25
|
+
hasAnswerJson: boolean;
|
|
26
|
+
sortOrder?: number;
|
|
27
|
+
status: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface FaqCategory {
|
|
31
|
+
id: string;
|
|
32
|
+
title: string;
|
|
33
|
+
sortOrder?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface QuestionRow {
|
|
37
|
+
id: string;
|
|
38
|
+
title: string;
|
|
39
|
+
answer: string;
|
|
40
|
+
answerJson: string;
|
|
41
|
+
hasAnswerJson: boolean;
|
|
42
|
+
expanded: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface CategorySection {
|
|
46
|
+
id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
questions: QuestionRow[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface FaqDisplayRow extends QuestionRow {
|
|
52
|
+
categoryTitle: string;
|
|
53
|
+
categoryHeaderHidden: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface FaqState {
|
|
57
|
+
status: "loading" | "ready" | "error" | "forbidden" | "notInstalled";
|
|
58
|
+
categories: FaqCategory[];
|
|
59
|
+
questions: FaqQuestion[];
|
|
60
|
+
sections: CategorySection[];
|
|
61
|
+
rows: FaqDisplayRow[];
|
|
62
|
+
query: string;
|
|
63
|
+
expandedIds: string[];
|
|
64
|
+
otherTitle: string;
|
|
65
|
+
loadingHidden: boolean;
|
|
66
|
+
contentHidden: boolean;
|
|
67
|
+
emptyHidden: boolean;
|
|
68
|
+
errorHidden: boolean;
|
|
69
|
+
forbiddenHidden: boolean;
|
|
70
|
+
notInstalledHidden: boolean;
|
|
71
|
+
/** The section's search field is off (the source's showSearchBar is false). */
|
|
72
|
+
searchHidden: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** What a source FAQ section sets. Every option defaults to what the himi_faq screen does. */
|
|
76
|
+
export interface FaqListOptions {
|
|
77
|
+
/** Show at most this many questions (the source's NumberOfFAQs). */
|
|
78
|
+
limit?: number;
|
|
79
|
+
/** false: no category headers. */
|
|
80
|
+
showCategories?: boolean;
|
|
81
|
+
/** Open the first question when the list first loads. */
|
|
82
|
+
firstOpen?: boolean;
|
|
83
|
+
/** Opening a question closes the others. */
|
|
84
|
+
oneAtATime?: boolean;
|
|
85
|
+
/** false: no search field. */
|
|
86
|
+
showSearch?: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const PAGE_SIZE = 100;
|
|
90
|
+
|
|
91
|
+
/** Caps on the static pairs, matching `BRANDED_LITE_FAQ_LIMITS` in the app contract. The
|
|
92
|
+
* param is re-bounded here because a worker must not trust a descriptor it did not build. */
|
|
93
|
+
const STATIC_LIMITS = { pairs: 20, question: 200, answer: 1500 } as const;
|
|
94
|
+
const STATIC_CATEGORY: FaqCategory = { id: "himi-static-faq", title: "" };
|
|
95
|
+
|
|
96
|
+
/** The site's own FAQ pairs — questions it publishes as page sections rather than
|
|
97
|
+
* through the Wix FAQ app, carried in by `site analyze --apply` as the `staticFaq` onAppear
|
|
98
|
+
* param (a JSON string: action params are string-valued). They are the FALLBACK: shown only
|
|
99
|
+
* when the FAQ app yields no visible question, so an owner-edited Wix FAQ always wins. */
|
|
100
|
+
|
|
101
|
+
function parseStaticFaq(raw: unknown): FaqQuestion[] {
|
|
102
|
+
let pairs: unknown = raw;
|
|
103
|
+
if (typeof raw === "string") {
|
|
104
|
+
try {
|
|
105
|
+
pairs = JSON.parse(raw);
|
|
106
|
+
} catch {
|
|
107
|
+
// A malformed param is a DESCRIPTOR bug, not an empty FAQ: there is no fallback to
|
|
108
|
+
// offer, so the screen shows exactly what the Wix FAQ read says — its content, its
|
|
109
|
+
// empty card, or its error card — rather than pretending the site has no questions.
|
|
110
|
+
pairs = undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!Array.isArray(pairs)) return [];
|
|
114
|
+
const out: FaqQuestion[] = [];
|
|
115
|
+
for (const pair of pairs) {
|
|
116
|
+
if (out.length >= STATIC_LIMITS.pairs) break;
|
|
117
|
+
const row = pair && typeof pair === "object" ? pair as { q?: unknown; a?: unknown } : {};
|
|
118
|
+
const question = typeof row.q === "string" ? row.q.trim().slice(0, STATIC_LIMITS.question) : "";
|
|
119
|
+
const answer = typeof row.a === "string" ? row.a.trim().slice(0, STATIC_LIMITS.answer) : "";
|
|
120
|
+
if (!question || !answer) continue;
|
|
121
|
+
out.push({
|
|
122
|
+
id: `himi-static-faq-${out.length}`,
|
|
123
|
+
categoryId: STATIC_CATEGORY.id,
|
|
124
|
+
question,
|
|
125
|
+
answer,
|
|
126
|
+
// The site's own pairs are plain strings: there is no document to render.
|
|
127
|
+
answerJson: "",
|
|
128
|
+
hasAnswerJson: false,
|
|
129
|
+
sortOrder: out.length,
|
|
130
|
+
status: "VISIBLE",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function sortByWixOrder<T extends { id: string; sortOrder?: number }>(left: T, right: T): number {
|
|
137
|
+
const a = Number.isFinite(left.sortOrder) ? left.sortOrder! : Number.POSITIVE_INFINITY;
|
|
138
|
+
const b = Number.isFinite(right.sortOrder) ? right.sortOrder! : Number.POSITIVE_INFINITY;
|
|
139
|
+
return a - b || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function uniqueById<T extends { id: string }>(rows: T[]): T[] {
|
|
143
|
+
return [...new Map(rows.filter((row) => row.id).map((row) => [row.id, row])).values()];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function sectionsFor(state: Pick<FaqState, "categories" | "questions" | "query" | "expandedIds" | "otherTitle">, limit?: number): CategorySection[] {
|
|
147
|
+
const needle = state.query.trim().toLowerCase();
|
|
148
|
+
const visible = state.questions
|
|
149
|
+
.filter((row) => row.status.toUpperCase() !== "HIDDEN")
|
|
150
|
+
.filter((row) => !needle || `${row.question}\n${row.answer}`.toLowerCase().includes(needle))
|
|
151
|
+
.sort(sortByWixOrder)
|
|
152
|
+
.slice(0, limit ?? Number.POSITIVE_INFINITY);
|
|
153
|
+
const expanded = new Set(state.expandedIds);
|
|
154
|
+
const known = new Set(state.categories.map((category) => category.id));
|
|
155
|
+
const row = (question: FaqQuestion): QuestionRow => ({
|
|
156
|
+
id: question.id,
|
|
157
|
+
title: question.question,
|
|
158
|
+
answer: question.answer,
|
|
159
|
+
answerJson: question.answerJson,
|
|
160
|
+
hasAnswerJson: question.hasAnswerJson,
|
|
161
|
+
expanded: expanded.has(question.id),
|
|
162
|
+
});
|
|
163
|
+
const sections = state.categories
|
|
164
|
+
.slice()
|
|
165
|
+
.sort(sortByWixOrder)
|
|
166
|
+
.map((category) => ({
|
|
167
|
+
id: category.id,
|
|
168
|
+
title: category.title,
|
|
169
|
+
questions: visible.filter((question) => question.categoryId === category.id).map(row),
|
|
170
|
+
}))
|
|
171
|
+
.filter((section) => section.questions.length > 0);
|
|
172
|
+
const orphaned = visible.filter((question) => !known.has(question.categoryId));
|
|
173
|
+
if (orphaned.length) sections.push({ id: "other", title: state.otherTitle, questions: orphaned.map(row) });
|
|
174
|
+
return sections;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function ready(state: FaqState, options: FaqListOptions = {}): FaqState {
|
|
178
|
+
const sections = sectionsFor(state, options.limit);
|
|
179
|
+
const rows = sections.flatMap((section) => section.questions.map((question, index) => ({
|
|
180
|
+
...question,
|
|
181
|
+
categoryTitle: section.title,
|
|
182
|
+
// An untitled section (the static fallback's) has no header to show.
|
|
183
|
+
categoryHeaderHidden: options.showCategories === false || index !== 0 || !section.title,
|
|
184
|
+
})));
|
|
185
|
+
return {
|
|
186
|
+
...state,
|
|
187
|
+
status: "ready",
|
|
188
|
+
sections,
|
|
189
|
+
rows,
|
|
190
|
+
loadingHidden: true,
|
|
191
|
+
contentHidden: sections.length === 0,
|
|
192
|
+
emptyHidden: sections.length > 0,
|
|
193
|
+
errorHidden: true,
|
|
194
|
+
forbiddenHidden: true,
|
|
195
|
+
notInstalledHidden: true,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function failure(state: FaqState, status: FaqState["status"]): FaqState {
|
|
200
|
+
return {
|
|
201
|
+
...state,
|
|
202
|
+
status,
|
|
203
|
+
categories: [],
|
|
204
|
+
questions: [],
|
|
205
|
+
sections: [],
|
|
206
|
+
rows: [],
|
|
207
|
+
loadingHidden: true,
|
|
208
|
+
contentHidden: true,
|
|
209
|
+
emptyHidden: true,
|
|
210
|
+
errorHidden: status !== "error",
|
|
211
|
+
forbiddenHidden: status !== "forbidden",
|
|
212
|
+
notInstalledHidden: status !== "notInstalled",
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function httpStatus(error: unknown): number | undefined {
|
|
217
|
+
if (!error || typeof error !== "object") return undefined;
|
|
218
|
+
const row = error as { status?: unknown; statusCode?: unknown; response?: { status?: unknown }; message?: unknown };
|
|
219
|
+
for (const value of [row.status, row.statusCode, row.response?.status]) {
|
|
220
|
+
if (typeof value === "number") return value;
|
|
221
|
+
}
|
|
222
|
+
const match = typeof row.message === "string" ? row.message.match(/\b(403|428)\b/) : null;
|
|
223
|
+
return match ? Number(match[1]) : undefined;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function allCategories(): Promise<FaqCategory[]> {
|
|
227
|
+
const rows: FaqCategory[] = [];
|
|
228
|
+
const seen = new Set<string>();
|
|
229
|
+
let cursor = "";
|
|
230
|
+
do {
|
|
231
|
+
const response = await queryCategories({ query: { cursorPaging: { limit: PAGE_SIZE, ...(cursor ? { cursor } : {}) } } });
|
|
232
|
+
rows.push(...(response.categories ?? []).map((category: WixCategory) => ({
|
|
233
|
+
id: category.id ?? "",
|
|
234
|
+
title: (category.title ?? "").trim() || "Other",
|
|
235
|
+
...(typeof category.sortOrder === "number" ? { sortOrder: category.sortOrder } : {}),
|
|
236
|
+
})));
|
|
237
|
+
const next = response.pagingMetadata?.cursors?.next ?? "";
|
|
238
|
+
if (!next || seen.has(next)) break;
|
|
239
|
+
seen.add(next);
|
|
240
|
+
cursor = next;
|
|
241
|
+
} while (cursor);
|
|
242
|
+
return uniqueById(rows);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** The answer's text with every whitespace run collapsed to one space: PLAIN_TEXT and a document's plain text
|
|
246
|
+
* may separate blocks differently ("\n" vs "\n\n"), and that is not a garbled conversion, but a space inside
|
|
247
|
+
* the text is content ("New York" is not "NewYork"). */
|
|
248
|
+
const normalizeSpace = (text: string): string => text.replace(/\s+/g, " ").trim();
|
|
249
|
+
|
|
250
|
+
/** [rico] #3372 — the RICH_CONTENT answer as a document string, trusted ONLY when its text matches the
|
|
251
|
+
* PLAIN_TEXT answer. Wix converts a legacy DraftJS answer to Ricos unreliably, and the plain answer is
|
|
252
|
+
* the one a visitor has always been shown, so a document that disagrees with it is dropped. */
|
|
253
|
+
function richAnswer(plain: string, rich: unknown): string {
|
|
254
|
+
// richBody encodes FIRST, so a document past the viewer's limits (too deep included) is rejected without an
|
|
255
|
+
// unbounded plain-text walk, and gives "". Answers render in a list, so their media are list-sized.
|
|
256
|
+
const { bodyJson, bodyText } = richBody(rich, "", ROW_IMAGE_WIDTH);
|
|
257
|
+
return bodyJson && normalizeSpace(bodyText) === normalizeSpace(plain) ? bodyJson : "";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Every question entry in one content format, following THAT query's own cursors: a cursor belongs to the
|
|
261
|
+
* request that returned it, so the two formats never share one. */
|
|
262
|
+
async function entriesIn(contentFormat: "PLAIN_TEXT" | "RICH_CONTENT"): Promise<WixQuestionEntry[]> {
|
|
263
|
+
const rows: WixQuestionEntry[] = [];
|
|
264
|
+
const seen = new Set<string>();
|
|
265
|
+
let cursor = "";
|
|
266
|
+
do {
|
|
267
|
+
const response = await queryQuestionEntries({
|
|
268
|
+
query: {
|
|
269
|
+
cursorPaging: { limit: PAGE_SIZE, ...(cursor ? { cursor } : {}) },
|
|
270
|
+
filter: { status: { $in: ["VISIBLE", "UNKNOWN"] } },
|
|
271
|
+
},
|
|
272
|
+
contentFormat,
|
|
273
|
+
});
|
|
274
|
+
rows.push(...(response.questionEntries ?? []));
|
|
275
|
+
const next = response.pagingMetadata?.cursors?.next ?? "";
|
|
276
|
+
if (!next || seen.has(next)) break;
|
|
277
|
+
seen.add(next);
|
|
278
|
+
cursor = next;
|
|
279
|
+
} while (cursor);
|
|
280
|
+
return rows;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function allQuestions(): Promise<FaqQuestion[]> {
|
|
284
|
+
// Both formats are read in parallel, each paged on its own. PLAIN_TEXT is the list; a RICH_CONTENT read
|
|
285
|
+
// that fails only costs the documents — every answer keeps its plain text.
|
|
286
|
+
const [plain, rich] = await Promise.all([
|
|
287
|
+
entriesIn("PLAIN_TEXT"),
|
|
288
|
+
entriesIn("RICH_CONTENT").catch(() => [] as WixQuestionEntry[]),
|
|
289
|
+
]);
|
|
290
|
+
const richById = new Map(rich.map((question: WixQuestionEntry) => [question.id ?? "", question.richContent]));
|
|
291
|
+
const rows = plain.map((question: WixQuestionEntry) => {
|
|
292
|
+
const answer = (question.plainText ?? "").trim();
|
|
293
|
+
const answerJson = richAnswer(answer, richById.get(question.id ?? ""));
|
|
294
|
+
return {
|
|
295
|
+
id: question.id ?? "",
|
|
296
|
+
categoryId: question.categoryId ?? "",
|
|
297
|
+
question: (question.question ?? "").trim(),
|
|
298
|
+
answer,
|
|
299
|
+
answerJson,
|
|
300
|
+
hasAnswerJson: answerJson !== "",
|
|
301
|
+
...(typeof question.sortOrder === "number" ? { sortOrder: question.sortOrder } : {}),
|
|
302
|
+
status: question.status ?? "UNKNOWN",
|
|
303
|
+
};
|
|
304
|
+
}).filter((question) =>
|
|
305
|
+
question.id && question.question && question.status.toUpperCase() !== "HIDDEN",
|
|
306
|
+
);
|
|
307
|
+
return uniqueById(rows);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const INITIAL: FaqState = {
|
|
311
|
+
status: "loading",
|
|
312
|
+
categories: [],
|
|
313
|
+
questions: [],
|
|
314
|
+
sections: [],
|
|
315
|
+
rows: [],
|
|
316
|
+
query: "",
|
|
317
|
+
expandedIds: [],
|
|
318
|
+
otherTitle: "Other",
|
|
319
|
+
loadingHidden: false,
|
|
320
|
+
contentHidden: true,
|
|
321
|
+
emptyHidden: true,
|
|
322
|
+
errorHidden: true,
|
|
323
|
+
forbiddenHidden: true,
|
|
324
|
+
notInstalledHidden: true,
|
|
325
|
+
searchHidden: false,
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
export function registerFaqList(serviceName: string, options: FaqListOptions = {}) {
|
|
329
|
+
/** The site's own FAQ pairs: the FALLBACK shown only when the FAQ app yields no visible question (see parseStaticFaq). */
|
|
330
|
+
let staticQuestions: FaqQuestion[] = [];
|
|
331
|
+
const initial: FaqState = { ...INITIAL, searchHidden: options.showSearch === false };
|
|
332
|
+
let latestState = initial;
|
|
333
|
+
let loadGeneration = 0;
|
|
334
|
+
/** The reader opened or closed a question: `firstOpen` then stops deciding what is open. */
|
|
335
|
+
let touched = false;
|
|
336
|
+
|
|
337
|
+
const settle = (state: FaqState): FaqState => ready(state, options);
|
|
338
|
+
|
|
339
|
+
/** The site's pairs as a ready state, or undefined when there are none to fall back to. */
|
|
340
|
+
function staticFallback(state: FaqState): FaqState | undefined {
|
|
341
|
+
if (!staticQuestions.length) return undefined;
|
|
342
|
+
return settle({ ...state, categories: [STATIC_CATEGORY], questions: staticQuestions });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function commit(state: FaqState): FaqState {
|
|
346
|
+
latestState = state;
|
|
347
|
+
return state;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function loadFaq(state: FaqState, arg?: { otherCategory?: string; staticFaq?: unknown }): Promise<FaqState> {
|
|
351
|
+
latestState = state;
|
|
352
|
+
// Only when the caller passed the param: `retry` is dispatched with no params and must keep
|
|
353
|
+
// the pairs the screen's onAppear delivered.
|
|
354
|
+
if (arg && "staticFaq" in arg) staticQuestions = parseStaticFaq(arg.staticFaq);
|
|
355
|
+
const generation = ++loadGeneration;
|
|
356
|
+
try {
|
|
357
|
+
const [categories, questions] = await Promise.all([allCategories(), allQuestions()]);
|
|
358
|
+
if (generation !== loadGeneration) return latestState;
|
|
359
|
+
const otherTitle = String(arg?.otherCategory ?? latestState.otherTitle).trim() || latestState.otherTitle;
|
|
360
|
+
let live = settle({ ...latestState, categories, questions, otherTitle });
|
|
361
|
+
const first = live.sections[0]?.questions[0]?.id;
|
|
362
|
+
if (options.firstOpen && !touched && !live.expandedIds.length && first) live = settle({ ...live, expandedIds: [first] });
|
|
363
|
+
// The Wix FAQ app answered but holds nothing a visitor can see — the site's own pairs,
|
|
364
|
+
// when it has any, instead of an empty state over a site whose FAQ is right there.
|
|
365
|
+
if (questions.length === 0) return commit(staticFallback(live) ?? live);
|
|
366
|
+
return commit(live);
|
|
367
|
+
} catch (error) {
|
|
368
|
+
if (generation !== loadGeneration) return latestState;
|
|
369
|
+
console.warn("faq_list: the questions could not be read", error);
|
|
370
|
+
const status = httpStatus(error);
|
|
371
|
+
// No FAQ app (428), no visitor access (403) or a failed read: a site whose FAQ is page
|
|
372
|
+
// content still has an FAQ to show, so its pairs replace the failure card.
|
|
373
|
+
const fallback = staticFallback(latestState);
|
|
374
|
+
if (fallback) return commit(fallback);
|
|
375
|
+
return commit(failure(latestState, status === 403 ? "forbidden" : status === 428 ? "notInstalled" : "error"));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return defineService(serviceName, {
|
|
380
|
+
state: initial,
|
|
381
|
+
actions: {
|
|
382
|
+
load: loadFaq,
|
|
383
|
+
retry: loadFaq,
|
|
384
|
+
search: (state: FaqState, arg?: { value?: string }) => commit(settle({ ...state, query: String(arg?.value ?? "").slice(0, 256) })),
|
|
385
|
+
toggle: (state: FaqState, arg?: { id?: string }) => {
|
|
386
|
+
const id = String(arg?.id ?? "");
|
|
387
|
+
if (!id || !state.questions.some((question) => question.id === id)) return state;
|
|
388
|
+
touched = true;
|
|
389
|
+
const open = state.expandedIds.includes(id);
|
|
390
|
+
const expandedIds = open
|
|
391
|
+
? state.expandedIds.filter((candidate) => candidate !== id)
|
|
392
|
+
: options.oneAtATime ? [id] : [...state.expandedIds, id];
|
|
393
|
+
return commit(settle({ ...state, expandedIds }));
|
|
394
|
+
},
|
|
395
|
+
// [rico] #3372 — an answer RichContent's on_link: `{ url }` of the tapped link. Only http(s), mailto and
|
|
396
|
+
// tel links reach open_url; the FAQ has no message line, so a refused link simply does nothing.
|
|
397
|
+
openLink: async (state: FaqState, arg?: unknown) => {
|
|
398
|
+
await openRichLink(arg);
|
|
399
|
+
return state;
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export { sectionsFor, httpStatus, parseStaticFaq };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// The site's featured event: the one on now, else the next one to start. A conference app is
|
|
2
|
+
// about one event at a time — its Home hero, its Tickets tab and its Agenda all show this one —
|
|
3
|
+
// and a site with several events reaches the rest from the events list.
|
|
4
|
+
//
|
|
5
|
+
// Read from the visitor-readable Events v3 query. "None" (no live or upcoming event) is a real
|
|
6
|
+
// answer, distinct from a failed read: the caller shows an empty state for the first and an
|
|
7
|
+
// error with Retry for the second, never a sample event.
|
|
8
|
+
import { queryEvents, startDateOf, endDateOf, type WixEvent, type WixEventFieldset } from "@himalaya/wix-events";
|
|
9
|
+
|
|
10
|
+
export type FeaturedEventRead = { ok: true; event: WixEvent | null } | { ok: false; event: null };
|
|
11
|
+
|
|
12
|
+
// Only live and upcoming events, earliest first, filtered and sorted by Wix (verified on a visitor
|
|
13
|
+
// token, 2026-11-10): the featured one is on the first page however many events the site has. The
|
|
14
|
+
// pick below still checks each row, and pages on (to Wix's own total) only while no page has
|
|
15
|
+
// produced an event to feature — never a fixed page cap that could miss one.
|
|
16
|
+
const FEATURED_QUERY = {
|
|
17
|
+
filter: { status: { $in: ["UPCOMING", "STARTED"] } },
|
|
18
|
+
sort: [{ fieldName: "dateAndTimeSettings.startDate", order: "ASC" }],
|
|
19
|
+
};
|
|
20
|
+
const PAGE = 50;
|
|
21
|
+
|
|
22
|
+
const millis = (iso: string | undefined): number => {
|
|
23
|
+
const ms = iso ? Date.parse(iso) : NaN;
|
|
24
|
+
return Number.isNaN(ms) ? NaN : ms;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The event to feature among `events` at `now`: a published event that has not ended — the one
|
|
28
|
+
* that started first when several run now, else the next to start. A draft, a canceled event
|
|
29
|
+
* and an ended one are never featured; an event with no date is featured only when no dated one
|
|
30
|
+
* qualifies (its date is "to be announced"). */
|
|
31
|
+
export function pickFeaturedEvent(events: WixEvent[], now: number): WixEvent | null {
|
|
32
|
+
const eligible = events.filter((e) => {
|
|
33
|
+
const status = String(e.eventStatus ?? (e as { status?: string }).status ?? "").toUpperCase();
|
|
34
|
+
if (status === "DRAFT" || status === "CANCELED" || status === "ENDED") return false;
|
|
35
|
+
const end = millis(endDateOf(e)), start = millis(startDateOf(e));
|
|
36
|
+
const last = Number.isNaN(end) ? start : end;
|
|
37
|
+
return Number.isNaN(last) || last >= now;
|
|
38
|
+
});
|
|
39
|
+
const dated = eligible.filter((e) => !Number.isNaN(millis(startDateOf(e))));
|
|
40
|
+
if (dated.length) return dated.slice().sort((a, b) => millis(startDateOf(a)) - millis(startDateOf(b)))[0];
|
|
41
|
+
return eligible[0] ?? null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Read the site's live and upcoming events and pick the featured one. */
|
|
45
|
+
export async function readFeaturedEvent(fields: WixEventFieldset[] = ["DETAILS", "REGISTRATION"], now: number = Date.now()): Promise<FeaturedEventRead> {
|
|
46
|
+
const events: WixEvent[] = [];
|
|
47
|
+
try {
|
|
48
|
+
for (let offset = 0; ; offset += PAGE) {
|
|
49
|
+
const res = await queryEvents({ limit: PAGE, offset, fields, query: FEATURED_QUERY as never });
|
|
50
|
+
const page = (res.events ?? []).filter((e) => !!e.id);
|
|
51
|
+
events.push(...page);
|
|
52
|
+
const total = Number((res as { pagingMetadata?: { total?: unknown } }).pagingMetadata?.total);
|
|
53
|
+
const done = page.length < PAGE || (Number.isFinite(total) && offset + PAGE >= total);
|
|
54
|
+
// A dated pick is final (a later page starts later); an undated one is not — a dated event
|
|
55
|
+
// may still follow, and a dated event is always featured before a "to be announced" one.
|
|
56
|
+
const pick = pickFeaturedEvent(events, now);
|
|
57
|
+
if (done || (pick && !Number.isNaN(millis(startDateOf(pick))))) break;
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
return { ok: false, event: null };
|
|
61
|
+
}
|
|
62
|
+
return { ok: true, event: pickFeaturedEvent(events, now) };
|
|
63
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { copyPlural } from "./himi-copy.js";
|
|
2
|
+
|
|
3
|
+
/** "840 members" / "1 member" for a group, through the copy pack so a translated app reads its own
|
|
4
|
+
* language. One key for every worker that shows the count: a screen that renders it must list the
|
|
5
|
+
* `groups.` prefix in its `appear()` so the pack carries the key. */
|
|
6
|
+
export function groupMemberCount(count: number): string {
|
|
7
|
+
return copyPlural("groups.memberCount", "{n, plural, one {# member} other {# members}}", count);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The label for a group read back from the offline cache. A cached row keeps the raw `count`, never
|
|
11
|
+
* the formatted label, so a pinned app reads it in its own language. A row written before that (label
|
|
12
|
+
* only) has no count and shows none, instead of a label in the wrong language. */
|
|
13
|
+
export function cachedMemberCount(count: unknown): string {
|
|
14
|
+
return typeof count === "number" && Number.isFinite(count) ? groupMemberCount(count) : "";
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { copyParam } from "./himi-copy.js";
|
|
2
|
+
|
|
3
|
+
/** The label for a group's privacy status ("Private"), through the copy pack so a translated app reads it in
|
|
4
|
+
* its own language. A status with no key of its own (anything Wix adds later) keeps its capitalised English.
|
|
5
|
+
* A screen that renders it must carry the `group.privacy*` keys: its `appear()` lists the `group.` prefix, or
|
|
6
|
+
* these keys exactly when it reads another namespace (the group About page). */
|
|
7
|
+
export function groupPrivacyLabel(status: string): string {
|
|
8
|
+
const lower = status.trim().toLowerCase();
|
|
9
|
+
if (lower === "public") return copyParam("group.privacyPublic", "Public");
|
|
10
|
+
if (lower === "private") return copyParam("group.privacyPrivate", "Private");
|
|
11
|
+
if (lower === "secret") return copyParam("group.privacySecret", "Secret");
|
|
12
|
+
if (lower === "unknown") return copyParam("group.privacyUnknown", "Unknown");
|
|
13
|
+
return lower ? lower[0].toUpperCase() + lower.slice(1) : "";
|
|
14
|
+
}
|