@wix/himalaya-cli 0.1852.0 → 0.1853.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.
Files changed (149) hide show
  1. package/dist/cli.mjs +95 -32
  2. package/guides/himi-json-output.md +8 -2
  3. package/guides/one-app-section-mappings.md +1 -1
  4. package/guides/one-app-to-himi-app.md +19 -6
  5. package/package.json +2 -2
  6. package/template-icons/bare-fashion.png +0 -0
  7. package/templates/bare-fashion/README.md +52 -0
  8. package/templates/bare-fashion/config.ts +474 -0
  9. package/templates/bare-fashion/dev/index.ts +16526 -0
  10. package/templates/bare-fashion/himalaya.content.json +70 -0
  11. package/templates/bare-fashion/himalaya.template.json +18 -0
  12. package/templates/bare-fashion/icon.png +0 -0
  13. package/templates/bare-fashion/platforms.json +3 -0
  14. package/templates/bare-fashion/tier5-src/_shared/app-locale.ts +70 -0
  15. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-book.ts +116 -0
  16. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-countries.ts +261 -0
  17. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-bag-count.ts +24 -0
  18. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-categories.ts +48 -0
  19. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-facets.ts +265 -0
  20. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-load-error.ts +38 -0
  21. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +136 -0
  22. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-store-options.ts +129 -0
  23. package/templates/bare-fashion/tier5-src/_shared/branded-lite-hosted.ts +282 -0
  24. package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +228 -0
  25. package/templates/bare-fashion/tier5-src/_shared/collection-query.ts +201 -0
  26. package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +429 -0
  27. package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +529 -0
  28. package/templates/bare-fashion/tier5-src/_shared/himi-account.ts +209 -0
  29. package/templates/bare-fashion/tier5-src/_shared/himi-copy.ts +123 -0
  30. package/templates/bare-fashion/tier5-src/_shared/himi-layouts.ts +142 -0
  31. package/templates/bare-fashion/tier5-src/_shared/himi-store-categories.ts +108 -0
  32. package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +57 -0
  33. package/templates/bare-fashion/tier5-src/_shared/himi-store.ts +7 -0
  34. package/templates/bare-fashion/tier5-src/_shared/himi-text.ts +24 -0
  35. package/templates/bare-fashion/tier5-src/_shared/hosted-checkout.ts +70 -0
  36. package/templates/bare-fashion/tier5-src/_shared/live-session.ts +172 -0
  37. package/templates/bare-fashion/tier5-src/_shared/local-preferences.ts +38 -0
  38. package/templates/bare-fashion/tier5-src/_shared/member-access.ts +63 -0
  39. package/templates/bare-fashion/tier5-src/_shared/member-avatar.ts +76 -0
  40. package/templates/bare-fashion/tier5-src/_shared/member-orders.ts +8 -0
  41. package/templates/bare-fashion/tier5-src/_shared/online-actions.ts +76 -0
  42. package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +348 -0
  43. package/templates/bare-fashion/tier5-src/himi-bare-fashion-account/index.ts +127 -0
  44. package/templates/bare-fashion/tier5-src/himi-bare-fashion-address-form/index.ts +367 -0
  45. package/templates/bare-fashion/tier5-src/himi-bare-fashion-addresses/index.ts +202 -0
  46. package/templates/bare-fashion/tier5-src/himi-bare-fashion-appearance/index.ts +73 -0
  47. package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +540 -0
  48. package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +111 -0
  49. package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +241 -0
  50. package/templates/bare-fashion/tier5-src/himi-bare-fashion-nav/index.ts +56 -0
  51. package/templates/bare-fashion/tier5-src/himi-bare-fashion-order/index.ts +437 -0
  52. package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +650 -0
  53. package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +142 -0
  54. package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +45 -0
  55. package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +199 -0
  56. package/templates/bare-fashion/tier5-src/himi-bare-fashion-shop/index.ts +79 -0
  57. package/templates/bare-fashion/tier5-src/himi-bare-fashion-sign-in/index.ts +269 -0
  58. package/templates/bare-fashion/tier5-src/himi-bare-fashion-wallet/index.ts +224 -0
  59. package/templates/bare-fashion/tier5-src/himi-branded-lite-info/index.ts +209 -0
  60. package/templates/bare-fashion/tier5-src/himi-branded-lite-orders/index.ts +327 -0
  61. package/templates/bare-fashion/tier5-src/wix-spaces-collections/index.ts +48 -0
  62. package/templates/bare-fashion/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  63. package/templates/bare-fashion/tier5-src/wix-spaces-view-profile/index.ts +119 -0
  64. package/templates/bare-fashion/tokens.json +348 -0
  65. package/templates/beauty-salon/tier5-src/_shared/collection-query.ts +8 -0
  66. package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -1
  67. package/templates/beauty-salon-owner/tier5-src/_shared/collection-query.ts +8 -0
  68. package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -1
  69. package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
  70. package/templates/branded-lite/tier5-src/_shared/collection-query-legacy.ts +7 -0
  71. package/templates/branded-lite/tier5-src/_shared/collection-query.ts +7 -0
  72. package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -1
  73. package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +55 -3
  74. package/templates/branded-lite/tier5-src/_shared/events-inline.ts +5 -3
  75. package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
  76. package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
  77. package/templates/brandy/tier5-src/_shared/collection-query-legacy.ts +7 -0
  78. package/templates/brandy/tier5-src/_shared/collection-query.ts +7 -0
  79. package/templates/brandy/tier5-src/_shared/collection-service.ts +7 -1
  80. package/templates/community-club/tier5-src/_shared/collection-query.ts +8 -0
  81. package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -1
  82. package/templates/community-club/tier5-src/_shared/events-inline-options.ts +77 -0
  83. package/templates/community-club/tier5-src/himi-events-list/index.ts +17 -0
  84. package/templates/community-club-owner/tier5-src/_shared/collection-query.ts +8 -0
  85. package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -1
  86. package/templates/conference/tier5-src/_shared/collection-query.ts +8 -0
  87. package/templates/conference/tier5-src/_shared/collection-service.ts +7 -1
  88. package/templates/conference/tier5-src/_shared/events-inline-options.ts +77 -0
  89. package/templates/conference/tier5-src/himi-events-list/index.ts +17 -0
  90. package/templates/events-meetups/tier5-src/_shared/collection-query.ts +8 -0
  91. package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -1
  92. package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +77 -0
  93. package/templates/events-meetups/tier5-src/himi-events-list/index.ts +17 -0
  94. package/templates/events-meetups-owner/tier5-src/_shared/collection-query.ts +8 -0
  95. package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -1
  96. package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +8 -0
  97. package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +7 -1
  98. package/templates/gym-fitness/tier5-src/_shared/collection-query.ts +8 -0
  99. package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -1
  100. package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +77 -0
  101. package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
  102. package/templates/gym-fitness-owner/tier5-src/_shared/collection-query.ts +8 -0
  103. package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -1
  104. package/templates/medical-services/tier5-src/_shared/collection-query.ts +8 -0
  105. package/templates/medical-services/tier5-src/_shared/collection-service.ts +7 -1
  106. package/templates/nonprofit-cause/tier5-src/_shared/collection-query.ts +8 -0
  107. package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -1
  108. package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +77 -0
  109. package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +17 -0
  110. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-query.ts +8 -0
  111. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -1
  112. package/templates/owner-lite/tier5-src/_shared/collection-query.ts +8 -0
  113. package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -1
  114. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +8 -0
  115. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +7 -1
  116. package/templates/podcast-creator/tier5-src/_shared/collection-query.ts +8 -0
  117. package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -1
  118. package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +77 -0
  119. package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +17 -0
  120. package/templates/podcast-creator-owner/tier5-src/_shared/collection-query.ts +8 -0
  121. package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -1
  122. package/templates/portfolio-creative/tier5-src/_shared/collection-query.ts +8 -0
  123. package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -1
  124. package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +77 -0
  125. package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +17 -0
  126. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-query.ts +8 -0
  127. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -1
  128. package/templates/restaurant/tier5-src/_shared/collection-query.ts +8 -0
  129. package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -1
  130. package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +77 -0
  131. package/templates/restaurant/tier5-src/himi-events-list/index.ts +17 -0
  132. package/templates/restaurant-owner/tier5-src/_shared/collection-query.ts +8 -0
  133. package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -1
  134. package/templates/retail-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
  135. package/templates/retail-store/tier5-src/_shared/collection-query.ts +7 -0
  136. package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -1
  137. package/templates/retail-store-owner/tier5-src/_shared/collection-query.ts +8 -0
  138. package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -1
  139. package/templates/salon-spa/tier5-src/_shared/collection-query.ts +8 -0
  140. package/templates/salon-spa/tier5-src/_shared/collection-service.ts +7 -1
  141. package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
  142. package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +7 -0
  143. package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +7 -1
  144. package/templates/yoga-studio/tier5-src/_shared/collection-query.ts +8 -0
  145. package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -1
  146. package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +77 -0
  147. package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
  148. package/templates/yoga-studio-owner/tier5-src/_shared/collection-query.ts +8 -0
  149. package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -1
