@wix/himalaya-cli 0.1852.0 → 0.1854.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/cli.mjs +1104 -711
- package/guides/himi-json-output.md +8 -2
- package/guides/iap-products.md +4 -0
- package/guides/one-app-section-mappings.md +2 -2
- package/guides/one-app-to-himi-app.md +28 -12
- package/guides/push-cli-onboarding.md +20 -0
- package/package.json +2 -2
- package/template-icons/bare-fashion.png +0 -0
- package/templates/bare-fashion/README.md +52 -0
- package/templates/bare-fashion/config.ts +474 -0
- package/templates/bare-fashion/dev/index.ts +16526 -0
- package/templates/bare-fashion/himalaya.content.json +70 -0
- package/templates/bare-fashion/himalaya.template.json +18 -0
- package/templates/bare-fashion/icon.png +0 -0
- package/templates/bare-fashion/platforms.json +3 -0
- package/templates/bare-fashion/tier5-src/_shared/app-locale.ts +70 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-book.ts +116 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-countries.ts +261 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-bag-count.ts +24 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-categories.ts +48 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-facets.ts +265 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-load-error.ts +38 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +136 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-store-options.ts +129 -0
- package/templates/bare-fashion/tier5-src/_shared/branded-lite-hosted.ts +282 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +228 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-query.ts +201 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +429 -0
- package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +529 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-account.ts +209 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-copy.ts +123 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-layouts.ts +142 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store-categories.ts +108 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +57 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/bare-fashion/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/bare-fashion/tier5-src/_shared/live-session.ts +172 -0
- package/templates/bare-fashion/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/bare-fashion/tier5-src/_shared/member-access.ts +63 -0
- package/templates/bare-fashion/tier5-src/_shared/member-avatar.ts +76 -0
- package/templates/bare-fashion/tier5-src/_shared/member-orders.ts +8 -0
- package/templates/bare-fashion/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-account/index.ts +127 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-address-form/index.ts +367 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-addresses/index.ts +202 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-appearance/index.ts +73 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +540 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +111 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +241 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-nav/index.ts +56 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-order/index.ts +437 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +650 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +142 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +45 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +199 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-shop/index.ts +79 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-sign-in/index.ts +269 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-wallet/index.ts +224 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-info/index.ts +209 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-orders/index.ts +327 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-collections/index.ts +48 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-view-profile/index.ts +119 -0
- package/templates/bare-fashion/tokens.json +348 -0
- package/templates/beauty-salon/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
- package/templates/branded-lite/tier5-src/_shared/announcement-section.ts +6 -14
- package/templates/branded-lite/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/branded-lite/tier5-src/_shared/draft-content.ts +66 -0
- package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +55 -3
- package/templates/branded-lite/tier5-src/_shared/events-inline.ts +5 -3
- package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/brandy/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/brandy/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/brandy/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/community-club/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/community-club/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/community-club/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/community-club-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/conference/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/conference/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/conference/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/conference/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/events-meetups/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/events-meetups/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/events-meetups-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/gym-fitness/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/medical-services/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/medical-services/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/nonprofit-cause/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/owner-lite/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/podcast-creator/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/restaurant/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/restaurant/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/restaurant-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/retail-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/retail-store-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/salon-spa/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/salon-spa/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/yoga-studio/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { defineService } from "@himalaya/state";
|
|
2
|
+
import { open as openUrl } from "@himalaya/open-url";
|
|
3
|
+
import { get as getAppInfo, type AppInfo } from "@himalaya/app-info";
|
|
4
|
+
import { available as pickerAvailable, active as activeRelease, list as listReleases, select as selectRelease } from "@himalaya/release-control";
|
|
5
|
+
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
6
|
+
|
|
7
|
+
// The App & support screen's worker. Besides opening the support/privacy/terms links it:
|
|
8
|
+
//
|
|
9
|
+
// • reads this app's REAL version + OTA release through @himalaya/app-info rather than letting
|
|
10
|
+
// the descriptor bake a literal — the mistake every other app's About screen makes (demo-app
|
|
11
|
+
// "0.1 (dev)", symphony "1.0 (1)"), which goes stale the moment the binary is bumped;
|
|
12
|
+
// • on a QA/dev build ONLY, offers the on-device release picker (@himalaya/release-control):
|
|
13
|
+
// list the published releases, pin one, and have the shell reload on it. Everything picker-
|
|
14
|
+
// related stays hidden unless `pickerAvailable()` resolves true, so a customer's branded app
|
|
15
|
+
// shows just the version card — an end user must not be able to downgrade themselves.
|
|
16
|
+
|
|
17
|
+
interface ReleaseRow {
|
|
18
|
+
/** `$item.` fields for the picker list. */
|
|
19
|
+
id: string;
|
|
20
|
+
title: string;
|
|
21
|
+
subtitle: string;
|
|
22
|
+
/** "✓" on the release currently being served, "" otherwise. */
|
|
23
|
+
mark: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface State {
|
|
27
|
+
message: string;
|
|
28
|
+
/** "0.2.0 (2)" — the user-facing version, or "" until loaded / unreadable. */
|
|
29
|
+
version: string;
|
|
30
|
+
/** "Release 89e391d84" in prod, "" on the dev-server (there is no release). */
|
|
31
|
+
releaseLine: string;
|
|
32
|
+
/** "HimalayaCore 1.1.0" — the min_binary_version basis, a developer-facing number. */
|
|
33
|
+
runtimeLine: string;
|
|
34
|
+
/** True only on a build that opted into the picker. */
|
|
35
|
+
pickerAvailable: boolean;
|
|
36
|
+
/** The INVERSE of pickerAvailable, because `hiddenWhen` hides on a truthy path — the
|
|
37
|
+
* descriptor's picker subtree binds `hiddenPath` to this (same convention as
|
|
38
|
+
* `$item.noImage`). Kept in lockstep with pickerAvailable by every writer. */
|
|
39
|
+
pickerHidden: boolean;
|
|
40
|
+
/** Releases offered by the picker (newest first). Empty until `loadReleases` runs. */
|
|
41
|
+
releases: ReleaseRow[];
|
|
42
|
+
/** Picker status line — loading / unavailable / refusal reasons. */
|
|
43
|
+
pickerMessage: string;
|
|
44
|
+
/** True while a list or select is in flight. */
|
|
45
|
+
pickerBusy: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function urlFrom(arg: unknown): string {
|
|
49
|
+
return typeof arg === "object" && arg !== null && typeof (arg as { url?: unknown }).url === "string"
|
|
50
|
+
? (arg as { url: string }).url
|
|
51
|
+
: "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function idFrom(arg: unknown): string {
|
|
55
|
+
return typeof arg === "object" && arg !== null && typeof (arg as { id?: unknown }).id === "string"
|
|
56
|
+
? (arg as { id: string }).id
|
|
57
|
+
: "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** `"0.2.0 (2)"`, collapsing a build number that is absent or a repeat of the version. */
|
|
61
|
+
function formatVersion(info: AppInfo): string {
|
|
62
|
+
if (!info.version) return "";
|
|
63
|
+
return info.buildNumber && info.buildNumber !== info.version
|
|
64
|
+
? `${info.version} (${info.buildNumber})`
|
|
65
|
+
: info.version;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** `Release <id>` (+ ` · pinned`), or "" when there is no release (the dev-server). */
|
|
69
|
+
function formatRelease(releaseId: string | null, pinned: boolean): string {
|
|
70
|
+
if (!releaseId) return "";
|
|
71
|
+
return `${copyParam("appInfo.releaseLabel", "Release")} ${releaseId}${pinned ? " · pinned" : ""}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** `2026-07-27` from an ISO timestamp — the date is what a QA person picks by; the clock time
|
|
75
|
+
* is noise. Falls back to the raw value rather than dropping it. */
|
|
76
|
+
function shortDate(iso: string): string {
|
|
77
|
+
const m = /^(\d{4}-\d{2}-\d{2})/.exec(iso);
|
|
78
|
+
return m ? m[1] : iso;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const svc = defineService<State, {
|
|
82
|
+
load: (state: State, arg?: unknown) => Promise<State>;
|
|
83
|
+
open: (state: State, arg?: unknown) => Promise<State>;
|
|
84
|
+
loadReleases: (state: State, arg?: unknown) => Promise<State>;
|
|
85
|
+
pick: (state: State, arg?: unknown) => Promise<State>;
|
|
86
|
+
resetRelease: (state: State, arg?: unknown) => Promise<State>;
|
|
87
|
+
}>("himiBrandedInfo", {
|
|
88
|
+
state: {
|
|
89
|
+
message: "", version: "", releaseLine: "", runtimeLine: "",
|
|
90
|
+
pickerAvailable: false, pickerHidden: true, releases: [], pickerMessage: "", pickerBusy: false,
|
|
91
|
+
},
|
|
92
|
+
actions: {
|
|
93
|
+
// onAppear. Never throws: a host that can't answer leaves the rows empty (they
|
|
94
|
+
// collapseWhenEmpty in the descriptor) rather than failing the screen.
|
|
95
|
+
load: async (state, arg) => {
|
|
96
|
+
stashCopy(arg);
|
|
97
|
+
let next = state;
|
|
98
|
+
try {
|
|
99
|
+
const info = await getAppInfo();
|
|
100
|
+
next = {
|
|
101
|
+
...next,
|
|
102
|
+
version: formatVersion(info),
|
|
103
|
+
// Only meaningful once the app is serving from prod; on the dev-server there is no
|
|
104
|
+
// release id at all, so the row collapses instead of showing "Release —".
|
|
105
|
+
releaseLine: formatRelease(info.releaseId, info.releasePinned),
|
|
106
|
+
runtimeLine: info.binaryVersion ? `HimalayaCore ${info.binaryVersion}` : "",
|
|
107
|
+
};
|
|
108
|
+
} catch {
|
|
109
|
+
// Keep whatever was already painted.
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
// Probe before revealing anything picker-shaped (spec R8) — on a customer build this
|
|
113
|
+
// stays false and the whole subtree is hidden.
|
|
114
|
+
const canPick = await pickerAvailable();
|
|
115
|
+
// The runtime line names the internal platform ("HimalayaCore 0.0.1") — a number for
|
|
116
|
+
// whoever debugs the build, not for a white-label app's customer ([branded-lite-qa]
|
|
117
|
+
// #3002/#3083). It shows only on a build that opted into the QA picker.
|
|
118
|
+
next = { ...next, pickerAvailable: canPick, pickerHidden: !canPick, runtimeLine: canPick ? next.runtimeLine : "" };
|
|
119
|
+
if (canPick) {
|
|
120
|
+
// `active()` is more precise than app-info's releasePinned: it also says WHICH pin
|
|
121
|
+
// (user vs baked) is holding the release.
|
|
122
|
+
const a = await activeRelease();
|
|
123
|
+
if (a.releaseId) {
|
|
124
|
+
next = { ...next, releaseLine: `${formatRelease(a.releaseId, a.pinned)}${a.source === "user" ? " (picked)" : ""}` };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
next = { ...next, pickerAvailable: false, pickerHidden: true, runtimeLine: "" };
|
|
129
|
+
}
|
|
130
|
+
return next;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
open: async (state, arg) => {
|
|
134
|
+
stashCopy(arg);
|
|
135
|
+
const url = urlFrom(arg);
|
|
136
|
+
if (!/^https?:\/\//i.test(url)) return { ...state, message: copyParam("appInfo.linkUnavailableMessage", "This link is unavailable.") };
|
|
137
|
+
try {
|
|
138
|
+
const result = await openUrl(url, "in_app_browser");
|
|
139
|
+
return { ...state, message: result.opened ? "" : copyParam("appInfo.linkOpenFailedMessage", "This link could not be opened.") };
|
|
140
|
+
} catch {
|
|
141
|
+
return { ...state, message: copyParam("appInfo.linkOpenFailedMessage", "This link could not be opened.") };
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
loadReleases: async (state, arg) => {
|
|
146
|
+
stashCopy(arg);
|
|
147
|
+
if (!state.pickerAvailable) return state;
|
|
148
|
+
const busy = { ...state, pickerBusy: true, pickerMessage: copyParam("appInfo.releasesLoading", "Loading releases…") };
|
|
149
|
+
try {
|
|
150
|
+
const result = await listReleases();
|
|
151
|
+
if (!result.supported) {
|
|
152
|
+
// NOT the same as an empty list: the serve backend keeps no release ledger.
|
|
153
|
+
return { ...busy, pickerBusy: false, releases: [], pickerMessage: copyParam("appInfo.releasesUnsupported", "Release history isn't available on this server.") };
|
|
154
|
+
}
|
|
155
|
+
if (result.releases.length === 0) {
|
|
156
|
+
return { ...busy, pickerBusy: false, releases: [], pickerMessage: copyParam("appInfo.releasesEmpty", "No published releases yet.") };
|
|
157
|
+
}
|
|
158
|
+
const rows: ReleaseRow[] = result.releases.map((r) => ({
|
|
159
|
+
id: r.releaseId,
|
|
160
|
+
title: r.label ? `${r.label} · ${r.releaseId}` : r.releaseId,
|
|
161
|
+
subtitle: shortDate(r.publishedAt),
|
|
162
|
+
mark: r.releaseId === result.current ? "✓" : "",
|
|
163
|
+
}));
|
|
164
|
+
return { ...busy, pickerBusy: false, releases: rows, pickerMessage: "" };
|
|
165
|
+
} catch {
|
|
166
|
+
return { ...busy, pickerBusy: false, releases: [], pickerMessage: copyParam("appInfo.releasesFailed", "Couldn't load releases.") };
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
// On success the host has already purged caches and restarted the shell, so this state
|
|
171
|
+
// update may never paint — that is fine. A refusal MUST paint, which is why the reason is
|
|
172
|
+
// mapped to copy rather than swallowed.
|
|
173
|
+
pick: async (state, arg) => {
|
|
174
|
+
if (!state.pickerAvailable) return state;
|
|
175
|
+
const id = idFrom(arg);
|
|
176
|
+
if (!id) return state;
|
|
177
|
+
const busy = { ...state, pickerBusy: true, pickerMessage: copyParam("appInfo.releaseApplying", "Switching release…") };
|
|
178
|
+
try {
|
|
179
|
+
const result = await selectRelease(id);
|
|
180
|
+
if (result.ok) return { ...busy, pickerBusy: false, pickerMessage: "" };
|
|
181
|
+
return {
|
|
182
|
+
...busy,
|
|
183
|
+
pickerBusy: false,
|
|
184
|
+
pickerMessage: result.reason === "preview_token_required"
|
|
185
|
+
// The deployed-serve case: reading a non-live release needs a short-lived claim.
|
|
186
|
+
? copyParam("appInfo.releaseNeedsToken", "This release is private — it needs a preview token.")
|
|
187
|
+
: copyParam("appInfo.releaseFailed", "Couldn't switch to that release."),
|
|
188
|
+
};
|
|
189
|
+
} catch {
|
|
190
|
+
return { ...busy, pickerBusy: false, pickerMessage: copyParam("appInfo.releaseFailed", "Couldn't switch to that release.") };
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
resetRelease: async (state) => {
|
|
195
|
+
if (!state.pickerAvailable) return state;
|
|
196
|
+
const busy = { ...state, pickerBusy: true, pickerMessage: copyParam("appInfo.releaseResetting", "Returning to the latest release…") };
|
|
197
|
+
try {
|
|
198
|
+
const result = await selectRelease(null);
|
|
199
|
+
return result.ok
|
|
200
|
+
? { ...busy, pickerBusy: false, pickerMessage: "" }
|
|
201
|
+
: { ...busy, pickerBusy: false, pickerMessage: copyParam("appInfo.releaseFailed", "Couldn't switch to that release.") };
|
|
202
|
+
} catch {
|
|
203
|
+
return { ...busy, pickerBusy: false, pickerMessage: copyParam("appInfo.releaseFailed", "Couldn't switch to that release.") };
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
export { svc };
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { defineBackendCollection } from "../_shared/collection-service.js";
|
|
2
|
+
import { searchOrders, type WixOrder } from "@himalaya/wix-ecom";
|
|
3
|
+
import { copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
4
|
+
import { getAll, upsert, type DbEntity } from "@himalaya/local-db";
|
|
5
|
+
import { formatDateMedium } from "../_shared/engine-intl.js";
|
|
6
|
+
import { orderMember, assertOrderMember, ownedOrderCache, orderAccessDenied, orderAccessChanged, type OrderMember } from "../_shared/member-orders.js";
|
|
7
|
+
import { wixMediaUrl } from "@himalaya/wix-media";
|
|
8
|
+
import { isHostedWorker, hostedSitePageOpener } from "../_shared/hosted-checkout.js";
|
|
9
|
+
|
|
10
|
+
// Only ownership-tagged rows from this account/business/member can be reused.
|
|
11
|
+
// Legacy untagged cache rows are deliberately ignored. Missing host scope or
|
|
12
|
+
// capability not granted => online-only, never a shared private cache.
|
|
13
|
+
const ENTITY = "orders";
|
|
14
|
+
async function readCachedOrders(member: OrderMember): Promise<OrderRow[]> {
|
|
15
|
+
if (!member.scope) return [];
|
|
16
|
+
let items: DbEntity[];
|
|
17
|
+
try { items = await getAll(ENTITY); }
|
|
18
|
+
catch { await assertOrderMember(member); return []; }
|
|
19
|
+
await assertOrderMember(member);
|
|
20
|
+
return items.filter(row => ownedOrderCache(row, member))
|
|
21
|
+
.map(({ memberOrderScope: _, ...row }) => row as unknown as OrderRow);
|
|
22
|
+
}
|
|
23
|
+
async function writeCachedOrders(rows: OrderRow[], member: OrderMember): Promise<void> {
|
|
24
|
+
if (!member.scope) return;
|
|
25
|
+
try {
|
|
26
|
+
for (const row of rows) {
|
|
27
|
+
await assertOrderMember(member);
|
|
28
|
+
await upsert(ENTITY, { ...row, memberOrderScope: member.scope } as unknown as DbEntity);
|
|
29
|
+
}
|
|
30
|
+
} catch { /* capability not granted / identity changed => stop caching */ }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface OrderRow {
|
|
34
|
+
id: string;
|
|
35
|
+
title: string;
|
|
36
|
+
subtitle: string;
|
|
37
|
+
meta: string;
|
|
38
|
+
status: string;
|
|
39
|
+
image: string;
|
|
40
|
+
initial: string;
|
|
41
|
+
hasImage: boolean;
|
|
42
|
+
noImage: boolean;
|
|
43
|
+
detailScreenId: string;
|
|
44
|
+
dateLabel?: string;
|
|
45
|
+
itemSummary?: string;
|
|
46
|
+
cancelledLabel?: string;
|
|
47
|
+
notCancelled?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface State {
|
|
51
|
+
status: "loading" | "ready" | "error";
|
|
52
|
+
permissionDenied?: boolean;
|
|
53
|
+
hideLoadError?: boolean;
|
|
54
|
+
hidePermissionError?: boolean;
|
|
55
|
+
rows: OrderRow[];
|
|
56
|
+
displayRows?: Array<OrderRow & { dateHeading: string; noDateHeading: boolean }>;
|
|
57
|
+
filterOptions?: Array<{ id: string; label: string; selected: boolean }>;
|
|
58
|
+
identityLine: string;
|
|
59
|
+
emptyText: string;
|
|
60
|
+
isLoading: boolean;
|
|
61
|
+
notLoading: boolean;
|
|
62
|
+
isErrored: boolean;
|
|
63
|
+
notErrored: boolean;
|
|
64
|
+
noEmpty: boolean;
|
|
65
|
+
hideList: boolean;
|
|
66
|
+
needsSignIn?: boolean;
|
|
67
|
+
noSignIn?: boolean;
|
|
68
|
+
nextCursor?: string;
|
|
69
|
+
complete?: boolean;
|
|
70
|
+
pageError?: boolean;
|
|
71
|
+
loadingMore?: boolean;
|
|
72
|
+
fromCache?: boolean;
|
|
73
|
+
/** Hosted in a host shell (Spaces), signed in: the member's orders live on the site's own page. */
|
|
74
|
+
onSite?: boolean;
|
|
75
|
+
/** A search or filter narrows this page: the list (and its Clear) stays visible beside the on-site card. */
|
|
76
|
+
narrowed?: boolean;
|
|
77
|
+
notOnSite?: boolean;
|
|
78
|
+
siteHint?: string;
|
|
79
|
+
noSiteHint?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function formatDate(value?: string): string {
|
|
83
|
+
if (!value) return "";
|
|
84
|
+
const date = new Date(value);
|
|
85
|
+
if (Number.isNaN(date.getTime())) return "";
|
|
86
|
+
return formatDateMedium(date);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function titleCase(value?: string): string {
|
|
90
|
+
return (value ?? "").replace(/_/g, " ").toLowerCase().replace(/(^|\s)\S/g, (part) => part.toUpperCase());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function orderEmail(order: WixOrder): string {
|
|
94
|
+
return (order.buyerInfo?.email ?? "").trim().toLowerCase();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function mediaUrl(value: unknown): string {
|
|
98
|
+
if (!value || typeof value !== "object") return "";
|
|
99
|
+
const item = value as {
|
|
100
|
+
image?: { url?: string } | string;
|
|
101
|
+
media?: {
|
|
102
|
+
mainMedia?: { image?: { url?: string }; thumbnail?: { url?: string }; url?: string };
|
|
103
|
+
items?: Array<{ image?: { url?: string }; thumbnail?: { url?: string }; url?: string }>;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const directImage = typeof item.image === "string" ? item.image : item.image?.url;
|
|
107
|
+
return directImage
|
|
108
|
+
?? item.media?.mainMedia?.image?.url
|
|
109
|
+
?? item.media?.mainMedia?.thumbnail?.url
|
|
110
|
+
?? item.media?.mainMedia?.url
|
|
111
|
+
?? item.media?.items?.[0]?.image?.url
|
|
112
|
+
?? item.media?.items?.[0]?.thumbnail?.url
|
|
113
|
+
?? item.media?.items?.[0]?.url
|
|
114
|
+
?? "";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function orderRow(order: WixOrder): OrderRow {
|
|
118
|
+
const count = (order.lineItems ?? []).reduce((sum, item) => sum + (item.quantity || 1), 0);
|
|
119
|
+
const total = order.priceSummary?.total?.formattedAmount || copyParam("orders.totalUnavailableLabel", "Total unavailable");
|
|
120
|
+
const id = order.id || order.number || "order";
|
|
121
|
+
const firstName = order.lineItems?.[0]?.productName?.original || order.lineItems?.[0]?.productName?.translated || "";
|
|
122
|
+
const title = copyTemplate("orders.orderTitle", "Order #{number}", { number: order.number || order.id || "" }).trim();
|
|
123
|
+
const image = wixMediaUrl(mediaUrl(order.lineItems?.[0]));
|
|
124
|
+
const itemSummary = copyTemplate(count === 1 ? "orders.oneItem" : "orders.manyItems", count === 1 ? "{count} item" : "{count} items", { count });
|
|
125
|
+
const status = (order as WixOrder & { status?: string }).status;
|
|
126
|
+
const cancelled = status === "CANCELED" || status === "CANCELLED";
|
|
127
|
+
return {
|
|
128
|
+
id,
|
|
129
|
+
title,
|
|
130
|
+
subtitle: total,
|
|
131
|
+
meta: [formatDate(order.createdDate), count ? `${count} ${count === 1 ? "item" : "items"}` : ""].filter(Boolean).join(" · "),
|
|
132
|
+
status: titleCase(order.fulfillmentStatus || order.paymentStatus) || copyParam("orders.statusFallback", "Order placed"),
|
|
133
|
+
image,
|
|
134
|
+
initial: ((firstName || title).trim()[0] || "O").toUpperCase(),
|
|
135
|
+
hasImage: Boolean(image),
|
|
136
|
+
noImage: !image,
|
|
137
|
+
// WS-C — canonical param-less detail screenId; the descriptor row binds the
|
|
138
|
+
// separate `id` field as a first-class nav param (no more baked suffixes).
|
|
139
|
+
detailScreenId: "himi_order",
|
|
140
|
+
dateLabel: formatDate(order.createdDate),
|
|
141
|
+
itemSummary,
|
|
142
|
+
cancelledLabel: cancelled ? copyParam("orders.cancelled", "Cancelled") : "",
|
|
143
|
+
notCancelled: !cancelled,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function derive(state: State): State {
|
|
148
|
+
const hasRows = state.rows.length > 0;
|
|
149
|
+
const rows = state.rows.map(row => {
|
|
150
|
+
// Earlier ownership-tagged cache entries only stored the combined meta and
|
|
151
|
+
// display status. Split those fields without inventing a missing date or
|
|
152
|
+
// cancellation status; current rows keep their explicit structured values.
|
|
153
|
+
const parts = (row.meta ?? "").split(" · ");
|
|
154
|
+
const cancelled = row.notCancelled === false || row.status === "Canceled" || row.status === "Cancelled";
|
|
155
|
+
return { ...row,
|
|
156
|
+
dateLabel: row.dateLabel ?? (parts.length > 1 ? parts[0] : ""),
|
|
157
|
+
itemSummary: row.itemSummary ?? (parts.length > 1 ? parts.slice(1).join(" · ") : row.meta ?? ""),
|
|
158
|
+
notCancelled: row.notCancelled ?? !cancelled,
|
|
159
|
+
cancelledLabel: row.cancelledLabel ?? (cancelled ? copyParam("orders.cancelled", "Cancelled") : ""),
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
...state,
|
|
164
|
+
nextCursor: state.nextCursor ?? "",
|
|
165
|
+
filterOptions: state.filterOptions ?? [{ id: "all", label: copyParam("collection.all", "All"), selected: true },
|
|
166
|
+
...Object.keys(FULFILLMENT).map(label => ({ id: `value:${label}`, label: copyParam(`collection.filter.${label}`, label), selected: false }))],
|
|
167
|
+
displayRows: rows.map((row, index, rows) => {
|
|
168
|
+
// Older owned cache rows retain their original date in meta. Group only
|
|
169
|
+
// adjacent days so pagination and an explicit backend sort remain authoritative.
|
|
170
|
+
const date = row.dateLabel;
|
|
171
|
+
const previous = rows[index - 1];
|
|
172
|
+
const previousDate = previous?.dateLabel;
|
|
173
|
+
return { ...row, dateHeading: date, noDateHeading: !date || date === previousDate };
|
|
174
|
+
}),
|
|
175
|
+
isLoading: state.status === "loading",
|
|
176
|
+
notLoading: state.status !== "loading",
|
|
177
|
+
hideLoadError: state.status !== "error" || state.permissionDenied === true,
|
|
178
|
+
hidePermissionError: state.status !== "error" || state.permissionDenied !== true,
|
|
179
|
+
isErrored: state.status === "error",
|
|
180
|
+
notErrored: state.status !== "error",
|
|
181
|
+
// A guest gets the shared member gate, not the "Browse products" empty card.
|
|
182
|
+
// Never "No orders" while a next page could still hold one.
|
|
183
|
+
noEmpty: state.status !== "ready" || hasRows || state.needsSignIn === true || state.onSite === true || !!state.nextCursor,
|
|
184
|
+
noSignIn: state.status !== "ready" || state.needsSignIn !== true,
|
|
185
|
+
// The on-site card replaces the list's empty state — except under a search or filter, where the list keeps
|
|
186
|
+
// its search, filters and Clear, so the member is never stranded behind criteria they cannot clear.
|
|
187
|
+
hideList: state.status !== "ready" || state.needsSignIn === true || (state.onSite === true && state.narrowed !== true),
|
|
188
|
+
notOnSite: state.status !== "ready" || state.onSite !== true || state.needsSignIn === true,
|
|
189
|
+
// Hidden outright when empty: a collapsed text still takes the card's stack spacing.
|
|
190
|
+
noSiteHint: !state.siteHint,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const FULFILLMENT: Record<string, string> = {
|
|
195
|
+
"Not fulfilled": "NOT_FULFILLED", "Partially fulfilled": "PARTIALLY_FULFILLED", "Fulfilled": "FULFILLED",
|
|
196
|
+
};
|
|
197
|
+
let lastReadDenied = false;
|
|
198
|
+
let pageMember: OrderMember | undefined;
|
|
199
|
+
let siteOpenInFlight = false;
|
|
200
|
+
// Whose open failed: the hint belongs to that member and scope only, never to whoever signs in next.
|
|
201
|
+
let siteHintOwner = "";
|
|
202
|
+
const memberKey = (member: { email: string; scope?: string }) => member.email ? `${member.email}\u0000${member.scope ?? ""}` : "";
|
|
203
|
+
let cacheWrite = Promise.resolve();
|
|
204
|
+
const svc = defineBackendCollection("himiBrandedOrders", {
|
|
205
|
+
restorePagesOnLoad: true,
|
|
206
|
+
// `nextCursor` and `filterOptions` are bound by himi_orders (pagination cursor, filter sheet), so they are
|
|
207
|
+
// seeded here: `himi validate --strict` refuses a binding the initial state cannot resolve.
|
|
208
|
+
state: derive({ status: "loading", rows: [], identityLine: "", emptyText: "", isLoading: true,
|
|
209
|
+
notLoading: false, isErrored: false, notErrored: true, noEmpty: true, hideList: true, siteHint: "",
|
|
210
|
+
nextCursor: "", filterOptions: [] }),
|
|
211
|
+
source: {
|
|
212
|
+
id: (row: OrderRow) => row.id,
|
|
213
|
+
clearOnError: orderAccessDenied,
|
|
214
|
+
errorMessage: error => {
|
|
215
|
+
lastReadDenied = orderAccessDenied(error);
|
|
216
|
+
return lastReadDenied ? copyParam("orders.accessErrorText", "Orders are unavailable for this account. Try signing in again.")
|
|
217
|
+
: copyParam("orders.loadErrorText", "Orders could not be loaded.");
|
|
218
|
+
},
|
|
219
|
+
async fetch(criteria, cursor) {
|
|
220
|
+
lastReadDenied = false;
|
|
221
|
+
const member = await orderMember();
|
|
222
|
+
if (cursor && (!pageMember || member.email !== pageMember.email || member.scope !== pageMember.scope)) throw orderAccessChanged();
|
|
223
|
+
const narrowed = !!criteria.query.trim() || criteria.filter !== "all";
|
|
224
|
+
const metadata = { email: member.email, scope: member.scope, needsSignIn: !member.email, fromCache: false, narrowed };
|
|
225
|
+
if (!member.email) return { items: [], nextCursor: "", metadata };
|
|
226
|
+
const query = criteria.query.replace(/^#/, "");
|
|
227
|
+
const validNumber = /^\d+$/.test(query) && Number.isSafeInteger(Number(query));
|
|
228
|
+
if ((query && !validNumber) || (criteria.filter === "saved" && !criteria.savedIds.length)) {
|
|
229
|
+
return { items: [], nextCursor: "", metadata };
|
|
230
|
+
}
|
|
231
|
+
const filter: Record<string, unknown> = { "buyerInfo.email": { $eq: member.email } };
|
|
232
|
+
if (query) filter.number = { $eq: Number(query) };
|
|
233
|
+
if (criteria.filter === "saved") filter.id = { $in: criteria.savedIds };
|
|
234
|
+
if (criteria.filter.startsWith("value:")) {
|
|
235
|
+
const status = FULFILLMENT[criteria.filter.slice(6)];
|
|
236
|
+
if (!status) throw new Error("Unsupported fulfillment filter");
|
|
237
|
+
filter.fulfillmentStatus = { $eq: status };
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
const response = await searchOrders({ search: { filter,
|
|
241
|
+
cursorPaging: { limit: 50, ...(cursor ? { cursor } : {}) },
|
|
242
|
+
sort: [{ fieldName: criteria.sort === "za" ? "number" : "createdDate", order: criteria.sort === "az" ? "ASC" : "DESC" }],
|
|
243
|
+
} });
|
|
244
|
+
await assertOrderMember(member);
|
|
245
|
+
const paging = response.metadata as { hasNext?: boolean; cursors?: { next?: string | null } } | undefined;
|
|
246
|
+
const nextCursor = paging?.cursors?.next ?? "";
|
|
247
|
+
if (paging?.hasNext && !nextCursor) throw new Error("Orders response is missing its next-page cursor");
|
|
248
|
+
const items = (response.orders ?? []).filter(order => !!order.id && orderEmail(order) === member.email).map(orderRow);
|
|
249
|
+
return { items, nextCursor, metadata };
|
|
250
|
+
} catch (error) {
|
|
251
|
+
await assertOrderMember(member);
|
|
252
|
+
// Cached rows never impersonate a backend query or survive access denial.
|
|
253
|
+
if (!orderAccessDenied(error) && !cursor && !criteria.query && criteria.filter === "all" && criteria.sort === "default") {
|
|
254
|
+
const items = await readCachedOrders(member);
|
|
255
|
+
if (items.length) return { items, nextCursor: "", complete: false, metadata: { ...metadata, fromCache: true } };
|
|
256
|
+
}
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
apply(state, page) {
|
|
262
|
+
const member = { email: String(page.metadata?.email ?? ""), scope: String(page.metadata?.scope ?? "") };
|
|
263
|
+
if (page.status === "ready" && !page.loadingMore && !page.pageError) pageMember = member;
|
|
264
|
+
if (page.status === "loading" || page.status === "error") pageMember = undefined;
|
|
265
|
+
if (page.status === "ready" && !page.loadingMore && !page.pageError && !page.metadata?.fromCache && member.email) {
|
|
266
|
+
cacheWrite = cacheWrite.then(() => writeCachedOrders(page.items, member));
|
|
267
|
+
}
|
|
268
|
+
const status = page.status === "idle" ? "loading" : page.status;
|
|
269
|
+
// Hosted in a host shell as its signed-in member, an empty answer is not proof of no orders: Wix documents
|
|
270
|
+
// `ecom/v1/orders/search` for a Wix user or app identity only, and answers the member a successful EMPTY list.
|
|
271
|
+
// So hosted, "No orders" is never claimed — once every page is read (none left to load), whatever the criteria,
|
|
272
|
+
// the site's own My Orders page is offered, opened by the host (`himi.host.memberSitePage {page:"orders"}`).
|
|
273
|
+
// Rows Wix does return still list here.
|
|
274
|
+
const onSite = isHostedWorker() && !!member.email && status === "ready" && !page.items.length && !page.nextCursor
|
|
275
|
+
&& !page.pageError && page.metadata?.fromCache !== true;
|
|
276
|
+
return derive({ ...state, permissionDenied: status === "error" && lastReadDenied, status, rows: page.items, nextCursor: page.nextCursor, complete: page.complete,
|
|
277
|
+
filterOptions: [{ id: "all", label: copyParam("collection.all", "All") }, ...Object.keys(FULFILLMENT).map(label => ({ id: `value:${label}`, label: copyParam(`collection.filter.${label}`, label) }))].map(option => ({ ...option, selected: option.id === page.criteria.filter })),
|
|
278
|
+
pageError: page.pageError, loadingMore: page.loadingMore, fromCache: page.metadata?.fromCache === true,
|
|
279
|
+
needsSignIn: page.metadata?.needsSignIn === true,
|
|
280
|
+
onSite,
|
|
281
|
+
narrowed: page.metadata?.narrowed === true,
|
|
282
|
+
siteHint: siteHintOwner && siteHintOwner === memberKey(member) && onSite ? state.siteHint : "",
|
|
283
|
+
identityLine: member.email ? copyTemplate("orders.identityLine", "Signed in as {email}", { email: member.email }) : "",
|
|
284
|
+
emptyText: status === "error" ? page.error : !member.email ? copyParam("orders.signInEmptyText", "Sign in to see your orders.")
|
|
285
|
+
: onSite ? copyParam("orders.onSiteText", "Your orders are on the site.")
|
|
286
|
+
: page.items.length ? "" : page.metadata?.narrowed ? copyParam("orders.noMatches", "No orders match your search or filter.") : copyParam("orders.emptyText", "No orders for this member yet."),
|
|
287
|
+
});
|
|
288
|
+
},
|
|
289
|
+
actions: {
|
|
290
|
+
chooseFilter(_s: State, arg: unknown): undefined {
|
|
291
|
+
const id = (arg as { id?: string } | undefined)?.id;
|
|
292
|
+
if (id === "all" || (id?.startsWith("value:") && FULFILLMENT[id.slice(6)])) {
|
|
293
|
+
// Return before the queued collection reducer runs; awaiting a reducer
|
|
294
|
+
// of the same service would prevent it from executing in native workers.
|
|
295
|
+
void svc.collectionFilter({ selectedIds: [id] });
|
|
296
|
+
}
|
|
297
|
+
return undefined;
|
|
298
|
+
},
|
|
299
|
+
// The site's My Orders page, opened by the host signed in as the lent member where it can (a visitor who
|
|
300
|
+
// signs in on the site otherwise). Nothing is charged, so the guard only re-checks the member is unchanged.
|
|
301
|
+
async openOnSite(s: State): Promise<State | undefined> {
|
|
302
|
+
// One host open at a time: a second tap while the first is in flight would only replace its ticket.
|
|
303
|
+
if (siteOpenInFlight || s.onSite !== true) return s;
|
|
304
|
+
siteOpenInFlight = true;
|
|
305
|
+
let opened: boolean | "withdrawn";
|
|
306
|
+
let member: OrderMember;
|
|
307
|
+
try {
|
|
308
|
+
member = await orderMember();
|
|
309
|
+
opened = await hostedSitePageOpener({ page: "orders" })(async () => {
|
|
310
|
+
const now = await orderMember();
|
|
311
|
+
return now.email === member.email && now.scope === member.scope;
|
|
312
|
+
});
|
|
313
|
+
} finally {
|
|
314
|
+
siteOpenInFlight = false;
|
|
315
|
+
}
|
|
316
|
+
// A member who changed while the host worked never inherits this answer.
|
|
317
|
+
const now = await orderMember();
|
|
318
|
+
if (memberKey(now) !== memberKey(member)) return undefined;
|
|
319
|
+
siteHintOwner = opened === false ? memberKey(member) : "";
|
|
320
|
+
const latest = svc.getState() as unknown as State;
|
|
321
|
+
return derive({ ...latest, siteHint: opened === false
|
|
322
|
+
? copyParam("orders.onSiteFailedText", "The site's orders page could not be opened. Visit the site to see your orders.") : "" });
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
svc.load();
|
|
327
|
+
export { svc };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Categories share the complete, site-ordered reader used by Home and Shop.
|
|
2
|
+
import { defineService } from "@himalaya/state";
|
|
3
|
+
import { loadStoreCategories, type StoreCategoryCard } from "../_shared/himi-store-categories.js";
|
|
4
|
+
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
5
|
+
interface State {
|
|
6
|
+
status: "loading" | "ready" | "error";
|
|
7
|
+
all: StoreCategoryCard[];
|
|
8
|
+
collections: StoreCategoryCard[];
|
|
9
|
+
query: string;
|
|
10
|
+
emptyText: string;
|
|
11
|
+
noCollections: boolean;
|
|
12
|
+
notLoading: boolean;
|
|
13
|
+
notErrored: boolean;
|
|
14
|
+
noEmpty: boolean;
|
|
15
|
+
}
|
|
16
|
+
function derive(s: State): State {
|
|
17
|
+
const query = s.query.trim().toLowerCase();
|
|
18
|
+
const collections = s.all.filter(row => row.name.toLowerCase().includes(query));
|
|
19
|
+
return { ...s, collections, noCollections: !collections.length, notLoading: s.status !== "loading",
|
|
20
|
+
notErrored: s.status !== "error", noEmpty: s.status !== "ready" || !!collections.length,
|
|
21
|
+
emptyText: query ? copyParam("collections.noMatches", "No categories match your search.") : copyParam("collections.empty", "No categories yet.") };
|
|
22
|
+
}
|
|
23
|
+
let generation = 0;
|
|
24
|
+
let currentQuery = "";
|
|
25
|
+
const svc = defineService<State, {
|
|
26
|
+
load: (s: State, arg?: unknown) => Promise<State | undefined>;
|
|
27
|
+
search: (s: State, arg?: { value?: string }) => State;
|
|
28
|
+
}>("spacesCollections", {
|
|
29
|
+
state: derive({ status: "loading", all: [], collections: [], query: "", emptyText: "", noCollections: true, notLoading: false, notErrored: true, noEmpty: true }),
|
|
30
|
+
actions: {
|
|
31
|
+
load: async (s, arg) => {
|
|
32
|
+
stashCopy(arg);
|
|
33
|
+
const run = ++generation;
|
|
34
|
+
try {
|
|
35
|
+
const all = await loadStoreCategories({ includeAllProducts: true });
|
|
36
|
+
return run === generation ? derive({ ...s, query: currentQuery, all, status: "ready" }) : undefined;
|
|
37
|
+
} catch {
|
|
38
|
+
return run === generation ? derive({ ...s, query: currentQuery, status: "error" }) : undefined;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
search: (s, arg) => {
|
|
42
|
+
currentQuery = (arg?.value ?? "").slice(0, 256);
|
|
43
|
+
return derive({ ...s, query: currentQuery });
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
svc.load();
|
|
48
|
+
export { svc };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Tier-5 bundle: Wix Spaces clone — Delete my account.
|
|
2
|
+
// Confirm calls DELETE /members/v1/members/my then signs out. Failures surface
|
|
3
|
+
// in `message` so the UI can keep the confirmation (no silent no-op).
|
|
4
|
+
import { defineService } from "@himalaya/state";
|
|
5
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
6
|
+
|
|
7
|
+
interface S {
|
|
8
|
+
status: "ready";
|
|
9
|
+
title: string;
|
|
10
|
+
body: string;
|
|
11
|
+
cta: string;
|
|
12
|
+
message: string;
|
|
13
|
+
done: boolean;
|
|
14
|
+
notDone: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function wixApi() {
|
|
18
|
+
return (globalThis as { himalaya?: { wixApi?: { call: (m: string, p: string, b?: unknown) => Promise<unknown> } } }).himalaya?.wixApi;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const svc = defineService<S, { confirm: (s: S) => Promise<S> }>("spacesDeleteAccount", {
|
|
22
|
+
state: {
|
|
23
|
+
status: "ready",
|
|
24
|
+
title: "Delete your account",
|
|
25
|
+
body: "This will permanently delete your membership on this site. This action can't be undone.",
|
|
26
|
+
cta: "Delete Account",
|
|
27
|
+
message: "",
|
|
28
|
+
done: false,
|
|
29
|
+
notDone: true,
|
|
30
|
+
},
|
|
31
|
+
actions: {
|
|
32
|
+
confirm: async (s) => {
|
|
33
|
+
try {
|
|
34
|
+
const api = wixApi();
|
|
35
|
+
if (!api) throw new Error("wixApi unavailable");
|
|
36
|
+
await api.call("DELETE", "/members/v1/members/my");
|
|
37
|
+
try { await dispatch("himi.wix.signOut"); } catch { /* best-effort */ }
|
|
38
|
+
return {
|
|
39
|
+
...s,
|
|
40
|
+
message: "Your membership was deleted. You’ve been signed out.",
|
|
41
|
+
done: true,
|
|
42
|
+
notDone: false,
|
|
43
|
+
cta: "Done",
|
|
44
|
+
};
|
|
45
|
+
} catch (err) {
|
|
46
|
+
const msg = String((err as { message?: unknown })?.message ?? err ?? "Delete failed");
|
|
47
|
+
return {
|
|
48
|
+
...s,
|
|
49
|
+
message: /403|FORBIDDEN|permission|denied/i.test(msg)
|
|
50
|
+
? "This site doesn’t allow members to delete their own account from the app."
|
|
51
|
+
: "Couldn’t delete the account. Try again or contact the site owner.",
|
|
52
|
+
done: false,
|
|
53
|
+
notDone: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
export { svc };
|