@wix/himalaya-cli 0.1944.0 → 0.1945.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/ecom/src/extensions.d.ts +27 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-ecom.mjs +16 -0
- package/dist/cli.mjs +1185 -644
- package/fixtures/wix-canned.json +6 -0
- package/guides/himi-json-output.md +8 -6
- package/guides/one-app-section-mappings.md +2 -2
- package/guides/one-app-to-himi-app.md +13 -4
- package/guides/release-notes.md +8 -0
- package/guides/sdk-reference.json +55 -0
- package/package.json +2 -2
- package/templates/bare-fashion/dev/index.ts +3 -1
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +5 -4
- package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +19 -12
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +9 -4
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +10 -4
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +17 -8
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +8 -4
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +31 -12
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +8 -4
- package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/beauty-salon/tier5-src/_shared/himi-store-facets.ts +4 -4
- package/templates/beauty-salon/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/beauty-salon/tier5-src/himi-branded-lite-cart/index.ts +13 -7
- package/templates/beauty-salon/tier5-src/himi-branded-lite-category/index.ts +6 -1
- package/templates/beauty-salon/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/beauty-salon/tier5-src/himi-branded-lite-shop/index.ts +9 -3
- package/templates/beauty-salon/tier5-src/himi-store-product/index.ts +7 -5
- package/templates/beauty-salon/tier5-src/himi-store-saved/index.ts +31 -12
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/branded-lite/recipes/wishlist-grid.json +1 -1
- package/templates/branded-lite/tier5-src/_shared/collection-service.ts +42 -19
- package/templates/branded-lite/tier5-src/_shared/himi-store-facets.ts +4 -4
- package/templates/branded-lite/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/branded-lite/tier5-src/_shared/saved-products-section.ts +14 -8
- package/templates/branded-lite/tier5-src/himi-branded-lite-cart/index.ts +13 -7
- package/templates/branded-lite/tier5-src/himi-branded-lite-category/index.ts +6 -1
- package/templates/branded-lite/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/branded-lite/tier5-src/himi-branded-lite-shop/index.ts +9 -3
- package/templates/branded-lite/tier5-src/himi-store-product/index.ts +32 -15
- package/templates/branded-lite/tier5-src/himi-store-saved/index.ts +31 -12
- package/templates/brandy/tier5-src/_shared/collection-service.ts +42 -19
- package/templates/brandy/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/brandy/tier5-src/himi-branded-lite-cart/index.ts +13 -7
- package/templates/community-club/l10n/ar.json +5 -0
- package/templates/community-club/l10n/cs.json +5 -0
- package/templates/community-club/l10n/da.json +5 -0
- package/templates/community-club/l10n/de.json +5 -0
- package/templates/community-club/l10n/el.json +5 -0
- package/templates/community-club/l10n/es.json +5 -0
- package/templates/community-club/l10n/fi.json +5 -0
- package/templates/community-club/l10n/fr.json +5 -0
- package/templates/community-club/l10n/he.json +4 -0
- package/templates/community-club/l10n/hu.json +5 -0
- package/templates/community-club/l10n/id.json +5 -0
- package/templates/community-club/l10n/it.json +5 -0
- package/templates/community-club/l10n/ja.json +5 -0
- package/templates/community-club/l10n/ko.json +5 -0
- package/templates/community-club/l10n/lt.json +5 -0
- package/templates/community-club/l10n/nl.json +5 -0
- package/templates/community-club/l10n/no.json +5 -0
- package/templates/community-club/l10n/pl.json +5 -0
- package/templates/community-club/l10n/pt.json +5 -0
- package/templates/community-club/l10n/ru.json +5 -0
- package/templates/community-club/l10n/sv.json +5 -0
- package/templates/community-club/l10n/th.json +5 -0
- package/templates/community-club/l10n/tr.json +5 -0
- package/templates/community-club/l10n/uk.json +5 -0
- package/templates/community-club/l10n/vi.json +5 -0
- package/templates/community-club/l10n/zh.json +5 -0
- package/templates/community-club/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/community-club/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/community-club/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/conference/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/events-meetups/l10n/ar.json +5 -0
- package/templates/events-meetups/l10n/cs.json +5 -0
- package/templates/events-meetups/l10n/da.json +5 -0
- package/templates/events-meetups/l10n/de.json +5 -0
- package/templates/events-meetups/l10n/el.json +5 -0
- package/templates/events-meetups/l10n/es.json +5 -0
- package/templates/events-meetups/l10n/fi.json +5 -0
- package/templates/events-meetups/l10n/fr.json +5 -0
- package/templates/events-meetups/l10n/he.json +4 -0
- package/templates/events-meetups/l10n/hu.json +5 -0
- package/templates/events-meetups/l10n/id.json +5 -0
- package/templates/events-meetups/l10n/it.json +5 -0
- package/templates/events-meetups/l10n/ja.json +5 -0
- package/templates/events-meetups/l10n/ko.json +5 -0
- package/templates/events-meetups/l10n/lt.json +5 -0
- package/templates/events-meetups/l10n/nl.json +5 -0
- package/templates/events-meetups/l10n/no.json +5 -0
- package/templates/events-meetups/l10n/pl.json +5 -0
- package/templates/events-meetups/l10n/pt.json +5 -0
- package/templates/events-meetups/l10n/ru.json +5 -0
- package/templates/events-meetups/l10n/sv.json +5 -0
- package/templates/events-meetups/l10n/th.json +5 -0
- package/templates/events-meetups/l10n/tr.json +5 -0
- package/templates/events-meetups/l10n/uk.json +5 -0
- package/templates/events-meetups/l10n/vi.json +5 -0
- package/templates/events-meetups/l10n/zh.json +5 -0
- package/templates/events-meetups/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/events-meetups/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/events-meetups/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/gym-fitness/tier5-src/_shared/himi-store-facets.ts +4 -4
- package/templates/gym-fitness/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/gym-fitness/tier5-src/himi-branded-lite-cart/index.ts +13 -7
- package/templates/gym-fitness/tier5-src/himi-branded-lite-category/index.ts +6 -1
- package/templates/gym-fitness/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/gym-fitness/tier5-src/himi-branded-lite-shop/index.ts +9 -3
- package/templates/gym-fitness/tier5-src/himi-store-product/index.ts +7 -5
- package/templates/gym-fitness/tier5-src/himi-store-saved/index.ts +31 -12
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/medical-services/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/nonprofit-cause/l10n/ar.json +5 -0
- package/templates/nonprofit-cause/l10n/cs.json +5 -0
- package/templates/nonprofit-cause/l10n/da.json +5 -0
- package/templates/nonprofit-cause/l10n/de.json +5 -0
- package/templates/nonprofit-cause/l10n/el.json +5 -0
- package/templates/nonprofit-cause/l10n/es.json +5 -0
- package/templates/nonprofit-cause/l10n/fi.json +5 -0
- package/templates/nonprofit-cause/l10n/fr.json +5 -0
- package/templates/nonprofit-cause/l10n/he.json +4 -0
- package/templates/nonprofit-cause/l10n/hu.json +5 -0
- package/templates/nonprofit-cause/l10n/id.json +5 -0
- package/templates/nonprofit-cause/l10n/it.json +5 -0
- package/templates/nonprofit-cause/l10n/ja.json +5 -0
- package/templates/nonprofit-cause/l10n/ko.json +5 -0
- package/templates/nonprofit-cause/l10n/lt.json +5 -0
- package/templates/nonprofit-cause/l10n/nl.json +5 -0
- package/templates/nonprofit-cause/l10n/no.json +5 -0
- package/templates/nonprofit-cause/l10n/pl.json +5 -0
- package/templates/nonprofit-cause/l10n/pt.json +5 -0
- package/templates/nonprofit-cause/l10n/ru.json +5 -0
- package/templates/nonprofit-cause/l10n/sv.json +5 -0
- package/templates/nonprofit-cause/l10n/th.json +5 -0
- package/templates/nonprofit-cause/l10n/tr.json +5 -0
- package/templates/nonprofit-cause/l10n/uk.json +5 -0
- package/templates/nonprofit-cause/l10n/vi.json +5 -0
- package/templates/nonprofit-cause/l10n/zh.json +5 -0
- package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/nonprofit-cause/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/nonprofit-cause/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/owner-lite/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/podcast-creator/l10n/ar.json +5 -0
- package/templates/podcast-creator/l10n/cs.json +5 -0
- package/templates/podcast-creator/l10n/da.json +5 -0
- package/templates/podcast-creator/l10n/de.json +5 -0
- package/templates/podcast-creator/l10n/el.json +5 -0
- package/templates/podcast-creator/l10n/es.json +5 -0
- package/templates/podcast-creator/l10n/fi.json +5 -0
- package/templates/podcast-creator/l10n/fr.json +5 -0
- package/templates/podcast-creator/l10n/he.json +4 -0
- package/templates/podcast-creator/l10n/hu.json +5 -0
- package/templates/podcast-creator/l10n/id.json +5 -0
- package/templates/podcast-creator/l10n/it.json +5 -0
- package/templates/podcast-creator/l10n/ja.json +5 -0
- package/templates/podcast-creator/l10n/ko.json +5 -0
- package/templates/podcast-creator/l10n/lt.json +5 -0
- package/templates/podcast-creator/l10n/nl.json +5 -0
- package/templates/podcast-creator/l10n/no.json +5 -0
- package/templates/podcast-creator/l10n/pl.json +5 -0
- package/templates/podcast-creator/l10n/pt.json +5 -0
- package/templates/podcast-creator/l10n/ru.json +5 -0
- package/templates/podcast-creator/l10n/sv.json +5 -0
- package/templates/podcast-creator/l10n/th.json +5 -0
- package/templates/podcast-creator/l10n/tr.json +5 -0
- package/templates/podcast-creator/l10n/uk.json +5 -0
- package/templates/podcast-creator/l10n/vi.json +5 -0
- package/templates/podcast-creator/l10n/zh.json +5 -0
- package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/podcast-creator/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/podcast-creator/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/portfolio-creative/tier5-src/_shared/himi-store-facets.ts +4 -4
- package/templates/portfolio-creative/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-cart/index.ts +13 -7
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-category/index.ts +6 -1
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-shop/index.ts +9 -3
- package/templates/portfolio-creative/tier5-src/himi-store-product/index.ts +7 -5
- package/templates/portfolio-creative/tier5-src/himi-store-saved/index.ts +31 -12
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/professional-services/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/restaurant/l10n/ar.json +5 -0
- package/templates/restaurant/l10n/cs.json +5 -0
- package/templates/restaurant/l10n/da.json +5 -0
- package/templates/restaurant/l10n/de.json +5 -0
- package/templates/restaurant/l10n/el.json +5 -0
- package/templates/restaurant/l10n/es.json +5 -0
- package/templates/restaurant/l10n/fi.json +5 -0
- package/templates/restaurant/l10n/fr.json +5 -0
- package/templates/restaurant/l10n/he.json +4 -0
- package/templates/restaurant/l10n/hu.json +5 -0
- package/templates/restaurant/l10n/id.json +5 -0
- package/templates/restaurant/l10n/it.json +5 -0
- package/templates/restaurant/l10n/ja.json +5 -0
- package/templates/restaurant/l10n/ko.json +5 -0
- package/templates/restaurant/l10n/lt.json +5 -0
- package/templates/restaurant/l10n/nl.json +5 -0
- package/templates/restaurant/l10n/no.json +5 -0
- package/templates/restaurant/l10n/pl.json +5 -0
- package/templates/restaurant/l10n/pt.json +5 -0
- package/templates/restaurant/l10n/ru.json +5 -0
- package/templates/restaurant/l10n/sv.json +5 -0
- package/templates/restaurant/l10n/th.json +5 -0
- package/templates/restaurant/l10n/tr.json +5 -0
- package/templates/restaurant/l10n/uk.json +5 -0
- package/templates/restaurant/l10n/vi.json +5 -0
- package/templates/restaurant/l10n/zh.json +5 -0
- package/templates/restaurant/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/restaurant/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/restaurant/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/retail-store/tier5-src/_shared/collection-service.ts +42 -19
- package/templates/retail-store/tier5-src/_shared/himi-store-facets.ts +4 -4
- package/templates/retail-store/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/retail-store/tier5-src/himi-branded-lite-cart/index.ts +13 -7
- package/templates/retail-store/tier5-src/himi-branded-lite-category/index.ts +6 -1
- package/templates/retail-store/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/retail-store/tier5-src/himi-branded-lite-shop/index.ts +9 -3
- package/templates/retail-store/tier5-src/himi-store-product/index.ts +32 -15
- package/templates/retail-store/tier5-src/himi-store-saved/index.ts +31 -12
- package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/salon-spa/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/wholesale-store/dev/index.ts +2 -2
- package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +42 -19
- package/templates/wholesale-store/tier5-src/_shared/himi-store-collection.ts +7 -3
- package/templates/wholesale-store/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/wholesale-store/tier5-src/himi-branded-lite-cart/index.ts +13 -7
- package/templates/wholesale-store/tier5-src/himi-store-product/index.ts +32 -15
- package/templates/wholesale-store/tier5-src/himi-store-saved/index.ts +31 -12
- package/templates/wholesale-store/tier5-src/himi-wholesale-home/index.ts +19 -8
- package/templates/yoga-studio/l10n/ar.json +5 -0
- package/templates/yoga-studio/l10n/cs.json +5 -0
- package/templates/yoga-studio/l10n/da.json +5 -0
- package/templates/yoga-studio/l10n/de.json +5 -0
- package/templates/yoga-studio/l10n/el.json +5 -0
- package/templates/yoga-studio/l10n/es.json +5 -0
- package/templates/yoga-studio/l10n/fi.json +5 -0
- package/templates/yoga-studio/l10n/fr.json +5 -0
- package/templates/yoga-studio/l10n/he.json +4 -0
- package/templates/yoga-studio/l10n/hu.json +5 -0
- package/templates/yoga-studio/l10n/id.json +5 -0
- package/templates/yoga-studio/l10n/it.json +5 -0
- package/templates/yoga-studio/l10n/ja.json +5 -0
- package/templates/yoga-studio/l10n/ko.json +5 -0
- package/templates/yoga-studio/l10n/lt.json +5 -0
- package/templates/yoga-studio/l10n/nl.json +5 -0
- package/templates/yoga-studio/l10n/no.json +5 -0
- package/templates/yoga-studio/l10n/pl.json +5 -0
- package/templates/yoga-studio/l10n/pt.json +5 -0
- package/templates/yoga-studio/l10n/ru.json +5 -0
- package/templates/yoga-studio/l10n/sv.json +5 -0
- package/templates/yoga-studio/l10n/th.json +5 -0
- package/templates/yoga-studio/l10n/tr.json +5 -0
- package/templates/yoga-studio/l10n/uk.json +5 -0
- package/templates/yoga-studio/l10n/vi.json +5 -0
- package/templates/yoga-studio/l10n/zh.json +5 -0
- package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +35 -15
- package/templates/yoga-studio/tier5-src/_shared/himi-store-saved.ts +275 -13
- package/templates/yoga-studio/tier5-src/himi-branded-lite-home/index.ts +6 -5
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +35 -15
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
// Saved products
|
|
1
|
+
// Saved products ("wishlist"). A signed-in member's list is their Wix account wishlist (eCommerce
|
|
2
|
+
// Wishlists, the list the Wix site and the One App show), so a product saved anywhere shows here.
|
|
3
|
+
// A visitor's list stays on this device in the host's durable, app-scoped KV, shared by screen workers.
|
|
4
|
+
// The two never mix: a member never sees the device list, and signing in copies nothing to the account.
|
|
2
5
|
// Adapted from Hip Shop; a failed write must never claim that a save succeeded.
|
|
6
|
+
//
|
|
7
|
+
// Each worker keeps the member's list as last read (`syncSavedProducts`), so the synchronous readers
|
|
8
|
+
// (`readSavedProducts`, `isProductSaved`) answer for whoever was signed in at that read. Call
|
|
9
|
+
// `syncSavedProducts` in a load before reading, and `listSavedProducts` where the list is shown.
|
|
10
|
+
import { addWishlistItem, getDefaultWishlist, removeWishlistItem, type WixWishlist, type WixWishlistCatalogReference } from "@himalaya/wix-ecom";
|
|
11
|
+
import { productImage, productPrice, searchStoreProducts, type StoreProduct } from "./himi-store.js";
|
|
12
|
+
import { cleanTitle } from "./himi-text.js";
|
|
13
|
+
// The identity read is `member-access.ts`'s, inlined: that module imports @himalaya/wix-users, which node (tests
|
|
14
|
+
// importing shared sources) cannot resolve, so its legacy rung calls the same route through the ecom bridge.
|
|
15
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
16
|
+
import { wixCall } from "@himalaya/wix-ecom";
|
|
17
|
+
|
|
3
18
|
export interface SavedProduct {
|
|
4
19
|
id: string;
|
|
5
20
|
name: string;
|
|
@@ -10,13 +25,19 @@ export interface SavedProduct {
|
|
|
10
25
|
}
|
|
11
26
|
type StorageLike = { getItem(key: string): string | null; setItem(key: string, value: string): void };
|
|
12
27
|
const KEY = "himi-store:saved-products:v1";
|
|
28
|
+
/** The Wix Stores app id. The One App and the account wishlist hold Stores products under it. */
|
|
29
|
+
const STORES_APP_ID = "1380b703-ce81-ff05-f115-39571d94dfcd";
|
|
30
|
+
/** The Stores catalog id eCommerce uses in cart and order references: a product saved under it is a Stores product too. */
|
|
31
|
+
const STORES_CATALOG_ID = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
|
|
32
|
+
const STORES_APPS = new Set([STORES_APP_ID, STORES_CATALOG_ID]);
|
|
33
|
+
|
|
13
34
|
function storage(): StorageLike {
|
|
14
35
|
const host = globalThis as { himalaya?: { storage?: StorageLike }; localStorage?: StorageLike };
|
|
15
36
|
const kv = host.himalaya?.storage ?? host.localStorage;
|
|
16
37
|
if (!kv) throw new Error("Saved-product storage is unavailable");
|
|
17
38
|
return kv;
|
|
18
39
|
}
|
|
19
|
-
|
|
40
|
+
function readDeviceProducts(): SavedProduct[] {
|
|
20
41
|
const raw = storage().getItem(KEY);
|
|
21
42
|
if (!raw) return [];
|
|
22
43
|
const parsed: unknown = JSON.parse(raw);
|
|
@@ -34,10 +55,7 @@ export function readSavedProducts(): SavedProduct[] {
|
|
|
34
55
|
}
|
|
35
56
|
return [...rows.values()];
|
|
36
57
|
}
|
|
37
|
-
|
|
38
|
-
return readSavedProducts().some(row => row.id === id);
|
|
39
|
-
}
|
|
40
|
-
export function writeSavedProducts(rows: SavedProduct[]): void {
|
|
58
|
+
function writeDeviceProducts(rows: SavedProduct[]): void {
|
|
41
59
|
const kv = storage();
|
|
42
60
|
const value = JSON.stringify(rows);
|
|
43
61
|
kv.setItem(KEY, value);
|
|
@@ -45,13 +63,257 @@ export function writeSavedProducts(rows: SavedProduct[]): void {
|
|
|
45
63
|
// before displaying success; a missing/mismatched read is a failed save.
|
|
46
64
|
if (kv.getItem(KEY) !== value) throw new Error("Saved-product write did not persist");
|
|
47
65
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
|
|
67
|
+
// ---- The signed-in member's account wishlist, as this worker last read it ----
|
|
68
|
+
|
|
69
|
+
interface MemberList {
|
|
70
|
+
/** Whose list: the site partition and the member, from `currentKey`. */
|
|
71
|
+
key: string;
|
|
72
|
+
/** Saved product ids, newest first. */
|
|
73
|
+
ids: string[];
|
|
74
|
+
/** The references each id is saved under: a variant saved on the website is its own item. */
|
|
75
|
+
refs: Map<string, WixWishlistCatalogReference[]>;
|
|
76
|
+
/** Product details for the ids, from the catalog or from the control that saved it. */
|
|
77
|
+
details: Map<string, SavedProduct>;
|
|
78
|
+
}
|
|
79
|
+
/** Whose list this worker answers, from its last read. Until a read says, nothing is saved: the device
|
|
80
|
+
* list may be a visitor's, and must never show for a member. */
|
|
81
|
+
let mode: "device" | "member" | undefined;
|
|
82
|
+
let member: MemberList | undefined;
|
|
83
|
+
/** Identity reads in flight. While one is, the synchronous readers answer nothing: the cached list may be
|
|
84
|
+
* the previous member's, or a visitor's, and a grid deriving its hearts now must not show it to whoever
|
|
85
|
+
* signed in since. */
|
|
86
|
+
let resolving = 0;
|
|
87
|
+
/** The newest `syncSavedProducts` call. An older read that lands after it never applies its answer. */
|
|
88
|
+
let syncGen = 0;
|
|
89
|
+
let latestSync: Promise<void> | undefined;
|
|
90
|
+
/** Bumped by every account write: a read that started before one never overwrites what it changed. */
|
|
91
|
+
let memberWrites = 0;
|
|
92
|
+
/** A toggle per product at a time: a second tap while the first is on the wire would read the same state. */
|
|
93
|
+
const toggles = new Map<string, Promise<boolean>>();
|
|
94
|
+
|
|
95
|
+
/** The error `member-access.ts`'s `memberAccessDenied` recognizes: the member changed under a read or write. */
|
|
96
|
+
function memberAccessChanged(): Error {
|
|
97
|
+
const error = new Error("Member access changed"); error.name = "MemberAccessChanged"; return error;
|
|
98
|
+
}
|
|
99
|
+
/** The member's email from the host, or "" for a visitor. A host without the identity action (an older
|
|
100
|
+
* binary) or one that fails it falls back, as `memberAccess` does, to the signed-in profile: only a 401 there
|
|
101
|
+
* says "visitor". Any other failure throws, so it is never read as a visitor and never answers the device list. */
|
|
102
|
+
async function signedInEmail(): Promise<{ signedIn: boolean; email: string }> {
|
|
103
|
+
type Identity = { status?: unknown; ok?: unknown; email?: unknown; signedIn?: unknown; payload?: { email?: unknown; signedIn?: unknown } } | null;
|
|
104
|
+
try {
|
|
105
|
+
const value = await dispatch("himi.wix.memberIdentity") as Identity;
|
|
106
|
+
if (value?.status === "error" || value?.ok === false) throw value;
|
|
107
|
+
const raw = value?.email ?? value?.payload?.email;
|
|
108
|
+
const email = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
109
|
+
return { signedIn: (value?.signedIn ?? value?.payload?.signedIn) === true || !!email, email };
|
|
110
|
+
} catch { /* the legacy rung below */ }
|
|
111
|
+
// No Wix bridge, no Wix session: nobody can be signed in.
|
|
112
|
+
if (!(globalThis as { himalaya?: { wixApi?: unknown } }).himalaya?.wixApi) return { signedIn: false, email: "" };
|
|
113
|
+
try {
|
|
114
|
+
const profile = await wixCall<{ email?: unknown; contactEmail?: unknown }>("GET", "https://users.wix.com/wix-users/v1/users/my-data?includeProfile=true");
|
|
115
|
+
const raw = profile?.email ?? profile?.contactEmail;
|
|
116
|
+
const email = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
117
|
+
return { signedIn: !!email, email };
|
|
118
|
+
} catch (error) {
|
|
119
|
+
const failure = error as { status?: unknown; statusCode?: unknown; code?: unknown; message?: unknown } | null;
|
|
120
|
+
const anonymous = failure?.status === 401 || failure?.statusCode === 401 || failure?.code === "UNAUTHENTICATED"
|
|
121
|
+
|| /^HTTP\s*401\b/i.test(String(failure?.message ?? ""));
|
|
122
|
+
// A web bridge refuses the owner-scoped profile route outright (`webwix_owner_only`): that host cannot tell
|
|
123
|
+
// through this rung, as `memberAccess` reads it too, so its session is a visitor's, never an error.
|
|
124
|
+
const ownerOnly = failure?.code === "webwix_owner_only";
|
|
125
|
+
if (anonymous || ownerOnly) return { signedIn: false, email: "" };
|
|
126
|
+
throw new Error("Who is signed in could not be read", { cause: error });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** Who is signed in, as a key for their list: the host's account and site partition plus the member's
|
|
130
|
+
* email; undefined for a visitor. Throws when it cannot tell. */
|
|
131
|
+
async function currentKey(): Promise<string | undefined> {
|
|
132
|
+
const { signedIn, email } = await signedInEmail();
|
|
133
|
+
if (!signedIn) return undefined;
|
|
134
|
+
const input = (globalThis as { himalaya?: { input?: Record<string, unknown> } }).himalaya?.input;
|
|
135
|
+
return JSON.stringify([input?.__himiPreferenceAccount ?? "", input?.__himiPreferenceBusiness ?? "", email]);
|
|
136
|
+
}
|
|
137
|
+
async function assertKey(key: string): Promise<void> {
|
|
138
|
+
if ((await currentKey()) !== key) throw memberAccessChanged();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function applyWishlist(key: string, wishlist: WixWishlist | undefined): void {
|
|
142
|
+
const items = [...(wishlist?.items ?? [])].sort((a, b) => Date.parse(b.addedDate ?? "") - Date.parse(a.addedDate ?? "") || 0);
|
|
143
|
+
const refs = new Map<string, WixWishlistCatalogReference[]>();
|
|
144
|
+
for (const item of items) {
|
|
145
|
+
const ref = item.catalogReference;
|
|
146
|
+
const id = typeof ref?.catalogItemId === "string" ? ref.catalogItemId.trim() : "";
|
|
147
|
+
if (!id || !STORES_APPS.has(ref?.appId ?? "")) continue;
|
|
148
|
+
refs.set(id, [...(refs.get(id) ?? []), ref!]);
|
|
149
|
+
}
|
|
150
|
+
const details = member?.key === key ? member.details : new Map<string, SavedProduct>();
|
|
151
|
+
member = { key, ids: [...refs.keys()], refs, details };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Resolve who is signed in and, for a member, read their account wishlist. A visitor's reads then
|
|
156
|
+
* answer the device list. Throws when the member's wishlist cannot be read; the synchronous readers
|
|
157
|
+
* then answer nothing for that member (never the device list), so a heart shows unsaved until a retry.
|
|
158
|
+
* A read that finishes after the member changed is read again for whoever is signed in now.
|
|
159
|
+
*/
|
|
160
|
+
export function syncSavedProducts(): Promise<void> {
|
|
161
|
+
const gen = ++syncGen;
|
|
162
|
+
const run = runSync(gen);
|
|
163
|
+
latestSync = run;
|
|
164
|
+
return run;
|
|
165
|
+
}
|
|
166
|
+
async function runSync(gen: number): Promise<void> {
|
|
167
|
+
let memberChanged = false;
|
|
168
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
169
|
+
let key: string | undefined;
|
|
170
|
+
resolving++;
|
|
171
|
+
try {
|
|
172
|
+
// Unknown identity: nothing is answered (never the device list) until a read can tell.
|
|
173
|
+
try { key = await currentKey(); } catch (error) { mode = undefined; member = undefined; throw error; }
|
|
174
|
+
if (key === undefined) { mode = "device"; member = undefined; return; }
|
|
175
|
+
mode = "member";
|
|
176
|
+
if (member?.key !== key) member = { key, ids: [], refs: new Map(), details: new Map() };
|
|
177
|
+
} finally { resolving--; }
|
|
178
|
+
const writes = memberWrites;
|
|
179
|
+
const { wishlist } = await getDefaultWishlist();
|
|
180
|
+
// A newer read started while this one was on the wire: its answer is the newer one. Wait for it.
|
|
181
|
+
if (gen !== syncGen && latestSync) return latestSync;
|
|
182
|
+
memberChanged = (await currentKey()) !== key;
|
|
183
|
+
// A save that landed while this read was on the wire is newer than it: read again.
|
|
184
|
+
if (memberChanged || writes !== memberWrites) continue;
|
|
185
|
+
applyWishlist(key, wishlist);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
throw memberChanged ? memberAccessChanged() : new Error("Saved products changed while they were read");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function detailsOf(p: StoreProduct): SavedProduct {
|
|
192
|
+
const name = cleanTitle(p.name ?? "") || "Product";
|
|
193
|
+
return { id: p.id ?? "", name, price: productPrice(p), image: productImage(p) };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The saved list as the saved-products screen and the wishlist sections show it. A member's ids come
|
|
197
|
+
* from their account wishlist and the details from the catalog; a product the store no longer has is
|
|
198
|
+
* left out. A visitor's list is the device list. */
|
|
199
|
+
export async function listSavedProducts(): Promise<SavedProduct[]> {
|
|
200
|
+
await syncSavedProducts();
|
|
201
|
+
if (mode !== "member" || !member) return readDeviceProducts();
|
|
202
|
+
const list = member;
|
|
203
|
+
if (list.ids.length) {
|
|
204
|
+
// A wishlist holds at most 100 items: one page. Fresh details every time, so a price change shows.
|
|
205
|
+
const { products } = await searchStoreProducts({ ids: list.ids, limit: 100 });
|
|
206
|
+
await assertKey(list.key);
|
|
207
|
+
const found = new Map((products ?? []).map(p => [p.id ?? "", p]));
|
|
208
|
+
for (const id of list.ids) {
|
|
209
|
+
const product = found.get(id);
|
|
210
|
+
if (product) list.details.set(id, { ...list.details.get(id), ...detailsOf(product) });
|
|
211
|
+
else list.details.delete(id);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return list.ids.flatMap(id => list.details.get(id) ?? []);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** The saved list as this worker last read it (see `syncSavedProducts`): empty before the first read.
|
|
218
|
+
* A member's product whose details were never read has an empty name: read ids from it, list with
|
|
219
|
+
* `listSavedProducts`. */
|
|
220
|
+
export function readSavedProducts(): SavedProduct[] {
|
|
221
|
+
if (mode === undefined || resolving > 0) return [];
|
|
222
|
+
if (mode === "member") {
|
|
223
|
+
const list = member;
|
|
224
|
+
if (!list) return [];
|
|
225
|
+
return list.ids.map(id => list.details.get(id) ?? { id, name: "", price: "", image: "" });
|
|
226
|
+
}
|
|
227
|
+
return readDeviceProducts();
|
|
228
|
+
}
|
|
229
|
+
export function isProductSaved(id: string): boolean {
|
|
230
|
+
if (mode === undefined || resolving > 0) return false;
|
|
231
|
+
if (mode === "member") return !!member?.ids.includes(id);
|
|
232
|
+
return readDeviceProducts().some(row => row.id === id);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function memberKeyForWrite(): Promise<string | undefined> {
|
|
236
|
+
const key = await currentKey();
|
|
237
|
+
if (key === undefined) { mode = "device"; member = undefined; return undefined; }
|
|
238
|
+
if (mode !== "member" || member?.key !== key) await syncSavedProducts();
|
|
239
|
+
if (member?.key !== key) throw memberAccessChanged();
|
|
240
|
+
return key;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Save or unsave one product in the member's account wishlist. The control's own state is not trusted:
|
|
244
|
+
* an unsave removes every reference the product is saved under. Throws when the member changed during
|
|
245
|
+
* the write, so the caller reloads for whoever is signed in now. */
|
|
246
|
+
async function writeMemberProduct(key: string, product: SavedProduct, saved: boolean): Promise<void> {
|
|
247
|
+
const list = member!;
|
|
248
|
+
const refs = saved ? [{ catalogItemId: product.id, appId: STORES_APP_ID }] : list.refs.get(product.id) ?? [{ catalogItemId: product.id, appId: STORES_APP_ID }];
|
|
249
|
+
let wishlist: WixWishlist | undefined;
|
|
250
|
+
memberWrites++;
|
|
251
|
+
try {
|
|
252
|
+
for (const ref of refs) wishlist = (saved ? await addWishlistItem(ref) : await removeWishlistItem(ref)).wishlist ?? wishlist;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
// A refusal that lands after the member changed is the member change, so the caller reloads for whoever
|
|
255
|
+
// is signed in now; for the same member it is a failed write.
|
|
256
|
+
if ((await currentKey().catch(() => undefined)) !== key) throw memberAccessChanged();
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
await assertKey(key);
|
|
260
|
+
if (wishlist) applyWishlist(key, wishlist);
|
|
261
|
+
else if (saved) { list.ids = [product.id, ...list.ids.filter(id => id !== product.id)]; list.refs.set(product.id, refs); }
|
|
262
|
+
else { list.ids = list.ids.filter(id => id !== product.id); list.refs.delete(product.id); }
|
|
263
|
+
if (saved && product.name.trim()) member!.details.set(product.id, product);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Replace the whole saved list (a collection's multi-select save). A member's account wishlist gets
|
|
267
|
+
* only the difference; a visitor's device list is written as given. */
|
|
268
|
+
export async function writeSavedProducts(rows: SavedProduct[]): Promise<void> {
|
|
269
|
+
const key = await memberKeyForWrite();
|
|
270
|
+
if (key === undefined) { writeDeviceProducts(rows); return; }
|
|
271
|
+
const wanted = new Map(rows.map(row => [row.id, row]));
|
|
272
|
+
for (const id of [...member!.ids]) if (!wanted.has(id)) await writeMemberProduct(key, { id, name: "", price: "", image: "" }, false);
|
|
273
|
+
for (const row of [...rows].reverse()) if (!member!.ids.includes(row.id)) await writeMemberProduct(key, row, true);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Save or unsave a product; answers the new saved state. A member's save is in their account wishlist. */
|
|
277
|
+
export function toggleSavedProduct(product: SavedProduct): Promise<boolean> {
|
|
278
|
+
if (!product.id.trim() || !product.name.trim()) return Promise.reject(new Error("No product to save"));
|
|
279
|
+
const pending = toggles.get(product.id);
|
|
280
|
+
if (pending) return pending;
|
|
281
|
+
const toggle = toggleOnce(product).finally(() => toggles.delete(product.id));
|
|
282
|
+
toggles.set(product.id, toggle);
|
|
283
|
+
return toggle;
|
|
284
|
+
}
|
|
285
|
+
async function toggleOnce(product: SavedProduct): Promise<boolean> {
|
|
286
|
+
const key = await memberKeyForWrite();
|
|
287
|
+
if (key === undefined) {
|
|
288
|
+
const rows = readDeviceProducts();
|
|
289
|
+
const saved = !rows.some(row => row.id === product.id);
|
|
290
|
+
writeDeviceProducts(saved ? [product, ...rows] : rows.filter(row => row.id !== product.id));
|
|
291
|
+
return saved;
|
|
292
|
+
}
|
|
293
|
+
const saved = !member!.ids.includes(product.id);
|
|
294
|
+
await writeMemberProduct(key, product, saved);
|
|
53
295
|
return saved;
|
|
54
296
|
}
|
|
55
|
-
export function removeSavedProduct(id: string): void {
|
|
56
|
-
|
|
297
|
+
export async function removeSavedProduct(id: string): Promise<void> {
|
|
298
|
+
const key = await memberKeyForWrite();
|
|
299
|
+
if (key === undefined) { writeDeviceProducts(readDeviceProducts().filter(row => row.id !== id)); return; }
|
|
300
|
+
await writeMemberProduct(key, { id, name: "", price: "", image: "" }, false);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Tests only: forget the member list this worker read. */
|
|
304
|
+
export function __resetSavedProductsForTests(): void { mode = undefined; member = undefined; toggles.clear(); }
|
|
305
|
+
|
|
306
|
+
/** Read the saved list in the background and, when the saved ids changed, run `apply` (a grid's re-derive of
|
|
307
|
+
* its CURRENT state), so hearts follow the signed-in member without holding the page. A failed read leaves the
|
|
308
|
+
* hearts as the last read left them (unsaved for a member never read). */
|
|
309
|
+
export function refreshSavedThen(apply: () => unknown): void {
|
|
310
|
+
// Storage a host does not offer is no saved product: hearts are optional, a failure never fails the screen.
|
|
311
|
+
const ids = () => { try { return JSON.stringify(readSavedProducts().map(row => row.id)); } catch { return "[]"; } };
|
|
312
|
+
const whose = () => `${mode ?? ""}:${member?.key ?? ""}`;
|
|
313
|
+
// Snapshot BEFORE the sync starts: once it does, the readers answer nothing until it knows who is signed in.
|
|
314
|
+
const before = ids(), beforeWhose = whose();
|
|
315
|
+
// Re-derive whenever a grid may show something else now: the list or its owner changed, or there are saves
|
|
316
|
+
// (a grid that derived while the identity read was in flight drew none). Only "nothing, as before" skips it.
|
|
317
|
+
const settle = () => { const now = ids(); if (now !== before || whose() !== beforeWhose || now !== "[]") apply(); };
|
|
318
|
+
void syncSavedProducts().then(settle, settle);
|
|
57
319
|
}
|
|
@@ -47,7 +47,7 @@ const WIX_STORES_APP_ID = "1380b703-ce81-ff05-f115-39571d94dfcd";
|
|
|
47
47
|
import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
48
48
|
import { getAll, upsert, remove as dbRemove, type DbEntity } from "@himalaya/local-db";
|
|
49
49
|
import { isOfflineFailure, writeMayHaveLanded } from "../_shared/owner-load-error.js";
|
|
50
|
-
import { isProductSaved, readSavedProducts, toggleSavedProduct } from "../_shared/himi-store-saved.js";
|
|
50
|
+
import { isProductSaved, readSavedProducts, refreshSavedThen, toggleSavedProduct } from "../_shared/himi-store-saved.js";
|
|
51
51
|
|
|
52
52
|
// Offline-first (data-offline): the cart is READ-THROUGH — paint the last-synced line
|
|
53
53
|
// items from the on-device `cart` entity first (instant, works offline), then
|
|
@@ -463,7 +463,8 @@ const svc = defineService<State, {
|
|
|
463
463
|
applyPromo: (state: State) => Promise<State>;
|
|
464
464
|
removePromo: (state: State) => Promise<State>;
|
|
465
465
|
remove: (state: State, arg?: unknown) => Promise<State>;
|
|
466
|
-
save: (state: State, arg?: unknown) => State
|
|
466
|
+
save: (state: State, arg?: unknown) => Promise<State>;
|
|
467
|
+
savedChanged: () => State;
|
|
467
468
|
increment: (state: State, arg?: unknown) => Promise<State>;
|
|
468
469
|
decrement: (state: State, arg?: unknown) => Promise<State>;
|
|
469
470
|
checkout: (state: State) => Promise<State>;
|
|
@@ -479,9 +480,14 @@ const svc = defineService<State, {
|
|
|
479
480
|
webSignedIn = (change as { signedIn?: unknown } | undefined)?.signedIn === true;
|
|
480
481
|
webGeneration++;
|
|
481
482
|
if (memberOnlyCart) queueSessionReload();
|
|
483
|
+
refreshSavedThen(() => svc.savedChanged());
|
|
482
484
|
return derive(state);
|
|
483
485
|
},
|
|
486
|
+
// The signed-in member's saved list landed: `derive` re-marks the hearts.
|
|
487
|
+
savedChanged: (): State => derive(svc.getState() as State),
|
|
484
488
|
load: async (state, arg) => {
|
|
489
|
+
// Hearts follow the signed-in member's account wishlist, read beside the cart.
|
|
490
|
+
refreshSavedThen(() => svc.savedChanged());
|
|
485
491
|
// A members-only cart (a site shell) never shows a signed-out shopper's native cart. `prepare` sets the flag
|
|
486
492
|
// before coalescing, so a load already in flight (the boot load) re-checks it before it lands.
|
|
487
493
|
if (memberOnlyArg(arg)) memberOnlyCart = true;
|
|
@@ -575,15 +581,15 @@ const svc = defineService<State, {
|
|
|
575
581
|
if (!id) return state;
|
|
576
582
|
return removeLine(state, id);
|
|
577
583
|
},
|
|
578
|
-
save: (state, arg) => {
|
|
584
|
+
save: async (state, arg): Promise<State> => {
|
|
579
585
|
const id = itemId(arg);
|
|
580
586
|
const item = state.items.find(candidate => candidate.id === id);
|
|
581
587
|
const productId = item?.catalogReference?.catalogItemId ?? item?.productId;
|
|
582
588
|
if (!item || !productId) return state;
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
589
|
+
// `derive` re-marks every row from the saved list, on the cart as it is once the write lands.
|
|
590
|
+
try { await toggleSavedProduct({ id: productId, name: item.name, price: item.unitPrice, wasPrice: item.wasPrice, image: item.image, swatches: item.swatches }); }
|
|
591
|
+
catch { return derive({ ...(svc.getState() as State), checkoutHint: copyParam("cart.saveError", "Could not save this item.") }); }
|
|
592
|
+
return derive(svc.getState() as State);
|
|
587
593
|
},
|
|
588
594
|
increment: async (state, arg) => {
|
|
589
595
|
const id = itemId(arg);
|
|
@@ -8,6 +8,7 @@ import { createCollectionQuery } from "../_shared/collection-query.js";
|
|
|
8
8
|
import { detailInputId, presence, presenceAfterError, type PresenceFlags } from "../_shared/detail-presence.js";
|
|
9
9
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
10
10
|
import { FACETS_BOOT, PAGE_SIZE, applyFacets, currencyOf, facetActions, idOf, readViewPrefs, tagFields, toRows, toggleSaved, type FacetState } from "../_shared/himi-store-facets.js";
|
|
11
|
+
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
11
12
|
import { withIapPresentation } from "../_shared/iap-presentation.js";
|
|
12
13
|
|
|
13
14
|
interface State extends FacetState, PresenceFlags {
|
|
@@ -109,6 +110,8 @@ const facets = facetActions<State>(derive);
|
|
|
109
110
|
const actions = {
|
|
110
111
|
load: async (s: State, arg?: unknown): Promise<State | undefined> => {
|
|
111
112
|
stashCopy(arg);
|
|
113
|
+
// Hearts follow the signed-in member's account wishlist, read beside the products.
|
|
114
|
+
refreshSavedThen(() => svc.savedChanged());
|
|
112
115
|
const version = ++loadVersion;
|
|
113
116
|
const id = detailInputId();
|
|
114
117
|
if (!id) return derive({ ...s, ...presence("missing"), loadId: version });
|
|
@@ -153,7 +156,9 @@ const actions = {
|
|
|
153
156
|
},
|
|
154
157
|
productsChanged: (s: State) => s.loadId === loadVersion ? derive(s) : undefined,
|
|
155
158
|
search: (s: State, arg?: { value?: string }) => derive({ ...s, query: (arg?.value ?? "").slice(0, 256), visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
|
|
156
|
-
toggleSave: (s: State, arg?: unknown) => { try { toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(
|
|
159
|
+
toggleSave: async (s: State, arg?: unknown): Promise<State> => { try { await toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(svc.getState() as State); },
|
|
160
|
+
// The signed-in member's saved list landed: re-mark the hearts.
|
|
161
|
+
savedChanged: (): State => derive(svc.getState() as State),
|
|
157
162
|
...facets,
|
|
158
163
|
clearSearch: (s: State) => derive({ ...s, query: "", priceSelected: [], opt1Selected: [], opt2Selected: [], opt3Selected: [], visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
|
|
159
164
|
toggleFacet: (s: State, arg?: { facet?: string; id?: string }) => {
|
|
@@ -33,7 +33,7 @@ import { groupMemberCount } from "../_shared/group-member-count.js";
|
|
|
33
33
|
import { parseWeeklyGoal, weeklyGoalProgress, weeklySessionsFromPages } from "../_shared/weekly-goal.js";
|
|
34
34
|
import { isBridgeUnavailable } from "../_shared/owner-load-error.js";
|
|
35
35
|
import { formatDateMedium } from "../_shared/engine-intl.js";
|
|
36
|
-
import {
|
|
36
|
+
import { listSavedProducts, type SavedProduct } from "../_shared/himi-store-saved.js";
|
|
37
37
|
import { loadStoreCategories, type StoreCategoryCard } from "../_shared/himi-store-categories.js";
|
|
38
38
|
import { readSavedIds } from "../_shared/himi-blog-saved.js";
|
|
39
39
|
import { withoutHidden } from "../_shared/himi-blog-hidden.js";
|
|
@@ -699,14 +699,15 @@ function savedPostCard(post: WixPost): SavedPostCard {
|
|
|
699
699
|
interface SavedSignal { savedProducts: SavedProductCard[]; savedPosts: SavedPostCard[]; }
|
|
700
700
|
function emptySavedSignal(): SavedSignal { return { savedProducts: [], savedPosts: [] }; }
|
|
701
701
|
|
|
702
|
-
/** Resolve supported
|
|
703
|
-
* in refreshPersonal(), so a visitor can never trigger
|
|
702
|
+
/** Resolve supported saves into public rails: saved products are a signed-in member's account wishlist,
|
|
703
|
+
* a visitor's device list. Member-only work remains in refreshPersonal(), so a visitor can never trigger
|
|
704
|
+
* a bookings query here. */
|
|
704
705
|
async function fetchSavedSignal(arg: unknown): Promise<SavedSignal> {
|
|
705
706
|
const verticals = parseVerticals(arg);
|
|
706
707
|
const signal = emptySavedSignal();
|
|
707
708
|
if (verticals.includes("store")) {
|
|
708
|
-
try { signal.savedProducts =
|
|
709
|
-
catch { /*
|
|
709
|
+
try { signal.savedProducts = (await listSavedProducts()).slice(0, 6).map(savedProductCard); }
|
|
710
|
+
catch { /* an unreadable list simply collapses the optional rail */ }
|
|
710
711
|
}
|
|
711
712
|
if (verticals.includes("blog")) {
|
|
712
713
|
let ids: string[] = [];
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
FACETS_BOOT, PAGE_SIZE, applyFacets, countText, currencyOf, facetActions, idOf, option, readViewPrefs, selected, tagFields, toRows, toggleSaved,
|
|
21
21
|
type FacetState, type Option, type Row,
|
|
22
22
|
} from "../_shared/himi-store-facets.js";
|
|
23
|
+
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
23
24
|
|
|
24
25
|
const ALL = "all";
|
|
25
26
|
const PAGE = 100;
|
|
@@ -481,6 +482,8 @@ function loadedState(s: S, arg?: unknown): S | undefined {
|
|
|
481
482
|
|
|
482
483
|
async function load(s: S, arg?: unknown, fresh = false): Promise<S | undefined> {
|
|
483
484
|
stashCopy(arg);
|
|
485
|
+
// Hearts follow the signed-in member's account wishlist, read beside the products.
|
|
486
|
+
refreshSavedThen(() => svc.savedChanged());
|
|
484
487
|
const route = input(arg);
|
|
485
488
|
const routeCategory = route.categoryId ?? route.category;
|
|
486
489
|
if (!fresh && routeCategory && (
|
|
@@ -733,10 +736,13 @@ const svc = register<S, Record<string, A>>("himiBrandedShop", {
|
|
|
733
736
|
if (query === s.query) return s;
|
|
734
737
|
return derive({ ...s, query, ...(query.trim() === s.query.trim() ? {} : { visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }) });
|
|
735
738
|
},
|
|
736
|
-
toggleSave: (s, arg) => {
|
|
737
|
-
try { toggleSaved(s.results, idOf(arg)); } catch { return s; }
|
|
738
|
-
|
|
739
|
+
toggleSave: async (s, arg): Promise<S> => {
|
|
740
|
+
try { await toggleSaved(s.results, idOf(arg)); } catch { return s; }
|
|
741
|
+
// The page as it is now: other actions may have run while the save was on the wire.
|
|
742
|
+
return derive(svc.getState() as S);
|
|
739
743
|
},
|
|
744
|
+
// The signed-in member's saved list landed: re-mark the hearts.
|
|
745
|
+
savedChanged: (): S => derive(svc.getState() as S),
|
|
740
746
|
...facets,
|
|
741
747
|
// The list view's load-more.
|
|
742
748
|
loadMore: (s) => facets.showMore(s),
|
|
@@ -18,7 +18,7 @@ import { cleanTitle } from "../_shared/himi-text.js";
|
|
|
18
18
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
19
19
|
import { isBridgeUnavailable } from "../_shared/owner-load-error.js";
|
|
20
20
|
import { logBi } from "../_shared/wix-bi.js";
|
|
21
|
-
import { isProductSaved, toggleSavedProduct } from "../_shared/himi-store-saved.js";
|
|
21
|
+
import { isProductSaved, syncSavedProducts, toggleSavedProduct } from "../_shared/himi-store-saved.js";
|
|
22
22
|
import { openRichLink } from "../_shared/rich-content-link.js";
|
|
23
23
|
import { descriptionBody } from "../_shared/rich-body.js";
|
|
24
24
|
import { PRODUCT_DETAIL_FIELDS, productInfoSections, type ProductInfoSection } from "../_shared/store-product-info.js";
|
|
@@ -85,6 +85,8 @@ function productPolicyBody(product: StoreProduct, kind: "returns" | "shipping"):
|
|
|
85
85
|
* DIFFERENT product (drop the picks) from the same product coming back (keep them). */
|
|
86
86
|
let lastLoadedId: string | undefined;
|
|
87
87
|
let productLoadSequence = 0;
|
|
88
|
+
/** Bumped by every heart tap: a load that started before one never overwrites the saved state it set. */
|
|
89
|
+
let saveEpoch = 0;
|
|
88
90
|
|
|
89
91
|
interface OptionSlots {
|
|
90
92
|
opt1Label: string; opt1Chips: OptionChip[]; opt1Selected: string[]; opt1SelectedId: string; opt1Placeholder: string; noOpt1: boolean;
|
|
@@ -537,7 +539,7 @@ const svc = onlineService<S, {
|
|
|
537
539
|
beginAdd: (s: S, arg?: unknown) => S;
|
|
538
540
|
setCartCount: (s: S, arg?: unknown) => S;
|
|
539
541
|
share: (s: S) => Promise<S>;
|
|
540
|
-
toggleSave: (s: S) => S
|
|
542
|
+
toggleSave: (s: S) => Promise<S>;
|
|
541
543
|
closeAddedSheet: (s: S) => S;
|
|
542
544
|
/** [rico] #3372 — RichContent's on_link: `{ url }` of the tapped link. */
|
|
543
545
|
openLink: (s: S, arg?: unknown) => Promise<S>;
|
|
@@ -640,9 +642,15 @@ const svc = onlineService<S, {
|
|
|
640
642
|
// A managed refresh retains the raw product used by the still-visible snapshot.
|
|
641
643
|
// Navigation and legacy loaders keep their existing reset behavior.
|
|
642
644
|
if (!readOptions(arg) || id !== lastLoadedId) lastProduct = undefined;
|
|
643
|
-
// Storage problems must not prevent browsing or buying a product.
|
|
644
|
-
|
|
645
|
-
|
|
645
|
+
// Storage problems must not prevent browsing or buying a product. A signed-in member's heart
|
|
646
|
+
// follows their account wishlist, read beside the product so it never holds the page.
|
|
647
|
+
// A failed read still answers for whoever is signed in now (nothing saved for a member whose list
|
|
648
|
+
// could not be read), never the flag a previous member left on this pooled worker.
|
|
649
|
+
const savedNow = (): boolean => { try { return isProductSaved(id); } catch { return false; } };
|
|
650
|
+
const epoch = saveEpoch;
|
|
651
|
+
const savedRead = syncSavedProducts().then(savedNow, savedNow);
|
|
652
|
+
// Read after the sync began: until it knows who is signed in, nothing shows as saved.
|
|
653
|
+
const saved = savedNow();
|
|
646
654
|
s = { ...s, saved, saveHint: "",
|
|
647
655
|
optionValidationTarget: "",
|
|
648
656
|
...(id !== lastLoadedId ? { adding: false, added: false, shareHint: "", addedSheetPresented: false, quantity: 1, showOptionErrors: false, optionValidationRequest: 0, galleryIndex: 0, returnPolicyExpanded: false, shippingInfoExpanded: false, infoSections: [] } : {}) };
|
|
@@ -711,9 +719,12 @@ const svc = onlineService<S, {
|
|
|
711
719
|
}
|
|
712
720
|
}
|
|
713
721
|
lastLoadedId = id;
|
|
722
|
+
const savedFlag = await savedRead;
|
|
723
|
+
if (sequence !== productLoadSequence || id !== inputId()) return svc.getState() as S;
|
|
714
724
|
return derive({
|
|
715
725
|
...base,
|
|
716
726
|
...keep,
|
|
727
|
+
...(epoch === saveEpoch ? { saved: savedFlag } : {}),
|
|
717
728
|
status: "ready",
|
|
718
729
|
optionGroups,
|
|
719
730
|
selection: { ...defaultSelection(optionGroups), ...carried },
|
|
@@ -859,18 +870,24 @@ const svc = onlineService<S, {
|
|
|
859
870
|
const confirmation = copyTemplate("product.cartHintAdded", "Added {name} to cart.", { name: s.name || "product" });
|
|
860
871
|
return derive({ ...s, adding: false, added: true, addedSheetPresented: true, cartHint: `${confirmation}${quantity > 1 ? ` Qty: ${quantity}` : ""}`, cartCount: count || s.cartCount });
|
|
861
872
|
},
|
|
862
|
-
|
|
863
|
-
|
|
873
|
+
// A member's save goes to their account wishlist.
|
|
874
|
+
toggleSave: async (s) => {
|
|
875
|
+
const id = inputId();
|
|
876
|
+
if (s.status !== "ready" || !s.name || !id) return s;
|
|
877
|
+
saveEpoch++;
|
|
878
|
+
let result: { saved: boolean } | undefined;
|
|
864
879
|
try {
|
|
865
880
|
const sale = lastProduct ? productSale(lastProduct) : { price: s.commercePrice ?? "", wasPrice: "" };
|
|
866
|
-
|
|
867
|
-
swatches: s.optionGroups.flatMap(g => g.kind === "color" ? g.choices.map(c => c.colorCode).filter(Boolean) : []).slice(0, 5) });
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
881
|
+
result = { saved: await toggleSavedProduct({ id, name: s.name, price: sale.price, wasPrice: sale.wasPrice, image: s.image,
|
|
882
|
+
swatches: s.optionGroups.flatMap(g => g.kind === "color" ? g.choices.map(c => c.colorCode).filter(Boolean) : []).slice(0, 5) }) };
|
|
883
|
+
} catch { /* reported below */ }
|
|
884
|
+
// Build on the page as it is now: the shopper may have changed the quantity meanwhile.
|
|
885
|
+
const now = svc.getState() as S;
|
|
886
|
+
if (inputId() !== id) return now;
|
|
887
|
+
if (!result) return derive({ ...now, saveHint: copyParam("product.saveError", "Could not save this change. Try again.") });
|
|
888
|
+
return derive({ ...now, saved: result.saved, saveHint: result.saved
|
|
889
|
+
? copyParam("product.saveSuccess", "Added to wishlist.")
|
|
890
|
+
: copyParam("product.saveRemoved", "Removed from wishlist.") });
|
|
874
891
|
},
|
|
875
892
|
share: async (s) => {
|
|
876
893
|
if (!s.name) return s;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { withIapPresentation } from "../_shared/iap-presentation.js";
|
|
2
2
|
import { withEmptyFlags } from "../_shared/empty-flags.js";
|
|
3
|
-
import {
|
|
3
|
+
import { listSavedProducts, removeSavedProduct, type SavedProduct } from "../_shared/himi-store-saved.js";
|
|
4
4
|
import { stashCopy, copyParam } from "../_shared/himi-copy.js";
|
|
5
5
|
|
|
6
6
|
interface Row extends SavedProduct {
|
|
@@ -23,8 +23,8 @@ interface S {
|
|
|
23
23
|
function shape(s: Pick<S, "status" | "rows" | "error">): S {
|
|
24
24
|
return { ...s, isLoading: s.status === "loading", notLoading: s.status !== "loading", notErrored: s.status !== "error", noEmpty: s.status !== "ready" || s.rows.length > 0, hasRows: s.rows.length > 0, emptyText: copyParam("savedProducts.empty", "Tap the heart on a product to add it to your wishlist.") };
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
return
|
|
26
|
+
function toRows(saved: SavedProduct[]): Row[] {
|
|
27
|
+
return saved.map(row => {
|
|
28
28
|
const swatches = (row.swatches ?? []).filter(value => /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(value)).slice(0, 5);
|
|
29
29
|
return { ...row, commercePrice: row.price, initial: row.name.slice(0, 1).toUpperCase(), hasImage: !!row.image, noImage: !row.image,
|
|
30
30
|
detailScreenId: "himi_product", notOnSale: !row.wasPrice, wasPriceEmpty: !!row.wasPrice, noSwatches: swatches.length === 0, noTagRow: !row.wasPrice && swatches.length === 0,
|
|
@@ -45,23 +45,42 @@ const defineService = withIapPresentation<S>({
|
|
|
45
45
|
return { ...row, price: next, wasPriceEmpty: !!row.wasPrice && !iapAdjusted, notOnSale: !row.wasPrice || iapAdjusted, noTagRow: (!row.wasPrice || iapAdjusted) && !row.swatches?.length };
|
|
46
46
|
}) }),
|
|
47
47
|
});
|
|
48
|
+
let reads = 0;
|
|
48
49
|
const svc = defineService<S, {
|
|
49
|
-
load: (s: S, arg?: unknown) => S
|
|
50
|
-
remove: (s: S, arg?: unknown) => S
|
|
50
|
+
load: (s: S, arg?: unknown) => Promise<S | undefined>;
|
|
51
|
+
remove: (s: S, arg?: unknown) => Promise<S | undefined>;
|
|
51
52
|
}>("himiStoreSaved", withEmptyFlags({
|
|
52
53
|
state: shape({ status: "loading", rows: [], error: "" }),
|
|
53
54
|
actions: {
|
|
54
|
-
|
|
55
|
+
// A signed-in member's list is their account wishlist; a visitor's is this device's.
|
|
56
|
+
// Only the latest read lands: one started before a sign-out never paints over the one after it.
|
|
57
|
+
load: async (s, arg) => {
|
|
55
58
|
stashCopy(arg);
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
const read = ++reads;
|
|
60
|
+
try {
|
|
61
|
+
const rows = toRows(await listSavedProducts());
|
|
62
|
+
return read === reads ? shape({ status: "ready", rows, error: "" }) : undefined;
|
|
63
|
+
}
|
|
64
|
+
// A failed read never keeps rows that may belong to whoever was signed in before.
|
|
65
|
+
catch { return read === reads ? failed(shape({ ...s, rows: [] })) : undefined; }
|
|
58
66
|
},
|
|
59
|
-
remove: (s, arg) => {
|
|
67
|
+
remove: async (s, arg) => {
|
|
60
68
|
const id = typeof arg === "string" ? arg : String((arg as { id?: unknown } | undefined)?.id ?? "");
|
|
69
|
+
// A member change re-reads the list for whoever is signed in now.
|
|
70
|
+
let removed = true;
|
|
71
|
+
try { await removeSavedProduct(id); }
|
|
72
|
+
// Only a member change re-reads the list; a refusal for the same member is a failed remove, and says so.
|
|
73
|
+
catch (error) { if ((error as { name?: string } | null)?.name !== "MemberAccessChanged") return failed(s); removed = false; }
|
|
74
|
+
const read = ++reads;
|
|
61
75
|
try {
|
|
62
|
-
|
|
63
|
-
return shape({ status: "ready", rows
|
|
64
|
-
} catch
|
|
76
|
+
const rows = toRows(await listSavedProducts());
|
|
77
|
+
return read === reads ? shape({ status: "ready", rows, error: "" }) : undefined;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (read !== reads) return undefined;
|
|
80
|
+
if (!removed || (error as { name?: string } | null)?.name === "MemberAccessChanged") return failed(shape({ ...s, rows: [] }));
|
|
81
|
+
// The remove landed: drop the row even when the list cannot be read again.
|
|
82
|
+
return shape({ ...s, status: "ready", rows: s.rows.filter(row => row.id !== id), error: "" });
|
|
83
|
+
}
|
|
65
84
|
},
|
|
66
85
|
},
|
|
67
86
|
}, { rows: "noRows" }));
|