@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,241 @@
|
|
|
1
|
+
// Tier-5 bundle: BARE home — hero (New Collection), category carousel, sale grid.
|
|
2
|
+
//
|
|
3
|
+
// Replaces the template's himi-branded-lite-home for this app. That worker awaited
|
|
4
|
+
// bookings/events/restaurant signals for verticals BARE does not have installed
|
|
5
|
+
// (the site runs store + forms only), and those awaits never settled off-device, so
|
|
6
|
+
// the screen sat on status:"loading" forever. This worker fetches exactly the two
|
|
7
|
+
// things the home needs: the product catalog and the collections.
|
|
8
|
+
import { defineService } from "@himalaya/state";
|
|
9
|
+
import { searchStoreProducts, type StoreProduct } from "@himalaya/wix-stores";
|
|
10
|
+
import { queryCollections, type WixCollection } from "@himalaya/wix-stores-collections";
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// CATALOG VERSION. This site runs CATALOG_V1 — every /stores/v3/* read answers
|
|
14
|
+
// CATALOG_V1_SITE_CALLING_CATALOG_V3_API. Both readers below are the sanctioned
|
|
15
|
+
// SDK helpers (calling /stores/v1 by hand is refused by `himi validate`):
|
|
16
|
+
// * searchStoreProducts is catalog-agnostic — it probes
|
|
17
|
+
// GET /stores/v3/provision/version once, then routes to V1 for this site.
|
|
18
|
+
// * queryCollections is V1-only by its own SDK documentation, which is the
|
|
19
|
+
// correct reader here; the V3 equivalent (queryStoreCategories) never
|
|
20
|
+
// settles against a V1 site.
|
|
21
|
+
//
|
|
22
|
+
// KNOWN LOCAL LIMITATION: `himi render --live` does not dispatch onAppear and
|
|
23
|
+
// does not deliver responses back to a module-scope boot fetch, so that probe
|
|
24
|
+
// shows liveReturned 0 and this screen renders its loading state locally. The
|
|
25
|
+
// real-data evidence for it is `himi test` against dev/net-mocks.json (captured
|
|
26
|
+
// from the live site) plus the draft preview in a browser. himi_shop hydrates
|
|
27
|
+
// live against the same endpoints, so the binding itself is proven.
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
import { cardId, productCards, refreshSaved, toggleFavorite, type ProductCard } from "../_shared/bare-fashion-product-card.js";
|
|
30
|
+
import { categoryCard, orderCategories, type CategoryCard } from "../_shared/bare-fashion-categories.js";
|
|
31
|
+
import { errorFlags, errorKindOf, type ErrorKind } from "../_shared/bare-fashion-load-error.js";
|
|
32
|
+
|
|
33
|
+
/** The site's own words. Every string here is quoted from the published BARE site —
|
|
34
|
+
* never invented. Replace them with your brand's words. */
|
|
35
|
+
const COPY = {
|
|
36
|
+
announcement: "FREE SHIPPING OVER $50 WORLDWIDE",
|
|
37
|
+
heroTitle: "SUMMER COLLECTION",
|
|
38
|
+
heroSubtitle: "EVERYDAY APPAREL FOR EVERYONE",
|
|
39
|
+
heroCta: "Shop Now",
|
|
40
|
+
categoriesTitle: "Top Categories",
|
|
41
|
+
newInTitle: "New In",
|
|
42
|
+
saleMarquee: "SALE IS ON / SALE IS ON / SALE IS ON",
|
|
43
|
+
saleTitle: "UP TO 40% OFF",
|
|
44
|
+
saleSubtitle: "Plus free shipping over $50",
|
|
45
|
+
saleCta: "Shop Sale",
|
|
46
|
+
viewMore: "View More",
|
|
47
|
+
errorText: "Couldn't load the store.",
|
|
48
|
+
retry: "Try again",
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
/** Hero art chosen by the site owner (wix:image://v1/0fc611_ea296f9ef99143ad9271b83419528020~mv2.jpg,
|
|
52
|
+
* 1512×1494), served from Wix media. */
|
|
53
|
+
const HERO_IMAGE =
|
|
54
|
+
"https://static.wixstatic.com/media/0fc611_ea296f9ef99143ad9271b83419528020~mv2.jpg/v1/fit/w_1512,h_1494,q_90/file.jpg";
|
|
55
|
+
|
|
56
|
+
interface S {
|
|
57
|
+
status: "loading" | "ready" | "error";
|
|
58
|
+
isLoading: boolean;
|
|
59
|
+
notLoading: boolean;
|
|
60
|
+
isErrored: boolean;
|
|
61
|
+
notErrored: boolean;
|
|
62
|
+
notReady: boolean;
|
|
63
|
+
/** Why the last load failed: the error state shows the offline or the server variant. */
|
|
64
|
+
errorKind?: ErrorKind;
|
|
65
|
+
hideOfflineError?: boolean;
|
|
66
|
+
hideServerError?: boolean;
|
|
67
|
+
|
|
68
|
+
announcement: string;
|
|
69
|
+
heroTitle: string;
|
|
70
|
+
heroSubtitle: string;
|
|
71
|
+
heroCta: string;
|
|
72
|
+
heroImage: string;
|
|
73
|
+
hasHeroImage: boolean;
|
|
74
|
+
noHeroImage: boolean;
|
|
75
|
+
|
|
76
|
+
categoriesTitle: string;
|
|
77
|
+
categories: CategoryCard[];
|
|
78
|
+
noCategories: boolean;
|
|
79
|
+
|
|
80
|
+
newInTitle: string;
|
|
81
|
+
newIn: ProductCard[];
|
|
82
|
+
/** The New In scroller: the products, then one "View More" card at the end. */
|
|
83
|
+
newInRow: NewInRowItem[];
|
|
84
|
+
noNewIn: boolean;
|
|
85
|
+
|
|
86
|
+
saleMarquee: string;
|
|
87
|
+
saleTitle: string;
|
|
88
|
+
saleSubtitle: string;
|
|
89
|
+
saleCta: string;
|
|
90
|
+
saleItems: ProductCard[];
|
|
91
|
+
noSaleItems: boolean;
|
|
92
|
+
|
|
93
|
+
viewMore: string;
|
|
94
|
+
errorText: string;
|
|
95
|
+
retryLabel: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type NewInRowItem = (ProductCard | Partial<ProductCard>) & { isMore: boolean; notMore: boolean };
|
|
99
|
+
|
|
100
|
+
const VIEW_MORE_ID = "__view_more__";
|
|
101
|
+
|
|
102
|
+
function newInRow(s: S): NewInRowItem[] {
|
|
103
|
+
if (s.newIn.length === 0) return [];
|
|
104
|
+
return [
|
|
105
|
+
...s.newIn.map((c) => ({ ...c, isMore: false, notMore: true })),
|
|
106
|
+
{ id: VIEW_MORE_ID, name: s.viewMore, isMore: true, notMore: false },
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function collectionIdsOf(p: StoreProduct): string[] {
|
|
111
|
+
const raw = (p as unknown as { collectionIds?: string[] }).collectionIds;
|
|
112
|
+
return Array.isArray(raw) ? raw : [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Recompute every derived flag. State is not reactive: each action must re-derive.
|
|
116
|
+
* (tier-5 guide — "Derived state is not reactive".) */
|
|
117
|
+
function derive(s: S): S {
|
|
118
|
+
return {
|
|
119
|
+
...s,
|
|
120
|
+
isLoading: s.status === "loading",
|
|
121
|
+
notLoading: s.status !== "loading",
|
|
122
|
+
isErrored: s.status === "error",
|
|
123
|
+
notErrored: s.status !== "error",
|
|
124
|
+
...errorFlags(s.status, s.errorKind),
|
|
125
|
+
notReady: s.status !== "ready",
|
|
126
|
+
noCategories: s.categories.length === 0,
|
|
127
|
+
newInRow: newInRow(s),
|
|
128
|
+
noNewIn: s.newIn.length === 0,
|
|
129
|
+
noSaleItems: s.saleItems.length === 0,
|
|
130
|
+
hasHeroImage: !!s.heroImage,
|
|
131
|
+
noHeroImage: !s.heroImage,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Boot state is DETERMINISTIC — no clock, no Math.random(). A boot state that varies
|
|
136
|
+
* rehashes the release on every build and no UX record can match it. */
|
|
137
|
+
const BOOT: S = derive({
|
|
138
|
+
status: "loading",
|
|
139
|
+
isLoading: true,
|
|
140
|
+
notLoading: false,
|
|
141
|
+
isErrored: false,
|
|
142
|
+
notErrored: true,
|
|
143
|
+
notReady: true,
|
|
144
|
+
announcement: COPY.announcement,
|
|
145
|
+
heroTitle: COPY.heroTitle,
|
|
146
|
+
heroSubtitle: COPY.heroSubtitle,
|
|
147
|
+
heroCta: COPY.heroCta,
|
|
148
|
+
heroImage: "",
|
|
149
|
+
hasHeroImage: false,
|
|
150
|
+
noHeroImage: true,
|
|
151
|
+
categoriesTitle: COPY.categoriesTitle,
|
|
152
|
+
categories: [],
|
|
153
|
+
noCategories: true,
|
|
154
|
+
newInTitle: COPY.newInTitle,
|
|
155
|
+
newIn: [],
|
|
156
|
+
newInRow: [],
|
|
157
|
+
noNewIn: true,
|
|
158
|
+
saleMarquee: COPY.saleMarquee,
|
|
159
|
+
saleTitle: COPY.saleTitle,
|
|
160
|
+
saleSubtitle: COPY.saleSubtitle,
|
|
161
|
+
saleCta: COPY.saleCta,
|
|
162
|
+
saleItems: [],
|
|
163
|
+
noSaleItems: true,
|
|
164
|
+
viewMore: COPY.viewMore,
|
|
165
|
+
errorText: COPY.errorText,
|
|
166
|
+
retryLabel: COPY.retry,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
async function load(state: S): Promise<S> {
|
|
170
|
+
try {
|
|
171
|
+
// Independent reads: a collections failure must not blank the catalog, so they
|
|
172
|
+
// settle separately rather than through one rejecting Promise.all.
|
|
173
|
+
// Independent reads: a collections failure must not blank the catalog, so they
|
|
174
|
+
// settle separately rather than through one rejecting Promise.all.
|
|
175
|
+
const [productsResult, categoriesResult] = await Promise.allSettled([
|
|
176
|
+
searchStoreProducts({ limit: 100 }),
|
|
177
|
+
queryCollections({ query: { paging: { limit: 50 } } }),
|
|
178
|
+
]);
|
|
179
|
+
|
|
180
|
+
if (productsResult.status === "rejected") {
|
|
181
|
+
return derive({ ...state, status: "error", errorKind: errorKindOf(productsResult.reason) });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const products = productsResult.value.products ?? [];
|
|
185
|
+
const categories = categoriesResult.status === "fulfilled"
|
|
186
|
+
? orderCategories(categoriesResult.value.collections ?? [])
|
|
187
|
+
: [];
|
|
188
|
+
|
|
189
|
+
const cards = productCards(products);
|
|
190
|
+
const saleItems = cards.filter((c) => c.onSale);
|
|
191
|
+
|
|
192
|
+
// "New In" is the site's own collection. Fall back to the head of the catalog
|
|
193
|
+
// when that collection is absent, so the rail is never empty on a site that
|
|
194
|
+
// never made one.
|
|
195
|
+
const newInId = categories.find((c) => (c.name ?? "").trim().toUpperCase() === "NEW IN")?.id ?? "";
|
|
196
|
+
const newInProducts = newInId
|
|
197
|
+
? products.filter((p) => collectionIdsOf(p).includes(newInId))
|
|
198
|
+
: [];
|
|
199
|
+
const newIn = productCards((newInProducts.length > 0 ? newInProducts : products).slice(0, 8));
|
|
200
|
+
|
|
201
|
+
return derive({
|
|
202
|
+
...state,
|
|
203
|
+
status: "ready",
|
|
204
|
+
heroImage: HERO_IMAGE,
|
|
205
|
+
categories: categories.map(categoryCard),
|
|
206
|
+
newIn,
|
|
207
|
+
saleItems,
|
|
208
|
+
});
|
|
209
|
+
} catch (e) {
|
|
210
|
+
return derive({ ...state, status: "error", errorKind: errorKindOf(e) });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const svc = defineService<S, {
|
|
215
|
+
refresh: (s: S) => Promise<S>;
|
|
216
|
+
retry: (s: S) => Promise<S>;
|
|
217
|
+
toggleSave: (s: S, arg: unknown) => S;
|
|
218
|
+
}>("bareFashionHome", {
|
|
219
|
+
state: BOOT,
|
|
220
|
+
actions: {
|
|
221
|
+
refresh: (s) => load(s),
|
|
222
|
+
retry: (s) => load(derive({ ...s, status: "loading" })),
|
|
223
|
+
toggleSave: (s, arg) => {
|
|
224
|
+
// New In and Sale can list the same product; both hearts must agree.
|
|
225
|
+
try { toggleFavorite([...s.newIn, ...s.saleItems], cardId(arg)); } catch { return s; }
|
|
226
|
+
return derive({ ...s, newIn: refreshSaved(s.newIn), saleItems: refreshSaved(s.saleItems) });
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Self-kick so the screen loads on cold boot as well as on onAppear.
|
|
232
|
+
// Mirrors the shipped store workers: the boot call is NOT voided and the handle is
|
|
233
|
+
// exported, which is how the harness finds the service to await.
|
|
234
|
+
// Cold-boot kick. The descriptor's root also dispatches `refresh` from onAppear, and
|
|
235
|
+
// `load()` is idempotent, so the screen paints whichever arrives first. NOTE: `himi
|
|
236
|
+
// render --live` does not dispatch onAppear and does not deliver responses to a
|
|
237
|
+
// module-scope kick (liveReturned 0), so the LIVE proof for this screen is the draft
|
|
238
|
+
// preview in a browser, not a local render. himi_shop hydrates live against the same
|
|
239
|
+
// endpoints, so the binding itself is sound.
|
|
240
|
+
svc.refresh();
|
|
241
|
+
export { svc };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Tier-5 nav bundle: himi-bare-fashion-nav — the app-level worker behind the tab bar's live bindings.
|
|
2
|
+
// It feeds the Bag tab's count badge. On boot it reads the live cart once; after that it
|
|
3
|
+
// polls the on-device count that the shop, product and bag workers publish
|
|
4
|
+
// (see _shared/bag-count.ts), so the badge never costs a network call per tick.
|
|
5
|
+
import { defineService } from "@himalaya/state";
|
|
6
|
+
import { getCurrentCart } from "@himalaya/wix-ecom";
|
|
7
|
+
import { publishBagCount, readBagCount } from "../_shared/bare-fashion-bag-count.js";
|
|
8
|
+
|
|
9
|
+
interface S {
|
|
10
|
+
// null = badge hidden (empty cart); positive number = item count shown on badge
|
|
11
|
+
bagCount: number | null;
|
|
12
|
+
/** Why the last live read failed ("" when it did not): the badge then shows the stored count. */
|
|
13
|
+
error: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const SYNC_POLL = { id: "bare-nav-bag", intervalMs: 1500, action: "bareFashionNav.sync" };
|
|
17
|
+
|
|
18
|
+
/** Live bag size (sum of line quantities), or the reason the cart could not be read. */
|
|
19
|
+
async function liveBagCount(): Promise<{ ok: true; count: number } | { ok: false; error: string }> {
|
|
20
|
+
try {
|
|
21
|
+
const cart = await getCurrentCart();
|
|
22
|
+
return { ok: true, count: (cart.lineItems ?? []).reduce((n, li) => n + (li.quantity ?? 1), 0) };
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return { ok: false, error: String((e as Error)?.message ?? e) };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Returns null when count is 0 (hides the badge) or the count when positive. */
|
|
29
|
+
function badgeValue(count: number | null): number | null {
|
|
30
|
+
return count !== null && count > 0 ? count : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const svc = defineService<S, {
|
|
34
|
+
load: (s: S) => Promise<S>;
|
|
35
|
+
sync: (s: S) => Promise<S | undefined>;
|
|
36
|
+
}>("bareFashionNav", {
|
|
37
|
+
state: { bagCount: null, error: "" },
|
|
38
|
+
actions: {
|
|
39
|
+
load: async (s) => {
|
|
40
|
+
const live = await liveBagCount();
|
|
41
|
+
if (live.ok) await publishBagCount(live.count);
|
|
42
|
+
const raw = live.ok ? live.count : await readBagCount();
|
|
43
|
+
const bagCount = badgeValue(raw);
|
|
44
|
+
return { ...s, bagCount, error: live.ok ? "" : live.error, _poll: { ...SYNC_POLL } } as S;
|
|
45
|
+
},
|
|
46
|
+
// Idle ticks return undefined, so an unchanged count costs no re-render.
|
|
47
|
+
sync: async (s) => {
|
|
48
|
+
const raw = await readBagCount();
|
|
49
|
+
const bagCount = badgeValue(raw);
|
|
50
|
+
return bagCount === s.bagCount ? undefined : { ...s, bagCount };
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
svc.load();
|
|
56
|
+
export { svc };
|