@wix/himalaya-cli 0.1750.0 → 0.1751.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/himi-package.d.ts +478 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/host-compatibility.d.ts +56 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/icon-catalog.generated.d.ts +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +4 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-shell.d.ts +154 -7
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/validator.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/index.d.ts +2 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/podcast-service.d.ts +105 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/podcast.d.ts +116 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +326 -13
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +730 -81
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +155 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{b40ea5d0d6251898ff5617139fde8be008dd11e99a70b14c1052093685401700.bin → 21f35a12bd94f4ab97a9a75453c4adcadc438daf024a4b1950d5c356c123bd01.bin} +1 -1
- package/dist/browser-plane/sw.js +7 -7
- package/dist/cli.mjs +34995 -31326
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/component-reference.json +1 -1
- package/guides/component-reference.md +4 -0
- package/guides/designing-himi-screens.md +7 -0
- package/guides/getting-started.md +2 -0
- package/guides/headless-loop.md +1 -1
- package/guides/himi-skill.md +2 -0
- package/guides/index.json +6 -0
- package/guides/qa-builds.md +12 -1
- package/guides/recipe-podcast.md +149 -0
- package/guides/tier-5-add-a-screen.md +16 -2
- package/guides/wix-business-context.md +29 -0
- package/guides/wix-platform-usage.md +7 -2
- package/package.json +10 -10
- package/template-icons/fitness-gym.png +0 -0
- package/templates/beauty-salon/dev/index.ts +1 -1
- package/templates/beauty-salon/l10n/en.json +1 -1
- package/templates/beauty-salon/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/beauty-salon/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/beauty-salon/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
- package/templates/branded-lite/dev/index.ts +101 -1
- package/templates/branded-lite/l10n/en.json +22 -1
- package/templates/branded-lite/l10n/es.json +22 -0
- package/templates/branded-lite/l10n/fr.json +18 -0
- package/templates/branded-lite/l10n/he.json +15 -0
- package/templates/branded-lite/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/branded-lite/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/branded-lite/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
- package/templates/branded-lite/tier5-src/himi-branded-lite-podcasts/index.ts +14 -234
- package/templates/brandy/README.md +33 -0
- package/templates/brandy/config.ts +51 -7
- package/templates/brandy/dev/index.ts +23 -9
- package/templates/community-club/l10n/en.json +1 -1
- package/templates/community-club/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/community-club/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/events-meetups/l10n/en.json +1 -1
- package/templates/events-meetups/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/events-meetups/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/fitness-gym/README.md +53 -0
- package/templates/fitness-gym/config.ts +560 -0
- package/templates/fitness-gym/dev/index.ts +25787 -0
- package/templates/fitness-gym/himalaya.content.json +64 -0
- package/templates/fitness-gym/himalaya.template.json +15 -0
- package/templates/fitness-gym/icon.png +0 -0
- package/templates/fitness-gym/platforms.json +1 -0
- package/templates/fitness-gym/tier5-src/_shared/app-locale.ts +61 -0
- package/templates/fitness-gym/tier5-src/_shared/booking-location.ts +147 -0
- package/templates/fitness-gym/tier5-src/_shared/booking-session.ts +224 -0
- package/templates/fitness-gym/tier5-src/_shared/branded-lite-hosted.ts +280 -0
- package/templates/fitness-gym/tier5-src/_shared/branded-load-state.ts +109 -0
- package/templates/fitness-gym/tier5-src/_shared/business-chat-copy.ts +40 -0
- package/templates/fitness-gym/tier5-src/_shared/business-chat-history.ts +51 -0
- package/templates/fitness-gym/tier5-src/_shared/business-chat-message-model.ts +177 -0
- package/templates/fitness-gym/tier5-src/_shared/business-chat-model.ts +56 -0
- package/templates/fitness-gym/tier5-src/_shared/business-chat-presenter.ts +576 -0
- package/templates/fitness-gym/tier5-src/_shared/business-chat-transport.ts +148 -0
- package/templates/fitness-gym/tier5-src/_shared/collection-contract.ts +228 -0
- package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +193 -0
- package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +400 -0
- package/templates/fitness-gym/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/fitness-gym/tier5-src/_shared/engine-intl.ts +523 -0
- package/templates/fitness-gym/tier5-src/_shared/himi-account.ts +194 -0
- package/templates/fitness-gym/tier5-src/_shared/himi-booking-saved.ts +88 -0
- package/templates/fitness-gym/tier5-src/_shared/himi-bookings.ts +318 -0
- package/templates/fitness-gym/tier5-src/_shared/himi-copy.ts +116 -0
- package/templates/fitness-gym/tier5-src/_shared/himi-media.ts +29 -0
- package/templates/fitness-gym/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/fitness-gym/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/fitness-gym/tier5-src/_shared/host-events.ts +66 -0
- package/templates/fitness-gym/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/fitness-gym/tier5-src/_shared/iap-attendance-form.ts +106 -0
- package/templates/fitness-gym/tier5-src/_shared/iap-attendance-purchase.ts +216 -0
- package/templates/fitness-gym/tier5-src/_shared/iap-attendance.ts +38 -0
- package/templates/fitness-gym/tier5-src/_shared/iap-worker.ts +127 -0
- package/templates/fitness-gym/tier5-src/_shared/inbox-rooms.ts +68 -0
- package/templates/fitness-gym/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/fitness-gym/tier5-src/_shared/member-access.ts +63 -0
- package/templates/fitness-gym/tier5-src/_shared/member-account-routes.ts +52 -0
- package/templates/fitness-gym/tier5-src/_shared/member-bookings.ts +107 -0
- package/templates/fitness-gym/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/fitness-gym/tier5-src/_shared/notification-target.ts +141 -0
- package/templates/fitness-gym/tier5-src/_shared/offset-page.ts +10 -0
- package/templates/fitness-gym/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/fitness-gym/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/fitness-gym/tier5-src/_shared/payment-setup.ts +6 -0
- package/templates/fitness-gym/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/fitness-gym/tier5-src/_shared/program-description.ts +11 -0
- package/templates/fitness-gym/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/fitness-gym/tier5-src/_shared/program-standing.ts +46 -0
- package/templates/fitness-gym/tier5-src/_shared/rich-body.ts +78 -0
- package/templates/fitness-gym/tier5-src/_shared/rich-content-link.ts +34 -0
- package/templates/fitness-gym/tier5-src/_shared/sign-in-sheet.ts +18 -0
- package/templates/fitness-gym/tier5-src/_shared/staff-name.ts +18 -0
- package/templates/fitness-gym/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/fitness-gym/tier5-src/_shared/wix-bi.ts +85 -0
- package/templates/fitness-gym/tier5-src/_shared/wix-member-links.ts +114 -0
- package/templates/fitness-gym/tier5-src/_shared/wix-service-price.ts +146 -0
- package/templates/fitness-gym/tier5-src/business-chat/index.ts +732 -0
- package/templates/fitness-gym/tier5-src/business-contact/index.ts +6 -0
- package/templates/fitness-gym/tier5-src/himi-booking-account/index.ts +267 -0
- package/templates/fitness-gym/tier5-src/himi-booking-bookings/index.ts +468 -0
- package/templates/fitness-gym/tier5-src/himi-booking-service/index.ts +1190 -0
- package/templates/fitness-gym/tier5-src/himi-booking-services/index.ts +791 -0
- package/templates/fitness-gym/tier5-src/himi-booking-time/index.ts +1729 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-agenda/index.ts +988 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-member-programs/index.ts +656 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-notifications/index.ts +256 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-plans/index.ts +495 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-program/facts.ts +52 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-program/index.ts +845 -0
- package/templates/fitness-gym/tier5-src/himi-fitcoach-goal/index.ts +191 -0
- package/templates/fitness-gym/tier5-src/himi-fitcoach-home/index.ts +619 -0
- package/templates/fitness-gym/tier5-src/himi-store-account/index.ts +1007 -0
- package/templates/fitness-gym/tier5-src/wix-spaces-my-subscriptions/index.ts +84 -0
- package/templates/fitness-gym/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
- package/templates/fitness-gym/tokens.json +414 -0
- package/templates/gym-fitness/dev/index.ts +1 -1
- package/templates/gym-fitness/l10n/en.json +1 -1
- package/templates/gym-fitness/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/gym-fitness/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/gym-fitness/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
- package/templates/medical-services/dev/index.ts +2 -1
- package/templates/medical-services/tier5-src/himi-booking-account/index.ts +16 -1
- package/templates/nonprofit-cause/l10n/en.json +1 -1
- package/templates/nonprofit-cause/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/nonprofit-cause/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/personal-fitness-trainer/dev/index.ts +2 -2
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
- package/templates/podcast-creator/dev/index.ts +100 -0
- package/templates/podcast-creator/l10n/en.json +22 -1
- package/templates/podcast-creator/l10n/es.json +22 -0
- package/templates/podcast-creator/l10n/fr.json +18 -0
- package/templates/podcast-creator/l10n/he.json +15 -0
- package/templates/podcast-creator/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/podcast-creator/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/podcast-creator/tier5-src/himi-branded-lite-podcasts/index.ts +14 -234
- package/templates/portfolio-creative/l10n/en.json +1 -1
- package/templates/portfolio-creative/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/portfolio-creative/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/restaurant/l10n/en.json +1 -1
- package/templates/restaurant/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/restaurant/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/retail-store/l10n/en.json +1 -1
- package/templates/retail-store/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/retail-store/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/salon-spa/dev/index.ts +1 -1
- package/templates/salon-spa/tier5-src/himi-booking-account/index.ts +16 -1
- package/templates/salon-spa/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
- package/templates/yoga-studio/dev/index.ts +1 -1
- package/templates/yoga-studio/l10n/en.json +1 -1
- package/templates/yoga-studio/tier5-src/_shared/program-fields.ts +16 -0
- package/templates/yoga-studio/tier5-src/_shared/programs-section.ts +5 -8
- package/templates/yoga-studio/tier5-src/himi-branded-lite-agenda/index.ts +37 -4
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copy-as-configuration for WORKER-emitted strings (`himi docs designing-himi-screens`,
|
|
2
|
+
// §"Copy is configuration"): a worker never hardcodes user-facing copy — the
|
|
3
|
+
// descriptor bakes the provisioned copy-pack overrides relevant to this worker
|
|
4
|
+
// into its onAppear action params as a `copy` JSON object (customer strings or
|
|
5
|
+
// source-matched stock translations, computed at descriptor-build time), and the
|
|
6
|
+
// worker reads every user-facing string through `copyParam(key, fallback)`.
|
|
7
|
+
//
|
|
8
|
+
// STASHED (the stashed appear-params idiom, himi-branded-lite-home): the
|
|
9
|
+
// param-carrying onAppear dispatch updates the stash; later arg-less calls
|
|
10
|
+
// (self-kick refreshes, retry buttons, pull-to-refresh) fall back to it, so
|
|
11
|
+
// resolution order can never drop the pack. With no pack the param is absent
|
|
12
|
+
// and every read returns `fallback` verbatim — routing a worker string through
|
|
13
|
+
// copyParam is byte-for-byte behavior-preserving.
|
|
14
|
+
//
|
|
15
|
+
// Pure + Hermes-safe (no host globals, no Node APIs; its only import is the pure `app-locale` sibling): bundled into
|
|
16
|
+
// every worker that emits user-facing copy, and copied verbatim into the
|
|
17
|
+
// generated templates' tier5-src/_shared/.
|
|
18
|
+
|
|
19
|
+
import { isSingular, setAppLocale, setBusinessTimeZone } from "./app-locale.js";
|
|
20
|
+
|
|
21
|
+
/** Customer strings override every read; translated stock is valid only for its
|
|
22
|
+
* original English fallback. Some existing keys serve more than one message. */
|
|
23
|
+
export type CopyPackValue = string | { source: string; translation: string };
|
|
24
|
+
|
|
25
|
+
let stashedCopy: Record<string, CopyPackValue> = Object.create(null);
|
|
26
|
+
/** Stock translations by the English text they replace, from the `textCopy` param. A pinned app's bake
|
|
27
|
+
* names each worker fallback its catalog translates by its text, because a catalog row for worker copy
|
|
28
|
+
* is often keyless. A key's own `copy` entry always wins over this. */
|
|
29
|
+
let stashedByText = new Map<string, string>();
|
|
30
|
+
let copyReceived = false;
|
|
31
|
+
|
|
32
|
+
/** Absorb the `copy` onAppear param (customer strings or stock translation records)
|
|
33
|
+
* from an action arg. Call first in every action that can receive onAppear
|
|
34
|
+
* params (load/refresh). Non-copy args and malformed packs are ignored — the
|
|
35
|
+
* stock fallbacks keep rendering. */
|
|
36
|
+
export function stashCopy(arg: unknown): void {
|
|
37
|
+
if (!arg || typeof arg !== "object") return;
|
|
38
|
+
// A param-carrying dispatch names the app language and business zone too (absent: the English house
|
|
39
|
+
// pattern, and no zone).
|
|
40
|
+
if ("copy" in arg || "locale" in arg || "businessTimeZone" in arg) {
|
|
41
|
+
setAppLocale((arg as Record<string, unknown>).locale);
|
|
42
|
+
setBusinessTimeZone((arg as Record<string, unknown>).businessTimeZone);
|
|
43
|
+
}
|
|
44
|
+
const text = (arg as Record<string, unknown>).textCopy;
|
|
45
|
+
if (typeof text === "string" && text) {
|
|
46
|
+
const parsed = parseTextCopy(text);
|
|
47
|
+
if (parsed) { stashedByText = parsed; copyReceived = true; }
|
|
48
|
+
}
|
|
49
|
+
const raw = (arg as Record<string, unknown>).copy;
|
|
50
|
+
if (typeof raw !== "string" || !raw) return;
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
53
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return;
|
|
54
|
+
const next: Record<string, CopyPackValue> = Object.create(null);
|
|
55
|
+
for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) {
|
|
56
|
+
if (typeof value === "string") next[key] = value;
|
|
57
|
+
else if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
58
|
+
const row = value as Record<string, unknown>;
|
|
59
|
+
if (typeof row.source === "string" && typeof row.translation === "string") {
|
|
60
|
+
next[key] = { source: row.source, translation: row.translation };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
stashedCopy = next;
|
|
65
|
+
copyReceived = true;
|
|
66
|
+
} catch {
|
|
67
|
+
// Malformed pack param — keep the stock copy rather than dying mid-action.
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** `textCopy`: a JSON object from English text to its translation. A malformed one is ignored (the
|
|
72
|
+
* stock copy keeps rendering); an entry that is not a non-empty string is dropped. */
|
|
73
|
+
function parseTextCopy(text: string): Map<string, string> | undefined {
|
|
74
|
+
try {
|
|
75
|
+
const parsed = JSON.parse(text) as unknown;
|
|
76
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return undefined;
|
|
77
|
+
const out = new Map<string, string>();
|
|
78
|
+
for (const [source, translation] of Object.entries(parsed as Record<string, unknown>)) {
|
|
79
|
+
if (typeof translation === "string" && translation !== "") out.set(source, translation);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
} catch {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The provisioned override for `key`, or `fallback` (the stock copy). An optional
|
|
88
|
+
* restored label survives only until a current copy pack arrives. */
|
|
89
|
+
export function copyParam(key: string, fallback: string, restoredFallback = fallback): string {
|
|
90
|
+
const value = stashedCopy[key];
|
|
91
|
+
// A disk-restored row may paint before onAppear supplies its copy pack. Keep its
|
|
92
|
+
// last label only before a pack arrives; even an empty current pack selects stock copy.
|
|
93
|
+
if (value === undefined) return stashedByText.get(fallback) ?? (copyReceived ? fallback : restoredFallback);
|
|
94
|
+
// A key can serve two messages: a row for another source text, or an empty one, must not hide the stock translation
|
|
95
|
+
// the app's catalog has for the fallback actually passed.
|
|
96
|
+
if (typeof value === "string") return value !== "" ? value : stashedByText.get(fallback) ?? fallback;
|
|
97
|
+
return value?.source === fallback && value.translation !== "" ? value.translation : stashedByText.get(fallback) ?? fallback;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Interpolate `{name}` placeholders in a (possibly overridden) template:
|
|
101
|
+
* `copyTemplate("plans.joinOnSite", "…join {name}.", { name })`. Unknown
|
|
102
|
+
* placeholders resolve to "" so a typo'd override degrades, never crashes. */
|
|
103
|
+
export function copyTemplate(key: string, fallback: string, values: Record<string, string | number>): string {
|
|
104
|
+
return copyParam(key, fallback).replace(/\{([A-Za-z0-9_]+)\}/g, (_all, name: string) =>
|
|
105
|
+
name in values ? String(values[name]) : "",
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The small ICU plural form used by Bookings spot counts. The provisioned copy may
|
|
110
|
+
* translate both branches without adding a second key for the singular. */
|
|
111
|
+
export function copyPlural(key: string, fallback: string, count: number): string {
|
|
112
|
+
const pattern = copyParam(key, fallback);
|
|
113
|
+
const match = /^\{n, plural, one \{([^{}]*)\} other \{([^{}]*)\}\}$/.exec(pattern);
|
|
114
|
+
if (!match) return copyTemplate(key, fallback, { n: count });
|
|
115
|
+
return (isSingular(count) ? match[1] : match[2])!.replace(/#/g, String(count));
|
|
116
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Cover selection is shared by list, detail and home so the same Wix object never
|
|
2
|
+
// loses its image on navigation. Relative SDK imports are rewritten by the template generator.
|
|
3
|
+
import { wixMediaUrl, WIX_LIST_IMAGE, type WixImageSize } from "@himalaya/wix-media";
|
|
4
|
+
import type { WixGroup } from "@himalaya/wix-groups";
|
|
5
|
+
import type { WixProgram } from "@himalaya/wix-online-programs";
|
|
6
|
+
|
|
7
|
+
function firstImage(references: unknown[], size: WixImageSize): string {
|
|
8
|
+
for (const reference of references) {
|
|
9
|
+
const image = wixMediaUrl(reference, size);
|
|
10
|
+
if (image) return image;
|
|
11
|
+
}
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function groupImage(group: WixGroup, size: WixImageSize = WIX_LIST_IMAGE): string {
|
|
16
|
+
const cover = group.coverImage as {
|
|
17
|
+
url?: unknown;
|
|
18
|
+
image?: { url?: unknown; fileUrl?: unknown; mediaId?: unknown; id?: unknown };
|
|
19
|
+
} | undefined;
|
|
20
|
+
return firstImage([cover?.image?.url, cover?.image?.fileUrl, cover?.url, cover?.image?.mediaId, cover?.image?.id], size);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_IMAGE): string {
|
|
24
|
+
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
|
+
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
|
+
const description = (program as { description?: unknown }).description;
|
|
27
|
+
const nested = description && typeof description === "object" ? (description as { image?: { url?: unknown; id?: unknown } }).image : undefined;
|
|
28
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id], size);
|
|
29
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Graduated to the SDK (SP-3): the store display helpers + v3 product query now live in
|
|
2
|
+
// @himalaya/wix-stores. This thin re-export keeps existing bundle imports working; new
|
|
3
|
+
// code should import from "@himalaya/wix-stores" directly.
|
|
4
|
+
// Relative so node (tests importing worker sources) resolves it too — the bare
|
|
5
|
+
// "@himalaya/wix-stores" name exists only in the esbuild alias map / the off-repo
|
|
6
|
+
// umbrella. gen-templates.mts rewrites this back to @himalaya/wix-stores off-repo.
|
|
7
|
+
export * from "@himalaya/wix-stores";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Shared display-text helpers for himi cards: trim catalog artifacts from titles and
|
|
2
|
+
// derive up-to-two-letter placeholder initials so same-first-letter lists still vary.
|
|
3
|
+
|
|
4
|
+
/** Trim trailing artifact markers (stray asterisks / footnote daggers) and whitespace
|
|
5
|
+
* that leak from test/seed catalogs, without touching interior punctuation. Falls back
|
|
6
|
+
* to the original when trimming would empty the string. */
|
|
7
|
+
export function cleanTitle(value?: string): string {
|
|
8
|
+
const raw = (value ?? "").trim();
|
|
9
|
+
const cleaned = raw.replace(/[\s*†‡]+$/u, "").trim();
|
|
10
|
+
return cleaned || raw;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Up to two significant initials for a placeholder avatar. Two-plus words → first
|
|
14
|
+
* letter of the first two; a single word → its first two alphanumerics. Keeps a list
|
|
15
|
+
* of similar names (e.g. many "Booking…") from collapsing to one identical glyph. */
|
|
16
|
+
export function initials(value?: string): string {
|
|
17
|
+
const words = (value ?? "").trim().split(/\s+/).filter(Boolean);
|
|
18
|
+
if (words.length === 0) return "#";
|
|
19
|
+
if (words.length === 1) {
|
|
20
|
+
const alnum = words[0].replace(/[^\p{L}\p{N}]/gu, "");
|
|
21
|
+
return (alnum.slice(0, 2) || "#").toUpperCase();
|
|
22
|
+
}
|
|
23
|
+
return ((words[0][0] ?? "") + (words[1][0] ?? "")).toUpperCase();
|
|
24
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Host events — what a member screen tells the app hosting it about something the member did
|
|
2
|
+
// (a booking confirmed or cancelled), so a host such as Symphony can say so in its chat and refresh
|
|
3
|
+
// what it shows.
|
|
4
|
+
//
|
|
5
|
+
// A worker dispatches `host.event` with `{ type, ...fields }` (string values only: a dispatch carries
|
|
6
|
+
// one string params map). An embed (`HimalayaEmbed`) hands it to the host's `onAction` as an action
|
|
7
|
+
// with that id; anywhere else nothing handles it and it is dropped. It is a notice, never a request:
|
|
8
|
+
// the host owns what happens next, and the worker never waits on it or depends on its answer.
|
|
9
|
+
//
|
|
10
|
+
// The contract (hosts parse exactly this — Symphony's `PlaceHostEvent`):
|
|
11
|
+
// type booking.created | booking.cancelled | plan.used
|
|
12
|
+
// serviceName the class / service title (bookings) planName the plan's name (plan.used)
|
|
13
|
+
// start, end ISO 8601 instants WITH an offset (`Z` or `+02:00`); a local time is left out
|
|
14
|
+
// remaining sessions left on the plan, when known (a whole number)
|
|
15
|
+
// bookingId, serviceId, planId when known
|
|
16
|
+
|
|
17
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
18
|
+
|
|
19
|
+
export const HOST_EVENT_ACTION_ID = "host.event";
|
|
20
|
+
|
|
21
|
+
/** The events a member screen reports. */
|
|
22
|
+
export type HostEventType = "booking.created" | "booking.cancelled" | "plan.used";
|
|
23
|
+
|
|
24
|
+
export interface HostEventFields {
|
|
25
|
+
bookingId?: string;
|
|
26
|
+
serviceId?: string;
|
|
27
|
+
serviceName?: string;
|
|
28
|
+
planId?: string;
|
|
29
|
+
planName?: string;
|
|
30
|
+
start?: string;
|
|
31
|
+
end?: string;
|
|
32
|
+
remaining?: number | string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const WITH_OFFSET = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})$/i;
|
|
36
|
+
|
|
37
|
+
/** [value] when it is an ISO 8601 instant that names its offset, else "". A slot's LOCAL wall time
|
|
38
|
+
* ("2026-11-02T18:30:00") would be read in the host's zone, i.e. a wrong hour, so it is left out. */
|
|
39
|
+
export function hostEventInstant(value: unknown): string {
|
|
40
|
+
return typeof value === "string" && WITH_OFFSET.test(value) && Number.isFinite(Date.parse(value)) ? value : "";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The `host.event` params for [type] and [fields]: unset and empty fields are left out, times
|
|
44
|
+
* without an offset are left out, and `remaining` is a whole number ≥ 0 or nothing. */
|
|
45
|
+
export function hostEventParams(type: HostEventType, fields: HostEventFields = {}): Record<string, string> {
|
|
46
|
+
const params: Record<string, string> = { type };
|
|
47
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
48
|
+
let out = "";
|
|
49
|
+
if (key === "start" || key === "end") out = hostEventInstant(value);
|
|
50
|
+
else if (key === "remaining") {
|
|
51
|
+
const n = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
|
|
52
|
+
out = Number.isInteger(n) && n >= 0 ? String(n) : "";
|
|
53
|
+
} else if (typeof value === "string") out = value.trim();
|
|
54
|
+
if (out) params[key] = out;
|
|
55
|
+
}
|
|
56
|
+
return params;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Tell the host about [type]. Never throws: a host that does not listen must not break the screen. */
|
|
60
|
+
export async function emitHostEvent(type: HostEventType, fields: HostEventFields = {}): Promise<void> {
|
|
61
|
+
try {
|
|
62
|
+
await dispatch(HOST_EVENT_ACTION_ID, hostEventParams(type, fields));
|
|
63
|
+
} catch {
|
|
64
|
+
// Not embedded, or the host has no handler: nothing to tell.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Hosted checkout. A Branded Lite hosted in a host shell (Spaces) pays as the member the host
|
|
2
|
+
// lent it: Headless `createRedirectSession` does not take a Member instance, so the HOST opens the site's
|
|
3
|
+
// checkout signed in as that member. The worker names only its ecom checkout; the host reads Wix's
|
|
4
|
+
// checkout URL, mints a one-time member session and opens the site's `createSessionCookie` → checkout.
|
|
5
|
+
// The session token never reaches this worker.
|
|
6
|
+
//
|
|
7
|
+
// Classic Wix Events tickets and classic Pricing Plans have no ecom checkout: for those the
|
|
8
|
+
// worker names the page by id (`himi.host.memberSitePage`) and the host opens the site's own event or
|
|
9
|
+
// plans page the same way, signed in — where the member picks and pays on the site. A member's orders
|
|
10
|
+
// are the same (Wix lists them to no member identity), so My orders opens the site's own page too.
|
|
11
|
+
|
|
12
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
13
|
+
import { hostSiteFromInput } from "./branded-lite-hosted.js";
|
|
14
|
+
|
|
15
|
+
/** The host verbs (registered by the host shell, never by the app itself). The first prepares the
|
|
16
|
+
* checkout and answers a one-time ticket; the second opens it. Two steps so the caller's charge guard
|
|
17
|
+
* is re-read after the host's network round trips and right before the checkout opens — the prepared
|
|
18
|
+
* URL (which carries the member's session token) stays in the host; only the ticket crosses here. */
|
|
19
|
+
export const HOSTED_CHECKOUT_ACTION = "himi.host.memberCheckout";
|
|
20
|
+
export const HOSTED_CHECKOUT_OPEN_ACTION = "himi.host.memberCheckout.open";
|
|
21
|
+
/** Prepares a site PAGE (not an ecom checkout) the same way; opened with [HOSTED_CHECKOUT_OPEN_ACTION]. */
|
|
22
|
+
export const HOSTED_SITE_PAGE_ACTION = "himi.host.memberSitePage";
|
|
23
|
+
|
|
24
|
+
/** A site page a hosted worker may ask its host for — ids only, never a URL: the host reads the URL
|
|
25
|
+
* from Wix itself and decides whether the member may be signed in there. */
|
|
26
|
+
export type HostedSitePage = { page: "event"; eventId: string } | { page: "plans"; planId?: string } | { page: "orders" };
|
|
27
|
+
|
|
28
|
+
/** Whether this worker runs inside a host that opened a site for it. */
|
|
29
|
+
export function isHostedWorker(): boolean {
|
|
30
|
+
return hostSiteFromInput((globalThis as { himalaya?: { input?: unknown } }).himalaya?.input) !== null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type HostAnswer = { opened?: unknown; ticket?: unknown; payload?: { opened?: unknown; ticket?: unknown } } | null;
|
|
34
|
+
type HostOpener = (stillMayCharge: () => Promise<boolean>) => Promise<boolean | "withdrawn">;
|
|
35
|
+
|
|
36
|
+
/** Prepare with [action] [params] → re-read the guard → open by ticket. A host without the verbs, or one
|
|
37
|
+
* that refused (Wix named no page, an unsafe URL, no account session), → false, never a throw. */
|
|
38
|
+
function hostOpener(action: string, params: Record<string, string>): HostOpener {
|
|
39
|
+
return async (stillMayCharge) => {
|
|
40
|
+
try {
|
|
41
|
+
const prepared = await dispatch(action, params) as HostAnswer;
|
|
42
|
+
const ticket = prepared?.ticket ?? prepared?.payload?.ticket;
|
|
43
|
+
if (typeof ticket !== "string" || !ticket) return false;
|
|
44
|
+
// An unopened ticket simply expires in the host: nothing to cancel.
|
|
45
|
+
if (!(await stillMayCharge())) return "withdrawn";
|
|
46
|
+
const result = await dispatch(HOSTED_CHECKOUT_OPEN_ACTION, { ticket }) as HostAnswer;
|
|
47
|
+
const opened = result?.opened ?? result?.payload?.opened;
|
|
48
|
+
return opened === true || opened === "true";
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** `payCashierOrder`'s `openCashier` for a hosted app: the host prepares [checkoutId]'s checkout as the
|
|
56
|
+
* lent member, the caller's guard is re-read, and only then does the host open it. Resolves whether it
|
|
57
|
+
* opened ("withdrawn" when the guard said no); a host without the verbs (or that refused) → false. */
|
|
58
|
+
export function hostedCheckoutOpener(checkoutId: string): HostOpener {
|
|
59
|
+
return hostOpener(HOSTED_CHECKOUT_ACTION, { checkoutId });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The site's own [page] opened by the host, signed in as the lent member where the host deems it safe
|
|
63
|
+
* (a visitor otherwise) — the same two steps and answers as [hostedCheckoutOpener]. */
|
|
64
|
+
export function hostedSitePageOpener(page: HostedSitePage): HostOpener {
|
|
65
|
+
const params: Record<string, string> = page.page === "event"
|
|
66
|
+
? { page: "event", eventId: page.eventId }
|
|
67
|
+
: page.page === "orders" ? { page: "orders" }
|
|
68
|
+
: { page: "plans", ...(page.planId ? { planId: page.planId } : {}) };
|
|
69
|
+
return hostOpener(HOSTED_SITE_PAGE_ACTION, params);
|
|
70
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { copyParam } from "./himi-copy.js";
|
|
2
|
+
|
|
3
|
+
export interface AttendanceField {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
kind: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
value: string;
|
|
9
|
+
selectedIds: string[];
|
|
10
|
+
options: { id: string; label: string }[];
|
|
11
|
+
error: string;
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
maxSize?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const object = (v: unknown): Record<string, unknown> => v !== null && typeof v === "object" && !Array.isArray(v) ? v as Record<string, unknown> : {};
|
|
17
|
+
const text = (v: unknown): string => typeof v === "string" ? v : "";
|
|
18
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
19
|
+
|
|
20
|
+
export function createAttendanceForm(prefix: string) {
|
|
21
|
+
let fields: AttendanceField[] = [];
|
|
22
|
+
let supported = false;
|
|
23
|
+
const label = (name: string) => copyParam(`${prefix}.${name}Label`, name === "firstName" ? "First name" : name === "lastName" ? "Last name" : "Email");
|
|
24
|
+
const field = (scope: string, name: string, input: Record<string, unknown> = {}): AttendanceField => ({
|
|
25
|
+
id: `${scope}:${name}`, label: text(input.label) || label(name), required: input.mandatory === true,
|
|
26
|
+
kind: name === "email" ? "email" : input.type === "NUMBER" ? "number" : input.type === "TEXT_ARRAY" ? "multiple" : Array.isArray(input.options) && input.options.length ? "choice" : "text",
|
|
27
|
+
value: "", selectedIds: [], error: "",
|
|
28
|
+
options: Array.isArray(input.options) ? input.options.filter((o): o is string => typeof o === "string").map((o) => ({ id: o, label: o })) : [],
|
|
29
|
+
...(typeof input.maxLength === "number" ? { maxLength: input.maxLength } : {}),
|
|
30
|
+
...(typeof input.maxSize === "number" ? { maxSize: input.maxSize } : {}),
|
|
31
|
+
});
|
|
32
|
+
const contact = (scope: string) => ["firstName", "lastName", "email"].map((name) => field(scope, name, { mandatory: true }));
|
|
33
|
+
|
|
34
|
+
function event(raw: unknown): void {
|
|
35
|
+
fields = contact("buyer");
|
|
36
|
+
const controls = object(raw).controls;
|
|
37
|
+
supported = Array.isArray(controls) && controls.length > 0;
|
|
38
|
+
const names = new Set<string>();
|
|
39
|
+
for (const control of Array.isArray(controls) ? controls : []) {
|
|
40
|
+
const c = object(control);
|
|
41
|
+
if (c.deleted === true) continue;
|
|
42
|
+
if (!Array.isArray(c.inputs) || !c.inputs.length) { supported = false; continue; }
|
|
43
|
+
for (const rawInput of c.inputs) {
|
|
44
|
+
const input = object(rawInput);
|
|
45
|
+
const name = text(input.name);
|
|
46
|
+
if (!name || names.has(name) || !["TEXT", "NUMBER", "TEXT_ARRAY"].includes(text(input.type)) || (input.type === "TEXT_ARRAY" && (!Array.isArray(input.options) || !input.options.length))) { supported = false; continue; }
|
|
47
|
+
names.add(name);
|
|
48
|
+
fields.push(field("guest", name, { ...input, mandatory: input.mandatory === true || ["firstName", "lastName", "email"].includes(name) }));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!["firstName", "lastName", "email"].every((name) => names.has(name))) supported = false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function booking(service: unknown): void {
|
|
55
|
+
fields = contact("buyer");
|
|
56
|
+
const id = text(object(object(service).form).id);
|
|
57
|
+
// Custom intake schemas need their own reader; never silently omit their required fields.
|
|
58
|
+
supported = id === "00000000-0000-0000-0000-000000000000";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function change(arg: unknown): void {
|
|
62
|
+
const a = object(arg);
|
|
63
|
+
const f = fields.find((candidate) => candidate.id === a.id);
|
|
64
|
+
if (!f) return;
|
|
65
|
+
if (typeof a.option === "string") {
|
|
66
|
+
if (f.kind === "multiple") f.selectedIds = f.selectedIds.includes(a.option) ? f.selectedIds.filter((v) => v !== a.option) : [...f.selectedIds, a.option];
|
|
67
|
+
else f.value = a.option;
|
|
68
|
+
f.error = "";
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
f.value = text(a.value ?? a.text ?? a.selectedId);
|
|
72
|
+
f.selectedIds = Array.isArray(a.selectedIds) ? a.selectedIds.filter((v): v is string => typeof v === "string") : [];
|
|
73
|
+
f.error = "";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function valid(f: AttendanceField): boolean {
|
|
77
|
+
const value = f.value.trim();
|
|
78
|
+
const values = f.kind === "multiple" ? f.selectedIds : value ? [value] : [];
|
|
79
|
+
if (!values.length) return !f.required;
|
|
80
|
+
if (f.options.length && values.some((v) => !f.options.some((o) => o.id === v))) return false;
|
|
81
|
+
if (f.maxSize !== undefined && values.length > f.maxSize) return false;
|
|
82
|
+
if (f.maxLength !== undefined && values.some((v) => v.length > f.maxLength!)) return false;
|
|
83
|
+
return f.kind === "email" ? EMAIL.test(value) : f.kind !== "number" || /^-?\d+(?:\.\d+)?$/.test(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function validate(): boolean {
|
|
87
|
+
for (const f of fields) f.error = valid(f) ? "" : copyParam(`${prefix}.formInvalidText`, "Check this field.");
|
|
88
|
+
return supported && fields.every((f) => !f.error);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function buyer(): Record<string, string> {
|
|
92
|
+
return Object.fromEntries(fields.filter((f) => f.id.startsWith("buyer:")).map((f) => [f.id.slice(6), f.value.trim()]));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function ticket(definitionId: string) {
|
|
96
|
+
const inputValues = fields.filter((f) => f.id.startsWith("guest:") && (f.value.trim() || f.selectedIds.length)).map((f) => ({ inputName: f.id.slice(6), ...(f.kind === "multiple" ? { values: f.selectedIds.slice() } : { value: f.value.trim() }) }));
|
|
97
|
+
return { buyer: buyer(), guests: [{ ticketDefinitionId: definitionId, form: { inputValues } }] };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
event, booking, change, validate, buyer, ticket,
|
|
102
|
+
supported: () => supported,
|
|
103
|
+
rows: () => fields.map((f) => ({ ...f, selectedIds: f.selectedIds.slice(), kind: f.kind === "text" && f.required ? "requiredText" : f.kind })),
|
|
104
|
+
clear: () => { for (const f of fields) { f.value = ""; f.selectedIds = []; f.error = ""; } },
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { attendanceCheckoutRoute, availableTicketAttendanceOf, bookingAttendanceOf, classifyForApple, hostSessionFromGlobal, iapPriceFields, type BookingAttendance, type CatalogReference, type IapPollDirective, type TicketAttendance } from "@himalaya/iap";
|
|
2
|
+
import { bookingOrders, createIapCommerce, eventTicketOrders, type IapOrderItem } from "@himalaya/iap-checkout";
|
|
3
|
+
import { copyParam, copyTemplate } from "./himi-copy.js";
|
|
4
|
+
import { createAttendanceForm, type AttendanceField } from "./iap-attendance-form.js";
|
|
5
|
+
import { attendancePlatform } from "./iap-attendance.js";
|
|
6
|
+
import { iapPriceCopy, iapPurchaseCopy } from "./iap-worker.js";
|
|
7
|
+
|
|
8
|
+
export interface AttendancePurchaseFields {
|
|
9
|
+
iapBuyHidden: boolean;
|
|
10
|
+
iapBuyDisabled: boolean;
|
|
11
|
+
iapBuyLabel: string;
|
|
12
|
+
iapBusy: boolean;
|
|
13
|
+
iapPrice: string;
|
|
14
|
+
iapNote: string;
|
|
15
|
+
iapRetryHidden: boolean;
|
|
16
|
+
iapFormHidden: boolean;
|
|
17
|
+
iapFormError: string;
|
|
18
|
+
iapSignInHidden: boolean;
|
|
19
|
+
iapFields: AttendanceField[];
|
|
20
|
+
_poll?: IapPollDirective;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const ATTENDANCE_INITIAL: AttendancePurchaseFields = {
|
|
24
|
+
iapBuyHidden: true, iapBuyDisabled: true, iapBuyLabel: "", iapBusy: false,
|
|
25
|
+
iapPrice: "", iapNote: "", iapRetryHidden: true, iapFormHidden: true, iapFormError: "", iapSignInHidden: true, iapFields: [],
|
|
26
|
+
};
|
|
27
|
+
export const ATTENDANCE_NOT_HYDRATED = [...Object.keys(ATTENDANCE_INITIAL), "_poll"] as (keyof AttendancePurchaseFields & string)[];
|
|
28
|
+
|
|
29
|
+
const CORRECTABLE = new Set(["orderRefused", "productChanged", "memberDetailsRequired", "bookingNotOwned"]);
|
|
30
|
+
|
|
31
|
+
export function createAttendancePurchase(options: { kind: "bookingsService" | "eventsTicket"; prefix: string; pollAction: string; onChange(): void }) {
|
|
32
|
+
const { prefix } = options;
|
|
33
|
+
let form = createAttendanceForm(prefix);
|
|
34
|
+
const submittedForms = new Map<string, ReturnType<typeof createAttendanceForm>>();
|
|
35
|
+
const session = hostSessionFromGlobal();
|
|
36
|
+
const commerce = createIapCommerce({ adapters: [options.kind === "bookingsService" ? bookingOrders : eventTicketOrders], onChange: options.onChange });
|
|
37
|
+
let generation = session.current().generation;
|
|
38
|
+
let reference: CatalogReference | undefined;
|
|
39
|
+
let metadata: BookingAttendance | TicketAttendance | undefined;
|
|
40
|
+
let platform = "unknown";
|
|
41
|
+
let started = false;
|
|
42
|
+
let inFlight = false;
|
|
43
|
+
let formError = "";
|
|
44
|
+
let sequence = 0;
|
|
45
|
+
let formRevision = 0;
|
|
46
|
+
const attempts = new Map<string, string>();
|
|
47
|
+
session.subscribe(() => { syncSession(); if (reference) options.onChange(); });
|
|
48
|
+
|
|
49
|
+
function syncSession(): void {
|
|
50
|
+
const next = session.current().generation;
|
|
51
|
+
if (next === generation) return;
|
|
52
|
+
generation = next;
|
|
53
|
+
form.clear();
|
|
54
|
+
submittedForms.clear();
|
|
55
|
+
formError = "";
|
|
56
|
+
attempts.clear();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function refresh(): Promise<void> {
|
|
60
|
+
const next = await attendancePlatform(publishPlatform);
|
|
61
|
+
if (next !== "unknown" || platform === "unknown") platform = next;
|
|
62
|
+
await resume();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function resume(): Promise<void> {
|
|
66
|
+
if (reference) await commerce.loadPrices([{ reference }]);
|
|
67
|
+
const first = !started;
|
|
68
|
+
started = true;
|
|
69
|
+
await (first ? commerce.start() : commerce.reconcile());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function publishPlatform(next: string): void {
|
|
73
|
+
if (next === "unknown" && platform !== "unknown") return;
|
|
74
|
+
platform = next;
|
|
75
|
+
void resume().then(options.onChange, options.onChange);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function show(): void {
|
|
79
|
+
void attendancePlatform(publishPlatform).then(publishPlatform, options.onChange);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function booking(id: string, service: unknown): Promise<void> {
|
|
83
|
+
syncSession();
|
|
84
|
+
reference = { kind: options.kind, id };
|
|
85
|
+
metadata = bookingAttendanceOf(service);
|
|
86
|
+
selectForm(id, (next) => next.booking(service));
|
|
87
|
+
formRevision++;
|
|
88
|
+
formError = "";
|
|
89
|
+
await show();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function ticket(id: string, event: unknown, available: unknown): Promise<void> {
|
|
93
|
+
syncSession();
|
|
94
|
+
reference = id ? { kind: options.kind, id } : undefined;
|
|
95
|
+
metadata = availableTicketAttendanceOf(event, available);
|
|
96
|
+
selectForm(id, (next) => next.event((event as { form?: unknown } | undefined)?.form));
|
|
97
|
+
formRevision++;
|
|
98
|
+
formError = "";
|
|
99
|
+
await show();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function selectForm(id: string, initialize: (next: ReturnType<typeof createAttendanceForm>) => void): void {
|
|
103
|
+
const key = `${options.kind}:${id}`;
|
|
104
|
+
const retained = submittedForms.get(key);
|
|
105
|
+
form = retained ?? createAttendanceForm(prefix);
|
|
106
|
+
if (!retained) initialize(form);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function fields(selected = true, publishPoll = true): AttendancePurchaseFields {
|
|
110
|
+
syncSession();
|
|
111
|
+
if (!reference || !metadata) return ATTENDANCE_INITIAL;
|
|
112
|
+
const currency = metadata.currency ?? "";
|
|
113
|
+
const classified = classifyForApple(metadata, currency);
|
|
114
|
+
const candidate = platform === "ios" && classified === "appleIap";
|
|
115
|
+
const price = iapPriceFields(commerce.pricing.view(reference), iapPriceCopy(prefix));
|
|
116
|
+
const copy = iapPurchaseCopy(prefix);
|
|
117
|
+
const purchase = commerce.purchaseFields(reference, copy);
|
|
118
|
+
const apple = candidate || (platform === "ios" && classified !== "wixPayments" && purchase.appleRoute);
|
|
119
|
+
const enabled = attendanceCheckoutRoute(metadata, currency, platform) === "appleIap";
|
|
120
|
+
const poll = publishPoll ? commerce.pollDirective(options.pollAction) : undefined;
|
|
121
|
+
const state = commerce.state();
|
|
122
|
+
for (const [target, attempt] of attempts) {
|
|
123
|
+
const key = `${reference.kind}:${reference.id}#${encodeURIComponent(attempt)}`;
|
|
124
|
+
if ((state.phase === "accessReady" && state.item === key) || state.payments.some((p) => p.item === key && p.access === "granted")) attempts.delete(target);
|
|
125
|
+
}
|
|
126
|
+
const formKey = `${reference.kind}:${reference.id}`;
|
|
127
|
+
if (![...attempts.keys()].some((target) => target.startsWith(`${formKey}:`))) submittedForms.delete(formKey);
|
|
128
|
+
const own = state.item?.startsWith(`${reference.kind}:${reference.id}#`);
|
|
129
|
+
const completed = state.phase === "accessReady" && own;
|
|
130
|
+
const member = session.current().kind === "member";
|
|
131
|
+
let note = "";
|
|
132
|
+
if (apple && !enabled) note = copy.unavailable;
|
|
133
|
+
else if (apple && !member) note = copy.signInRequired;
|
|
134
|
+
else if (apple && purchase.buyNote) note = purchase.buyNote;
|
|
135
|
+
else if (apple && !form.supported()) note = copyParam(`${prefix}.formUnavailableText`, "This registration form is not supported yet.");
|
|
136
|
+
else if (apple && completed) note = copyParam(`${prefix}.purchaseCompleteText`, options.kind === "bookingsService" ? "Your booking is confirmed." : "Your ticket is confirmed.");
|
|
137
|
+
else if (apple && own && state.phase === "cancelled") note = copyParam(`${prefix}.purchaseCancelledText`, "Purchase cancelled. Your place is not confirmed.");
|
|
138
|
+
return {
|
|
139
|
+
iapBuyHidden: !apple, iapBuyDisabled: !enabled || !selected || !member || !form.supported() || purchase.buyDisabled || inFlight,
|
|
140
|
+
iapBuyLabel: purchase.buyLabel || copy.buy, iapBusy: purchase.buyBusy || inFlight,
|
|
141
|
+
iapPrice: apple ? price.priceText : "", iapRetryHidden: !apple || (price.hidePriceRetry && commerce.scopeComplete()),
|
|
142
|
+
iapNote: note,
|
|
143
|
+
iapFormHidden: !apple || !selected || !form.supported(), iapFormError: formError,
|
|
144
|
+
iapSignInHidden: !apple || member || options.kind === "bookingsService",
|
|
145
|
+
iapFields: form.rows().map((f, index, rows) => ({ ...f,
|
|
146
|
+
id: `${generation}:${formRevision}:${f.id}`, fieldId: f.id,
|
|
147
|
+
errorHidden: !f.error,
|
|
148
|
+
options: f.options.map((o) => ({ ...o, fieldId: f.id, displayLabel: (f.kind === "multiple" ? f.selectedIds.includes(o.id) : f.value === o.id) ? `${o.label} ✓` : o.label })),
|
|
149
|
+
label: f.required ? `${f.label} *` : f.label,
|
|
150
|
+
inputLabel: copyTemplate(`${prefix}.fieldAccessibilityLabel`, "{section}: {field}", { section: f.id.startsWith("buyer:") ? copyParam(`${prefix}.buyerDetailsLabel`, "Buyer details") : copyParam(`${prefix}.guestDetailsLabel`, "Ticket holder details"), field: f.label }),
|
|
151
|
+
sectionLabel: index === 0 ? copyParam(`${prefix}.buyerDetailsLabel`, "Buyer details") : f.id.startsWith("guest:") && rows[index - 1].id.startsWith("buyer:") ? copyParam(`${prefix}.guestDetailsLabel`, "Ticket holder details") : "",
|
|
152
|
+
})), ...(poll ? { _poll: poll } : {}),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function buy(selection: { key: string; slot?: Record<string, unknown>; eventId?: string }): Promise<void> {
|
|
157
|
+
syncSession();
|
|
158
|
+
if (!reference || !metadata || fields(true, false).iapBuyDisabled || inFlight) return;
|
|
159
|
+
if (options.kind === "eventsTicket" && reference.id !== selection.key) return;
|
|
160
|
+
if (!form.validate()) { formError = copyParam(`${prefix}.formRequiredText`, "Complete the required details before purchasing."); return; }
|
|
161
|
+
if (session.current().kind !== "member") { formError = iapPurchaseCopy(prefix).signInRequired; return; }
|
|
162
|
+
const currentGeneration = generation;
|
|
163
|
+
const ref = reference;
|
|
164
|
+
submittedForms.set(`${ref.kind}:${ref.id}`, form);
|
|
165
|
+
const target = `${ref.kind}:${ref.id}:${selection.key}`;
|
|
166
|
+
let attemptId = attempts.get(target);
|
|
167
|
+
const state = commerce.state();
|
|
168
|
+
const attemptKey = attemptId ? `${ref.kind}:${ref.id}#${encodeURIComponent(attemptId)}` : "";
|
|
169
|
+
const completed = attemptId && ((state.phase === "accessReady" && state.item === attemptKey) || state.payments.some((p) => p.item === attemptKey && p.access === "granted"));
|
|
170
|
+
if (!attemptId || completed) { attemptId = `${Date.now().toString(36)}-${++sequence}-${Math.random().toString(36).slice(2)}`; attempts.set(target, attemptId); }
|
|
171
|
+
const item: IapOrderItem = { reference: ref, attemptId, quantity: 1, attendance: {
|
|
172
|
+
amount: metadata.amount!, currency: metadata.currency!,
|
|
173
|
+
...(options.kind === "bookingsService" ? { booking: { slot: selection.slot ?? {}, contactDetails: form.buyer() } } : { ticket: { eventId: selection.eventId ?? "", ...form.ticket(ref.id) } }),
|
|
174
|
+
} };
|
|
175
|
+
inFlight = true;
|
|
176
|
+
formError = "";
|
|
177
|
+
options.onChange();
|
|
178
|
+
try {
|
|
179
|
+
await commerce.buy(item);
|
|
180
|
+
const after = commerce.state();
|
|
181
|
+
if (after.phase === "accessReady" && after.item === `${ref.kind}:${ref.id}#${encodeURIComponent(attemptId)}`) attempts.delete(target);
|
|
182
|
+
}
|
|
183
|
+
finally { inFlight = false; syncSession(); if (generation !== currentGeneration) form.clear(); options.onChange(); }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function change(arg: unknown): void {
|
|
187
|
+
syncSession();
|
|
188
|
+
const state = commerce.state();
|
|
189
|
+
if (reference) {
|
|
190
|
+
for (const [target, attempt] of attempts) {
|
|
191
|
+
const item = `${reference.kind}:${reference.id}#${encodeURIComponent(attempt)}`;
|
|
192
|
+
// Refusals that leave nothing to pay: the member may fix the details (a profile, a booking the
|
|
193
|
+
// server did not attribute to them) and start a fresh attempt. A transient failure keeps the
|
|
194
|
+
// attempt, so its next tap reopens the same order instead of booking twice.
|
|
195
|
+
const canCorrect = state.phase === "cancelled" || (state.phase === "refused" && CORRECTABLE.has(state.failure ?? ""));
|
|
196
|
+
if (canCorrect && state.item === item) { attempts.delete(target); submittedForms.delete(`${reference.kind}:${reference.id}`); }
|
|
197
|
+
}
|
|
198
|
+
const referencePrefix = `${reference.kind}:${reference.id}:`;
|
|
199
|
+
if (inFlight || [...attempts.keys()].some((target) => target.startsWith(referencePrefix))) {
|
|
200
|
+
formError = copyParam(`${prefix}.detailsLockedText`, "Finish the current purchase before changing registration details.");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
form.change(arg);
|
|
205
|
+
formError = "";
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
booking, ticket, fields, buy,
|
|
210
|
+
usesRegularPlatform: () => platform === "android" || platform === "web",
|
|
211
|
+
invalidate: () => { reference = undefined; metadata = undefined; options.onChange(); },
|
|
212
|
+
change,
|
|
213
|
+
refresh,
|
|
214
|
+
poll: async () => { syncSession(); await commerce.poll(); },
|
|
215
|
+
};
|
|
216
|
+
}
|