@@ -0,0 +1,265 @@
1
+ // Shared BARE sort + filter: the Products gallery and the Search results use the same
2
+ // sort picker, filter panel (price + the store's product options) and derive rules.
3
+ // Each screen owns its scope (a category, a search query); this module only narrows
4
+ // and orders the rows inside that scope.
5
+ import type { StoreProduct } from "@himalaya/wix-stores";
6
+ import { money, productCard, refreshSaved, type ProductCard } from "./bare-fashion-product-card.js";
7
+
8
+ const OPTION_SLOTS = 3;
9
+
10
+ export interface Chip { id: string; label: string }
11
+ export interface Option extends Chip { selected: boolean; notSelected: boolean }
12
+ export type Panel = "none" | "filters" | "sort";
13
+
14
+ export const SORTS: Chip[] = [
15
+ { id: "recommended", label: "Recommended" },
16
+ { id: "newest", label: "Newest" },
17
+ { id: "price_asc", label: "Price: Low to High" },
18
+ { id: "price_desc", label: "Price: High to Low" },
19
+ { id: "name_asc", label: "Name: A–Z" },
20
+ { id: "name_desc", label: "Name: Z–A" },
21
+ ];
22
+
23
+ /** A product plus the facts the filters and sorts read. */
24
+ export interface Row {
25
+ card: ProductCard;
26
+ categoryIds: string[];
27
+ price: number;
28
+ created: string;
29
+ name: string;
30
+ options: Record<string, string[]>;
31
+ }
32
+
33
+ /** The sort + filter slice of a screen's state. */
34
+ export interface FacetState {
35
+ sort: string;
36
+ sortOptions: Option[];
37
+ sortLabel: string;
38
+ panel: Panel;
39
+ /** The filter panel and the sort picker are bottom sheets over the gallery. */
40
+ filtersOpen: boolean;
41
+ sortOpen: boolean;
42
+ filterLabel: string;
43
+ priceChips: Chip[];
44
+ priceSelected: string[];
45
+ hidePrice: boolean;
46
+ opt1Name: string; opt1Chips: Chip[]; opt1Selected: string[]; hideOpt1: boolean;
47
+ opt2Name: string; opt2Chips: Chip[]; opt2Selected: string[]; hideOpt2: boolean;
48
+ opt3Name: string; opt3Chips: Chip[]; opt3Selected: string[]; hideOpt3: boolean;
49
+ results: ProductCard[];
50
+ }
51
+
52
+ export const FACETS_BOOT: FacetState = {
53
+ sort: "recommended", sortOptions: [], sortLabel: "",
54
+ panel: "none", filtersOpen: false, sortOpen: false, filterLabel: "Filter",
55
+ priceChips: [], priceSelected: [], hidePrice: true,
56
+ opt1Name: "", opt1Chips: [], opt1Selected: [], hideOpt1: true,
57
+ opt2Name: "", opt2Chips: [], opt2Selected: [], hideOpt2: true,
58
+ opt3Name: "", opt3Chips: [], opt3Selected: [], hideOpt3: true,
59
+ results: [],
60
+ };
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // Reading products (V1 shapes first — this site runs CATALOG_V1 — V3 defensively)
64
+ // ---------------------------------------------------------------------------
65
+
66
+ function categoryIdsOf(p: StoreProduct): string[] {
67
+ const raw = p as unknown as {
68
+ collectionIds?: string[];
69
+ allCategoriesInfo?: { categories?: { id?: string }[] };
70
+ directCategoriesInfo?: { categories?: { id?: string }[] };
71
+ };
72
+ const v3 = [...(raw.allCategoriesInfo?.categories ?? []), ...(raw.directCategoriesInfo?.categories ?? [])]
73
+ .map((c) => c.id ?? "");
74
+ return [...(Array.isArray(raw.collectionIds) ? raw.collectionIds : []), ...v3].filter(Boolean);
75
+ }
76
+
77
+ /** The price a shopper pays: the sale price when discounted. */
78
+ function priceOf(p: StoreProduct): number {
79
+ const raw = p as unknown as {
80
+ price?: { price?: number; discountedPrice?: number };
81
+ priceData?: { price?: number; discountedPrice?: number };
82
+ actualPriceRange?: { minValue?: { amount?: string } };
83
+ };
84
+ const bag = raw.price ?? raw.priceData;
85
+ const v = bag?.discountedPrice ?? bag?.price ?? Number(raw.actualPriceRange?.minValue?.amount);
86
+ return typeof v === "number" && isFinite(v) ? v : 0;
87
+ }
88
+
89
+ export function currencyOf(p: StoreProduct): string | undefined {
90
+ const raw = p as unknown as { price?: { currency?: string }; priceData?: { currency?: string }; currency?: string };
91
+ return raw.price?.currency ?? raw.priceData?.currency ?? raw.currency;
92
+ }
93
+
94
+ /** Option name → choice labels. V1 `productOptions[].choices[].description`;
95
+ * V3 `options[].choicesSettings.choices[].name`. */
96
+ function optionsOf(p: StoreProduct): Record<string, string[]> {
97
+ const raw = p as unknown as {
98
+ productOptions?: { name?: string; choices?: { description?: string; value?: string }[] }[];
99
+ options?: { name?: string; choicesSettings?: { choices?: { name?: string }[] } }[];
100
+ };
101
+ const out: Record<string, string[]> = {};
102
+ for (const o of raw.productOptions ?? []) {
103
+ const name = (o.name ?? "").trim();
104
+ const values = (o.choices ?? []).map((c) => (c.description ?? c.value ?? "").trim()).filter(Boolean);
105
+ if (name && values.length) out[name.toUpperCase()] = values;
106
+ }
107
+ for (const o of raw.options ?? []) {
108
+ const name = (o.name ?? "").trim();
109
+ const values = (o.choicesSettings?.choices ?? []).map((c) => (c.name ?? "").trim()).filter(Boolean);
110
+ if (name && values.length && !out[name.toUpperCase()]) out[name.toUpperCase()] = values;
111
+ }
112
+ return out;
113
+ }
114
+
115
+ export function toRow(p: StoreProduct): Row {
116
+ const card = productCard(p);
117
+ const raw = p as unknown as { createdDate?: string; _createdDate?: string };
118
+ return {
119
+ card,
120
+ categoryIds: categoryIdsOf(p),
121
+ price: priceOf(p),
122
+ created: raw.createdDate ?? raw._createdDate ?? "",
123
+ name: card.name.toLowerCase(),
124
+ options: optionsOf(p),
125
+ };
126
+ }
127
+
128
+ // ---------------------------------------------------------------------------
129
+ // Facets
130
+ // ---------------------------------------------------------------------------
131
+
132
+ /** Round price buckets over the scope's price span, e.g. Under €25 · €25–€50 · Over €75. */
133
+ function priceBuckets(scope: Row[], currency: string | undefined): Chip[] {
134
+ const max = Math.max(0, ...scope.map((r) => r.price));
135
+ if (max <= 0) return [];
136
+ const step = max <= 100 ? 25 : max <= 200 ? 50 : max <= 500 ? 100 : 250;
137
+ const edges: number[] = [];
138
+ for (let e = step; e < max; e += step) edges.push(e);
139
+ if (edges.length === 0) return [];
140
+ const m = (n: number) => money(n, currency).replace(/\.00$/, "");
141
+ const chips: Chip[] = [{ id: `0-${edges[0]}`, label: `Under ${m(edges[0])}` }];
142
+ for (let i = 1; i < edges.length; i++) chips.push({ id: `${edges[i - 1]}-${edges[i]}`, label: `${m(edges[i - 1])} – ${m(edges[i])}` });
143
+ chips.push({ id: `${edges[edges.length - 1]}-`, label: `Over ${m(edges[edges.length - 1])}` });
144
+ return chips;
145
+ }
146
+
147
+ function inBucket(price: number, id: string): boolean {
148
+ const [lo, hi] = id.split("-");
149
+ const min = Number(lo) || 0;
150
+ return price >= min && (hi === "" || hi === undefined ? true : price < Number(hi));
151
+ }
152
+
153
+ const SIZE_ORDER = ["XXS", "XS", "S", "M", "L", "XL", "XXL", "XXXL"];
154
+ /** Clothing sizes in size order; anything else keeps the store's order. */
155
+ function sortChoices(values: string[]): string[] {
156
+ const rank = (v: string) => SIZE_ORDER.indexOf(v.trim().toUpperCase());
157
+ return values.every((v) => rank(v) >= 0) ? values.slice().sort((a, b) => rank(a) - rank(b)) : values;
158
+ }
159
+
160
+ function optionFacets(scope: Row[]): { name: string; chips: Chip[] }[] {
161
+ const seen = new Map<string, Set<string>>();
162
+ for (const r of scope) {
163
+ for (const [name, values] of Object.entries(r.options)) {
164
+ const set = seen.get(name) ?? new Set<string>();
165
+ values.forEach((v) => set.add(v));
166
+ seen.set(name, set);
167
+ }
168
+ }
169
+ return [...seen.entries()].slice(0, OPTION_SLOTS).map(([name, set]) => ({
170
+ name,
171
+ chips: sortChoices([...set]).map((v) => ({ id: v, label: v.toUpperCase() })),
172
+ }));
173
+ }
174
+
175
+ const SLOT_KEYS = [
176
+ ["opt1Name", "opt1Chips", "opt1Selected", "hideOpt1"],
177
+ ["opt2Name", "opt2Chips", "opt2Selected", "hideOpt2"],
178
+ ["opt3Name", "opt3Chips", "opt3Selected", "hideOpt3"],
179
+ ] as const;
180
+
181
+ function sortRows(list: Row[], sort: string): Row[] {
182
+ const out = list.slice();
183
+ switch (sort) {
184
+ case "newest": return out.sort((a, b) => b.created.localeCompare(a.created));
185
+ case "price_asc": return out.sort((a, b) => a.price - b.price);
186
+ case "price_desc": return out.sort((a, b) => b.price - a.price);
187
+ case "name_asc": return out.sort((a, b) => a.name.localeCompare(b.name));
188
+ case "name_desc": return out.sort((a, b) => b.name.localeCompare(a.name));
189
+ default: return out;
190
+ }
191
+ }
192
+
193
+ export function option(c: Chip, on: boolean): Option {
194
+ return { ...c, selected: on, notSelected: !on };
195
+ }
196
+
197
+ /** Narrow `scope` by the selected filters and order it by the selected sort.
198
+ * Facets follow the scope; a selection the scope no longer offers is dropped.
199
+ * Returns the next state plus the active-filter count for the screen's own labels. */
200
+ export function applyFacets<T extends FacetState>(s: T, scope: Row[], currency: string | undefined): { next: T; active: number } {
201
+ const priceChips = priceBuckets(scope, currency);
202
+ const priceSelected = s.priceSelected.filter((id) => priceChips.some((c) => c.id === id));
203
+ const facets = optionFacets(scope);
204
+ const next: T = { ...s, priceChips, priceSelected, hidePrice: priceChips.length === 0 };
205
+ SLOT_KEYS.forEach(([nameK, chipsK, selK, hideK], i) => {
206
+ const f = facets[i];
207
+ const prevName = s[nameK];
208
+ const chips = f?.chips ?? [];
209
+ next[nameK] = f?.name ?? "";
210
+ next[chipsK] = chips;
211
+ next[selK] = f && f.name === prevName ? s[selK].filter((id) => chips.some((c) => c.id === id)) : [];
212
+ next[hideK] = !f;
213
+ });
214
+
215
+ const optionFilters = SLOT_KEYS
216
+ .map(([nameK, , selK]) => ({ name: next[nameK], values: next[selK] }))
217
+ .filter((f) => f.name && f.values.length);
218
+ const matched = scope.filter((r) =>
219
+ (priceSelected.length === 0 || priceSelected.some((id) => inBucket(r.price, id)))
220
+ && optionFilters.every((f) => (r.options[f.name] ?? []).some((v) => f.values.includes(v))));
221
+
222
+ const active = priceSelected.length + optionFilters.reduce((n, f) => n + f.values.length, 0);
223
+ next.results = refreshSaved(sortRows(matched, s.sort).map((r) => r.card));
224
+ next.sortOptions = SORTS.map((c) => option(c, c.id === s.sort));
225
+ next.sortLabel = `Sort: ${(SORTS.find((c) => c.id === s.sort) ?? SORTS[0]).label}`;
226
+ next.filtersOpen = s.panel === "filters";
227
+ next.sortOpen = s.panel === "sort";
228
+ next.filterLabel = active ? `Filter (${active})` : "Filter";
229
+ return { next, active };
230
+ }
231
+
232
+ export function countText(n: number): string {
233
+ return `${n} ${n === 1 ? "product" : "products"}`;
234
+ }
235
+
236
+ /** A tapped row's `{ id }` param. */
237
+ export function idOf(arg: unknown): string {
238
+ return String((arg as { id?: unknown } | undefined)?.id ?? "");
239
+ }
240
+
241
+ /** A FilterChips `onChange` payload's selected ids. */
242
+ export function selected(arg: unknown): string[] {
243
+ const ids = (arg as { selectedIds?: unknown } | undefined)?.selectedIds;
244
+ return Array.isArray(ids) ? ids.filter((x): x is string => typeof x === "string") : [];
245
+ }
246
+
247
+ /** The sort + filter actions, identical on every screen that has the panel. */
248
+ export function facetActions<T extends FacetState>(derive: (s: T) => T) {
249
+ return {
250
+ // Choosing a sort applies it and closes the sort sheet.
251
+ sort: (s: T, arg?: unknown): T => {
252
+ const id = idOf(arg);
253
+ if (!SORTS.some((c) => c.id === id)) return s;
254
+ return derive({ ...s, sort: id, panel: "none" });
255
+ },
256
+ openFilters: (s: T): T => derive({ ...s, panel: "filters" }),
257
+ openSort: (s: T): T => derive({ ...s, panel: "sort" }),
258
+ closePanel: (s: T): T => derive({ ...s, panel: "none" }),
259
+ selectPrice: (s: T, arg?: unknown): T => derive({ ...s, priceSelected: selected(arg) }),
260
+ selectOpt1: (s: T, arg?: unknown): T => derive({ ...s, opt1Selected: selected(arg) }),
261
+ selectOpt2: (s: T, arg?: unknown): T => derive({ ...s, opt2Selected: selected(arg) }),
262
+ selectOpt3: (s: T, arg?: unknown): T => derive({ ...s, opt3Selected: selected(arg) }),
263
+ clearFilters: (s: T): T => derive({ ...s, priceSelected: [], opt1Selected: [], opt2Selected: [], opt3Selected: [] }),
264
+ };
265
+ }
@@ -0,0 +1,38 @@
1
+ // Why a screen load failed, so the screen can show the matching ErrorState variant.
2
+ // Workers do not receive the host's connectivity signal, so the kind is read from the
3
+ // failure itself: a native transport failure (no network, DNS, a dropped socket)
4
+ // reaches the worker with no `HTTP <status>`, while an answer from Wix always carries
5
+ // one. `permission` and `signIn` are set by the worker that knows the access rules.
6
+
7
+ export type ErrorKind = "offline" | "server" | "permission" | "signIn";
8
+
9
+ const HTTP_STATUS = /HTTP \d{3}\b/;
10
+ const TRANSPORT = /offline|network|internet|not connected|unable to resolve host|unknownhost|failed to connect|could not connect|connection (lost|refused|reset|abort)|timed? ?out|socket|enotfound|econnrefused|econnreset|failed to fetch|load failed/i;
11
+
12
+ function browserOffline(): boolean {
13
+ const nav = (globalThis as { navigator?: { onLine?: boolean } }).navigator;
14
+ return nav?.onLine === false;
15
+ }
16
+
17
+ /** Classify one load failure as offline or server. Unknown failures count as `server`. */
18
+ export function errorKindOf(e: unknown): ErrorKind {
19
+ if (browserOffline()) return "offline";
20
+ const msg = String((e as Error)?.message ?? e ?? "");
21
+ if (HTTP_STATUS.test(msg)) return "server";
22
+ return TRANSPORT.test(msg) ? "offline" : "server";
23
+ }
24
+
25
+ const SPECIFIC: ErrorKind[] = ["offline", "permission", "signIn"];
26
+
27
+ /** The flags `errorState()` in dev/index.ts binds to. Exactly one is false on error. */
28
+ export function errorFlags(status: string, errorKind: ErrorKind | undefined): {
29
+ hideOfflineError: boolean; hideServerError: boolean; hidePermissionError: boolean; hideSignInError: boolean;
30
+ } {
31
+ const errored = status === "error";
32
+ return {
33
+ hideOfflineError: !(errored && errorKind === "offline"),
34
+ hidePermissionError: !(errored && errorKind === "permission"),
35
+ hideSignInError: !(errored && errorKind === "signIn"),
36
+ hideServerError: !(errored && !SPECIFIC.includes(errorKind as ErrorKind)),
37
+ };
38
+ }
@@ -0,0 +1,136 @@
1
+ // Shared BARE product card: one row shape for every product gallery (Home New In and
2
+ // Sale, Shop search, category page, Favorites) so they all render the Sale card —
3
+ // image, "On Sale" tag, name, colour swatches, was/now price — plus the favorites heart.
4
+ import { productImage, type StoreProduct } from "@himalaya/wix-stores";
5
+ import { productOptions } from "./bare-fashion-store-options.js";
6
+ import { cleanTitle } from "./himi-text.js";
7
+ import { readSavedProducts, toggleSavedProduct, type SavedProduct } from "./himi-store-saved.js";
8
+
9
+ export interface ProductCard {
10
+ id: string;
11
+ name: string;
12
+ image: string;
13
+ hasImage: boolean;
14
+ noImage: boolean;
15
+ price: string;
16
+ wasPrice: string;
17
+ onSale: boolean;
18
+ notOnSale: boolean;
19
+ saved: boolean;
20
+ notSaved: boolean;
21
+ /** Colour-option hexes; the layout binds fixed slots swatch1…swatch5. */
22
+ swatches: string[];
23
+ noSwatches: boolean;
24
+ /** Hides the On Sale / swatch row when it has nothing to show. */
25
+ noTagRow: boolean;
26
+ swatch1: string; swatch2: string; swatch3: string; swatch4: string; swatch5: string;
27
+ swatch1Hidden: boolean; swatch2Hidden: boolean; swatch3Hidden: boolean; swatch4Hidden: boolean; swatch5Hidden: boolean;
28
+ }
29
+
30
+ /** The layout has no nested repeater inside a grid item, so swatches ride in five
31
+ * fixed slots; a product with more colours shows the first five. */
32
+ const MAX_SWATCHES = 5;
33
+
34
+ type SwatchFields = Pick<ProductCard, "swatches" | "noSwatches" | "noTagRow" | "swatch1" | "swatch2" | "swatch3" | "swatch4" | "swatch5"
35
+ | "swatch1Hidden" | "swatch2Hidden" | "swatch3Hidden" | "swatch4Hidden" | "swatch5Hidden">;
36
+
37
+ function swatchFields(hexes: string[], onSale: boolean): SwatchFields {
38
+ const s = hexes.filter(Boolean).slice(0, MAX_SWATCHES);
39
+ return {
40
+ swatches: s, noSwatches: s.length === 0, noTagRow: !onSale && s.length === 0,
41
+ swatch1: s[0] ?? "", swatch2: s[1] ?? "", swatch3: s[2] ?? "", swatch4: s[3] ?? "", swatch5: s[4] ?? "",
42
+ swatch1Hidden: !s[0], swatch2Hidden: !s[1], swatch3Hidden: !s[2], swatch4Hidden: !s[3], swatch5Hidden: !s[4],
43
+ };
44
+ }
45
+
46
+ /** Hexes of the product's first colour option ([] when it has none). */
47
+ function productSwatches(p: StoreProduct): string[] {
48
+ const color = productOptions(p).find((o) => o.kind === "color");
49
+ return (color?.choices ?? []).map((c) => c.hex);
50
+ }
51
+
52
+ /** V1 carries the sale price on `price.discountedPrice`; V3 puts the pre-discount
53
+ * figure in `actualPriceRange`. Read both shapes defensively — the SDK's declared
54
+ * type covers neither, and a missing field must degrade to "not on sale", never NaN. */
55
+ interface PriceBag {
56
+ price?: number;
57
+ discountedPrice?: number;
58
+ currency?: string;
59
+ formatted?: { price?: string; discountedPrice?: string };
60
+ }
61
+ function priceBag(p: StoreProduct): PriceBag {
62
+ const raw = (p as unknown as { price?: PriceBag; priceData?: PriceBag });
63
+ return raw.price ?? raw.priceData ?? {};
64
+ }
65
+
66
+ export function money(n: number | undefined, currency: string | undefined): string {
67
+ if (typeof n !== "number" || !isFinite(n)) return "";
68
+ const symbol = currency === "EUR" ? "€" : currency === "USD" ? "$" : currency === "GBP" ? "£" : "";
69
+ const body = n.toFixed(2);
70
+ return symbol ? symbol + body : body + (currency ? " " + currency : "");
71
+ }
72
+
73
+ function savedIds(): Set<string> {
74
+ try { return new Set(readSavedProducts().map((row) => row.id)); } catch { return new Set(); }
75
+ }
76
+
77
+ export function productCard(p: StoreProduct, saved: Set<string> = savedIds()): ProductCard {
78
+ const bag = priceBag(p);
79
+ const list = bag.price;
80
+ const sale = bag.discountedPrice;
81
+ const discounted = typeof list === "number" && typeof sale === "number" && sale < list;
82
+ // Prefer Wix's own formatted strings; fall back to our own only when absent.
83
+ const nowText = discounted
84
+ ? (bag.formatted?.discountedPrice ?? money(sale, bag.currency))
85
+ : (bag.formatted?.price ?? money(list, bag.currency));
86
+ const wasText = discounted ? (bag.formatted?.price ?? money(list, bag.currency)) : "";
87
+ const image = productImage(p);
88
+ const id = p.id ?? "";
89
+ return {
90
+ id,
91
+ name: cleanTitle(p.name) || "",
92
+ image,
93
+ hasImage: !!image,
94
+ noImage: !image,
95
+ price: nowText,
96
+ wasPrice: wasText,
97
+ onSale: discounted,
98
+ notOnSale: !discounted,
99
+ saved: saved.has(id),
100
+ notSaved: !saved.has(id),
101
+ ...swatchFields(productSwatches(p), discounted),
102
+ };
103
+ }
104
+
105
+ export function productCards(products: StoreProduct[]): ProductCard[] {
106
+ const saved = savedIds();
107
+ return products.map((p) => productCard(p, saved)).filter((c) => c.id);
108
+ }
109
+
110
+ /** A card rebuilt from device storage, for the Favorites gallery. */
111
+ export function savedCard(row: SavedProduct): ProductCard {
112
+ const onSale = !!row.wasPrice;
113
+ return {
114
+ id: row.id, name: row.name, image: row.image, hasImage: !!row.image, noImage: !row.image,
115
+ price: row.price, wasPrice: row.wasPrice ?? "", onSale, notOnSale: !onSale, saved: true, notSaved: false,
116
+ ...swatchFields(row.swatches ?? [], onSale),
117
+ };
118
+ }
119
+
120
+ /** Re-read saved state so hearts match changes made on other screens. */
121
+ export function refreshSaved(cards: ProductCard[]): ProductCard[] {
122
+ const saved = savedIds();
123
+ return cards.map((c) => ({ ...c, saved: saved.has(c.id), notSaved: !saved.has(c.id) }));
124
+ }
125
+
126
+ /** The heart's `{ id }` arg — tolerant of a bare string. */
127
+ export function cardId(arg: unknown): string {
128
+ return typeof arg === "string" ? arg : String((arg as { id?: unknown } | undefined)?.id ?? "");
129
+ }
130
+
131
+ /** Toggle one card's favorite. Throws when storage fails, so the caller keeps its state. */
132
+ export function toggleFavorite(cards: ProductCard[], id: string): void {
133
+ const card = cards.find((c) => c.id === id);
134
+ if (!card) return;
135
+ toggleSavedProduct({ id: card.id, name: card.name, price: card.price, image: card.image, wasPrice: card.wasPrice, swatches: card.swatches });
136
+ }
@@ -0,0 +1,129 @@
1
+ // Wix Stores product OPTIONS (colour, size, …) — read model shared by any screen
2
+ // that must let a shopper choose a variant before adding to the cart.
3
+ //
4
+ // Why this file exists: `@wix/himalaya/wix-stores` graduated the display helpers
5
+ // (productImage, productPrice, productGallery, plainText) but NOT the options.
6
+ // The payload carries them on both catalog versions and the two spellings differ,
7
+ // so every app would otherwise re-derive this.
8
+ //
9
+ // Catalog V1: product.productOptions[] = { name, optionType, choices[] }
10
+ // choice = { value, description, inStock, visible, media }
11
+ // Catalog V3: product.options[] = { name, optionRenderType, choicesSettings.choices[] }
12
+ // choice = { name, choiceId, key, inStock, linkedMedia }
13
+
14
+ /** One selectable choice inside an option group. */
15
+ export interface StoreOptionChoice {
16
+ /** Stable id AND the value sent to the cart (the shopper-visible choice name). */
17
+ id: string;
18
+ label: string;
19
+ inStock: boolean;
20
+ /** Choice-linked image ("" when the choice has none) — colour swatches carry one. */
21
+ image: string;
22
+ /** Swatch colour as `#RRGGBB` ("" when the choice has none — non-colour options). */
23
+ hex: string;
24
+ }
25
+
26
+ /** One option group, e.g. `COLOR` with `BEIGE` / `PINK`. */
27
+ export interface StoreOption {
28
+ name: string;
29
+ /** "color" renders as swatch-style chips where the host supports it. */
30
+ kind: "color" | "list";
31
+ choices: StoreOptionChoice[];
32
+ }
33
+
34
+ function str(v: unknown): string {
35
+ return typeof v === "string" ? v.trim() : "";
36
+ }
37
+
38
+ function hexOf(v: unknown): string {
39
+ const s = str(v);
40
+ return /^#[0-9a-f]{3}([0-9a-f]{3})?$/i.test(s) ? s : "";
41
+ }
42
+
43
+ function mediaUrl(slot: unknown): string {
44
+ const m = slot as { mainMedia?: { image?: { url?: string } }; image?: { url?: string }; url?: string } | undefined;
45
+ return str(m?.mainMedia?.image?.url) || str(m?.image?.url) || str(m?.url);
46
+ }
47
+
48
+ function v1Choices(raw: unknown): StoreOptionChoice[] {
49
+ const list = Array.isArray(raw) ? raw : [];
50
+ const out: StoreOptionChoice[] = [];
51
+ for (const c of list) {
52
+ const o = c as { value?: unknown; description?: unknown; inStock?: unknown; visible?: unknown; media?: unknown };
53
+ // `visible: false` is an option the site owner hid — it must not be offered.
54
+ if (o.visible === false) continue;
55
+ // Colour choices carry a hex in `value` and the shopper-facing word in
56
+ // `description`; drop-downs repeat the same string in both.
57
+ const label = str(o.description) || str(o.value);
58
+ if (!label || out.some((x) => x.id === label)) continue;
59
+ out.push({ id: label, label, inStock: o.inStock !== false, image: mediaUrl(o.media), hex: hexOf(o.value) });
60
+ }
61
+ return out;
62
+ }
63
+
64
+ function v3Choices(raw: unknown): StoreOptionChoice[] {
65
+ const settings = raw as { choices?: unknown } | undefined;
66
+ const list = Array.isArray(settings?.choices) ? settings.choices : [];
67
+ const out: StoreOptionChoice[] = [];
68
+ for (const c of list) {
69
+ const o = c as { name?: unknown; key?: unknown; inStock?: unknown; visible?: unknown; linkedMedia?: unknown; colorCode?: unknown };
70
+ if (o.visible === false) continue;
71
+ const label = str(o.name) || str(o.key);
72
+ if (!label || out.some((x) => x.id === label)) continue;
73
+ const media = Array.isArray(o.linkedMedia) ? o.linkedMedia[0] : undefined;
74
+ out.push({ id: label, label, inStock: o.inStock !== false, image: mediaUrl(media), hex: hexOf(o.colorCode) });
75
+ }
76
+ return out;
77
+ }
78
+
79
+ function kindOf(raw: unknown): "color" | "list" {
80
+ return /color/i.test(str(raw)) ? "color" : "list";
81
+ }
82
+
83
+ /** Every offerable option group on a product, in site order. `[]` when the
84
+ * product has none — which is the common case, so callers must handle it. */
85
+ export function productOptions(product: unknown): StoreOption[] {
86
+ const p = product as { productOptions?: unknown; options?: unknown } | undefined;
87
+ const out: StoreOption[] = [];
88
+
89
+ for (const raw of Array.isArray(p?.productOptions) ? p.productOptions : []) {
90
+ const o = raw as { name?: unknown; optionType?: unknown; choices?: unknown };
91
+ const name = str(o.name);
92
+ const choices = v1Choices(o.choices);
93
+ if (name && choices.length) out.push({ name, kind: kindOf(o.optionType), choices });
94
+ }
95
+ if (out.length) return out;
96
+
97
+ for (const raw of Array.isArray(p?.options) ? p.options : []) {
98
+ const o = raw as { name?: unknown; optionRenderType?: unknown; choicesSettings?: unknown };
99
+ const name = str(o.name);
100
+ const choices = v3Choices(o.choicesSettings);
101
+ if (name && choices.length) out.push({ name, kind: kindOf(o.optionRenderType), choices });
102
+ }
103
+ return out;
104
+ }
105
+
106
+ /** The choice to preselect for a group: the only choice when there is exactly
107
+ * one, otherwise "" so the shopper makes a deliberate pick. */
108
+ export function defaultChoice(option: StoreOption): string {
109
+ return option.choices.length === 1 ? option.choices[0].id : "";
110
+ }
111
+
112
+ /** The `catalogReference.options` payload for `addToCurrentCart`.
113
+ * Wix Stores expects `{ options: { "<option name>": "<choice name>" } }`. */
114
+ export function cartOptionsPayload(
115
+ options: StoreOption[],
116
+ selected: string[],
117
+ ): Record<string, unknown> | undefined {
118
+ const picked: Record<string, string> = {};
119
+ options.forEach((o, i) => {
120
+ const choice = selected[i] ?? "";
121
+ if (choice) picked[o.name] = choice;
122
+ });
123
+ return Object.keys(picked).length ? { options: picked } : undefined;
124
+ }
125
+
126
+ /** Human summary of the current selection, e.g. "BEIGE · M" ("" when nothing picked). */
127
+ export function selectionSummary(options: StoreOption[], selected: string[]): string {
128
+ return options.map((_, i) => selected[i] ?? "").filter(Boolean).join(" · ");
129
+ }