@wix/himalaya-cli 0.1646.0 → 0.1647.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/blog-v3/src/extensions.d.ts +21 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/members-v1/src/index.d.ts +5 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-blog.mjs +8 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-members.mjs +5 -0
- package/dist/cli.mjs +4 -6
- package/guides/sdk-reference.json +33 -1
- package/package.json +2 -2
- package/templates/beauty-salon/config.ts +1 -1
- package/templates/beauty-salon/dev/index.ts +2773 -2969
- package/templates/beauty-salon/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/beauty-salon/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/beauty-salon/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/beauty-salon/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/beauty-salon/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/beauty-salon/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/branded-lite/config.ts +1 -1
- package/templates/branded-lite/dev/index.ts +2741 -2937
- package/templates/branded-lite/l10n/en.json +12 -12
- package/templates/branded-lite/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/branded-lite/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/branded-lite/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/branded-lite/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/branded-lite/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/branded-lite/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/community-club/config.ts +1 -1
- package/templates/community-club/dev/index.ts +2799 -2995
- package/templates/community-club/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/community-club/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/community-club/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/community-club/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/community-club/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/community-club/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/community-club-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/conference/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/events-meetups/config.ts +1 -1
- package/templates/events-meetups/dev/index.ts +2859 -3055
- package/templates/events-meetups/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/events-meetups/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/events-meetups/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/events-meetups/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/events-meetups/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/events-meetups/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/events-meetups-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/gym-fitness/config.ts +1 -1
- package/templates/gym-fitness/dev/index.ts +2733 -2929
- package/templates/gym-fitness/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/gym-fitness/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/gym-fitness/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/gym-fitness/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/gym-fitness/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/gym-fitness/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/nonprofit-cause/config.ts +1 -1
- package/templates/nonprofit-cause/dev/index.ts +2813 -3009
- package/templates/nonprofit-cause/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/nonprofit-cause/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/nonprofit-cause/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/nonprofit-cause/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/owner-lite/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/podcast-creator/config.ts +1 -1
- package/templates/podcast-creator/dev/index.ts +2862 -3058
- package/templates/podcast-creator/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/podcast-creator/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/podcast-creator/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/podcast-creator/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/podcast-creator/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/podcast-creator/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/portfolio-creative/config.ts +1 -1
- package/templates/portfolio-creative/dev/index.ts +2803 -2999
- package/templates/portfolio-creative/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/portfolio-creative/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/portfolio-creative/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/portfolio-creative/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/portfolio-creative/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/portfolio-creative/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/restaurant/config.ts +1 -1
- package/templates/restaurant/dev/index.ts +2845 -3041
- package/templates/restaurant/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/restaurant/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/restaurant/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/restaurant/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/restaurant/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/restaurant/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/restaurant-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/retail-store/config.ts +1 -1
- package/templates/retail-store/dev/index.ts +2809 -3005
- package/templates/retail-store/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/retail-store/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/retail-store/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/retail-store/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/retail-store/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/retail-store/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/retail-store-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/salon-spa/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/yoga-studio/config.ts +1 -1
- package/templates/yoga-studio/dev/index.ts +2752 -2948
- package/templates/yoga-studio/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/yoga-studio/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/yoga-studio/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/yoga-studio/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/yoga-studio/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/yoga-studio/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/beauty-salon/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/branded-lite/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/community-club/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/events-meetups/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/gym-fitness/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/podcast-creator/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/portfolio-creative/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/restaurant/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/retail-store/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/yoga-studio/tier5-src/_shared/himi-blog-collection.ts +0 -7
|
@@ -82,7 +82,6 @@ export const COLLECTIONS: Record<string, CollectionConfig> = {
|
|
|
82
82
|
defaultFilter: 'value:Upcoming', searchPlaceholder: 'Search by booking ID', countNoun: ['booking', 'bookings'], filterValues: ['Upcoming', 'Past', 'Cancelled'],
|
|
83
83
|
sortLabels: { default: 'Soonest', az: 'Oldest', za: 'Latest' } },
|
|
84
84
|
himiEvents: { rows: 'results', title: 'title', subtitle: 'dateLine', image: 'image', dateBadge: { text: 'dateBadge', hidden: 'noDateBadge' }, gridColumns: 1, view: 'grid', backendQuery: true, defaultFilter: 'value:Upcoming', searchPlaceholder: 'Search events', countNoun: ['event', 'events'], filterValues: ['Upcoming', 'Past'], sortLabels: { default: 'Date', az: 'Title A–Z', za: 'Title Z–A' }, primaryVerb: { label: 'Register', labelPath: 'actionLabel', hiddenPath: 'noAction' }, shareAction: 'share', endedWhen: 'isPast' },
|
|
85
|
-
himiBlogFeed: { rows: 'posts', title: 'title', subtitle: 'excerpt', image: 'image', filter: 'category', filterValuesFrom: 'categories', view: 'grid', narrowedBy: 'selectedCategoryId' },
|
|
86
85
|
himiOwnerLiteProducts: { rows: 'products', title: 'name', subtitle: 'price', image: 'image', view: 'grid', backendQuery: true, countNoun: ['product', 'products'] },
|
|
87
86
|
himiOwnerModules: { instanceInput: 'module', rows: 'rows', title: 'title', subtitle: 'subtitle', image: 'image', filter: 'statusLabel', view: 'list', paged: true, reviewAction: 'prepareRecord', reviewSelectedAction: 'prepareSelected' },
|
|
88
87
|
himiOwnerLiteServices: { rows: 'services', title: 'name', subtitle: 'subtitle', view: 'list', backendQuery: true, searchPlaceholder: 'Service name starts with…' },
|
|
@@ -0,0 +1,210 @@
|
|
|
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
|
+
export const sizedCover = (url: unknown, size: WixImageSize): string => wixMediaUrl(url, size);
|
|
105
|
+
|
|
106
|
+
/** A cached row's photo at `size`: from the stored source when the row has it, else its `cover`. */
|
|
107
|
+
export function cachedCover(row: object, size: WixImageSize): string {
|
|
108
|
+
const r = row as { coverSource?: unknown; cover?: unknown };
|
|
109
|
+
return sizedCover(typeof r.coverSource === "string" && r.coverSource ? r.coverSource : r.cover, size);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A row the feed cached before the redesign (it has no `hasCounts`) can hold two values the old
|
|
113
|
+
* feed invented: the "Blog" category of a post with none, and a filler excerpt. Both read as
|
|
114
|
+
* nothing here, wherever a cached row is painted. */
|
|
115
|
+
export function legacyRowFixes(cached: object): { category?: string; excerpt?: string } {
|
|
116
|
+
const row = cached as { hasCounts?: unknown; category?: unknown; categoryId?: unknown; excerpt?: unknown };
|
|
117
|
+
if (typeof row.hasCounts === "boolean") return {};
|
|
118
|
+
return {
|
|
119
|
+
...(row.category === "Blog" && !row.categoryId ? { category: "" } : {}),
|
|
120
|
+
...(row.excerpt === "Open to read the full note." ? { excerpt: "" } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The publish date alone ("" when absent). */
|
|
125
|
+
export function dateOf(post: BlogPostShape): string {
|
|
126
|
+
return post.firstPublishedDate ? formatDateMedium(new Date(post.firstPublishedDate)) : "";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface BlogAuthor { name: string; photo: string; initial: string }
|
|
130
|
+
|
|
131
|
+
/** The author fields a row binds. `hasAuthor` gates the whole author row: no name, no row. */
|
|
132
|
+
export interface AuthorFields {
|
|
133
|
+
authorName: string;
|
|
134
|
+
authorPhoto: string;
|
|
135
|
+
authorInitial: string;
|
|
136
|
+
hasAuthor: boolean;
|
|
137
|
+
noAuthor: boolean;
|
|
138
|
+
hasAuthorPhoto: boolean;
|
|
139
|
+
noAuthorPhoto: boolean;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const NO_AUTHOR: AuthorFields = { authorName: "", authorPhoto: "", authorInitial: "", hasAuthor: false, noAuthor: true, hasAuthorPhoto: false, noAuthorPhoto: true };
|
|
143
|
+
|
|
144
|
+
export function authorFields(author: BlogAuthor | undefined): AuthorFields {
|
|
145
|
+
if (!author?.name) return NO_AUTHOR;
|
|
146
|
+
return { authorName: author.name, authorPhoto: author.photo, authorInitial: author.initial, hasAuthor: true, noAuthor: false, hasAuthorPhoto: !!author.photo, noAuthorPhoto: !author.photo };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// One worker reads the same few authors again and again (every page, every post), so the
|
|
150
|
+
// answers are kept. An id the site did not answer for is kept as "no author" too, so it is not
|
|
151
|
+
// asked for again on the next page. Bounded: past AUTHOR_CACHE_LIMIT the oldest entries go (a Map
|
|
152
|
+
// iterates in insertion order), so a long scroll through many authors cannot grow it forever.
|
|
153
|
+
const authorCache = new Map<string, BlogAuthor | null>();
|
|
154
|
+
const AUTHOR_CACHE_LIMIT = 500;
|
|
155
|
+
/** The members query's page size. */
|
|
156
|
+
const MEMBERS_PER_QUERY = 100;
|
|
157
|
+
/** At most this many single-profile reads when the directory query is refused. */
|
|
158
|
+
const SINGLE_READ_LIMIT = 20;
|
|
159
|
+
|
|
160
|
+
function rememberMember(member: WixMember | undefined): void {
|
|
161
|
+
const name = (member?.profile?.nickname ?? "").trim();
|
|
162
|
+
if (member?.id && name) remember(member.id, { name, photo: wixMediaUrl(member.profile?.photo?.url, BLOG_AVATAR_IMAGE), initial: name[0]!.toUpperCase() });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function remember(id: string, author: BlogAuthor | null): void {
|
|
166
|
+
authorCache.delete(id);
|
|
167
|
+
authorCache.set(id, author);
|
|
168
|
+
while (authorCache.size > AUTHOR_CACHE_LIMIT) authorCache.delete(authorCache.keys().next().value!);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Lookups run one after another: a worker loads at boot and again on the screen's onAppear, and
|
|
172
|
+
// two overlapping lookups would each ask for the same unknown ids. The second waits, then finds
|
|
173
|
+
// them in the cache.
|
|
174
|
+
let lookupChain: Promise<unknown> = Promise.resolve();
|
|
175
|
+
|
|
176
|
+
/** The public name and photo of each member id. One members query for the ids not yet known.
|
|
177
|
+
* A failed query (no access, offline) leaves those authors unknown: rows show no author line. */
|
|
178
|
+
export function resolveAuthors(memberIds: ReadonlyArray<string | undefined>): Promise<Map<string, BlogAuthor>> {
|
|
179
|
+
const run = lookupChain.then(() => lookUp(memberIds));
|
|
180
|
+
lookupChain = run.catch(() => undefined);
|
|
181
|
+
return run;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function lookUp(memberIds: ReadonlyArray<string | undefined>): Promise<Map<string, BlogAuthor>> {
|
|
185
|
+
const wanted = Array.from(new Set(memberIds.filter((id): id is string => typeof id === "string" && id.length > 0)));
|
|
186
|
+
const missing = wanted.filter((id) => !authorCache.has(id));
|
|
187
|
+
// In batches the query's page holds, so an id is marked "no author" only when the batch that
|
|
188
|
+
// asked for it came back without it.
|
|
189
|
+
for (let at = 0; at < missing.length; at += MEMBERS_PER_QUERY) {
|
|
190
|
+
const batch = missing.slice(at, at + MEMBERS_PER_QUERY);
|
|
191
|
+
let directoryRefused = false;
|
|
192
|
+
try {
|
|
193
|
+
const response = await queryMembers({ query: { filter: { id: { $in: batch } }, paging: { limit: batch.length } }, fieldsets: ["PUBLIC"] });
|
|
194
|
+
for (const member of response?.members ?? []) rememberMember(member);
|
|
195
|
+
for (const id of batch) if (!authorCache.has(id)) remember(id, null);
|
|
196
|
+
} catch {
|
|
197
|
+
// A site whose member directory is private refuses the query to a visitor, while each
|
|
198
|
+
// public profile still reads one by one. Unknown, not "no author", when that fails too.
|
|
199
|
+
directoryRefused = true;
|
|
200
|
+
}
|
|
201
|
+
if (directoryRefused) {
|
|
202
|
+
for (const id of batch.slice(0, SINGLE_READ_LIMIT)) {
|
|
203
|
+
try { rememberMember((await getPublicMember(id))?.member); } catch { /* unknown: asked again on a later load */ }
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const out = new Map<string, BlogAuthor>();
|
|
208
|
+
for (const id of wanted) { const author = authorCache.get(id); if (author) out.set(id, author); }
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
@@ -49,16 +49,6 @@ export function writeSavedIds(ids: string[]): string[] {
|
|
|
49
49
|
return next;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/** Collection actions report failure instead of claiming a worker-only save. */
|
|
53
|
-
export function writeSavedIdsVerified(ids: string[]): void {
|
|
54
|
-
const kv = storage();
|
|
55
|
-
if (!kv) throw new Error("Saved-post storage is unavailable");
|
|
56
|
-
const next = unique(ids), value = JSON.stringify(next);
|
|
57
|
-
kv.setItem(KEY, value);
|
|
58
|
-
if (kv.getItem(KEY) !== value) throw new Error("Saved-post write did not persist");
|
|
59
|
-
host.__himiBlogSavedIds = next;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
52
|
export function isSavedId(id: string): boolean {
|
|
63
53
|
return readSavedIds().includes(id);
|
|
64
54
|
}
|