@wix/himalaya-cli 0.1871.0 → 0.1873.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/dev-server/src/app-module.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/portfolio/src/index.d.ts +19 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{ab91dfb9c348c8c78f942a5b88ba90df456c5b436e135d97791d5dd95d6a40dc.bin → a9d34f09c807f1cde9ab000737f0f7b849670c37908aa47cb77889b7e01d34cb.bin} +1 -1
- package/dist/browser-plane/sw.js +9 -9
- package/dist/cli.mjs +506 -323
- package/dist/preview-assets.generated.bin +0 -0
- package/fixtures/wix-canned.json +8 -0
- package/guides/release-notes.md +18 -0
- package/guides/sdk-reference.json +8 -1
- package/package.json +2 -2
- package/template-icons/professional-services.png +0 -0
- package/templates/bare-fashion/config.ts +37 -2
- package/templates/bare-fashion/dev/index.ts +4006 -48
- package/templates/bare-fashion/himalaya.content.json +15 -0
- package/templates/bare-fashion/tier5-src/_shared/member-account-routes.ts +56 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/branded-lite/dev/index.ts +2 -1
- package/templates/branded-lite/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-coupons/index.ts +13 -2
- package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
- package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/community-club/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/conference/config.ts +43 -1
- package/templates/conference/dev/index.ts +4127 -0
- package/templates/conference/himalaya.content.json +18 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/conference/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/conference/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/events-meetups/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/medical-services/config.ts +42 -0
- package/templates/medical-services/dev/index.ts +4136 -0
- package/templates/medical-services/himalaya.content.json +18 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/medical-services/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/portfolio-creative/dev/index.ts +2 -1
- package/templates/portfolio-creative/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
- package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/professional-services/README.md +55 -0
- package/templates/professional-services/config.ts +436 -0
- package/templates/professional-services/dev/index.ts +44772 -0
- package/templates/professional-services/himalaya.content.json +100 -0
- package/templates/professional-services/himalaya.template.json +16 -0
- package/templates/professional-services/icon.png +0 -0
- package/templates/professional-services/platforms.json +1 -0
- package/templates/professional-services/tier5-src/_shared/app-locale.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/booking-location.ts +147 -0
- package/templates/professional-services/tier5-src/_shared/booking-session.ts +224 -0
- package/templates/professional-services/tier5-src/_shared/branded-lite-hosted.ts +282 -0
- package/templates/professional-services/tier5-src/_shared/branded-load-state.ts +109 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-copy.ts +40 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-history.ts +51 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-message-model.ts +177 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-model.ts +56 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-presenter.ts +587 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-transport.ts +164 -0
- package/templates/professional-services/tier5-src/_shared/chat-live.ts +242 -0
- package/templates/professional-services/tier5-src/_shared/collection-contract.ts +232 -0
- package/templates/professional-services/tier5-src/_shared/collection-query.ts +201 -0
- package/templates/professional-services/tier5-src/_shared/collection-service.ts +429 -0
- package/templates/professional-services/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/professional-services/tier5-src/_shared/engine-intl.ts +538 -0
- package/templates/professional-services/tier5-src/_shared/event-registration.ts +86 -0
- package/templates/professional-services/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/professional-services/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/professional-services/tier5-src/_shared/featured-event.ts +63 -0
- package/templates/professional-services/tier5-src/_shared/group-member-count.ts +15 -0
- package/templates/professional-services/tier5-src/_shared/group-privacy.ts +14 -0
- package/templates/professional-services/tier5-src/_shared/guest-sign-in.ts +36 -0
- package/templates/professional-services/tier5-src/_shared/himi-account.ts +222 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-hidden.ts +66 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-post-row.ts +214 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-saved.ts +64 -0
- package/templates/professional-services/tier5-src/_shared/himi-booking-saved.ts +88 -0
- package/templates/professional-services/tier5-src/_shared/himi-bookings.ts +318 -0
- package/templates/professional-services/tier5-src/_shared/himi-copy.ts +123 -0
- package/templates/professional-services/tier5-src/_shared/himi-events.ts +92 -0
- package/templates/professional-services/tier5-src/_shared/himi-media.ts +33 -0
- package/templates/professional-services/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/professional-services/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/professional-services/tier5-src/_shared/host-events.ts +66 -0
- package/templates/professional-services/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance-form.ts +106 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance-purchase.ts +235 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance.ts +38 -0
- package/templates/professional-services/tier5-src/_shared/iap-worker.ts +127 -0
- package/templates/professional-services/tier5-src/_shared/inbox-rooms.ts +163 -0
- package/templates/professional-services/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/professional-services/tier5-src/_shared/member-access.ts +63 -0
- package/templates/professional-services/tier5-src/_shared/member-account-routes.ts +56 -0
- package/templates/professional-services/tier5-src/_shared/member-avatar.ts +76 -0
- package/templates/professional-services/tier5-src/_shared/member-bookings.ts +107 -0
- package/templates/professional-services/tier5-src/_shared/member-read.ts +82 -0
- package/templates/professional-services/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/professional-services/tier5-src/_shared/notification-target.ts +141 -0
- package/templates/professional-services/tier5-src/_shared/offset-page.ts +10 -0
- package/templates/professional-services/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/professional-services/tier5-src/_shared/payment-setup.ts +6 -0
- package/templates/professional-services/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/professional-services/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/professional-services/tier5-src/_shared/result-snackbar.ts +26 -0
- package/templates/professional-services/tier5-src/_shared/rich-body.ts +78 -0
- package/templates/professional-services/tier5-src/_shared/rich-content-link.ts +34 -0
- package/templates/professional-services/tier5-src/_shared/sign-in-sheet.ts +18 -0
- package/templates/professional-services/tier5-src/_shared/staff-name.ts +18 -0
- package/templates/professional-services/tier5-src/_shared/weekly-goal.ts +111 -0
- package/templates/professional-services/tier5-src/_shared/wix-bi.ts +85 -0
- package/templates/professional-services/tier5-src/_shared/wix-member-links.ts +114 -0
- package/templates/professional-services/tier5-src/_shared/wix-service-price.ts +146 -0
- package/templates/professional-services/tier5-src/business-chat/index.ts +797 -0
- package/templates/professional-services/tier5-src/business-contact/index.ts +6 -0
- package/templates/professional-services/tier5-src/himi-blog-feed/index.ts +444 -0
- package/templates/professional-services/tier5-src/himi-blog-post/index.ts +1239 -0
- package/templates/professional-services/tier5-src/himi-booking-account/index.ts +278 -0
- package/templates/professional-services/tier5-src/himi-booking-bookings/index.ts +475 -0
- package/templates/professional-services/tier5-src/himi-booking-service/index.ts +1197 -0
- package/templates/professional-services/tier5-src/himi-booking-services/index.ts +795 -0
- package/templates/professional-services/tier5-src/himi-booking-time/index.ts +1840 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-coupons/index.ts +96 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-faq/index.ts +6 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-file-share/index.ts +12 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-group/index.ts +310 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-group-about/index.ts +240 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-my-groups/index.ts +237 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-notifications/index.ts +263 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-plans/index.ts +498 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-portfolio/index.ts +136 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-portfolio-project/index.ts +198 -0
- package/templates/professional-services/tier5-src/himi-events-detail/index.ts +1306 -0
- package/templates/professional-services/tier5-src/himi-events-list/index.ts +171 -0
- package/templates/professional-services/tier5-src/himi-events-my-events/index.ts +227 -0
- package/templates/professional-services/tier5-src/himi-events-rsvp/index.ts +230 -0
- package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts +318 -0
- package/templates/professional-services/tier5-src/himi-professional-services-home/index.ts +772 -0
- package/templates/professional-services/tier5-src/himi-store-account/index.ts +1514 -0
- package/templates/professional-services/tier5-src/wix-spaces-coupon-detail/index.ts +43 -0
- package/templates/professional-services/tier5-src/wix-spaces-my-subscriptions/index.ts +89 -0
- package/templates/professional-services/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
- package/templates/professional-services/tokens.json +456 -0
- package/templates/restaurant/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/salon-spa/config.ts +42 -0
- package/templates/salon-spa/dev/index.ts +4136 -0
- package/templates/salon-spa/himalaya.content.json +18 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/salon-spa/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/wholesale-store/config.ts +43 -1
- package/templates/wholesale-store/dev/index.ts +4136 -0
- package/templates/wholesale-store/himalaya.content.json +18 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/wholesale-store/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +5 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// A member-only screen that a guest opens offers the app's sign-in at once, as the sheet the app's other
|
|
2
|
+
// screens use (`signInPresentation`, and `signInSheetStyle: "page"` where the app asks for it). Opt-in: the
|
|
3
|
+
// screen's load params must name `signInScreenId`, so an app that passes none keeps the screen's own Sign in state.
|
|
4
|
+
//
|
|
5
|
+
// The sheet is a modal with no return path: closing it, signed in or not, leaves the guest on this screen, which
|
|
6
|
+
// loads again and shows the member's content, or its Sign in state when the sheet was only closed. One offer per
|
|
7
|
+
// guest: a reload that follows a dismissed sheet does not open a second one, and a member's visit resets it.
|
|
8
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
9
|
+
import { signInPageStyle, signInSheetStyle } from "./sign-in-sheet.js";
|
|
10
|
+
|
|
11
|
+
const field = (arg: unknown, key: string): string => {
|
|
12
|
+
const value = (arg as Record<string, unknown> | null | undefined)?.[key];
|
|
13
|
+
return typeof value === "string" ? value.trim() : "";
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export interface GuestSignIn {
|
|
17
|
+
/** The screen loaded for a guest: open the sign-in sheet, once. */
|
|
18
|
+
offer(arg: unknown): void;
|
|
19
|
+
/** The screen loaded for a member: the next guest is offered the sheet again. */
|
|
20
|
+
member(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function guestSignIn(): GuestSignIn {
|
|
24
|
+
let offered = false;
|
|
25
|
+
return {
|
|
26
|
+
offer(arg) {
|
|
27
|
+
const screenId = field(arg, "signInScreenId");
|
|
28
|
+
const presentation = field(arg, "signInPresentation");
|
|
29
|
+
if (!screenId || offered || (presentation !== "sheet" && presentation !== "full_screen")) return;
|
|
30
|
+
offered = true;
|
|
31
|
+
const args = { screenId, mode: "signin", presentation, modal: "1", ...signInSheetStyle(presentation, signInPageStyle(field(arg, "signInSheetStyle"))) };
|
|
32
|
+
void Promise.resolve(dispatch("himi.open", args)).catch(() => undefined);
|
|
33
|
+
},
|
|
34
|
+
member() { offered = false; },
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
2
|
+
// Relative for node resolution (see himi-store.ts note); rewritten off-repo.
|
|
3
|
+
import { displayName, getMyData, initials, type WixMyData } from "@himalaya/wix-users";
|
|
4
|
+
import { getMyMember } from "@himalaya/wix-members";
|
|
5
|
+
import { wixMediaUrl } from "@himalaya/wix-media";
|
|
6
|
+
import { formatDateMedium, formatWeekdayDateTime } from "../_shared/engine-intl.js";
|
|
7
|
+
import { copyParam } from "./himi-copy.js";
|
|
8
|
+
|
|
9
|
+
export interface AccountProfile {
|
|
10
|
+
isMember: boolean;
|
|
11
|
+
identityLine: string;
|
|
12
|
+
detailLine: string;
|
|
13
|
+
memberName: string;
|
|
14
|
+
memberEmail: string;
|
|
15
|
+
memberImage: string;
|
|
16
|
+
memberInitials: string;
|
|
17
|
+
hasMemberImage: boolean;
|
|
18
|
+
noMemberImage: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AccountActivityRow {
|
|
22
|
+
id: string;
|
|
23
|
+
title: string;
|
|
24
|
+
subtitle: string;
|
|
25
|
+
meta: string;
|
|
26
|
+
status: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function strOf(arg: unknown): string {
|
|
30
|
+
if (typeof arg === "string") return arg;
|
|
31
|
+
const a = arg as { value?: string; text?: string } | undefined;
|
|
32
|
+
return a?.value ?? a?.text ?? "";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function titleCase(value?: string): string {
|
|
36
|
+
return (value || "")
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
.split(/[_\s-]+/)
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.map((part) => part[0].toUpperCase() + part.slice(1))
|
|
41
|
+
.join(" ");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function fmtDate(value?: string): string {
|
|
45
|
+
if (!value) return "";
|
|
46
|
+
const date = new Date(value);
|
|
47
|
+
if (Number.isNaN(date.getTime())) return "";
|
|
48
|
+
return formatDateMedium(date);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function fmtDateTime(value?: string): string {
|
|
52
|
+
if (!value) return "";
|
|
53
|
+
const date = new Date(value);
|
|
54
|
+
if (Number.isNaN(date.getTime())) return "";
|
|
55
|
+
return formatWeekdayDateTime(date);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function initialsFromName(value: string): string {
|
|
59
|
+
const parts = value.trim().split(/\s+/).filter(Boolean);
|
|
60
|
+
if (!parts.length) return "";
|
|
61
|
+
const first = parts[0]?.[0] ?? "";
|
|
62
|
+
const last = parts.length > 1 ? parts[parts.length - 1]?.[0] ?? "" : "";
|
|
63
|
+
return (first + last).toUpperCase();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function profileImage(data: WixMyData): string {
|
|
67
|
+
const profile = data.profile as { profileImage?: string; photo?: { url?: string }; imageUrl?: string } | undefined;
|
|
68
|
+
return profile?.profileImage || profile?.photo?.url || profile?.imageUrl || "";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function profileFromData(data: WixMyData, fallbackEmail = ""): AccountProfile {
|
|
72
|
+
const email = fallbackEmail || data.email || data.contactEmail || "";
|
|
73
|
+
const name = displayName(data) || email || "Member";
|
|
74
|
+
const image = profileImage(data);
|
|
75
|
+
return {
|
|
76
|
+
isMember: true,
|
|
77
|
+
identityLine: copyParam("account.signedIn", "Signed in"),
|
|
78
|
+
detailLine: email || name,
|
|
79
|
+
memberName: name,
|
|
80
|
+
memberEmail: email,
|
|
81
|
+
memberImage: image,
|
|
82
|
+
memberInitials: initials(data) || initialsFromName(name) || "M",
|
|
83
|
+
hasMemberImage: !!image,
|
|
84
|
+
noMemberImage: !image,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The signed-in site member's name and photo from their member record, or undefined when it
|
|
89
|
+
* cannot be read or names nobody (the caller then shows the email). */
|
|
90
|
+
/** The host refused a read because the signed-in principal changed while it was in flight. Right
|
|
91
|
+
* after a sign-in on Android, the account screen's first read races the session switch this way. */
|
|
92
|
+
const PRINCIPAL_CHANGED = /PRINCIPAL_CHANGED/;
|
|
93
|
+
|
|
94
|
+
async function siteMemberProfile(email: string): Promise<AccountProfile | undefined> {
|
|
95
|
+
try {
|
|
96
|
+
const read = () => getMyMember({ fieldsets: ["FULL"] });
|
|
97
|
+
// Asked again once, as the member who is signed in now; otherwise a fresh sign-in shows the
|
|
98
|
+
// member's email where their name belongs until the next refresh. Only for the same member:
|
|
99
|
+
// the name must never come from another account than `email`.
|
|
100
|
+
const member = (await read().catch(async (error: unknown) => {
|
|
101
|
+
if (!PRINCIPAL_CHANGED.test(String((error as { message?: unknown })?.message ?? error))) throw error;
|
|
102
|
+
const now = await memberIdentity();
|
|
103
|
+
if (!now.signedIn || (email && now.email !== email)) throw error;
|
|
104
|
+
return read();
|
|
105
|
+
}))?.member;
|
|
106
|
+
const name = [member?.contact?.firstName, member?.contact?.lastName].map((part) => (part ?? "").trim()).filter(Boolean).join(" ")
|
|
107
|
+
|| (member?.profile?.nickname ?? "").trim();
|
|
108
|
+
if (!name) return undefined;
|
|
109
|
+
const image = wixMediaUrl(member?.profile?.photo?.url) || wixMediaUrl(member?.profile?.photo?.id) || "";
|
|
110
|
+
return {
|
|
111
|
+
isMember: true,
|
|
112
|
+
identityLine: copyParam("account.signedIn", "Signed in"),
|
|
113
|
+
detailLine: email || name,
|
|
114
|
+
memberName: name,
|
|
115
|
+
memberEmail: email || member?.loginEmail || "",
|
|
116
|
+
memberImage: image,
|
|
117
|
+
memberInitials: initialsFromName(name) || "M",
|
|
118
|
+
hasMemberImage: !!image,
|
|
119
|
+
noMemberImage: !image,
|
|
120
|
+
};
|
|
121
|
+
} catch {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function guestProfile(detailLine: string): AccountProfile {
|
|
127
|
+
return {
|
|
128
|
+
isMember: false,
|
|
129
|
+
identityLine: copyParam("account.guestIdentity", "Browsing as a guest"),
|
|
130
|
+
detailLine,
|
|
131
|
+
memberName: "",
|
|
132
|
+
memberEmail: "",
|
|
133
|
+
memberImage: "",
|
|
134
|
+
memberInitials: "M",
|
|
135
|
+
hasMemberImage: false,
|
|
136
|
+
noMemberImage: true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface MemberIdentity {
|
|
141
|
+
email: string;
|
|
142
|
+
signedIn: boolean;
|
|
143
|
+
/** The member's session ended on its own (not their sign-out) and they are a visitor now. */
|
|
144
|
+
sessionEnded: boolean;
|
|
145
|
+
/** That member's email, to pre-fill sign-in; "" when unknown or when `sessionEnded` is false. */
|
|
146
|
+
lastEmail: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const NO_IDENTITY: MemberIdentity = { email: "", signedIn: false, sessionEnded: false, lastEmail: "" };
|
|
150
|
+
|
|
151
|
+
/** `himi.wix.memberIdentity`: the member's email ("" when none is known) and whether a member is
|
|
152
|
+
* signed in. `signedIn` is true only when the host says so explicitly — native hosts answer it
|
|
153
|
+
* for a member whose email is not known yet (an injected or hosted session before `members/my`
|
|
154
|
+
* answers); hosts that predate it answer the email alone. `sessionEnded` / `lastEmail` come from
|
|
155
|
+
* native hosts only, for a visitor whose member session could not be refreshed. */
|
|
156
|
+
export async function memberIdentity(): Promise<MemberIdentity> {
|
|
157
|
+
try {
|
|
158
|
+
const identity = await dispatch("himi.wix.memberIdentity") as unknown;
|
|
159
|
+
type Answer = { email?: unknown; signedIn?: unknown; sessionEnded?: unknown; lastEmail?: unknown } | null | undefined;
|
|
160
|
+
const direct = identity as Answer;
|
|
161
|
+
const wrapped = (identity as { payload?: Answer } | null)?.payload;
|
|
162
|
+
const field = (key: keyof NonNullable<Answer>) => direct?.[key] ?? wrapped?.[key];
|
|
163
|
+
const text = (value: unknown) => (typeof value === "string" ? value : "");
|
|
164
|
+
const email = text(field("email"));
|
|
165
|
+
const signedIn = field("signedIn") === true || !!email;
|
|
166
|
+
const sessionEnded = !signedIn && field("sessionEnded") === true;
|
|
167
|
+
return { email, signedIn, sessionEnded, lastEmail: sessionEnded ? text(field("lastEmail")) : "" };
|
|
168
|
+
} catch {
|
|
169
|
+
return NO_IDENTITY;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function signedInEmail(): Promise<string> {
|
|
174
|
+
return (await memberIdentity()).email;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** A signed-in member nothing names yet: signed in, with a neutral label rather than another
|
|
178
|
+
* member's name or the sign-in form. */
|
|
179
|
+
function neutralMemberProfile(): AccountProfile {
|
|
180
|
+
const name = copyParam("account.member", "Member");
|
|
181
|
+
return {
|
|
182
|
+
isMember: true,
|
|
183
|
+
identityLine: copyParam("account.signedIn", "Signed in"),
|
|
184
|
+
detailLine: name,
|
|
185
|
+
memberName: name,
|
|
186
|
+
memberEmail: "",
|
|
187
|
+
memberImage: "",
|
|
188
|
+
memberInitials: "M",
|
|
189
|
+
hasMemberImage: false,
|
|
190
|
+
noMemberImage: true,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export async function loadMemberProfile(guestDetailLine: string, known?: MemberIdentity): Promise<AccountProfile> {
|
|
195
|
+
// `himi.wix.memberIdentity` is the session source of truth. Visitor-scoped
|
|
196
|
+
// getMyData can still return a site/account nickname (e.g. apptestercoowner)
|
|
197
|
+
// after sign-out or for anonymous — never treat that as a signed-in member.
|
|
198
|
+
const identity = known ?? await memberIdentity();
|
|
199
|
+
if (!identity.signedIn) return guestProfile(guestDetailLine);
|
|
200
|
+
const storedEmail = identity.email;
|
|
201
|
+
if (!storedEmail) return (await siteMemberProfile("")) ?? neutralMemberProfile();
|
|
202
|
+
try {
|
|
203
|
+
const data = await getMyData();
|
|
204
|
+
return profileFromData(data, storedEmail);
|
|
205
|
+
} catch {
|
|
206
|
+
// The account profile is an owner endpoint: the web host refuses it, and a site member need
|
|
207
|
+
// not have one. The member's own record (the Members API) still names them.
|
|
208
|
+
const member = await siteMemberProfile(storedEmail);
|
|
209
|
+
if (member) return member;
|
|
210
|
+
return {
|
|
211
|
+
isMember: true,
|
|
212
|
+
identityLine: copyParam("account.signedIn", "Signed in"),
|
|
213
|
+
detailLine: storedEmail,
|
|
214
|
+
memberName: storedEmail,
|
|
215
|
+
memberEmail: storedEmail,
|
|
216
|
+
memberImage: "",
|
|
217
|
+
memberInitials: initialsFromName(storedEmail) || "M",
|
|
218
|
+
hasMemberImage: false,
|
|
219
|
+
noMemberImage: true,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// The posts this device's reader chose to hide, as the One App blog does: a client-side list of post ids that the
|
|
2
|
+
// blog feed, the Home cards and Saved leave out. Nothing is sent to the site, and another device or account does not
|
|
3
|
+
// share it. It is the saved-posts store's twin (see himi-blog-saved.ts) and reads storage the same way: native workers
|
|
4
|
+
// have only the sync `himalaya.storage` KV, a browser has `localStorage`, and each screen runs its own worker, so
|
|
5
|
+
// the durable arm is what lets a Hide on the post screen reach the feed's worker.
|
|
6
|
+
const KEY = "himi-blog:hidden-posts:v1";
|
|
7
|
+
|
|
8
|
+
type StorageLike = {
|
|
9
|
+
getItem: (key: string) => string | null;
|
|
10
|
+
setItem: (key: string, value: string) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type HiddenHost = typeof globalThis & {
|
|
14
|
+
himalaya?: { storage?: StorageLike };
|
|
15
|
+
localStorage?: StorageLike;
|
|
16
|
+
__himiBlogHiddenIds?: string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const host = globalThis as HiddenHost;
|
|
20
|
+
|
|
21
|
+
function storage(): StorageLike | undefined {
|
|
22
|
+
return host.himalaya?.storage ?? host.localStorage;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const unique = (ids: string[]): string[] => Array.from(new Set(ids.map((id) => id.trim()).filter(Boolean)));
|
|
26
|
+
|
|
27
|
+
export function readHiddenIds(): string[] {
|
|
28
|
+
try {
|
|
29
|
+
const raw = storage()?.getItem(KEY);
|
|
30
|
+
if (raw) {
|
|
31
|
+
const parsed = JSON.parse(raw);
|
|
32
|
+
if (Array.isArray(parsed)) return unique(parsed.filter((id): id is string => typeof id === "string"));
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
// Unreadable storage: fall back to what this worker context holds in memory.
|
|
36
|
+
}
|
|
37
|
+
return unique(host.__himiBlogHiddenIds ?? []);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function writeHiddenIds(ids: string[]): void {
|
|
41
|
+
const next = unique(ids);
|
|
42
|
+
host.__himiBlogHiddenIds = next;
|
|
43
|
+
try {
|
|
44
|
+
storage()?.setItem(KEY, JSON.stringify(next));
|
|
45
|
+
} catch {
|
|
46
|
+
// Storage-less hosts keep the in-memory arm only.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isHiddenId(id: string): boolean {
|
|
51
|
+
return readHiddenIds().includes(id);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function hideId(id: string): void {
|
|
55
|
+
writeHiddenIds([id, ...readHiddenIds()]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function unhideId(id: string): void {
|
|
59
|
+
writeHiddenIds(readHiddenIds().filter((hiddenId) => hiddenId !== id));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The items a list may show: every one whose `id` this device has not hidden. */
|
|
63
|
+
export function withoutHidden<T extends { id?: string | null }>(items: T[]): T[] {
|
|
64
|
+
const hidden = new Set(readHiddenIds());
|
|
65
|
+
return hidden.size ? items.filter((item) => !item.id || !hidden.has(item.id)) : items;
|
|
66
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// The fields the Blog feed, the post screen and Saved all show for a post: its photo, its
|
|
2
|
+
// counts and its author. One place, so the three screens read the Blog v3 shapes the same way.
|
|
3
|
+
//
|
|
4
|
+
// Blog v3 facts these rely on (visitor token, verified live on the amit1 demo site):
|
|
5
|
+
// - `metrics` and `url` are returned ONLY when the read asks for the METRICS / URL fieldsets.
|
|
6
|
+
// - `metrics` carries `likes`, `comments` and `views`. Older payloads and fixtures used
|
|
7
|
+
// `likeCount` / `totalComments` / `commentCount`, which stay as fallbacks.
|
|
8
|
+
// - A post names its author by `memberId` only (no `writer` / `owner` object). The author's
|
|
9
|
+
// public name and photo come from `POST /members/v1/members/query` with fieldsets PUBLIC,
|
|
10
|
+
// which a visitor may call.
|
|
11
|
+
import { getPublicMember, queryMembers, type WixMember } from "@himalaya/wix-members";
|
|
12
|
+
import { wixMediaUrl, WIX_DETAIL_IMAGE, WIX_LIST_IMAGE, type WixImageSize } from "@himalaya/wix-media";
|
|
13
|
+
import { formatDateMedium } from "./engine-intl.js";
|
|
14
|
+
import { copyPlural } from "./himi-copy.js";
|
|
15
|
+
|
|
16
|
+
/** The post fields this module reads. Every field is optional: fixtures and cached rows omit most. */
|
|
17
|
+
export interface BlogPostShape {
|
|
18
|
+
id?: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
firstPublishedDate?: string;
|
|
21
|
+
lastPublishedDate?: string;
|
|
22
|
+
minutesToRead?: number;
|
|
23
|
+
memberId?: string;
|
|
24
|
+
pinned?: boolean;
|
|
25
|
+
media?: { wixMedia?: { image?: { url?: string }; videoV2?: { posters?: Array<{ url?: string }> } }; embedMedia?: { thumbnail?: { url?: string } }; displayed?: boolean };
|
|
26
|
+
coverImage?: { image?: { url?: string }; url?: string };
|
|
27
|
+
metrics?: { likes?: number; comments?: number; views?: number; likeCount?: number; totalComments?: number; commentCount?: number };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The fieldsets every list read asks for, so a row can show its counts. */
|
|
31
|
+
export const LIST_FIELDSETS = ["METRICS"];
|
|
32
|
+
|
|
33
|
+
// Every photo is asked for at the size it shows at: Blog v3 returns the stored
|
|
34
|
+
// original, which can be megabytes per row.
|
|
35
|
+
/** A full-width card in the feed. */
|
|
36
|
+
export const BLOG_CARD_IMAGE: WixImageSize = WIX_LIST_IMAGE;
|
|
37
|
+
/** The full-width photo at the top of a post. */
|
|
38
|
+
export const BLOG_HERO_IMAGE: WixImageSize = WIX_DETAIL_IMAGE;
|
|
39
|
+
/** A 72pt row thumbnail (Saved, Recent posts), at 3x. */
|
|
40
|
+
export const BLOG_THUMB_IMAGE: WixImageSize = { width: 216, height: 216, quality: 85 };
|
|
41
|
+
/** A 40pt author avatar, at 3x. */
|
|
42
|
+
export const BLOG_AVATAR_IMAGE: WixImageSize = { width: 120, height: 120, quality: 85 };
|
|
43
|
+
|
|
44
|
+
/** The post's photo URL at `size`: its image, a video poster, an embed thumbnail, or "" for none.
|
|
45
|
+
* `media.displayed: false` means the owner turned the cover off: no photo. */
|
|
46
|
+
export function coverOf(post: BlogPostShape, size: WixImageSize = BLOG_CARD_IMAGE): string {
|
|
47
|
+
return wixMediaUrl(coverSourceOf(post), size);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The post's photo as stored (unsized), or "" for none. The feed caches it beside the card-sized
|
|
51
|
+
* `cover`, so an offline screen sizes it for itself (a hero needs more pixels than a card). */
|
|
52
|
+
export function coverSourceOf(post: BlogPostShape): string {
|
|
53
|
+
if (post.media?.displayed === false) return "";
|
|
54
|
+
return (
|
|
55
|
+
post.media?.wixMedia?.image?.url ??
|
|
56
|
+
post.media?.wixMedia?.videoV2?.posters?.[0]?.url ??
|
|
57
|
+
post.media?.embedMedia?.thumbnail?.url ??
|
|
58
|
+
post.coverImage?.image?.url ??
|
|
59
|
+
post.coverImage?.url ??
|
|
60
|
+
""
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface BlogCounts { likes: number; comments: number; views: number }
|
|
65
|
+
|
|
66
|
+
const count = (...values: Array<number | undefined>): number | null => {
|
|
67
|
+
for (const value of values) if (typeof value === "number" && Number.isFinite(value) && value >= 0) return Math.floor(value);
|
|
68
|
+
return null;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** The post's counts, or null when the read did not carry all three (no METRICS fieldset, the
|
|
72
|
+
* SDK's list fallback, a row cached by an older build, a partial `metrics`): unknown is not zero. */
|
|
73
|
+
export function countsOf(post: BlogPostShape): BlogCounts | null {
|
|
74
|
+
const m = post.metrics;
|
|
75
|
+
if (!m || typeof m !== "object") return null;
|
|
76
|
+
const likes = count(m.likes, m.likeCount), comments = count(m.comments, m.totalComments, m.commentCount), views = count(m.views);
|
|
77
|
+
return likes === null || comments === null || views === null ? null : { likes, comments, views };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The spoken form of each count ("1 like", "3 views"): the counts row shows bare numbers
|
|
81
|
+
* beside icons, so each number gets a label a screen reader can say. */
|
|
82
|
+
export interface CountLabels { likesLabel: string; viewsLabel: string; commentsLabel: string }
|
|
83
|
+
|
|
84
|
+
export const likesLabelFor = (n: number): string => copyPlural("blogCommon.likesCount", "{n, plural, one {# like} other {# likes}}", n);
|
|
85
|
+
export const viewsLabelFor = (n: number): string => copyPlural("blogCommon.viewsCount", "{n, plural, one {# view} other {# views}}", n);
|
|
86
|
+
export const commentsLabelFor = (n: number): string => copyPlural("blogCommon.commentsCount", "{n, plural, one {# comment} other {# comments}}", n);
|
|
87
|
+
|
|
88
|
+
/** Empty labels for unknown counts: a "0 likes" read aloud would be invented data too. */
|
|
89
|
+
export function countLabels(counts: BlogCounts | null): CountLabels {
|
|
90
|
+
if (!counts) return { likesLabel: "", viewsLabel: "", commentsLabel: "" };
|
|
91
|
+
return { likesLabel: likesLabelFor(counts.likes), viewsLabel: viewsLabelFor(counts.views), commentsLabel: commentsLabelFor(counts.comments) };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** "Jul 30, 2026 · 4 min read" ("" when the post has neither). */
|
|
95
|
+
export function dateLineOf(post: BlogPostShape): string {
|
|
96
|
+
const bits: string[] = [];
|
|
97
|
+
if (post.firstPublishedDate) bits.push(formatDateMedium(new Date(post.firstPublishedDate)));
|
|
98
|
+
if (post.minutesToRead) bits.push(copyPlural("blogCommon.minRead", "{n, plural, one {# min read} other {# min read}}", post.minutesToRead));
|
|
99
|
+
return bits.join(" · ");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A cached photo URL at `size`. A row cached by an older build holds the stored original, and a
|
|
103
|
+
* newer one a sized URL: both are re-sized for where they show (an already sized URL is rewritten). */
|
|
104
|
+
/** A member's public photo: its URL, or its media id when the profile carries only that. */
|
|
105
|
+
export const profilePhoto = (photo: { url?: string; id?: string } | undefined): string =>
|
|
106
|
+
wixMediaUrl(photo?.url, BLOG_AVATAR_IMAGE) || wixMediaUrl(photo?.id, BLOG_AVATAR_IMAGE) || "";
|
|
107
|
+
|
|
108
|
+
export const sizedCover = (url: unknown, size: WixImageSize): string => wixMediaUrl(url, size);
|
|
109
|
+
|
|
110
|
+
/** A cached row's photo at `size`: from the stored source when the row has it, else its `cover`. */
|
|
111
|
+
export function cachedCover(row: object, size: WixImageSize): string {
|
|
112
|
+
const r = row as { coverSource?: unknown; cover?: unknown };
|
|
113
|
+
return sizedCover(typeof r.coverSource === "string" && r.coverSource ? r.coverSource : r.cover, size);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A row the feed cached before the redesign (it has no `hasCounts`) can hold two values the old
|
|
117
|
+
* feed invented: the "Blog" category of a post with none, and a filler excerpt. Both read as
|
|
118
|
+
* nothing here, wherever a cached row is painted. */
|
|
119
|
+
export function legacyRowFixes(cached: object): { category?: string; excerpt?: string } {
|
|
120
|
+
const row = cached as { hasCounts?: unknown; category?: unknown; categoryId?: unknown; excerpt?: unknown };
|
|
121
|
+
if (typeof row.hasCounts === "boolean") return {};
|
|
122
|
+
return {
|
|
123
|
+
...(row.category === "Blog" && !row.categoryId ? { category: "" } : {}),
|
|
124
|
+
...(row.excerpt === "Open to read the full note." ? { excerpt: "" } : {}),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The publish date alone ("" when absent). */
|
|
129
|
+
export function dateOf(post: BlogPostShape): string {
|
|
130
|
+
return post.firstPublishedDate ? formatDateMedium(new Date(post.firstPublishedDate)) : "";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface BlogAuthor { name: string; photo: string; initial: string }
|
|
134
|
+
|
|
135
|
+
/** The author fields a row binds. `hasAuthor` gates the whole author row: no name, no row. */
|
|
136
|
+
export interface AuthorFields {
|
|
137
|
+
authorName: string;
|
|
138
|
+
authorPhoto: string;
|
|
139
|
+
authorInitial: string;
|
|
140
|
+
hasAuthor: boolean;
|
|
141
|
+
noAuthor: boolean;
|
|
142
|
+
hasAuthorPhoto: boolean;
|
|
143
|
+
noAuthorPhoto: boolean;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export const NO_AUTHOR: AuthorFields = { authorName: "", authorPhoto: "", authorInitial: "", hasAuthor: false, noAuthor: true, hasAuthorPhoto: false, noAuthorPhoto: true };
|
|
147
|
+
|
|
148
|
+
export function authorFields(author: BlogAuthor | undefined): AuthorFields {
|
|
149
|
+
if (!author?.name) return NO_AUTHOR;
|
|
150
|
+
return { authorName: author.name, authorPhoto: author.photo, authorInitial: author.initial, hasAuthor: true, noAuthor: false, hasAuthorPhoto: !!author.photo, noAuthorPhoto: !author.photo };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// One worker reads the same few authors again and again (every page, every post), so the
|
|
154
|
+
// answers are kept. An id the site did not answer for is kept as "no author" too, so it is not
|
|
155
|
+
// asked for again on the next page. Bounded: past AUTHOR_CACHE_LIMIT the oldest entries go (a Map
|
|
156
|
+
// iterates in insertion order), so a long scroll through many authors cannot grow it forever.
|
|
157
|
+
const authorCache = new Map<string, BlogAuthor | null>();
|
|
158
|
+
const AUTHOR_CACHE_LIMIT = 500;
|
|
159
|
+
/** The members query's page size. */
|
|
160
|
+
const MEMBERS_PER_QUERY = 100;
|
|
161
|
+
/** At most this many single-profile reads when the directory query is refused. */
|
|
162
|
+
const SINGLE_READ_LIMIT = 20;
|
|
163
|
+
|
|
164
|
+
function rememberMember(member: WixMember | undefined): void {
|
|
165
|
+
const name = (member?.profile?.nickname ?? "").trim();
|
|
166
|
+
if (member?.id && name) remember(member.id, { name, photo: profilePhoto(member.profile?.photo), initial: name[0]!.toUpperCase() });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function remember(id: string, author: BlogAuthor | null): void {
|
|
170
|
+
authorCache.delete(id);
|
|
171
|
+
authorCache.set(id, author);
|
|
172
|
+
while (authorCache.size > AUTHOR_CACHE_LIMIT) authorCache.delete(authorCache.keys().next().value!);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Lookups run one after another: a worker loads at boot and again on the screen's onAppear, and
|
|
176
|
+
// two overlapping lookups would each ask for the same unknown ids. The second waits, then finds
|
|
177
|
+
// them in the cache.
|
|
178
|
+
let lookupChain: Promise<unknown> = Promise.resolve();
|
|
179
|
+
|
|
180
|
+
/** The public name and photo of each member id. One members query for the ids not yet known.
|
|
181
|
+
* A failed query (no access, offline) leaves those authors unknown: rows show no author line. */
|
|
182
|
+
export function resolveAuthors(memberIds: ReadonlyArray<string | undefined>): Promise<Map<string, BlogAuthor>> {
|
|
183
|
+
const run = lookupChain.then(() => lookUp(memberIds));
|
|
184
|
+
lookupChain = run.catch(() => undefined);
|
|
185
|
+
return run;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function lookUp(memberIds: ReadonlyArray<string | undefined>): Promise<Map<string, BlogAuthor>> {
|
|
189
|
+
const wanted = Array.from(new Set(memberIds.filter((id): id is string => typeof id === "string" && id.length > 0)));
|
|
190
|
+
const missing = wanted.filter((id) => !authorCache.has(id));
|
|
191
|
+
// In batches the query's page holds, so an id is marked "no author" only when the batch that
|
|
192
|
+
// asked for it came back without it.
|
|
193
|
+
for (let at = 0; at < missing.length; at += MEMBERS_PER_QUERY) {
|
|
194
|
+
const batch = missing.slice(at, at + MEMBERS_PER_QUERY);
|
|
195
|
+
let directoryRefused = false;
|
|
196
|
+
try {
|
|
197
|
+
const response = await queryMembers({ query: { filter: { id: { $in: batch } }, paging: { limit: batch.length } }, fieldsets: ["PUBLIC"] });
|
|
198
|
+
for (const member of response?.members ?? []) rememberMember(member);
|
|
199
|
+
for (const id of batch) if (!authorCache.has(id)) remember(id, null);
|
|
200
|
+
} catch {
|
|
201
|
+
// A site whose member directory is private refuses the query to a visitor, while each
|
|
202
|
+
// public profile still reads one by one. Unknown, not "no author", when that fails too.
|
|
203
|
+
directoryRefused = true;
|
|
204
|
+
}
|
|
205
|
+
if (directoryRefused) {
|
|
206
|
+
for (const id of batch.slice(0, SINGLE_READ_LIMIT)) {
|
|
207
|
+
try { rememberMember((await getPublicMember(id))?.member); } catch { /* unknown: asked again on a later load */ }
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const out = new Map<string, BlogAuthor>();
|
|
212
|
+
for (const id of wanted) { const author = authorCache.get(id); if (author) out.set(id, author); }
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const KEY = "himi-blog:saved-posts:v1";
|
|
2
|
+
|
|
3
|
+
type StorageLike = {
|
|
4
|
+
getItem: (key: string) => string | null;
|
|
5
|
+
setItem: (key: string, value: string) => void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type SavedHost = typeof globalThis & {
|
|
9
|
+
himalaya?: { storage?: StorageLike };
|
|
10
|
+
localStorage?: StorageLike;
|
|
11
|
+
__himiBlogSavedIds?: string[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const host = globalThis as SavedHost;
|
|
15
|
+
|
|
16
|
+
/** Durable-storage seam — same as _shared/himi-events.ts: native workers (iOS
|
|
17
|
+
* JSC / Android WebView) expose ONLY the sync `himalaya.storage` KV; localStorage
|
|
18
|
+
* exists just in web/browser contexts. Each screen runs its OWN worker, so the
|
|
19
|
+
* in-memory global below is a same-context cache of last resort — without the
|
|
20
|
+
* durable arm, a Save on himi_blog_post never reaches himi_saved's worker and
|
|
21
|
+
* nothing survives a relaunch. */
|
|
22
|
+
function storage(): StorageLike | undefined {
|
|
23
|
+
return host.himalaya?.storage ?? host.localStorage;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const unique = (ids: string[]): string[] => Array.from(new Set(ids.map((id) => id.trim()).filter(Boolean)));
|
|
27
|
+
|
|
28
|
+
export function readSavedIds(): string[] {
|
|
29
|
+
try {
|
|
30
|
+
const raw = storage()?.getItem(KEY);
|
|
31
|
+
if (raw) {
|
|
32
|
+
const parsed = JSON.parse(raw);
|
|
33
|
+
if (Array.isArray(parsed)) return unique(parsed.filter((id): id is string => typeof id === "string"));
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
// Fall through to the in-memory fallback.
|
|
37
|
+
}
|
|
38
|
+
return unique(host.__himiBlogSavedIds ?? []);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function writeSavedIds(ids: string[]): string[] {
|
|
42
|
+
const next = unique(ids);
|
|
43
|
+
host.__himiBlogSavedIds = next;
|
|
44
|
+
try {
|
|
45
|
+
storage()?.setItem(KEY, JSON.stringify(next));
|
|
46
|
+
} catch {
|
|
47
|
+
// Storage-less hosts keep the in-memory arm only.
|
|
48
|
+
}
|
|
49
|
+
return next;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function isSavedId(id: string): boolean {
|
|
53
|
+
return readSavedIds().includes(id);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function toggleSavedId(id: string): boolean {
|
|
57
|
+
const current = readSavedIds();
|
|
58
|
+
if (current.includes(id)) {
|
|
59
|
+
writeSavedIds(current.filter((savedId) => savedId !== id));
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
writeSavedIds([id, ...current]);
|
|
63
|
+
return true;
|
|
64
|
+
}
|