@wix/himalaya-cli 0.1858.0 → 0.1860.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/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{b2b76cc19f21f7c6d8b1a3cd6aa1ac0f194b052fa183761d08bd4f43fd46f844.bin → a60c092217d4c21970ff66e8b63221007e49d0792eb9d5fe66238f8efbce884a.bin} +1 -1
- package/dist/browser-plane/sw.js +7 -7
- package/dist/cli.mjs +633 -335
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/one-app-to-himi-app.md +2 -1
- package/guides/testing-himi-apps.md +4 -5
- package/package.json +2 -2
- package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/beauty-salon/l10n/ar.json +0 -5
- package/templates/beauty-salon/l10n/cs.json +0 -5
- package/templates/beauty-salon/l10n/da.json +0 -5
- package/templates/beauty-salon/l10n/de.json +0 -5
- package/templates/beauty-salon/l10n/el.json +0 -5
- package/templates/beauty-salon/l10n/en.json +1 -6
- package/templates/beauty-salon/l10n/es.json +0 -5
- package/templates/beauty-salon/l10n/fi.json +0 -5
- package/templates/beauty-salon/l10n/fr.json +0 -5
- package/templates/beauty-salon/l10n/he.json +0 -5
- package/templates/beauty-salon/l10n/hu.json +0 -5
- package/templates/beauty-salon/l10n/id.json +0 -5
- package/templates/beauty-salon/l10n/it.json +0 -5
- package/templates/beauty-salon/l10n/ja.json +0 -5
- package/templates/beauty-salon/l10n/ko.json +0 -5
- package/templates/beauty-salon/l10n/lt.json +0 -5
- package/templates/beauty-salon/l10n/nl.json +0 -5
- package/templates/beauty-salon/l10n/no.json +0 -5
- package/templates/beauty-salon/l10n/pl.json +0 -5
- package/templates/beauty-salon/l10n/pt.json +0 -5
- package/templates/beauty-salon/l10n/ru.json +0 -5
- package/templates/beauty-salon/l10n/sv.json +0 -5
- package/templates/beauty-salon/l10n/th.json +0 -5
- package/templates/beauty-salon/l10n/tr.json +0 -5
- package/templates/beauty-salon/l10n/uk.json +0 -5
- package/templates/beauty-salon/l10n/vi.json +0 -5
- package/templates/beauty-salon/l10n/zh.json +0 -5
- package/templates/beauty-salon/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/branded-lite/dev/index.ts +3148 -2899
- package/templates/branded-lite/l10n/ar.json +181 -87
- package/templates/branded-lite/l10n/cs.json +181 -87
- package/templates/branded-lite/l10n/da.json +181 -87
- package/templates/branded-lite/l10n/de.json +181 -87
- package/templates/branded-lite/l10n/el.json +181 -87
- package/templates/branded-lite/l10n/en.json +105 -37
- package/templates/branded-lite/l10n/es.json +181 -87
- package/templates/branded-lite/l10n/fi.json +181 -87
- package/templates/branded-lite/l10n/fr.json +181 -87
- package/templates/branded-lite/l10n/he.json +150 -77
- package/templates/branded-lite/l10n/hu.json +181 -87
- package/templates/branded-lite/l10n/id.json +181 -87
- package/templates/branded-lite/l10n/it.json +181 -87
- package/templates/branded-lite/l10n/ja.json +181 -87
- package/templates/branded-lite/l10n/ko.json +181 -87
- package/templates/branded-lite/l10n/lt.json +181 -87
- package/templates/branded-lite/l10n/nl.json +181 -87
- package/templates/branded-lite/l10n/no.json +181 -87
- package/templates/branded-lite/l10n/pl.json +181 -87
- package/templates/branded-lite/l10n/pt.json +181 -87
- package/templates/branded-lite/l10n/ru.json +181 -87
- package/templates/branded-lite/l10n/sv.json +181 -87
- package/templates/branded-lite/l10n/th.json +181 -87
- package/templates/branded-lite/l10n/tr.json +181 -87
- package/templates/branded-lite/l10n/uk.json +181 -87
- package/templates/branded-lite/l10n/vi.json +181 -87
- package/templates/branded-lite/l10n/zh.json +181 -87
- package/templates/branded-lite/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/branded-lite/tier5-src/_shared/loyalty-offerings.ts +23 -5
- package/templates/branded-lite/tier5-src/_shared/loyalty-status-section.ts +1 -1
- package/templates/branded-lite/tier5-src/himi-branded-lite-loyalty/index.ts +280 -99
- package/templates/branded-lite/tier5-src/himi-branded-lite-loyalty-rewards/index.ts +158 -43
- package/templates/brandy/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/community-club/l10n/ar.json +0 -5
- package/templates/community-club/l10n/cs.json +0 -5
- package/templates/community-club/l10n/da.json +0 -5
- package/templates/community-club/l10n/de.json +0 -5
- package/templates/community-club/l10n/el.json +0 -5
- package/templates/community-club/l10n/en.json +1 -6
- package/templates/community-club/l10n/es.json +0 -5
- package/templates/community-club/l10n/fi.json +0 -5
- package/templates/community-club/l10n/fr.json +0 -5
- package/templates/community-club/l10n/he.json +0 -5
- package/templates/community-club/l10n/hu.json +0 -5
- package/templates/community-club/l10n/id.json +0 -5
- package/templates/community-club/l10n/it.json +0 -5
- package/templates/community-club/l10n/ja.json +0 -5
- package/templates/community-club/l10n/ko.json +0 -5
- package/templates/community-club/l10n/lt.json +0 -5
- package/templates/community-club/l10n/nl.json +0 -5
- package/templates/community-club/l10n/no.json +0 -5
- package/templates/community-club/l10n/pl.json +0 -5
- package/templates/community-club/l10n/pt.json +0 -5
- package/templates/community-club/l10n/ru.json +0 -5
- package/templates/community-club/l10n/sv.json +0 -5
- package/templates/community-club/l10n/th.json +0 -5
- package/templates/community-club/l10n/tr.json +0 -5
- package/templates/community-club/l10n/uk.json +0 -5
- package/templates/community-club/l10n/vi.json +0 -5
- package/templates/community-club/l10n/zh.json +0 -5
- package/templates/community-club/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/community-club-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/conference/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/events-meetups/l10n/ar.json +0 -5
- package/templates/events-meetups/l10n/cs.json +0 -5
- package/templates/events-meetups/l10n/da.json +0 -5
- package/templates/events-meetups/l10n/de.json +0 -5
- package/templates/events-meetups/l10n/el.json +0 -5
- package/templates/events-meetups/l10n/en.json +1 -6
- package/templates/events-meetups/l10n/es.json +0 -5
- package/templates/events-meetups/l10n/fi.json +0 -5
- package/templates/events-meetups/l10n/fr.json +0 -5
- package/templates/events-meetups/l10n/he.json +0 -5
- package/templates/events-meetups/l10n/hu.json +0 -5
- package/templates/events-meetups/l10n/id.json +0 -5
- package/templates/events-meetups/l10n/it.json +0 -5
- package/templates/events-meetups/l10n/ja.json +0 -5
- package/templates/events-meetups/l10n/ko.json +0 -5
- package/templates/events-meetups/l10n/lt.json +0 -5
- package/templates/events-meetups/l10n/nl.json +0 -5
- package/templates/events-meetups/l10n/no.json +0 -5
- package/templates/events-meetups/l10n/pl.json +0 -5
- package/templates/events-meetups/l10n/pt.json +0 -5
- package/templates/events-meetups/l10n/ru.json +0 -5
- package/templates/events-meetups/l10n/sv.json +0 -5
- package/templates/events-meetups/l10n/th.json +0 -5
- package/templates/events-meetups/l10n/tr.json +0 -5
- package/templates/events-meetups/l10n/uk.json +0 -5
- package/templates/events-meetups/l10n/vi.json +0 -5
- package/templates/events-meetups/l10n/zh.json +0 -5
- package/templates/events-meetups/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/events-meetups-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/fitness-gym/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/gym-fitness/l10n/ar.json +0 -5
- package/templates/gym-fitness/l10n/cs.json +0 -5
- package/templates/gym-fitness/l10n/da.json +0 -5
- package/templates/gym-fitness/l10n/de.json +0 -5
- package/templates/gym-fitness/l10n/el.json +0 -5
- package/templates/gym-fitness/l10n/en.json +1 -6
- package/templates/gym-fitness/l10n/es.json +0 -5
- package/templates/gym-fitness/l10n/fi.json +0 -5
- package/templates/gym-fitness/l10n/fr.json +0 -5
- package/templates/gym-fitness/l10n/he.json +0 -5
- package/templates/gym-fitness/l10n/hu.json +0 -5
- package/templates/gym-fitness/l10n/id.json +0 -5
- package/templates/gym-fitness/l10n/it.json +0 -5
- package/templates/gym-fitness/l10n/ja.json +0 -5
- package/templates/gym-fitness/l10n/ko.json +0 -5
- package/templates/gym-fitness/l10n/lt.json +0 -5
- package/templates/gym-fitness/l10n/nl.json +0 -5
- package/templates/gym-fitness/l10n/no.json +0 -5
- package/templates/gym-fitness/l10n/pl.json +0 -5
- package/templates/gym-fitness/l10n/pt.json +0 -5
- package/templates/gym-fitness/l10n/ru.json +0 -5
- package/templates/gym-fitness/l10n/sv.json +0 -5
- package/templates/gym-fitness/l10n/th.json +0 -5
- package/templates/gym-fitness/l10n/tr.json +0 -5
- package/templates/gym-fitness/l10n/uk.json +0 -5
- package/templates/gym-fitness/l10n/vi.json +0 -5
- package/templates/gym-fitness/l10n/zh.json +0 -5
- package/templates/gym-fitness/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/medical-services/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/nonprofit-cause/l10n/ar.json +0 -5
- package/templates/nonprofit-cause/l10n/cs.json +0 -5
- package/templates/nonprofit-cause/l10n/da.json +0 -5
- package/templates/nonprofit-cause/l10n/de.json +0 -5
- package/templates/nonprofit-cause/l10n/el.json +0 -5
- package/templates/nonprofit-cause/l10n/en.json +1 -6
- package/templates/nonprofit-cause/l10n/es.json +0 -5
- package/templates/nonprofit-cause/l10n/fi.json +0 -5
- package/templates/nonprofit-cause/l10n/fr.json +0 -5
- package/templates/nonprofit-cause/l10n/he.json +0 -5
- package/templates/nonprofit-cause/l10n/hu.json +0 -5
- package/templates/nonprofit-cause/l10n/id.json +0 -5
- package/templates/nonprofit-cause/l10n/it.json +0 -5
- package/templates/nonprofit-cause/l10n/ja.json +0 -5
- package/templates/nonprofit-cause/l10n/ko.json +0 -5
- package/templates/nonprofit-cause/l10n/lt.json +0 -5
- package/templates/nonprofit-cause/l10n/nl.json +0 -5
- package/templates/nonprofit-cause/l10n/no.json +0 -5
- package/templates/nonprofit-cause/l10n/pl.json +0 -5
- package/templates/nonprofit-cause/l10n/pt.json +0 -5
- package/templates/nonprofit-cause/l10n/ru.json +0 -5
- package/templates/nonprofit-cause/l10n/sv.json +0 -5
- package/templates/nonprofit-cause/l10n/th.json +0 -5
- package/templates/nonprofit-cause/l10n/tr.json +0 -5
- package/templates/nonprofit-cause/l10n/uk.json +0 -5
- package/templates/nonprofit-cause/l10n/vi.json +0 -5
- package/templates/nonprofit-cause/l10n/zh.json +0 -5
- package/templates/nonprofit-cause/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/owner-lite/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/podcast-creator/l10n/ar.json +0 -5
- package/templates/podcast-creator/l10n/cs.json +0 -5
- package/templates/podcast-creator/l10n/da.json +0 -5
- package/templates/podcast-creator/l10n/de.json +0 -5
- package/templates/podcast-creator/l10n/el.json +0 -5
- package/templates/podcast-creator/l10n/en.json +1 -6
- package/templates/podcast-creator/l10n/es.json +0 -5
- package/templates/podcast-creator/l10n/fi.json +0 -5
- package/templates/podcast-creator/l10n/fr.json +0 -5
- package/templates/podcast-creator/l10n/he.json +0 -5
- package/templates/podcast-creator/l10n/hu.json +0 -5
- package/templates/podcast-creator/l10n/id.json +0 -5
- package/templates/podcast-creator/l10n/it.json +0 -5
- package/templates/podcast-creator/l10n/ja.json +0 -5
- package/templates/podcast-creator/l10n/ko.json +0 -5
- package/templates/podcast-creator/l10n/lt.json +0 -5
- package/templates/podcast-creator/l10n/nl.json +0 -5
- package/templates/podcast-creator/l10n/no.json +0 -5
- package/templates/podcast-creator/l10n/pl.json +0 -5
- package/templates/podcast-creator/l10n/pt.json +0 -5
- package/templates/podcast-creator/l10n/ru.json +0 -5
- package/templates/podcast-creator/l10n/sv.json +0 -5
- package/templates/podcast-creator/l10n/th.json +0 -5
- package/templates/podcast-creator/l10n/tr.json +0 -5
- package/templates/podcast-creator/l10n/uk.json +0 -5
- package/templates/podcast-creator/l10n/vi.json +0 -5
- package/templates/podcast-creator/l10n/zh.json +0 -5
- package/templates/podcast-creator/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/portfolio-creative/l10n/ar.json +0 -5
- package/templates/portfolio-creative/l10n/cs.json +0 -5
- package/templates/portfolio-creative/l10n/da.json +0 -5
- package/templates/portfolio-creative/l10n/de.json +0 -5
- package/templates/portfolio-creative/l10n/el.json +0 -5
- package/templates/portfolio-creative/l10n/en.json +1 -6
- package/templates/portfolio-creative/l10n/es.json +0 -5
- package/templates/portfolio-creative/l10n/fi.json +0 -5
- package/templates/portfolio-creative/l10n/fr.json +0 -5
- package/templates/portfolio-creative/l10n/he.json +0 -5
- package/templates/portfolio-creative/l10n/hu.json +0 -5
- package/templates/portfolio-creative/l10n/id.json +0 -5
- package/templates/portfolio-creative/l10n/it.json +0 -5
- package/templates/portfolio-creative/l10n/ja.json +0 -5
- package/templates/portfolio-creative/l10n/ko.json +0 -5
- package/templates/portfolio-creative/l10n/lt.json +0 -5
- package/templates/portfolio-creative/l10n/nl.json +0 -5
- package/templates/portfolio-creative/l10n/no.json +0 -5
- package/templates/portfolio-creative/l10n/pl.json +0 -5
- package/templates/portfolio-creative/l10n/pt.json +0 -5
- package/templates/portfolio-creative/l10n/ru.json +0 -5
- package/templates/portfolio-creative/l10n/sv.json +0 -5
- package/templates/portfolio-creative/l10n/th.json +0 -5
- package/templates/portfolio-creative/l10n/tr.json +0 -5
- package/templates/portfolio-creative/l10n/uk.json +0 -5
- package/templates/portfolio-creative/l10n/vi.json +0 -5
- package/templates/portfolio-creative/l10n/zh.json +0 -5
- package/templates/portfolio-creative/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/restaurant/l10n/ar.json +0 -5
- package/templates/restaurant/l10n/cs.json +0 -5
- package/templates/restaurant/l10n/da.json +0 -5
- package/templates/restaurant/l10n/de.json +0 -5
- package/templates/restaurant/l10n/el.json +0 -5
- package/templates/restaurant/l10n/en.json +1 -6
- package/templates/restaurant/l10n/es.json +0 -5
- package/templates/restaurant/l10n/fi.json +0 -5
- package/templates/restaurant/l10n/fr.json +0 -5
- package/templates/restaurant/l10n/he.json +0 -5
- package/templates/restaurant/l10n/hu.json +0 -5
- package/templates/restaurant/l10n/id.json +0 -5
- package/templates/restaurant/l10n/it.json +0 -5
- package/templates/restaurant/l10n/ja.json +0 -5
- package/templates/restaurant/l10n/ko.json +0 -5
- package/templates/restaurant/l10n/lt.json +0 -5
- package/templates/restaurant/l10n/nl.json +0 -5
- package/templates/restaurant/l10n/no.json +0 -5
- package/templates/restaurant/l10n/pl.json +0 -5
- package/templates/restaurant/l10n/pt.json +0 -5
- package/templates/restaurant/l10n/ru.json +0 -5
- package/templates/restaurant/l10n/sv.json +0 -5
- package/templates/restaurant/l10n/th.json +0 -5
- package/templates/restaurant/l10n/tr.json +0 -5
- package/templates/restaurant/l10n/uk.json +0 -5
- package/templates/restaurant/l10n/vi.json +0 -5
- package/templates/restaurant/l10n/zh.json +0 -5
- package/templates/restaurant/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/restaurant-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/retail-store/l10n/ar.json +0 -5
- package/templates/retail-store/l10n/cs.json +0 -5
- package/templates/retail-store/l10n/da.json +0 -5
- package/templates/retail-store/l10n/de.json +0 -5
- package/templates/retail-store/l10n/el.json +0 -5
- package/templates/retail-store/l10n/en.json +1 -6
- package/templates/retail-store/l10n/es.json +0 -5
- package/templates/retail-store/l10n/fi.json +0 -5
- package/templates/retail-store/l10n/fr.json +0 -5
- package/templates/retail-store/l10n/he.json +0 -5
- package/templates/retail-store/l10n/hu.json +0 -5
- package/templates/retail-store/l10n/id.json +0 -5
- package/templates/retail-store/l10n/it.json +0 -5
- package/templates/retail-store/l10n/ja.json +0 -5
- package/templates/retail-store/l10n/ko.json +0 -5
- package/templates/retail-store/l10n/lt.json +0 -5
- package/templates/retail-store/l10n/nl.json +0 -5
- package/templates/retail-store/l10n/no.json +0 -5
- package/templates/retail-store/l10n/pl.json +0 -5
- package/templates/retail-store/l10n/pt.json +0 -5
- package/templates/retail-store/l10n/ru.json +0 -5
- package/templates/retail-store/l10n/sv.json +0 -5
- package/templates/retail-store/l10n/th.json +0 -5
- package/templates/retail-store/l10n/tr.json +0 -5
- package/templates/retail-store/l10n/uk.json +0 -5
- package/templates/retail-store/l10n/vi.json +0 -5
- package/templates/retail-store/l10n/zh.json +0 -5
- package/templates/retail-store/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/retail-store-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/salon-spa/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/wholesale-store/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/yoga-studio/l10n/ar.json +0 -5
- package/templates/yoga-studio/l10n/cs.json +0 -5
- package/templates/yoga-studio/l10n/da.json +0 -5
- package/templates/yoga-studio/l10n/de.json +0 -5
- package/templates/yoga-studio/l10n/el.json +0 -5
- package/templates/yoga-studio/l10n/en.json +1 -6
- package/templates/yoga-studio/l10n/es.json +0 -5
- package/templates/yoga-studio/l10n/fi.json +0 -5
- package/templates/yoga-studio/l10n/fr.json +0 -5
- package/templates/yoga-studio/l10n/he.json +0 -5
- package/templates/yoga-studio/l10n/hu.json +0 -5
- package/templates/yoga-studio/l10n/id.json +0 -5
- package/templates/yoga-studio/l10n/it.json +0 -5
- package/templates/yoga-studio/l10n/ja.json +0 -5
- package/templates/yoga-studio/l10n/ko.json +0 -5
- package/templates/yoga-studio/l10n/lt.json +0 -5
- package/templates/yoga-studio/l10n/nl.json +0 -5
- package/templates/yoga-studio/l10n/no.json +0 -5
- package/templates/yoga-studio/l10n/pl.json +0 -5
- package/templates/yoga-studio/l10n/pt.json +0 -5
- package/templates/yoga-studio/l10n/ru.json +0 -5
- package/templates/yoga-studio/l10n/sv.json +0 -5
- package/templates/yoga-studio/l10n/th.json +0 -5
- package/templates/yoga-studio/l10n/tr.json +0 -5
- package/templates/yoga-studio/l10n/uk.json +0 -5
- package/templates/yoga-studio/l10n/vi.json +0 -5
- package/templates/yoga-studio/l10n/zh.json +0 -5
- package/templates/yoga-studio/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-contract.ts +0 -1
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
// Public Loyalty offering plus the current member's separately verified balance.
|
|
2
|
-
// The
|
|
3
|
-
// StatusSection): tier, points expiry and "Rewards available (N)"
|
|
4
|
-
// balance, read only beside it, and each one is blank rather
|
|
5
|
-
|
|
2
|
+
// The status card carries the one-app `loyalty_status_section` lines (wix-loyalty-mobile
|
|
3
|
+
// StatusSection): tier, points expiry and "Rewards available (N)", plus the progress to the next
|
|
4
|
+
// reward. They are private like the balance, read only beside it, and each one is blank rather
|
|
5
|
+
// than guessed when its read fails.
|
|
6
|
+
//
|
|
7
|
+
// Redesign phase 1 (Branded Lite loyalty redesign, revision 2): the public catalog (title, ways to
|
|
8
|
+
// earn, rewards, tiers) is cached and painted at once; every row field that depends on the member
|
|
9
|
+
// (a reward's "Available" / "180 more", the "Your tier" chip, the birthday and follow links) is
|
|
10
|
+
// composed from that public cache plus private state that never reaches the disk. Until member
|
|
11
|
+
// access is known the status card is a skeleton at its final height, so nothing under it moves.
|
|
12
|
+
import { defineService } from "@himalaya/state";
|
|
6
13
|
import { LOADING, loaded, loadFailed, type LoadCopy, type LoadFlags } from "../_shared/branded-load-state.js";
|
|
7
|
-
import { copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
8
|
-
import { calendarDay,
|
|
9
|
-
import { appLocale
|
|
14
|
+
import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
15
|
+
import { calendarDay, formatDateMedium, formatNumber } from "../_shared/engine-intl.js";
|
|
16
|
+
import { appLocale } from "../_shared/app-locale.js";
|
|
10
17
|
import { memberAccess, assertMemberAccess } from "../_shared/member-access.js";
|
|
11
18
|
import {
|
|
12
19
|
getLoyaltyProgram, listLoyaltyRewards, listLoyaltyEarningRules, getCurrentMemberLoyaltyAccount, getLoyaltyTiersProgram, listMyLoyaltyCoupons, listMyReferralRewards,
|
|
@@ -14,65 +21,68 @@ import {
|
|
|
14
21
|
type WixLoyaltyCoupon, type WixReferralReward,
|
|
15
22
|
} from "@himalaya/wix-loyalty";
|
|
16
23
|
|
|
17
|
-
import { buildOfferings, visibleOfferings, offeringRewardLabel, memberRewardCost, OFFERING_TIER_LIMIT, type OfferingGroup } from "../_shared/loyalty-offerings.js";
|
|
24
|
+
import { buildOfferings, visibleOfferings, offeringRewardLabel, earningLabel, memberRewardCost, configFor, currentTierName, customPointName, pointLabel, OFFERING_TIER_LIMIT, type OfferingGroup } from "../_shared/loyalty-offerings.js";
|
|
18
25
|
|
|
19
|
-
import { createEarningController, EARNING_EMPTY, type EarningState } from "./earning.js";
|
|
26
|
+
import { createEarningController, birthdayRule, EARNING_EMPTY, type EarningState } from "./earning.js";
|
|
20
27
|
import { withOnlineWrites } from "../_shared/online-actions.js";
|
|
21
28
|
|
|
29
|
+
/** A public reward (cached): its name and "₪70 off · 500 points". */
|
|
22
30
|
interface Row { id: string; name: string; subtitle: string }
|
|
31
|
+
/** A public ways-to-earn rule (cached). `kind` picks the member link; `screen` is the screen a tap
|
|
32
|
+
* opens ("" when this build has none). */
|
|
33
|
+
export interface RuleRow extends Row { icon: string; kind: "rule" | "birthday" | "social"; screen: string }
|
|
34
|
+
/** A ways-to-earn row as drawn. Exactly one of the four variants shows: a plain row, a row that
|
|
35
|
+
* opens a screen (chevron), a birthday row and a follow row (each with a trailing link). */
|
|
36
|
+
export interface EarnRow extends Row {
|
|
37
|
+
icon: string; screen: string; linkLabel: string; channel: string;
|
|
38
|
+
notStatic: boolean; notNav: boolean; notBirthday: boolean; notSocial: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** A reward row as drawn: the right side is "Available", "180 more", a skeleton while the member's
|
|
41
|
+
* account is pending, or nothing (a visitor). */
|
|
42
|
+
export interface RewardRow extends Row { more: string; noAvailable: boolean; noMore: boolean; noPending: boolean }
|
|
43
|
+
/** A tier row as drawn: the member's own tier carries the chip; a tap expands its benefits. */
|
|
44
|
+
export interface TierRow extends OfferingGroup { noYourTier: boolean; collapsed: boolean; noBenefits: boolean }
|
|
45
|
+
|
|
23
46
|
interface S extends LoadFlags, EarningState {
|
|
24
|
-
offeringGroups: OfferingGroup[]; offeringsExpanded: boolean;
|
|
25
|
-
|
|
47
|
+
offeringGroups: OfferingGroup[]; offeringsExpanded: boolean; tierRows: TierRow[];
|
|
48
|
+
hideTiers: boolean; hideShowAllTiers: boolean; tierError: string; noTierError: boolean;
|
|
49
|
+
/** The screen title: the program's name, "Rewards" when it has none; "" until the first load. */
|
|
50
|
+
title: string; noTitle: boolean; hasTitle: boolean;
|
|
26
51
|
programName: string; unit: string; currency: string;
|
|
27
|
-
rewards: Row[]; earningRules:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
52
|
+
rewards: Row[]; earningRules: RuleRow[]; rewardRows: RewardRow[]; earnRows: EarnRow[];
|
|
53
|
+
emptyText: string; earningEmptyText: string;
|
|
54
|
+
hideCatalog: boolean; hideContent: boolean; hideInactive: boolean; inactiveText: string;
|
|
55
|
+
rewardError: string; earningError: string; hideRewardError: boolean; hideEarningError: boolean;
|
|
56
|
+
hideRewardRows: boolean; hideEarnRows: boolean; hideRewardEmpty: boolean; hideEarnEmpty: boolean;
|
|
57
|
+
/** The status card: a skeleton until member access is known, then exactly one of member / visitor. */
|
|
58
|
+
noStatusSkeleton: boolean; noMemberStatus: boolean; noVisitorStatus: boolean;
|
|
59
|
+
joinTitle: string; joinBody: string;
|
|
60
|
+
memberPoints: string; memberMessage: string; noPointsError: boolean; noMyRewards: boolean;
|
|
32
61
|
/** "Gold tier"; "" while the tiers program is off or its read failed. */
|
|
33
|
-
memberTier: string;
|
|
62
|
+
memberTier: string; noTier: boolean;
|
|
63
|
+
/** Progress to the cheapest reward the member cannot afford yet. */
|
|
64
|
+
progress: number; progressText: string; noProgress: boolean;
|
|
34
65
|
/** The expiry sentence; urgent (≤ 7 days) goes in its own field so it can be painted danger. */
|
|
35
66
|
memberExpiry: string; memberExpiryUrgent: string;
|
|
36
67
|
/** "Rewards available (N)"; hidden when N is 0 or cannot be counted honestly. */
|
|
37
68
|
memberRewards: string; hideMemberRewards: boolean;
|
|
38
69
|
}
|
|
39
70
|
const PRIVATE_EMPTY = { ...EARNING_EMPTY,
|
|
40
|
-
|
|
41
|
-
|
|
71
|
+
rewardRows: [] as RewardRow[], earnRows: [] as EarnRow[], tierRows: [] as TierRow[],
|
|
72
|
+
noStatusSkeleton: false, noMemberStatus: true, noVisitorStatus: true, joinTitle: "", joinBody: "",
|
|
73
|
+
memberPoints: "", memberMessage: "", noPointsError: true, noMyRewards: false,
|
|
74
|
+
memberTier: "", noTier: true, progress: 0, progressText: "", noProgress: true,
|
|
75
|
+
memberExpiry: "", memberExpiryUrgent: "", memberRewards: "", hideMemberRewards: true,
|
|
42
76
|
};
|
|
43
77
|
const PRIVATE_KEYS = Object.keys(PRIVATE_EMPTY) as (keyof typeof PRIVATE_EMPTY)[];
|
|
44
|
-
const OFFERING_EMPTY = { offeringGroups: [] as OfferingGroup[], offeringsExpanded: false,
|
|
45
|
-
const
|
|
78
|
+
const OFFERING_EMPTY = { offeringGroups: [] as OfferingGroup[], offeringsExpanded: false, hideTiers: true, hideShowAllTiers: true, tierError: "", noTierError: true };
|
|
79
|
+
const SECTIONS_HIDDEN = { rewardError: "", earningError: "", hideRewardError: true, hideEarningError: true, hideRewardRows: true, hideEarnRows: true, hideRewardEmpty: true, hideEarnEmpty: true };
|
|
80
|
+
const INITIAL: S = { ...OFFERING_EMPTY, ...LOADING, ...PRIVATE_EMPTY, ...SECTIONS_HIDDEN, title: "", noTitle: true, hasTitle: false,
|
|
81
|
+
programName: "", unit: "", currency: "", rewards: [], earningRules: [], emptyText: "", earningEmptyText: "",
|
|
82
|
+
hideCatalog: false, hideContent: true, hideInactive: true, inactiveText: "" };
|
|
46
83
|
|
|
47
84
|
function amount(value: unknown): value is number { return typeof value === "number" && Number.isFinite(value) && value >= 0; }
|
|
48
|
-
|
|
49
|
-
const base = configs?.filter(config => !config.tierId);
|
|
50
|
-
return base?.length === 1 ? base[0] : undefined;
|
|
51
|
-
}
|
|
52
|
-
function points(value: number, customUnit: string): string {
|
|
53
|
-
const unit = customUnit || copyParam(isSingular(value) ? "loyalty.pointOne" : "loyalty.pointMany", isSingular(value) ? "point" : "points");
|
|
54
|
-
return copyTemplate("loyalty.pointsLabel", "{points} {unit}", { points: formatNumber(value), unit });
|
|
55
|
-
}
|
|
56
|
-
function rewardLabel(reward: WixLoyaltyReward, customUnit: string): string {
|
|
57
|
-
const configs = reward.discountAmount?.configsByTier ?? reward.couponReward?.fixedAmount?.configsByTier
|
|
58
|
-
?? reward.couponReward?.percentage?.configsByTier ?? reward.couponReward?.freeShipping?.configsByTier;
|
|
59
|
-
const cost = configs?.length ? baseConfig<{ tierId?: string; costInPoints?: number }>(configs)?.costInPoints : reward.requiredPoints;
|
|
60
|
-
if (!amount(cost)) return copyParam("loyalty.costUnavailable", "Points details unavailable");
|
|
61
|
-
return cost === 0 ? copyParam("loyalty.free", "Free") : points(cost, customUnit);
|
|
62
|
-
}
|
|
63
|
-
function earningLabel(rule: WixLoyaltyEarningRule, customUnit: string, currency: string): string {
|
|
64
|
-
if (rule.fixedAmount) {
|
|
65
|
-
const value = baseConfig(rule.fixedAmount.configs)?.points;
|
|
66
|
-
return amount(value) ? points(value, customUnit) : copyParam("loyalty.earningUnavailable", "Points details unavailable");
|
|
67
|
-
}
|
|
68
|
-
const rate = baseConfig(rule.conversionRate?.configs);
|
|
69
|
-
if (!rate || !amount(rate.points) || !amount(rate.moneyAmount) || rate.moneyAmount === 0 || !currency) {
|
|
70
|
-
return copyParam("loyalty.earningUnavailable", "Points details unavailable");
|
|
71
|
-
}
|
|
72
|
-
return copyTemplate("loyalty.pointsPerSpend", "{points} per {amount}", {
|
|
73
|
-
points: points(rate.points, customUnit), amount: formatCurrency(rate.moneyAmount, currency, undefined, Number.isInteger(rate.moneyAmount) ? 0 : undefined),
|
|
74
|
-
});
|
|
75
|
-
}
|
|
85
|
+
const points = pointLabel;
|
|
76
86
|
function businessStamp(): unknown {
|
|
77
87
|
return (globalThis as { himalaya?: { input?: Record<string, unknown> } }).himalaya?.input?.__himiPreferenceBusiness;
|
|
78
88
|
}
|
|
@@ -81,6 +91,112 @@ function currencyFrom(s: S, arg: unknown): string {
|
|
|
81
91
|
const raw = (arg as { currency?: unknown }).currency;
|
|
82
92
|
return typeof raw === "string" && /^[A-Z]{3}$/.test(raw) ? raw : "";
|
|
83
93
|
}
|
|
94
|
+
|
|
95
|
+
/** The screens a ways-to-earn row may open, from the descriptor (only the verticals this build
|
|
96
|
+
* has). Kept outside state: the descriptor sends them on every load. */
|
|
97
|
+
let earnScreens: Record<string, string> = {};
|
|
98
|
+
function screensFrom(arg: unknown): void {
|
|
99
|
+
const raw = arg && typeof arg === "object" ? (arg as { earnScreens?: unknown }).earnScreens : undefined;
|
|
100
|
+
if (typeof raw !== "string") return;
|
|
101
|
+
try {
|
|
102
|
+
const parsed = JSON.parse(raw) as Record<string, unknown>;
|
|
103
|
+
earnScreens = Object.fromEntries(Object.entries(parsed).filter((entry): entry is [string, string] =>
|
|
104
|
+
["events", "plans", "restaurants"].includes(entry[0]) && typeof entry[1] === "string" && /^himi_[a-z_]+$/.test(entry[1])));
|
|
105
|
+
} catch { earnScreens = {}; }
|
|
106
|
+
}
|
|
107
|
+
/** Which app a rule is for, from its trigger (`wix_events-ticket_purchase` → events). */
|
|
108
|
+
export function ruleVertical(trigger: string | undefined): string {
|
|
109
|
+
if (!trigger) return "";
|
|
110
|
+
if (trigger.startsWith("wix_events-")) return "events";
|
|
111
|
+
if (trigger.startsWith("wix_pricing_plans-")) return "plans";
|
|
112
|
+
if (trigger.startsWith("restaurants-")) return "restaurants";
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
const SIGN_UP_TRIGGER = "wix_members-uou_signs_up";
|
|
116
|
+
function ruleIcon(rule: WixLoyaltyEarningRule): string {
|
|
117
|
+
const vertical = ruleVertical(rule.triggerActivityType);
|
|
118
|
+
if (vertical === "events") return "ticket";
|
|
119
|
+
if (vertical === "plans" || vertical === "restaurants") return "tag";
|
|
120
|
+
if (rule.triggerActivityType === SIGN_UP_TRIGGER) return "person";
|
|
121
|
+
return "star";
|
|
122
|
+
}
|
|
123
|
+
/** The visitor's reason to join: the points of the ACTIVE fixed-amount sign-up rule, or "" when the
|
|
124
|
+
* program has none (then the card says "Sign in to see your points"). */
|
|
125
|
+
export function signUpPoints(rules: WixLoyaltyEarningRule[], customUnit: string): string {
|
|
126
|
+
const rule = rules.find(r => r.status === "ACTIVE" && r.triggerActivityType === SIGN_UP_TRIGGER && !!r.fixedAmount);
|
|
127
|
+
const value = configFor(rule?.fixedAmount?.configs, undefined)?.points;
|
|
128
|
+
return amount(value) && value > 0 ? points(value, customUnit) : "";
|
|
129
|
+
}
|
|
130
|
+
const CHANNEL_NAMES: Record<string, string> = { FACEBOOK: "Facebook", INSTAGRAM: "Instagram", LINKEDIN: "LinkedIn", TIKTOK: "TikTok", X: "X" };
|
|
131
|
+
|
|
132
|
+
/** The private part of the view, kept out of state so a cached revisit can never show it. */
|
|
133
|
+
interface Viewer {
|
|
134
|
+
/** Member access is known (false until the first load answers). */
|
|
135
|
+
known: boolean; member: boolean;
|
|
136
|
+
/** The account read answered with a balance. */
|
|
137
|
+
balance?: number; tierId?: string;
|
|
138
|
+
/** Who the member rows were made for (email + scope); "" for a visitor. */
|
|
139
|
+
key: string;
|
|
140
|
+
}
|
|
141
|
+
let viewer: Viewer = { known: false, member: false, key: "" };
|
|
142
|
+
/** The load whose viewer reset may still apply; cleared when that load publishes. */
|
|
143
|
+
let resetFor = -1;
|
|
144
|
+
const viewerKey = (member: { email: string; scope: string }) => member.email ? JSON.stringify([member.email, member.scope]) : "";
|
|
145
|
+
/** The raw rewards of the last load: their per-tier costs decide "Available" and the progress. */
|
|
146
|
+
let rawRewards: WixLoyaltyReward[] = [];
|
|
147
|
+
|
|
148
|
+
function earnRow(rule: RuleRow, s: Pick<S, "hideBirthday" | "birthdayLabel" | "socialChannels">): EarnRow[] {
|
|
149
|
+
const base = { id: rule.id, name: rule.name, subtitle: rule.subtitle, icon: rule.icon, screen: "", linkLabel: "", channel: "",
|
|
150
|
+
notStatic: true, notNav: true, notBirthday: true, notSocial: true };
|
|
151
|
+
// Birthday and follow links are member actions; a visitor reads the rule only.
|
|
152
|
+
if (viewer.member && rule.kind === "birthday" && !s.hideBirthday) return [{ ...base, linkLabel: s.birthdayLabel, notBirthday: false }];
|
|
153
|
+
if (viewer.member && rule.kind === "social" && s.socialChannels.length) {
|
|
154
|
+
return s.socialChannels.map(channel => ({ ...base, id: `${rule.id}:${channel.id}`, name: CHANNEL_NAMES[channel.id] ?? channel.name,
|
|
155
|
+
channel: channel.id, linkLabel: channel.label, notSocial: false }));
|
|
156
|
+
}
|
|
157
|
+
if (rule.screen) return [{ ...base, screen: rule.screen, notNav: false }];
|
|
158
|
+
return [{ ...base, notStatic: false }];
|
|
159
|
+
}
|
|
160
|
+
export function composeEarnRows(s: Pick<S, "earningRules" | "hideBirthday" | "birthdayLabel" | "socialChannels">): EarnRow[] {
|
|
161
|
+
return s.earningRules.flatMap(rule => earnRow(rule, s));
|
|
162
|
+
}
|
|
163
|
+
/** The reward rows: the cached public row plus the member's state on the right. */
|
|
164
|
+
export function composeRewardRows(rewards: Row[]): RewardRow[] {
|
|
165
|
+
return rewards.map(row => {
|
|
166
|
+
const none = { ...row, more: "", noAvailable: true, noMore: true, noPending: true };
|
|
167
|
+
if (!viewer.known) return { ...none, noPending: false };
|
|
168
|
+
if (!viewer.member || viewer.balance === undefined) return none;
|
|
169
|
+
const reward = rawRewards.find(r => r.id === row.id);
|
|
170
|
+
if (!reward || reward.type === "SPI_DISCOUNT_AMOUNT") return none;
|
|
171
|
+
const cost = memberRewardCost(reward, viewer.tierId);
|
|
172
|
+
if (cost === undefined) return none;
|
|
173
|
+
if (cost <= viewer.balance) return { ...none, noAvailable: false };
|
|
174
|
+
return { ...none, noMore: false, more: copyTemplate("loyalty.moreNeeded", "{points} more", { points: formatNumber(cost - viewer.balance) }) };
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function composeTierRows(groups: OfferingGroup[], expanded: Set<string>): TierRow[] {
|
|
178
|
+
return groups.map(group => ({ ...group,
|
|
179
|
+
noYourTier: !(viewer.member && viewer.balance !== undefined && (viewer.tierId ?? "base") === group.id),
|
|
180
|
+
collapsed: !expanded.has(group.id), noBenefits: group.hideEarning && group.hideRewards }));
|
|
181
|
+
}
|
|
182
|
+
const expandedTiers = new Set<string>();
|
|
183
|
+
function compose(s: S): S {
|
|
184
|
+
return { ...s, earnRows: composeEarnRows(s), rewardRows: composeRewardRows(s.rewards), tierRows: composeTierRows(s.offeringGroups, expandedTiers) };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Progress to the cheapest reward the member cannot afford yet, on the member's tier. Hidden when
|
|
188
|
+
* every reward is affordable or no reward has a points cost. */
|
|
189
|
+
export function nextReward(rewards: WixLoyaltyReward[], balance: number, tierId: string | undefined): { cost: number; name: string } | undefined {
|
|
190
|
+
let best: { cost: number; name: string } | undefined;
|
|
191
|
+
for (const reward of rewards) {
|
|
192
|
+
if (reward.active !== true || reward.type === "SPI_DISCOUNT_AMOUNT") continue;
|
|
193
|
+
const cost = memberRewardCost(reward, tierId);
|
|
194
|
+
if (cost === undefined || cost <= balance || cost === 0) continue;
|
|
195
|
+
if (!best || cost < best.cost) best = { cost, name: reward.name || copyParam("loyalty.rewardFallback", "Reward") };
|
|
196
|
+
}
|
|
197
|
+
return best;
|
|
198
|
+
}
|
|
199
|
+
|
|
84
200
|
/** The one-app `calculateAvailableRewardsToClaim`: active rewards the balance covers on the
|
|
85
201
|
* member's tier (an SPI discount prices itself in text, not points, so it is left out), plus
|
|
86
202
|
* claimed coupons that are still ACTIVE and not deleted. */
|
|
@@ -92,13 +208,7 @@ export function countAvailableRewards(rewards: WixLoyaltyReward[], coupons: WixL
|
|
|
92
208
|
}).length;
|
|
93
209
|
return claimable + coupons.filter(coupon => coupon.status === "ACTIVE" && !coupon.couponReference?.deleted).length;
|
|
94
210
|
}
|
|
95
|
-
|
|
96
|
-
* `tier.id` means the base tier, whose name lives in the program settings. */
|
|
97
|
-
export function currentTierName(tiers: WixLoyaltyTiersProgram | undefined, tierId: string | undefined): string {
|
|
98
|
-
if (tiers?.programSettings?.status !== "ACTIVE") return "";
|
|
99
|
-
if (!tierId) return (tiers.programSettings.baseTierDefinition?.name ?? "").trim();
|
|
100
|
-
return (tiers.tiers?.find(tier => tier.id === tierId)?.tierDefinition?.name ?? "").trim();
|
|
101
|
-
}
|
|
211
|
+
export { currentTierName };
|
|
102
212
|
const DAY_MS = 86_400_000;
|
|
103
213
|
/** Nothing further out than this is shown (one-app `estimatePointsExpirationDuration`). */
|
|
104
214
|
const EXPIRY_HORIZON_DAYS = 365;
|
|
@@ -127,29 +237,38 @@ const settle = <T>(read: Promise<T>): Promise<Settled<T>> => read.then(value =>
|
|
|
127
237
|
/** The status lines for a member whose balance is known. A failed tiers read only drops the tier;
|
|
128
238
|
* a failed coupon or rewards read drops the count, because a partial total would understate it. */
|
|
129
239
|
function statusLines(program: WixLoyaltyProgram, account: WixLoyaltyAccount, balance: number, tiers: Settled<WixLoyaltyTiersProgram>,
|
|
130
|
-
coupons: Settled<{ loyaltyCoupons?: WixLoyaltyCoupon[] }>, referrals: Settled<{ referralRewards: WixReferralReward[] }>, rewards: WixLoyaltyReward[] | undefined) {
|
|
240
|
+
coupons: Settled<{ loyaltyCoupons?: WixLoyaltyCoupon[] }>, referrals: Settled<{ referralRewards: WixReferralReward[] }>, rewards: WixLoyaltyReward[] | undefined, customUnit: string) {
|
|
131
241
|
const tierId = account.tier?.id || undefined;
|
|
132
242
|
const tier = tiers.failed ? "" : currentTierName(tiers.value, tierId);
|
|
133
243
|
const [expiry, urgent] = expirySentence(program, account);
|
|
134
244
|
const referralCount = referrals.value?.referralRewards.filter(r => r.rewardType === "COUPON" && r.coupon?.status === "ACTIVE").length ?? 0;
|
|
135
245
|
const count = coupons.failed || referrals.failed || !rewards ? 0 : countAvailableRewards(rewards, coupons.value?.loyaltyCoupons ?? [], balance, tierId) + referralCount;
|
|
246
|
+
const next = rewards ? nextReward(rewards, balance, tierId) : undefined;
|
|
136
247
|
return {
|
|
137
|
-
memberTier: tier ? copyTemplate("loyalty.memberTier", "{tier} tier", { tier }) : "",
|
|
248
|
+
memberTier: tier ? copyTemplate("loyalty.memberTier", "{tier} tier", { tier }) : "", noTier: !tier,
|
|
249
|
+
progress: next ? Math.max(0, Math.min(1, balance / next.cost)) : 0, noProgress: !next,
|
|
250
|
+
progressText: next ? copyTemplate("loyalty.progressTo", "{points} to {reward}", { points: points(next.cost - balance, customUnit), reward: next.name }) : "",
|
|
138
251
|
memberExpiry: urgent ? "" : expiry, memberExpiryUrgent: urgent ? expiry : "",
|
|
139
252
|
memberRewards: count > 0 ? copyTemplate("loyalty.rewardsAvailable", "Rewards available ({count})", { count }) : "", hideMemberRewards: count === 0,
|
|
140
253
|
};
|
|
141
254
|
}
|
|
142
255
|
const COPY: LoadCopy<Row> = {
|
|
143
|
-
prefix: "loyalty", empty: "No rewards
|
|
256
|
+
prefix: "loyalty", empty: "No rewards yet",
|
|
144
257
|
error: "The rewards program couldn't be loaded.", signIn: "The rewards program couldn't be loaded.",
|
|
145
258
|
sample: () => [{ id: "sample-reward", name: copyParam("loyalty.sampleReward", "5% off your next order"), subtitle: points(500, "") }],
|
|
146
259
|
};
|
|
260
|
+
/** The visitor card: "Join {program}" and the sign-up points, or "Sign in to see your points". */
|
|
261
|
+
function visitorStatus(programName: string, signUp: string) {
|
|
262
|
+
return { ...PRIVATE_EMPTY, noStatusSkeleton: true, noVisitorStatus: false,
|
|
263
|
+
joinTitle: copyTemplate("loyalty.joinTitle", "Join {program}", { program: programName }),
|
|
264
|
+
joinBody: signUp ? copyTemplate("loyalty.joinBody", "Sign up and get {points}", { points: signUp }) : copyParam("loyalty.joinSignIn", "Sign in to see your points") };
|
|
265
|
+
}
|
|
147
266
|
|
|
148
267
|
let loadRevision = 0;
|
|
149
268
|
let allOfferings: OfferingGroup[] = [];
|
|
150
269
|
const earning: ReturnType<typeof createEarningController<S>> = createEarningController<S>((): Promise<unknown> => svc.finishEarning());
|
|
151
270
|
const register = withOnlineWrites(defineService, ["saveBirthday", "followChannel"], { messageFields: ["earnMessage"] });
|
|
152
|
-
const svc = register<S, { prepare: (s: S) => S; load: (s: S, arg?: unknown) => Promise<S>; showAllTiers: (s: S) => S;
|
|
271
|
+
const svc = register<S, { prepare: (s: S) => S; load: (s: S, arg?: unknown) => Promise<S | undefined>; resetViewer: (s: S, arg?: unknown) => S | undefined; showAllTiers: (s: S) => S; toggleTier: (s: S, arg?: unknown) => S;
|
|
153
272
|
openBirthday: (s: S) => Promise<S>; draftBirthday: (s: S, arg?: unknown) => S; closeBirthday: (s: S) => S;
|
|
154
273
|
saveBirthday: (s: S) => S; followChannel: (s: S, arg?: unknown) => Promise<S>; finishEarning: (s: S) => Promise<S>;
|
|
155
274
|
}>("himiBrandedLoyalty", {
|
|
@@ -157,25 +276,61 @@ const svc = register<S, { prepare: (s: S) => S; load: (s: S, arg?: unknown) => P
|
|
|
157
276
|
notHydrated: PRIVATE_KEYS,
|
|
158
277
|
notPersisted: PRIVATE_KEYS,
|
|
159
278
|
actions: {
|
|
160
|
-
showAllTiers: s => allOfferings.length ? ({ ...s, offeringsExpanded: true, offeringGroups: allOfferings, hideShowAllTiers: true }) : s,
|
|
279
|
+
showAllTiers: s => allOfferings.length ? compose({ ...s, offeringsExpanded: true, offeringGroups: allOfferings, hideShowAllTiers: true }) : s,
|
|
280
|
+
toggleTier: (s, arg) => {
|
|
281
|
+
const id = arg && typeof arg === "object" ? (arg as { id?: unknown }).id : undefined;
|
|
282
|
+
if (typeof id !== "string" || !s.offeringGroups.some(group => group.id === id)) return s;
|
|
283
|
+
if (expandedTiers.has(id)) expandedTiers.delete(id); else expandedTiers.add(id);
|
|
284
|
+
return { ...s, tierRows: composeTierRows(s.offeringGroups, expandedTiers) };
|
|
285
|
+
},
|
|
161
286
|
openBirthday: s => earning.openBirthday(s), draftBirthday: (s, arg) => earning.draftBirthday(s, arg),
|
|
162
287
|
closeBirthday: s => earning.closeBirthday(s), saveBirthday: s => earning.saveBirthday(s),
|
|
163
|
-
followChannel: (s, arg) => earning.followChannel(s, arg),
|
|
164
|
-
|
|
288
|
+
followChannel: (s, arg) => earning.followChannel(s, arg),
|
|
289
|
+
finishEarning: async s => compose(await earning.finishEarning(s)),
|
|
290
|
+
// Published from inside `load` when the viewer is not the one the rows were made for (a sign-out
|
|
291
|
+
// or another member while the screen stays mounted): the card goes back to its skeleton and every
|
|
292
|
+
// member field to pending at once, instead of showing the previous member's state until the reads
|
|
293
|
+
// finish. Ignored once that load has settled or a newer one started.
|
|
294
|
+
resetViewer: (s, arg) => {
|
|
295
|
+
const revision = arg && typeof arg === "object" ? (arg as { revision?: unknown }).revision : undefined;
|
|
296
|
+
if (revision !== loadRevision || revision !== resetFor) return undefined;
|
|
297
|
+
return compose({ ...s, ...PRIVATE_EMPTY });
|
|
298
|
+
},
|
|
299
|
+
// A cached revisit paints the public catalog at once; every member field starts pending.
|
|
300
|
+
prepare: s => { loadRevision++; allOfferings = []; rawRewards = []; viewer = { known: false, member: false, key: "" }; expandedTiers.clear(); earning.clear();
|
|
301
|
+
return compose({ ...s, ...PRIVATE_EMPTY }); },
|
|
165
302
|
load: async (s, arg) => {
|
|
303
|
+
stashCopy(arg);
|
|
304
|
+
screensFrom(arg);
|
|
166
305
|
const revision = ++loadRevision;
|
|
167
306
|
earning.clear(); allOfferings = [];
|
|
168
307
|
const currency = currencyFrom(s, arg);
|
|
169
308
|
const business = businessStamp();
|
|
170
309
|
try {
|
|
171
|
-
|
|
310
|
+
// Who is looking is answered first (the program read runs beside it): a different viewer resets
|
|
311
|
+
// the previous member's card and rows at once, not after the catalog reads.
|
|
312
|
+
const programRead = getLoyaltyProgram();
|
|
313
|
+
programRead.catch(() => undefined); // awaited below; an early return must not leave it unhandled
|
|
314
|
+
const member = await memberAccess();
|
|
315
|
+
if (revision !== loadRevision) return undefined;
|
|
316
|
+
if (viewer.known && viewerKey(member) !== viewer.key) {
|
|
317
|
+
viewer = { known: false, member: false, key: "" };
|
|
318
|
+
resetFor = revision;
|
|
319
|
+
void svc.resetViewer({ revision });
|
|
320
|
+
}
|
|
321
|
+
const response = await programRead;
|
|
172
322
|
const program = response.loyaltyProgram ?? response.program;
|
|
173
323
|
if (!program || !["ACTIVE", "DRAFT", "PAUSED"].includes(program.status ?? "")) throw new Error("Loyalty program response is unavailable");
|
|
174
|
-
const customUnit = (program.pointDefinition?.customName
|
|
175
|
-
const
|
|
324
|
+
const customUnit = customPointName(program.pointDefinition?.customName);
|
|
325
|
+
const programName = (program.name ?? "").trim() || copyParam("loyalty.programFallback", "Rewards");
|
|
326
|
+
const common = { ...s, ...OFFERING_EMPTY, ...SECTIONS_HIDDEN, currency, programName, title: programName, noTitle: false, hasTitle: true,
|
|
327
|
+
unit: customUnit || copyParam("loyalty.pointMany", "points"), inactiveText: "", hideInactive: true };
|
|
176
328
|
if (program.status !== "ACTIVE" || program.premiumFeatures?.loyaltyProgram === false) {
|
|
177
|
-
|
|
178
|
-
|
|
329
|
+
if (revision !== loadRevision) return undefined;
|
|
330
|
+
viewer = { known: true, member: false, key: "" }; resetFor = -1; rawRewards = [];
|
|
331
|
+
// No status card, no catalog, no primary action: only the notice and its way out.
|
|
332
|
+
return compose({ ...common, ...PRIVATE_EMPTY, ...loaded("rewards", [], COPY), noStatusSkeleton: true, earningRules: [], earningEmptyText: "", emptyText: "",
|
|
333
|
+
hideCatalog: true, hideContent: true, hideInactive: false, inactiveText: copyParam("loyalty.inactive", "The rewards program isn't available right now.") });
|
|
179
334
|
}
|
|
180
335
|
// Balance failures cannot discard a public offering that loaded correctly.
|
|
181
336
|
const privateStateSupported = !!member.scope && ((globalThis as { himalaya?: { readLifecycleVersion?: number } }).himalaya?.readLifecycleVersion ?? 0) >= 1;
|
|
@@ -196,53 +351,79 @@ const svc = register<S, { prepare: (s: S) => S; load: (s: S, arg?: unknown) => P
|
|
|
196
351
|
const earningResponse = earningResult.status === "fulfilled" ? earningResult.value : undefined;
|
|
197
352
|
if (businessStamp() !== business) throw new Error("Business changed while Loyalty loaded");
|
|
198
353
|
if (rewardResult.status === "rejected" && earningResult.status === "rejected") throw new Error("Loyalty catalog is unavailable");
|
|
199
|
-
const
|
|
200
|
-
|
|
354
|
+
const allRewards = rewardResponse?.rewards ?? [];
|
|
355
|
+
const allRules = earningResponse?.earningRules ?? [];
|
|
356
|
+
const balance = account.value?.account?.points?.balance;
|
|
357
|
+
const known = !!member.email && privateStateSupported && !account.failed && typeof balance === "number" && Number.isFinite(balance);
|
|
358
|
+
const tierId = known ? account.value?.account?.tier?.id || undefined : undefined;
|
|
359
|
+
// The public rows are cached on disk, so they carry the BASE-tier price and amount: a member's
|
|
360
|
+
// own tier shows only in what is composed from private state ("Available", "180 more").
|
|
361
|
+
const rewards = allRewards.filter(reward => reward.active === true).map((reward, i) => ({
|
|
362
|
+
id: reward.id || `reward-${i}`, name: reward.name || copyParam("loyalty.rewardFallback", "Reward"), subtitle: offeringRewardLabel(reward, undefined, customUnit, currency),
|
|
201
363
|
}));
|
|
202
|
-
const earningRules =
|
|
203
|
-
id: rule.id || `earning-${i}`, name: rule.title || copyParam("loyalty.earnFallback", "Earn points"), subtitle: earningLabel(rule, customUnit, currency),
|
|
364
|
+
const earningRules: RuleRow[] = allRules.filter(rule => rule.status === "ACTIVE").map((rule, i) => ({
|
|
365
|
+
id: rule.id || `earning-${i}`, name: rule.title || copyParam("loyalty.earnFallback", "Earn points"), subtitle: earningLabel(rule, undefined, customUnit, currency),
|
|
366
|
+
icon: ruleIcon(rule), screen: earnScreens[ruleVertical(rule.triggerActivityType)] ?? "",
|
|
367
|
+
kind: birthdayRule(rule) ? "birthday" : rule.triggerActivityType === "wix_loyalty-social_media_channel_followed" ? "social" : "rule",
|
|
204
368
|
}));
|
|
205
369
|
const tiered = !tiers.failed && tiers.value?.programSettings?.status === "ACTIVE" && program.premiumFeatures?.tiers !== false;
|
|
206
|
-
const allOfferingGroups = tiered ? buildOfferings(tiers.value,
|
|
370
|
+
const allOfferingGroups = tiered ? buildOfferings(tiers.value, allRewards, allRules, customUnit, currency) : [];
|
|
207
371
|
const offeringsExpanded = s.offeringsExpanded;
|
|
208
372
|
const offeringState = { offeringGroups: visibleOfferings(allOfferingGroups, offeringsExpanded), offeringsExpanded,
|
|
209
|
-
|
|
210
|
-
tierError: tiers.failed ? copyParam("loyalty.tiersError", "Tier benefits couldn't be loaded.
|
|
211
|
-
if (revision !== loadRevision) return
|
|
373
|
+
hideTiers: !tiered, hideShowAllTiers: !tiered || offeringsExpanded || allOfferingGroups.length <= OFFERING_TIER_LIMIT,
|
|
374
|
+
tierError: tiers.failed ? copyParam("loyalty.tiersError", "Tier benefits couldn't be loaded.") : "", noTierError: !tiers.failed };
|
|
375
|
+
if (revision !== loadRevision) return undefined;
|
|
212
376
|
allOfferings = allOfferingGroups;
|
|
213
|
-
const earningState = member.email && !privateStateSupported ? { ...EARNING_EMPTY } : await earning.load(member, program,
|
|
377
|
+
const earningState = member.email && !privateStateSupported ? { ...EARNING_EMPTY } : await earning.load(member, program, allRules);
|
|
378
|
+
// A newer load owns the screen: this completion publishes nothing.
|
|
379
|
+
if (revision !== loadRevision) return undefined;
|
|
214
380
|
if (businessStamp() !== business) throw new Error("Business changed while Loyalty loaded");
|
|
215
|
-
let privateState =
|
|
381
|
+
let privateState: typeof PRIVATE_EMPTY = visitorStatus(programName, signUpPoints(allRules, customUnit));
|
|
382
|
+
// Staged, and published to `viewer` only after the last revision check: a load that a newer
|
|
383
|
+
// prepare or load superseded while it awaited must not write its member into the module.
|
|
384
|
+
let nextViewer: Viewer = { known: true, member: false, key: "" };
|
|
216
385
|
if (member.email) {
|
|
217
386
|
try {
|
|
218
387
|
await assertMemberAccess(member);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
memberMessage: !privateStateSupported ? copyParam("loyalty.updateApp", "Update the app to see your points
|
|
226
|
-
:
|
|
227
|
-
|
|
388
|
+
nextViewer = { known: true, member: true, balance: known ? balance : undefined, tierId, key: viewerKey(member) };
|
|
389
|
+
privateState = { ...PRIVATE_EMPTY, noStatusSkeleton: true, noMemberStatus: false,
|
|
390
|
+
...(known ? statusLines(program, account.value?.account ?? {}, balance, tiers, coupons, referrals, rewardResult.status === "fulfilled" ? allRewards : undefined, customUnit) : {}),
|
|
391
|
+
memberPoints: known ? points(balance, customUnit) : "",
|
|
392
|
+
// An old app cannot read the balance securely: it says so and offers no "My rewards".
|
|
393
|
+
noMyRewards: !privateStateSupported,
|
|
394
|
+
memberMessage: !privateStateSupported ? copyParam("loyalty.updateApp", "Update the app to see your points.")
|
|
395
|
+
: !account.failed && !known ? copyParam("loyalty.pointsUnavailable", "Your points aren't available yet.") : "",
|
|
396
|
+
noPointsError: !(privateStateSupported && account.failed) };
|
|
228
397
|
} catch {
|
|
229
398
|
const current = await memberAccess();
|
|
230
|
-
|
|
231
|
-
|
|
399
|
+
nextViewer = { known: true, member: !!current.email, key: viewerKey(current) };
|
|
400
|
+
privateState = current.email
|
|
401
|
+
? { ...PRIVATE_EMPTY, noStatusSkeleton: true, noMemberStatus: false, noPointsError: false }
|
|
402
|
+
: visitorStatus(programName, signUpPoints(allRules, customUnit));
|
|
232
403
|
}
|
|
233
|
-
} else {
|
|
234
|
-
privateState.hideMemberSignIn = false;
|
|
235
404
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
405
|
+
if (revision !== loadRevision) return undefined;
|
|
406
|
+
viewer = nextViewer; resetFor = -1;
|
|
407
|
+
rawRewards = allRewards;
|
|
408
|
+
const rewardsFailed = rewardResult.status === "rejected", earningFailed = earningResult.status === "rejected";
|
|
409
|
+
return compose({ ...common, ...loaded("rewards", rewards, COPY), ...privateState, ...offeringState, ...earningState, earningRules,
|
|
410
|
+
hideCatalog: false, hideContent: false,
|
|
411
|
+
rewardError: rewardsFailed ? copyParam("loyalty.rewardsError", "Rewards couldn't be loaded.") : "",
|
|
412
|
+
earningError: earningFailed ? copyParam("loyalty.earningError", "Ways to earn points couldn't be loaded.") : "",
|
|
413
|
+
hideRewardError: !rewardsFailed, hideEarningError: !earningFailed,
|
|
414
|
+
hideRewardRows: rewardsFailed || !rewards.length, hideEarnRows: earningFailed || !earningRules.length,
|
|
415
|
+
hideRewardEmpty: rewardsFailed || rewards.length > 0, hideEarnEmpty: earningFailed || earningRules.length > 0,
|
|
416
|
+
emptyText: rewardsFailed || rewards.length ? "" : copyParam("loyalty.emptyTitle", COPY.empty),
|
|
417
|
+
earningEmptyText: earningFailed || earningRules.length ? "" : copyParam("loyalty.earningEmpty", "No ways to earn points yet") });
|
|
242
418
|
} catch (error) {
|
|
419
|
+
if (revision !== loadRevision) return undefined;
|
|
243
420
|
const failure = loadFailed("rewards", error, COPY);
|
|
244
|
-
|
|
245
|
-
|
|
421
|
+
viewer = { known: true, member: false, key: "" }; resetFor = -1; rawRewards = [];
|
|
422
|
+
// The explicit sample preview keeps its sample rows; a real failure is the screen ErrorState only.
|
|
423
|
+
return compose({ ...s, ...PRIVATE_EMPTY, ...OFFERING_EMPTY, ...SECTIONS_HIDDEN, currency, earningRules: [], earningEmptyText: "", inactiveText: "", hideInactive: true,
|
|
424
|
+
title: s.title || copyParam("loyalty.programFallback", "Rewards"), noTitle: false, hasTitle: true, noStatusSkeleton: true,
|
|
425
|
+
hideCatalog: !failure.isMock, hideContent: !failure.isMock, hideRewardRows: !failure.isMock,
|
|
426
|
+
...failure, signInRequired: false, noSignIn: true });
|
|
246
427
|
}
|
|
247
428
|
},
|
|
248
429
|
},
|