@wix/himalaya-cli 0.1749.0 → 0.1750.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/core/ts/src/site-shell.d.ts +2 -1
- package/dist/cli.mjs +13347 -8151
- package/guides/getting-started.md +3 -1
- package/guides/himi-json-output.md +54 -1
- package/guides/himi-skill.md +3 -1
- package/guides/one-app-to-himi-app.md +31 -8
- package/guides/skill.md +3 -1
- package/guides/store-submission.md +149 -34
- package/guides/wix-business-context.md +14 -0
- package/package.json +10 -10
- package/template-icons/personal-fitness-trainer.png +0 -0
- package/templates/beauty-salon/config.ts +12 -0
- package/templates/beauty-salon/tier5-src/_shared/booking-session.ts +3 -1
- package/templates/beauty-salon/tier5-src/_shared/business-chat-transport.ts +148 -0
- package/templates/beauty-salon/tier5-src/_shared/header-badges.ts +113 -0
- package/templates/beauty-salon/tier5-src/_shared/location-pin.ts +97 -0
- package/templates/beauty-salon/tier5-src/_shared/member-access.ts +17 -6
- package/templates/beauty-salon/tier5-src/_shared/source-badges.ts +72 -0
- package/templates/beauty-salon/tier5-src/himi-branded-lite-nav/index.ts +152 -0
- package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/beauty-salon/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/branded-lite/config.ts +12 -0
- package/templates/branded-lite/l10n/fr.json +5 -0
- package/templates/branded-lite/l10n/he.json +4 -0
- package/templates/branded-lite/tier5-src/_shared/booking-session.ts +3 -1
- package/templates/branded-lite/tier5-src/_shared/location-pin.ts +97 -0
- package/templates/branded-lite/tier5-src/_shared/member-access.ts +17 -6
- package/templates/branded-lite/tier5-src/himi-branded-lite-access-nav/index.ts +10 -5
- package/templates/branded-lite/tier5-src/himi-branded-lite-nav/index.ts +152 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-video/index.ts +12 -1
- package/templates/branded-lite/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/branded-lite/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/community-club/tier5-src/_shared/member-access.ts +17 -6
- package/templates/community-club/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/community-club/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/conference/tier5-src/_shared/member-access.ts +17 -6
- package/templates/conference/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/events-meetups/tier5-src/_shared/member-access.ts +17 -6
- package/templates/events-meetups/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/events-meetups/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/gym-fitness/config.ts +12 -0
- package/templates/gym-fitness/tier5-src/_shared/booking-session.ts +3 -1
- package/templates/gym-fitness/tier5-src/_shared/business-chat-transport.ts +148 -0
- package/templates/gym-fitness/tier5-src/_shared/header-badges.ts +113 -0
- package/templates/gym-fitness/tier5-src/_shared/location-pin.ts +97 -0
- package/templates/gym-fitness/tier5-src/_shared/member-access.ts +17 -6
- package/templates/gym-fitness/tier5-src/_shared/source-badges.ts +72 -0
- package/templates/gym-fitness/tier5-src/himi-branded-lite-nav/index.ts +152 -0
- package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/gym-fitness/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/medical-services/tier5-src/_shared/booking-session.ts +3 -1
- package/templates/medical-services/tier5-src/_shared/member-access.ts +17 -6
- package/templates/medical-services/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/nonprofit-cause/tier5-src/_shared/member-access.ts +17 -6
- package/templates/nonprofit-cause/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/nonprofit-cause/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/personal-fitness-trainer/README.md +51 -0
- package/templates/personal-fitness-trainer/config.ts +343 -0
- package/templates/personal-fitness-trainer/dev/index.ts +24813 -0
- package/templates/personal-fitness-trainer/himalaya.content.json +79 -0
- package/templates/personal-fitness-trainer/himalaya.template.json +14 -0
- package/templates/personal-fitness-trainer/icon.png +0 -0
- package/templates/personal-fitness-trainer/platforms.json +3 -0
- package/templates/personal-fitness-trainer/splash.json +3 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/app-locale.ts +61 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/booking-location.ts +147 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/booking-session.ts +224 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/branded-lite-hosted.ts +280 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/branded-load-state.ts +109 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-copy.ts +40 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-history.ts +51 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-message-model.ts +177 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-model.ts +56 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-presenter.ts +576 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/business-chat-transport.ts +148 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-contract.ts +228 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +193 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +400 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/empty-flags.ts +33 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/engine-intl.ts +523 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/himi-account.ts +194 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/himi-booking-saved.ts +88 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/himi-bookings.ts +318 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/himi-copy.ts +116 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/himi-layouts.ts +142 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/host-events.ts +66 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/iap-attendance-form.ts +106 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/iap-attendance-purchase.ts +216 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/iap-attendance.ts +38 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/iap-worker.ts +127 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/inbox-rooms.ts +68 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/member-access.ts +63 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/member-account-routes.ts +52 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/member-bookings.ts +107 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/offset-page.ts +10 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/payment-setup.ts +6 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/rich-body.ts +78 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/rich-content-link.ts +34 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/sign-in-sheet.ts +18 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/staff-name.ts +18 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/video-caption.ts +21 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/wix-bi.ts +85 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/wix-service-price.ts +146 -0
- package/templates/personal-fitness-trainer/tier5-src/business-chat/index.ts +732 -0
- package/templates/personal-fitness-trainer/tier5-src/business-contact/index.ts +6 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-booking-bookings/index.ts +468 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-booking-service/index.ts +1190 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-booking-services/index.ts +791 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-booking-time/index.ts +1729 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +242 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-account-settings/index.ts +1094 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-agenda/index.ts +955 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-appearance/index.ts +94 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-notifsettings/index.ts +173 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-plans/index.ts +495 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-splash/index.ts +35 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-video/index.ts +226 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-videos/index.ts +145 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-fitness-trainer-home/index.ts +70 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-fitness-trainer-profile/index.ts +53 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-store-account/index.ts +1007 -0
- package/templates/personal-fitness-trainer/tier5-src/wix-spaces-app-language/index.ts +73 -0
- package/templates/personal-fitness-trainer/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/personal-fitness-trainer/tier5-src/wix-spaces-my-subscriptions/index.ts +84 -0
- package/templates/personal-fitness-trainer/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
- package/templates/personal-fitness-trainer/tier5-src/wix-spaces-view-profile/index.ts +119 -0
- package/templates/personal-fitness-trainer/tokens.json +381 -0
- package/templates/podcast-creator/tier5-src/_shared/member-access.ts +17 -6
- package/templates/podcast-creator/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/podcast-creator/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/portfolio-creative/tier5-src/_shared/member-access.ts +17 -6
- package/templates/portfolio-creative/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/portfolio-creative/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/restaurant/tier5-src/_shared/member-access.ts +17 -6
- package/templates/restaurant/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/restaurant/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/retail-store/tier5-src/_shared/member-access.ts +17 -6
- package/templates/retail-store/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/retail-store/tier5-src/wix-spaces-view-profile/index.ts +68 -55
- package/templates/salon-spa/tier5-src/_shared/booking-session.ts +3 -1
- package/templates/salon-spa/tier5-src/_shared/member-access.ts +17 -6
- package/templates/salon-spa/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/wholesale-store/tier5-src/_shared/member-access.ts +17 -6
- package/templates/wholesale-store/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/yoga-studio/config.ts +12 -0
- package/templates/yoga-studio/tier5-src/_shared/booking-session.ts +3 -1
- package/templates/yoga-studio/tier5-src/_shared/business-chat-transport.ts +148 -0
- package/templates/yoga-studio/tier5-src/_shared/header-badges.ts +113 -0
- package/templates/yoga-studio/tier5-src/_shared/location-pin.ts +97 -0
- package/templates/yoga-studio/tier5-src/_shared/member-access.ts +17 -6
- package/templates/yoga-studio/tier5-src/_shared/source-badges.ts +72 -0
- package/templates/yoga-studio/tier5-src/himi-branded-lite-nav/index.ts +152 -0
- package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +13 -4
- package/templates/yoga-studio/tier5-src/wix-spaces-view-profile/index.ts +68 -55
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Tier-5 bundle: App Language settings (ON-DEVICE).
|
|
2
|
+
// Options bound via $service:spacesAppLanguage.options.
|
|
3
|
+
// select → updates the Selected marker + dispatches locale.set so the native
|
|
4
|
+
// LocaleStore flips Accept-Language, purges descriptor caches, and reloads.
|
|
5
|
+
import { defineService } from "@himalaya/state";
|
|
6
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
7
|
+
|
|
8
|
+
/** `selected` drives the row's radio; `subtitle` stays for older descriptors. */
|
|
9
|
+
interface Row { id: string; name: string; subtitle: string; selected: boolean }
|
|
10
|
+
interface S { status: "ready"; options: Row[] }
|
|
11
|
+
|
|
12
|
+
/** What a host that cannot say which languages the app ships offers: the three the template's first catalogs cover. A host
|
|
13
|
+
* that answers `locale.get` with its `available` list (every current one) replaces this with the real list. */
|
|
14
|
+
const DEFAULT_OPTIONS: Omit<Row, "subtitle" | "selected">[] = [
|
|
15
|
+
{ id: "en", name: "English" },
|
|
16
|
+
{ id: "es", name: "Español" },
|
|
17
|
+
{ id: "he", name: "עברית" },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
let LOCALE_OPTIONS = DEFAULT_OPTIONS;
|
|
21
|
+
|
|
22
|
+
/** The host's `available` list (`{ tag, nativeName }[]`), or undefined when it sent none that can be used. */
|
|
23
|
+
function optionsFrom(payload: { available?: unknown } | null): Omit<Row, "subtitle" | "selected">[] | undefined {
|
|
24
|
+
if (!Array.isArray(payload?.available)) return undefined;
|
|
25
|
+
const rows = (payload.available as { tag?: unknown; nativeName?: unknown }[])
|
|
26
|
+
.filter((a) => typeof a?.tag === "string" && a.tag !== "")
|
|
27
|
+
.map((a) => ({ id: a.tag as string, name: typeof a.nativeName === "string" && a.nativeName ? a.nativeName : (a.tag as string) }));
|
|
28
|
+
return rows.length ? rows : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function withSelected(selected: string): Row[] {
|
|
32
|
+
return LOCALE_OPTIONS.map((o) => ({
|
|
33
|
+
...o,
|
|
34
|
+
subtitle: o.id === selected ? "Selected" : "",
|
|
35
|
+
selected: o.id === selected,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const svc = defineService<S, {
|
|
40
|
+
select: (s: S, arg?: unknown) => Promise<S>;
|
|
41
|
+
hydrate: (s: S) => Promise<S>;
|
|
42
|
+
}>("spacesAppLanguage", {
|
|
43
|
+
state: { status: "ready", options: withSelected("en") },
|
|
44
|
+
actions: {
|
|
45
|
+
select: async (s, arg) => {
|
|
46
|
+
const id = typeof arg === "string" ? arg : ((arg as { id?: string })?.id ?? "");
|
|
47
|
+
if (!id || !LOCALE_OPTIONS.some((o) => o.id === id)) return s;
|
|
48
|
+
const next = { ...s, options: withSelected(id) };
|
|
49
|
+
try {
|
|
50
|
+
await dispatch("locale.set", { tag: id });
|
|
51
|
+
} catch {
|
|
52
|
+
// Native handler missing (web / older binary) — keep UI selection only.
|
|
53
|
+
}
|
|
54
|
+
return next;
|
|
55
|
+
},
|
|
56
|
+
hydrate: async (s) => {
|
|
57
|
+
try {
|
|
58
|
+
const payload = (await dispatch("locale.get")) as { tag?: string; available?: unknown } | null;
|
|
59
|
+
// The app's own languages, as its host reports them: a catalog added to the app is selectable with no change here.
|
|
60
|
+
LOCALE_OPTIONS = optionsFrom(payload) ?? DEFAULT_OPTIONS;
|
|
61
|
+
const tag = typeof payload?.tag === "string" ? payload.tag : "en";
|
|
62
|
+
if (LOCALE_OPTIONS.some((o) => o.id === tag)) {
|
|
63
|
+
return { ...s, options: withSelected(tag) };
|
|
64
|
+
}
|
|
65
|
+
return { ...s, options: withSelected("") };
|
|
66
|
+
} catch {
|
|
67
|
+
// ignore — leave default Selected
|
|
68
|
+
}
|
|
69
|
+
return s;
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
export { svc };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Tier-5 bundle: Wix Spaces clone — Delete my account.
|
|
2
|
+
// Confirm calls DELETE /members/v1/members/my then signs out. Failures surface
|
|
3
|
+
// in `message` so the UI can keep the confirmation (no silent no-op).
|
|
4
|
+
import { defineService } from "@himalaya/state";
|
|
5
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
6
|
+
|
|
7
|
+
interface S {
|
|
8
|
+
status: "ready";
|
|
9
|
+
title: string;
|
|
10
|
+
body: string;
|
|
11
|
+
cta: string;
|
|
12
|
+
message: string;
|
|
13
|
+
done: boolean;
|
|
14
|
+
notDone: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function wixApi() {
|
|
18
|
+
return (globalThis as { himalaya?: { wixApi?: { call: (m: string, p: string, b?: unknown) => Promise<unknown> } } }).himalaya?.wixApi;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const svc = defineService<S, { confirm: (s: S) => Promise<S> }>("spacesDeleteAccount", {
|
|
22
|
+
state: {
|
|
23
|
+
status: "ready",
|
|
24
|
+
title: "Delete your account",
|
|
25
|
+
body: "This will permanently delete your membership on this site. This action can't be undone.",
|
|
26
|
+
cta: "Delete Account",
|
|
27
|
+
message: "",
|
|
28
|
+
done: false,
|
|
29
|
+
notDone: true,
|
|
30
|
+
},
|
|
31
|
+
actions: {
|
|
32
|
+
confirm: async (s) => {
|
|
33
|
+
try {
|
|
34
|
+
const api = wixApi();
|
|
35
|
+
if (!api) throw new Error("wixApi unavailable");
|
|
36
|
+
await api.call("DELETE", "/members/v1/members/my");
|
|
37
|
+
try { await dispatch("himi.wix.signOut"); } catch { /* best-effort */ }
|
|
38
|
+
return {
|
|
39
|
+
...s,
|
|
40
|
+
message: "Your membership was deleted. You’ve been signed out.",
|
|
41
|
+
done: true,
|
|
42
|
+
notDone: false,
|
|
43
|
+
cta: "Done",
|
|
44
|
+
};
|
|
45
|
+
} catch (err) {
|
|
46
|
+
const msg = String((err as { message?: unknown })?.message ?? err ?? "Delete failed");
|
|
47
|
+
return {
|
|
48
|
+
...s,
|
|
49
|
+
message: /403|FORBIDDEN|permission|denied/i.test(msg)
|
|
50
|
+
? "This site doesn’t allow members to delete their own account from the app."
|
|
51
|
+
: "Couldn’t delete the account. Try again or contact the site owner.",
|
|
52
|
+
done: false,
|
|
53
|
+
notDone: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
export { svc };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { defineService } from "@himalaya/state";
|
|
2
|
+
import { listMyPlanOrders, type WixPlanOrder } from "@himalaya/wix-pricing-plans";
|
|
3
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
4
|
+
import { memberAccess, assertMemberAccess, memberAccessDenied, memberChanged } from "../_shared/member-access.js";
|
|
5
|
+
import { orderDate, orderPrice, orderStatus } from "../_shared/pricing-plan-display.js";
|
|
6
|
+
import { descriptionBody } from "../_shared/rich-body.js";
|
|
7
|
+
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
8
|
+
|
|
9
|
+
interface Row { id: string; name: string; subtitle: string; description: string; price: string; endDate: string; noEndDate: boolean; expired: boolean; dateLabel: string }
|
|
10
|
+
interface S {
|
|
11
|
+
status: string; orders: Row[]; rows: Row[]; allOrders: Row[]; selectedTab: string; nextCursor: string;
|
|
12
|
+
emptyText: string; hideAccountCta: boolean; noOrders: boolean;
|
|
13
|
+
isLoading: boolean; notLoading: boolean; hideError: boolean; denied: boolean;
|
|
14
|
+
hideEmpty: boolean; hideEmptyLoadMore: boolean; hideDeniedError: boolean; hideRetryError: boolean; pageError: boolean; loadingPage: boolean;
|
|
15
|
+
}
|
|
16
|
+
const initial = (): S => ({ status: "loading", orders: [], rows: [], allOrders: [], selectedTab: "active", nextCursor: "", emptyText: "", hideAccountCta: true, noOrders: true, isLoading: true, notLoading: false, hideError: true, denied: false, hideEmpty: true, hideEmptyLoadMore: true, hideDeniedError: true, hideRetryError: true, pageError: false, loadingPage: false });
|
|
17
|
+
let sequence = 0;
|
|
18
|
+
let scope = "";
|
|
19
|
+
let offset = 0;
|
|
20
|
+
let pending = false;
|
|
21
|
+
const session = hostSessionFromGlobal();
|
|
22
|
+
|
|
23
|
+
function project(state: S): S {
|
|
24
|
+
// Keep the unfiltered `orders` contract for older descriptors without tabs.
|
|
25
|
+
const orders = state.allOrders;
|
|
26
|
+
const rows = orders.filter(row => row.expired === (state.selectedTab === "expired"));
|
|
27
|
+
return { ...state, orders, rows, noOrders: rows.length === 0, hideEmpty: state.status !== "ready" || rows.length > 0 || Boolean(state.nextCursor),
|
|
28
|
+
hideEmptyLoadMore: state.status !== "ready" || rows.length > 0 || !state.nextCursor,
|
|
29
|
+
emptyText: orders.length ? "" : state.selectedTab === "expired" ? copyParam("mySubscriptions.expiredEmpty", "No expired subscriptions") : copyParam("mySubscriptions.activeEmpty", "No active subscriptions") };
|
|
30
|
+
}
|
|
31
|
+
function norm(order: WixPlanOrder): Row {
|
|
32
|
+
const periodEnd = !order.earliestEndDate && !order.endDate && order.status === "ACTIVE" && (order.pricing?.subscription ?? order.priceDetails?.subscription) ? orderDate(order.currentCycle?.endedDate) : "";
|
|
33
|
+
const endDate = orderDate(order.earliestEndDate ?? order.endDate) || periodEnd;
|
|
34
|
+
return { id: order.id, name: order.planName || copyParam("plans.planFallbackName", "Plan"), subtitle: orderStatus(order),
|
|
35
|
+
description: descriptionBody(order.planDescription).bodyText, price: orderPrice(order), endDate, noEndDate: !endDate, dateLabel: periodEnd ? copyParam("subscriptionDetail.periodEnd", "Current period ends") : order.status === "CANCELED" ? copyParam("subscriptionDetail.endDate", "End date") : order.status === "ENDED" ? copyParam("mySubscriptions.expiredOn", "Expired on") : copyParam("mySubscriptions.validUntil", "Valid until"),
|
|
36
|
+
expired: ["ENDED", "CANCELED"].includes(order.status ?? "") };
|
|
37
|
+
}
|
|
38
|
+
async function readPage(state: S, reset: boolean): Promise<S | undefined> {
|
|
39
|
+
if (!reset && pending) return undefined;
|
|
40
|
+
const seq = reset ? ++sequence : sequence;
|
|
41
|
+
pending = true;
|
|
42
|
+
if (!reset) void svc.beginPage();
|
|
43
|
+
const member = await memberAccess();
|
|
44
|
+
const key = JSON.stringify([member.email, member.scope]);
|
|
45
|
+
if (seq !== sequence) return undefined;
|
|
46
|
+
if (key !== scope) { scope = key; offset = 0; state = initial(); void svc.clear(); }
|
|
47
|
+
if (!member.email) { pending = false; return { ...initial(), status: "guest", emptyText: copyParam("mySubscriptions.guestBody", "Sign in to see your subscriptions."), isLoading: false, notLoading: true, hideAccountCta: false }; }
|
|
48
|
+
try {
|
|
49
|
+
const start = reset ? 0 : offset;
|
|
50
|
+
const result = await listMyPlanOrders({ statuses: ["ACTIVE", "PENDING", "PAUSED", "CANCELED", "ENDED"], limit: 50, offset: start });
|
|
51
|
+
await assertMemberAccess(member);
|
|
52
|
+
if (seq !== sequence) return undefined;
|
|
53
|
+
const raw = result.orders ?? [];
|
|
54
|
+
offset = start + raw.length;
|
|
55
|
+
const rows = raw.filter(order => order.id && order.status !== "DRAFT").map(norm);
|
|
56
|
+
const allOrders = [...new Map([...(reset ? [] : state.allOrders), ...rows].map(row => [row.id, row])).values()];
|
|
57
|
+
return project({ ...state, status: "ready", allOrders, isLoading: false, notLoading: true, hideError: true, denied: false, hideAccountCta: true,
|
|
58
|
+
selectedTab: svc.getState().selectedTab, hideDeniedError: true, hideRetryError: true, nextCursor: raw.length === 50 ? String(offset) : "", pageError: false, loadingPage: false });
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (seq !== sequence) return undefined;
|
|
61
|
+
if (await memberChanged(member, error)) { scope = ""; void svc.clear(); void svc.load(); return undefined; }
|
|
62
|
+
state = project({ ...state, selectedTab: svc.getState().selectedTab });
|
|
63
|
+
const denied = memberAccessDenied(error);
|
|
64
|
+
if (denied) return { ...initial(), selectedTab: state.selectedTab, status: "error", emptyText: copyParam("mySubscriptions.accessDenied", "Subscriptions are unavailable for this account."), isLoading: false, notLoading: true, hideError: false, denied: true, hideDeniedError: false, hideRetryError: true };
|
|
65
|
+
return { ...state, status: "error", emptyText: copyParam("mySubscriptions.loadError", "Subscriptions could not be loaded."), isLoading: false, notLoading: true, hideError: false, denied: false, hideDeniedError: true, hideRetryError: false, hideEmpty: true, hideEmptyLoadMore: true, pageError: !reset && state.allOrders.length > 0, loadingPage: false };
|
|
66
|
+
} finally { if (seq === sequence) pending = false; }
|
|
67
|
+
}
|
|
68
|
+
const svc = defineService<S, {
|
|
69
|
+
clear: (s: S) => S; beginPage: (s: S) => S; load: (s: S, arg?: unknown) => Promise<S | undefined>;
|
|
70
|
+
retry: (s: S) => Promise<S | undefined>; nextPage: (s: S) => Promise<S | undefined>; selectTab: (s: S, arg?: unknown) => S;
|
|
71
|
+
}>("spacesMySubscriptions", {
|
|
72
|
+
state: initial(), notHydrated: Object.keys(initial()) as Array<keyof S>,
|
|
73
|
+
actions: {
|
|
74
|
+
clear: () => initial(),
|
|
75
|
+
beginPage: state => ({ ...state, loadingPage: true }),
|
|
76
|
+
load: (state, arg) => { stashCopy(arg); return readPage(state, true); },
|
|
77
|
+
retry: state => readPage(state, !state.pageError),
|
|
78
|
+
nextPage: state => state.nextCursor ? readPage(state, false) : Promise.resolve(undefined),
|
|
79
|
+
selectTab: (state, arg) => { const raw = typeof arg === "string" ? arg : (arg as { selectedId?: string; id?: string; value?: string })?.selectedId ?? (arg as { id?: string })?.id ?? (arg as { value?: string })?.value; return project({ ...state, selectedTab: raw === "expired" ? "expired" : "active" }); },
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
session.subscribe(() => { ++sequence; scope = ""; pending = false; void svc.clear(); void svc.load(); });
|
|
83
|
+
svc.load();
|
|
84
|
+
export { svc };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { defineService } from "@himalaya/state";
|
|
2
|
+
import { getMyPlanOrder, requestCancellation, type WixPlanOrder } from "@himalaya/wix-pricing-plans";
|
|
3
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
4
|
+
import { memberAccess, assertMemberAccess, memberAccessDenied, memberChanged, type MemberAccess } from "../_shared/member-access.js";
|
|
5
|
+
import { orderDate, orderPrice, orderStatus, orderFacts } from "../_shared/pricing-plan-display.js";
|
|
6
|
+
import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
|
|
7
|
+
import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
8
|
+
|
|
9
|
+
interface S extends PresenceFlags {
|
|
10
|
+
denied: boolean; hideDeniedError: boolean; notActive: boolean; isActive: boolean;
|
|
11
|
+
status: string; name: string; subtitle: string; price: string; validity: string;
|
|
12
|
+
facts: ReturnType<typeof orderFacts>; hideAccountCta: boolean;
|
|
13
|
+
hideCancel: boolean; hideConfirmation: boolean; showConfirmation: boolean; busy: boolean; noScheduledOption: boolean;
|
|
14
|
+
effectiveAt: string; confirmation: string; actionMessage: string; actionError: string; hasActionError: boolean; noActionError: boolean;
|
|
15
|
+
}
|
|
16
|
+
const initial = (): S => ({ denied: false, hideDeniedError: true, notActive: true, isActive: false, status: "loading", name: "", subtitle: "", price: "", validity: "", facts: [], hideAccountCta: true,
|
|
17
|
+
hideCancel: true, hideConfirmation: true, showConfirmation: false, busy: false, noScheduledOption: true, effectiveAt: "IMMEDIATELY", confirmation: "", actionMessage: "", actionError: "none", hasActionError: false, noActionError: true, ...presence("loading") });
|
|
18
|
+
let order: WixPlanOrder | null = null;
|
|
19
|
+
let sequence = 0;
|
|
20
|
+
let cancelInFlight = false;
|
|
21
|
+
const cancellationsSent = new Set<string>();
|
|
22
|
+
let orderMemberKey = "";
|
|
23
|
+
const memberKey = (member: MemberAccess): string => JSON.stringify([member.scope, member.email]);
|
|
24
|
+
const cancellationKey = (id: string, owner = orderMemberKey): string => JSON.stringify([owner, id]);
|
|
25
|
+
const session = hostSessionFromGlobal();
|
|
26
|
+
function canCancel(o: WixPlanOrder): boolean {
|
|
27
|
+
// The member API enforces the PURCHASED policy. Current public plan settings are not the
|
|
28
|
+
// historical policy, and an archived plan must not prevent canceling an existing order.
|
|
29
|
+
return Boolean(o.id) && ["ACTIVE", "PENDING", "PAUSED"].includes(o.status ?? "") && o.type !== "EXTERNAL"
|
|
30
|
+
&& !o.autoRenewCanceled && o.cancellation?.effectiveAt !== "NEXT_PAYMENT_DATE";
|
|
31
|
+
}
|
|
32
|
+
function project(o: WixPlanOrder, message = ""): S {
|
|
33
|
+
const end = orderDate(o.earliestEndDate ?? o.endDate ?? o.currentCycle?.endedDate);
|
|
34
|
+
const scheduled = Boolean((o.pricing?.subscription ?? o.priceDetails?.subscription) && o.currentCycle?.endedDate && Date.parse(o.currentCycle.endedDate) > Date.now());
|
|
35
|
+
const renews = o.status === "ACTIVE" && scheduled ? orderDate(o.currentCycle?.endedDate) : "";
|
|
36
|
+
return { ...initial(), ...presence("found"), status: "ready", notActive: o.status !== "ACTIVE", isActive: o.status === "ACTIVE", name: o.planName || copyParam("subscriptionDetail.fallbackName", "Subscription"), subtitle: orderStatus(o), price: orderPrice(o),
|
|
37
|
+
validity: (o.earliestEndDate || o.autoRenewCanceled || o.cancellation?.effectiveAt === "NEXT_PAYMENT_DATE") && end ? copyTemplate("subscriptionDetail.scheduledEndMessage", "Your subscription ends on {date}.", { date: end }) : renews ? copyTemplate("placeSummary.planRenews", "Renews {date}", { date: renews }) : "",
|
|
38
|
+
facts: orderFacts(o), hideCancel: !canCancel(o) || cancellationsSent.has(cancellationKey(o.id)), noScheduledOption: !scheduled,
|
|
39
|
+
effectiveAt: scheduled ? "NEXT_PAYMENT_DATE" : "IMMEDIATELY", actionMessage: message };
|
|
40
|
+
}
|
|
41
|
+
function confirmation(effectiveAt: string): string {
|
|
42
|
+
const end = orderDate(order?.currentCycle?.endedDate);
|
|
43
|
+
return effectiveAt === "NEXT_PAYMENT_DATE" && end
|
|
44
|
+
? copyTemplate("subscriptionDetail.cancelAtPeriodEndBody", "Request cancellation at the next payment date, {date}?", { date: end })
|
|
45
|
+
: copyParam("subscriptionDetail.cancelImmediatelyBody", "Request cancellation now? Your access can end immediately.");
|
|
46
|
+
}
|
|
47
|
+
async function load(_state: S, arg?: unknown): Promise<S | undefined> {
|
|
48
|
+
stashCopy(arg);
|
|
49
|
+
const seq = ++sequence;
|
|
50
|
+
if (order && order.id !== detailInputId()) { order = null; void svc.clear(); }
|
|
51
|
+
const member = await memberAccess();
|
|
52
|
+
if (seq !== sequence) return undefined;
|
|
53
|
+
if (!member.email) { order = null; return { ...initial(), status: "guest", subtitle: copyParam("mySubscriptions.guestBody", "Sign in to see your subscriptions."), hideAccountCta: false, ...presence("missing"), hideNotFound: true }; }
|
|
54
|
+
const id = detailInputId();
|
|
55
|
+
if (!id) return { ...initial(), status: "ready", subtitle: copyParam("subscriptionDetail.missingId", "Open a subscription from My Subscriptions."), ...presence("missing") };
|
|
56
|
+
try {
|
|
57
|
+
const result = await getMyPlanOrder(id);
|
|
58
|
+
await assertMemberAccess(member);
|
|
59
|
+
if (seq !== sequence) return undefined;
|
|
60
|
+
orderMemberKey = memberKey(member);
|
|
61
|
+
order = result.order;
|
|
62
|
+
if (!order?.id || order.status === "DRAFT") { order = null; return { ...initial(), status: "ready", ...presence("missing") }; }
|
|
63
|
+
return project(order, cancellationsSent.has(cancellationKey(order.id)) && canCancel(order) ? copyParam("subscriptionDetail.cancelPending", "Cancellation requested. Refresh to see the latest status.") : "");
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (seq !== sequence) return undefined;
|
|
66
|
+
order = null;
|
|
67
|
+
if (await memberChanged(member, error)) { void svc.clear(); void svc.load(); return undefined; }
|
|
68
|
+
const denied = memberAccessDenied(error);
|
|
69
|
+
const flags = presenceAfterError(error);
|
|
70
|
+
return { ...initial(), status: "ready", subtitle: copyParam("subscriptionDetail.loadError", "This subscription could not be loaded."), ...flags, denied, hideLoadError: denied || flags.hideLoadError, hideDeniedError: !denied };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
type SubscriptionActions = {
|
|
74
|
+
beginCancel: (s: S) => S; clear: (s: S) => S; load: typeof load; requestCancel: (s: S) => S;
|
|
75
|
+
dismissCancel: (s: S) => S; chooseEffectiveAt: (s: S, arg?: unknown) => S;
|
|
76
|
+
confirmCancel: (s: S) => Promise<S | undefined>;
|
|
77
|
+
};
|
|
78
|
+
const svc: ReturnType<typeof defineService<S, SubscriptionActions>> = defineService<S, SubscriptionActions>("spacesSubscriptionDetail", {
|
|
79
|
+
state: initial(), notHydrated: Object.keys(initial()) as Array<keyof S>,
|
|
80
|
+
actions: {
|
|
81
|
+
beginCancel: state => ({ ...state, busy: true }),
|
|
82
|
+
clear: () => initial(), load,
|
|
83
|
+
requestCancel: state => !order || order.id !== detailInputId() || state.hideCancel || cancelInFlight ? state : { ...state, hideConfirmation: false, showConfirmation: true, actionMessage: "", actionError: "none", hasActionError: false, noActionError: true, confirmation: confirmation(state.effectiveAt) },
|
|
84
|
+
dismissCancel: state => cancelInFlight ? state : { ...state, hideConfirmation: true, showConfirmation: false },
|
|
85
|
+
chooseEffectiveAt: (state, arg) => {
|
|
86
|
+
if (cancelInFlight || state.hideConfirmation) return state;
|
|
87
|
+
const value = typeof arg === "string" ? arg : (arg as { value?: string; selectedId?: string })?.value ?? (arg as { selectedId?: string })?.selectedId;
|
|
88
|
+
const effectiveAt = value === "NEXT_PAYMENT_DATE" && !state.noScheduledOption ? value : "IMMEDIATELY";
|
|
89
|
+
return { ...state, effectiveAt, confirmation: confirmation(effectiveAt) };
|
|
90
|
+
},
|
|
91
|
+
confirmCancel: async (state): Promise<S | undefined> => {
|
|
92
|
+
if (state.hideConfirmation || state.hideCancel || !order || order.id !== detailInputId() || !canCancel(order) || cancelInFlight || cancellationsSent.has(cancellationKey(order.id))) return undefined;
|
|
93
|
+
cancelInFlight = true;
|
|
94
|
+
void svc.beginCancel();
|
|
95
|
+
const seq = sequence;
|
|
96
|
+
const id = order.id;
|
|
97
|
+
const isCurrent = (): boolean => seq === sequence && detailInputId() === id;
|
|
98
|
+
const member = await memberAccess();
|
|
99
|
+
const requestKey = cancellationKey(id, memberKey(member));
|
|
100
|
+
try {
|
|
101
|
+
if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
|
|
102
|
+
await assertMemberAccess(member);
|
|
103
|
+
if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
|
|
104
|
+
// Refresh policy/lifecycle facts before writing; never cancel a stale/other member order.
|
|
105
|
+
const latest = (await getMyPlanOrder(id)).order;
|
|
106
|
+
await assertMemberAccess(member);
|
|
107
|
+
if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
|
|
108
|
+
if (!latest || !canCancel(latest)) { order = latest; return latest ? project(latest) : { ...initial(), ...presence("missing") }; }
|
|
109
|
+
if (state.effectiveAt === "NEXT_PAYMENT_DATE" && (!latest.currentCycle?.endedDate || Date.parse(latest.currentCycle.endedDate) <= Date.now())) {
|
|
110
|
+
order = latest; return { ...project(latest), actionMessage: copyParam("subscriptionDetail.changedBeforeCancel", "Your subscription changed. Review the details before canceling.") };
|
|
111
|
+
}
|
|
112
|
+
await requestCancellation(id, state.effectiveAt === "NEXT_PAYMENT_DATE" ? "NEXT_PAYMENT_DATE" : "IMMEDIATELY");
|
|
113
|
+
// An accepted write remains fenced for its original member even when a session
|
|
114
|
+
// change overtakes its response. Check ownership before publishing, not before
|
|
115
|
+
// remembering the acknowledgement; reads can still report ACTIVE afterward.
|
|
116
|
+
cancellationsSent.add(requestKey);
|
|
117
|
+
if (!isCurrent()) return load(svc.getState());
|
|
118
|
+
await assertMemberAccess(member);
|
|
119
|
+
if (!isCurrent()) return load(svc.getState());
|
|
120
|
+
const refreshed = (await getMyPlanOrder(id)).order;
|
|
121
|
+
await assertMemberAccess(member);
|
|
122
|
+
if (!isCurrent()) return load(svc.getState());
|
|
123
|
+
order = refreshed;
|
|
124
|
+
return project(refreshed, canCancel(refreshed) ? copyParam("subscriptionDetail.cancelPending", "Cancellation requested. Refresh to see the latest status.") : "");
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
|
|
127
|
+
if (await memberChanged(member, error)) { order = null; orderMemberKey = ""; void svc.clear(); void svc.load(); return undefined; }
|
|
128
|
+
if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
|
|
129
|
+
return { ...state, busy: false, hideConfirmation: true, showConfirmation: false, actionError: cancellationsSent.has(requestKey) ? "cancelRefreshFailed" : memberAccessDenied(error) ? "cancelDenied" : "cancelFailed", hasActionError: true, noActionError: false, hideCancel: cancellationsSent.has(requestKey) || memberAccessDenied(error) || state.hideCancel,
|
|
130
|
+
actionMessage: cancellationsSent.has(requestKey) ? copyParam("subscriptionDetail.cancelRefreshFailed", "Cancellation requested, but the latest status could not be loaded. Refresh the details.")
|
|
131
|
+
: memberAccessDenied(error) ? copyParam("subscriptionDetail.cancelDenied", "This subscription cannot be canceled from this account. Contact the business for help.")
|
|
132
|
+
: copyParam("subscriptionDetail.cancelFailed", "Cancellation failed. Try again.") };
|
|
133
|
+
} finally { cancelInFlight = false; }
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
session.subscribe(() => { ++sequence; order = null; orderMemberKey = ""; void svc.clear(); void svc.load(); });
|
|
138
|
+
svc.load();
|
|
139
|
+
export { svc };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Tier-5 bundle: Wix Spaces clone — View Profile (member's own public profile).
|
|
2
|
+
// Prefer site Members Area (`GET /members/v1/members/my`) + session email; never
|
|
3
|
+
// paint the seeded "apptestercoowner" demo identity when the session is a real
|
|
4
|
+
// member (or a guest — show honesty instead).
|
|
5
|
+
import { defineService } from "@himalaya/state";
|
|
6
|
+
import { memberAccess } from "../_shared/member-access.js";
|
|
7
|
+
import { getMyData, displayName } from "@himalaya/wix-users";
|
|
8
|
+
|
|
9
|
+
// `needsSignIn` / `noSignIn` drive the shared member gate: a guest gets the
|
|
10
|
+
// gate with a Sign in button and no placeholder profile. `profileHidden` stays true until
|
|
11
|
+
// `load` has resolved a member, so a guest never glimpses the placeholder avatar while
|
|
12
|
+
// the membership check is still running; `hideLoading` is false for exactly that moment,
|
|
13
|
+
// so the screen shows a loading line instead of going blank.
|
|
14
|
+
interface S { status: "loading" | "ready"; name: string; handle: string; about: string; initial: string; photo: string; needsSignIn: boolean; noSignIn: boolean; profileHidden: boolean; hideLoading: boolean; hideError: boolean; hideAbout: boolean }
|
|
15
|
+
|
|
16
|
+
const EMPTY: S = {
|
|
17
|
+
status: "loading",
|
|
18
|
+
name: "",
|
|
19
|
+
handle: "",
|
|
20
|
+
about: "No info to display.",
|
|
21
|
+
initial: "?",
|
|
22
|
+
photo: "",
|
|
23
|
+
needsSignIn: false,
|
|
24
|
+
noSignIn: true,
|
|
25
|
+
profileHidden: true,
|
|
26
|
+
hideLoading: false,
|
|
27
|
+
hideError: true,
|
|
28
|
+
hideAbout: false,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// The SAME member check create-post and orders use (`memberAccess`: the host's
|
|
32
|
+
// memberIdentity, falling back to wix-users only on hosts that predate that action), so
|
|
33
|
+
// one shared gate never gives two answers in one app.
|
|
34
|
+
async function sessionEmail(): Promise<string> {
|
|
35
|
+
return (await memberAccess()).email;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function wixApi() {
|
|
39
|
+
return (globalThis as { himalaya?: { wixApi?: { call: (m: string, p: string, b?: unknown) => Promise<unknown> } } }).himalaya?.wixApi;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function fromParts(name: string, handleRaw: string, about: string, photo = ""): S {
|
|
43
|
+
const clean = name.trim();
|
|
44
|
+
const handle = "@" + (handleRaw || clean || "member").replace(/\s+/g, "").replace(/^@+/, "").toLowerCase();
|
|
45
|
+
const initial = (clean.split(/\s+/).filter(Boolean).map((w) => w[0]).join("").slice(0, 2) || "?").toUpperCase();
|
|
46
|
+
return { status: "ready", name: clean || "Member", handle, about: about || "No info to display.", initial, photo, needsSignIn: false, noSignIn: true, profileHidden: false, hideLoading: true, hideError: true, hideAbout: false };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function readProfile(): Promise<S> {
|
|
50
|
+
const email = await sessionEmail();
|
|
51
|
+
if (!email) {
|
|
52
|
+
return {
|
|
53
|
+
status: "ready",
|
|
54
|
+
// Kept for hosts without the shared member gate (the Spaces clone renders these
|
|
55
|
+
// fields directly); branded-lite hides the profile block behind `profileHidden`.
|
|
56
|
+
name: "Sign in to view your profile",
|
|
57
|
+
handle: "",
|
|
58
|
+
about: "Your public profile is available after you sign in from Account.",
|
|
59
|
+
initial: "?",
|
|
60
|
+
photo: "",
|
|
61
|
+
needsSignIn: true,
|
|
62
|
+
noSignIn: false,
|
|
63
|
+
profileHidden: true,
|
|
64
|
+
hideLoading: true,
|
|
65
|
+
hideError: true,
|
|
66
|
+
hideAbout: false,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const api = wixApi();
|
|
71
|
+
if (api) {
|
|
72
|
+
const res = (await api.call("GET", "/members/v1/members/my?fieldSet=FULL")) as {
|
|
73
|
+
member?: {
|
|
74
|
+
loginEmail?: string;
|
|
75
|
+
contact?: { firstName?: string; lastName?: string };
|
|
76
|
+
profile?: { nickname?: string; slug?: string; title?: string; photo?: { url?: string } };
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const m = res.member;
|
|
80
|
+
if (m) {
|
|
81
|
+
const nick = m.profile?.nickname?.trim() || "";
|
|
82
|
+
const full = [m.contact?.firstName, m.contact?.lastName].filter(Boolean).join(" ").trim();
|
|
83
|
+
const name = full || nick || m.loginEmail || email;
|
|
84
|
+
const slug = m.profile?.slug || nick || name;
|
|
85
|
+
const about = m.profile?.title || "No info to display.";
|
|
86
|
+
return fromParts(name, slug, about, m.profile?.photo?.url || "");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} catch { /* fall through to users my-data / email */ }
|
|
90
|
+
try {
|
|
91
|
+
const d = await getMyData();
|
|
92
|
+
const name = displayName(d) || email;
|
|
93
|
+
const dd = d as unknown as { nickname?: string; slug?: string; about?: string; aboutPlain?: string; profile?: { photo?: { url?: string } }; photo?: { url?: string } };
|
|
94
|
+
return fromParts(
|
|
95
|
+
name,
|
|
96
|
+
dd.slug || dd.nickname || name,
|
|
97
|
+
dd.aboutPlain || dd.about || "No info to display.",
|
|
98
|
+
dd.profile?.photo?.url || dd.photo?.url || "",
|
|
99
|
+
);
|
|
100
|
+
} catch {
|
|
101
|
+
// Session identity is still known; missing profile data is not an empty biography.
|
|
102
|
+
return { ...fromParts(email, email.split("@")[0] || email, ""), about: "Profile details could not be loaded. Please try again.", hideError: false, hideAbout: true };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
let generation = 0;
|
|
106
|
+
const svc = defineService<S, { load: (s: S) => Promise<S | undefined> }>("spacesViewProfile", {
|
|
107
|
+
state: { ...EMPTY },
|
|
108
|
+
notHydrated: Object.keys(EMPTY) as (keyof S & string)[],
|
|
109
|
+
actions: {
|
|
110
|
+
load: async () => {
|
|
111
|
+
const request = ++generation;
|
|
112
|
+
const next = await readProfile();
|
|
113
|
+
return request === generation ? next : undefined;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
if (!(globalThis as { himalaya?: { hydrationOptOut?: boolean } }).himalaya?.hydrationOptOut) Object.assign(svc.getState(), EMPTY);
|
|
118
|
+
void svc.load();
|
|
119
|
+
export { svc };
|