@wix/himalaya-cli 0.2008.0 → 0.2010.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.
Files changed (57) hide show
  1. package/dist/cli.mjs +175 -46
  2. package/guides/one-app-section-mappings.md +1 -1
  3. package/guides/one-app-to-himi-app.md +4 -1
  4. package/package.json +2 -2
  5. package/templates/beauty-salon/tier5-src/_shared/himi-store-facets.ts +2 -7
  6. package/templates/beauty-salon/tier5-src/_shared/store-ribbon.ts +11 -0
  7. package/templates/branded-lite/l10n/ar.json +30 -0
  8. package/templates/branded-lite/l10n/cs.json +30 -0
  9. package/templates/branded-lite/l10n/da.json +30 -0
  10. package/templates/branded-lite/l10n/de.json +30 -0
  11. package/templates/branded-lite/l10n/el.json +30 -0
  12. package/templates/branded-lite/l10n/es.json +30 -0
  13. package/templates/branded-lite/l10n/fi.json +30 -0
  14. package/templates/branded-lite/l10n/fr.json +30 -0
  15. package/templates/branded-lite/l10n/he.json +26 -0
  16. package/templates/branded-lite/l10n/hu.json +30 -0
  17. package/templates/branded-lite/l10n/id.json +30 -0
  18. package/templates/branded-lite/l10n/it.json +30 -0
  19. package/templates/branded-lite/l10n/ja.json +30 -0
  20. package/templates/branded-lite/l10n/ko.json +30 -0
  21. package/templates/branded-lite/l10n/lt.json +30 -0
  22. package/templates/branded-lite/l10n/nl.json +30 -0
  23. package/templates/branded-lite/l10n/no.json +30 -0
  24. package/templates/branded-lite/l10n/pl.json +30 -0
  25. package/templates/branded-lite/l10n/pt.json +30 -0
  26. package/templates/branded-lite/l10n/ru.json +30 -0
  27. package/templates/branded-lite/l10n/sv.json +30 -0
  28. package/templates/branded-lite/l10n/th.json +30 -0
  29. package/templates/branded-lite/l10n/tr.json +30 -0
  30. package/templates/branded-lite/l10n/uk.json +30 -0
  31. package/templates/branded-lite/l10n/vi.json +30 -0
  32. package/templates/branded-lite/l10n/zh.json +30 -0
  33. package/templates/branded-lite/recipes/group-feed.json +135 -5
  34. package/templates/branded-lite/recipes/groups-newsfeed.json +241 -95
  35. package/templates/branded-lite/recipes/members-carousel.json +55 -3
  36. package/templates/branded-lite/recipes/plans-card.json +630 -3
  37. package/templates/branded-lite/recipes/products-carousel.json +74 -10
  38. package/templates/branded-lite/recipes/products-grid.json +74 -10
  39. package/templates/branded-lite/recipes/programs-filters.json +51 -2
  40. package/templates/branded-lite/tier5-src/_shared/group-feed-section.ts +131 -17
  41. package/templates/branded-lite/tier5-src/_shared/groups-newsfeed-section.ts +8 -5
  42. package/templates/branded-lite/tier5-src/_shared/groups-section.ts +7 -1
  43. package/templates/branded-lite/tier5-src/_shared/himi-store-facets.ts +2 -7
  44. package/templates/branded-lite/tier5-src/_shared/member-row-extras.ts +18 -17
  45. package/templates/branded-lite/tier5-src/_shared/members-directory-view.ts +12 -0
  46. package/templates/branded-lite/tier5-src/_shared/members-directory.ts +26 -13
  47. package/templates/branded-lite/tier5-src/_shared/plan-facts.ts +15 -6
  48. package/templates/branded-lite/tier5-src/_shared/plans-section.ts +32 -6
  49. package/templates/branded-lite/tier5-src/_shared/products-section.ts +5 -0
  50. package/templates/branded-lite/tier5-src/_shared/programs-section.ts +19 -16
  51. package/templates/branded-lite/tier5-src/_shared/store-ribbon.ts +11 -0
  52. package/templates/gym-fitness/tier5-src/_shared/himi-store-facets.ts +2 -7
  53. package/templates/gym-fitness/tier5-src/_shared/store-ribbon.ts +11 -0
  54. package/templates/portfolio-creative/tier5-src/_shared/himi-store-facets.ts +2 -7
  55. package/templates/portfolio-creative/tier5-src/_shared/store-ribbon.ts +11 -0
  56. package/templates/retail-store/tier5-src/_shared/himi-store-facets.ts +2 -7
  57. package/templates/retail-store/tier5-src/_shared/store-ribbon.ts +11 -0
@@ -11,6 +11,7 @@
11
11
  // retitles them like any other worker string.
12
12
  import { normalizeFormattedPrice, productImage, productOptions, productPrice, type StoreProduct } from "./himi-store.js";
13
13
  import { readSavedProducts, toggleSavedProduct } from "./himi-store-saved.js";
14
+ import { ribbonText } from "./store-ribbon.js";
14
15
  import { cleanTitle, initials } from "./himi-text.js";
15
16
  import { copyParam, copyTemplate } from "./himi-copy.js";
16
17
  import { formatCurrency } from "./engine-intl.js";
@@ -185,13 +186,7 @@ function swatchFields(hexes: string[], onSale: boolean) {
185
186
  };
186
187
  }
187
188
 
188
- /** The ribbon the merchant set, whichever catalog answered: V3 `{ id, name }`, V1 a plain string. Read through a
189
- * local type, not a `StoreProduct` member: other workers already extend that type with their own `ribbon`. */
190
- export function ribbonText(p: StoreProduct): string {
191
- const ribbon = (p as { ribbon?: unknown }).ribbon;
192
- const name = typeof ribbon === "string" ? ribbon : typeof (ribbon as { name?: unknown } | null | undefined)?.name === "string" ? (ribbon as { name: string }).name : "";
193
- return name.trim();
194
- }
189
+ export { ribbonText };
195
190
 
196
191
  /** What the tag row (Sale tag, ribbon, swatches) shows. One rule for every screen that rebuilds it, including
197
192
  * after the App Store presentation changes `onSale`: the ribbon wins over the Sale tag, so a product never
@@ -6,6 +6,7 @@ import { getMyMember, listFollowedMembers, queryMemberActivity } from "@himalaya
6
6
  import { compareIso } from "./engine-intl.js";
7
7
  import { copyParam } from "./himi-copy.js";
8
8
  import { activityText } from "./member-activity.js";
9
+ import { roleLabel } from "./members-directory-view.js";
9
10
  import type { ReadAccess } from "./member-read.js";
10
11
 
11
12
  /** The One App row draws ONE badge chip and a "+N" chip for the rest. */
@@ -17,9 +18,8 @@ const ASSIGNMENT_PAGES = 10;
17
18
  const MIN_CONTRAST = 3;
18
19
 
19
20
  export interface MemberRowExtras {
20
- /** Role line, then the last-active line when there is one. The role line reads "Member" for everyone: the activity route
21
- * also answers a role (an admin's is "ADMIN"), but the One App's wording for the other roles is not recorded here,
22
- * so none is guessed. */
21
+ /** Role line, then the last-active line when there is one. The role is the One App members service's ("Owner", "Admin",
22
+ * "Member", by `roleLabel`); a member it did not answer for, or a role it has no wording for, shows none rather than a guess. */
23
23
  subtitle: string;
24
24
  badgeTitle: string; badgeColor: string; noBadge: boolean;
25
25
  badgeMore: string; noBadgeMore: boolean;
@@ -108,23 +108,23 @@ async function readBadges(ids: string[], tenant: string): Promise<Map<string, Ba
108
108
  return result;
109
109
  }
110
110
 
111
- /** memberId → "Active 11h ago" etc., for the members the One App service knows and has something to say about.
112
- * An older native build refuses the route; that leaves the activity line out and nothing else. */
113
- export async function readActivity(ids: string[]): Promise<Map<string, string>> {
114
- return (await readMemberActivity(ids)).texts;
115
- }
116
-
117
- /** The same read, plus the members the service answered for: one it answered for with nothing to say (never opened the app) is
118
- * known and shows no line, which is different from one it did not answer for at all. */
119
- export async function readMemberActivity(ids: string[]): Promise<{ texts: Map<string, string>; known: Set<string> }> {
111
+ /** memberId → "Active 11h ago" etc. (`texts`), for the members the One App service knows and has something to say about. An older
112
+ * native build refuses the route; that leaves the activity line and the role out, and nothing else. Also the members the service
113
+ * answered for: one it answered for with nothing to say (never opened the app) is
114
+ * known and shows no line, which is different from one it did not answer for at all. `roles` is the role line's word for each
115
+ * member the service named a role for ("Owner", "Admin", "Member"); a member with none, or one it did not answer for, has no entry. */
116
+ export async function readMemberActivity(ids: string[]): Promise<{ texts: Map<string, string>; known: Set<string>; roles: Map<string, string> }> {
120
117
  const texts = new Map<string, string>();
121
118
  const known = new Set<string>();
119
+ const roles = new Map<string, string>();
122
120
  for (const activity of await queryMemberActivity(ids)) {
123
121
  known.add(activity.id);
124
122
  const text = activityText(activity);
125
123
  if (text) texts.set(activity.id, text);
124
+ const role = roleLabel(activity.role);
125
+ if (role) roles.set(activity.id, role);
126
126
  }
127
- return { texts, known };
127
+ return { texts, known, roles };
128
128
  }
129
129
 
130
130
  async function readFollowed(ids: string[], access: ReadAccess): Promise<Set<string>> {
@@ -134,7 +134,9 @@ async function readFollowed(ids: string[], access: ReadAccess): Promise<Set<stri
134
134
 
135
135
  let selfScope = "";
136
136
  let selfId = "";
137
- async function ownMemberId(access: ReadAccess): Promise<string> {
137
+ /** The signed-in member's own id ("" for a Visitor, or when it cannot be read), remembered per site and member: a list hides Follow on
138
+ * the reader's own row. */
139
+ export async function ownMemberId(access: ReadAccess): Promise<string> {
138
140
  if (!access.member.email) return "";
139
141
  const scope = JSON.stringify([access.tenant, access.member.email]);
140
142
  if (selfScope !== scope) {
@@ -154,18 +156,17 @@ const attempt = async <T>(read: Promise<T>, fallback: T): Promise<T> => { try {
154
156
  export async function memberRowExtras(ids: string[], access: ReadAccess): Promise<(id: string) => MemberRowExtras> {
155
157
  const [badges, activity, followed, self] = await Promise.all([
156
158
  attempt(readBadges(ids, access.tenant), new Map<string, BadgeInfo[]>()),
157
- attempt(readActivity(ids), new Map<string, string>()),
159
+ attempt(readMemberActivity(ids), { texts: new Map<string, string>(), known: new Set<string>(), roles: new Map<string, string>() }),
158
160
  attempt(readFollowed(ids, access), new Set<string>()),
159
161
  attempt(ownMemberId(access), ""),
160
162
  ]);
161
163
  const visitor = !access.member.email;
162
- const role = copyParam("members.roleMember", "Member");
163
164
  return (id) => {
164
165
  const held = badges.get(id) ?? [];
165
166
  const more = held.length - MAX_BADGE_CHIPS;
166
167
  const isFollowing = followed.has(id);
167
168
  return {
168
- subtitle: [role, activity.get(id)].filter(Boolean).join(" · "),
169
+ subtitle: [activity.roles.get(id), activity.texts.get(id)].filter(Boolean).join(" · "),
169
170
  badgeTitle: held[0]?.title ?? "", badgeColor: held[0]?.color ?? "", noBadge: !held.length,
170
171
  badgeMore: more > 0 ? `+${more}` : "", noBadgeMore: more <= 0,
171
172
  followLabel: followLabel(isFollowing), isFollowing,
@@ -27,6 +27,18 @@ export function badgeToken(hex: string | undefined): string {
27
27
  return best[0];
28
28
  }
29
29
 
30
+ /** The role line's word for a member's site role, as the One App members list words it ("Owner", "Admin", "Member"). The role comes
31
+ * from the One App members service; a role it did not answer (the route refused, an older native build, a member it does not know)
32
+ * or one this list has no wording for is "", so the row shows no role rather than a guessed "Member". */
33
+ export function roleLabel(role: string | undefined): string {
34
+ switch ((role ?? "").trim().toUpperCase()) {
35
+ case "OWNER": return copyParam("members.roleOwner", "Owner");
36
+ case "ADMIN": return copyParam("members.roleAdmin", "Admin");
37
+ case "MEMBER": return copyParam("members.roleMember", "Member");
38
+ default: return "";
39
+ }
40
+ }
41
+
30
42
  /** "Active 11h ago" within a day, "Last seen <date>" after; "" with no login date (or one in the future). */
31
43
  export function activityLine(lastLogin: string | undefined, now: number): string {
32
44
  const at = lastLogin ? Date.parse(lastLogin) : NaN;
@@ -10,13 +10,13 @@ import { createCollectionQuery } from "./collection-query.js";
10
10
  import { readAccess, assertReadAccess, readAccessDenied, type ReadAccess } from "./member-read.js";
11
11
  import { memberAccessChanged } from "./member-access.js";
12
12
  // The paged badge-assignments read (POST /badges/v4/assignments/query; the generated listMembersBadgeIds route answers 404 live).
13
- import { badgesByMember, readMemberActivity } from "./member-row-extras.js";
13
+ import { badgesByMember, ownMemberId, readMemberActivity } from "./member-row-extras.js";
14
14
  import { withEmptyFlags } from "./empty-flags.js";
15
15
  import { stashCopy, copyParam, copyTemplate, copyPlural } from "./himi-copy.js";
16
16
  import { activityLine, badgeToken } from "./members-directory-view.js";
17
17
 
18
18
  export interface MembersDirectoryOptions {
19
- /** "Member" under the name. */
19
+ /** The member's role under the name ("Owner", "Admin", "Member"), as the One App members service names it; none when it names none. */
20
20
  showRole?: boolean;
21
21
  /** "Active 11h ago" / "Last seen <date>", from the member's last login. */
22
22
  showActivity?: boolean;
@@ -40,7 +40,7 @@ const BADGE_PAGES = 5;
40
40
  interface Chip { id: string; label: string; token: string }
41
41
  interface Row {
42
42
  id: string; name: string; subtitle: string; initial: string; photo: string; sectionTitle: string;
43
- role: string; hasRole: boolean; activity: string; hasActivity: boolean; roleLine: string; hasRoleLine: boolean; noRoleLine: boolean;
43
+ role: string; hasRole: boolean; activity: string; hasActivity: boolean; noActivity: boolean; roleLine: string; hasRoleLine: boolean; noRoleLine: boolean;
44
44
  badges: Chip[]; hasBadges: boolean; noBadges: boolean; badgeOverflow: string; hasOverflow: boolean; noOverflow: boolean;
45
45
  badge1Label: string; badge1Token: string; hasBadge1: boolean; noBadge1: boolean;
46
46
  canFollow: boolean; noFollow: boolean; isFollowing: boolean; followLabel: string;
@@ -64,7 +64,13 @@ function name(m: WixMember): string {
64
64
  }
65
65
 
66
66
  /** What the page's extra reads found: unknown stays absent. */
67
- interface Extras { badges: Map<string, Chip[]>; following: Set<string> | undefined; /** "Active 4h ago" / "Last seen …" per member from the One App members service, and the members it answered for. */ activity: { texts: Map<string, string>; known: Set<string> } | undefined }
67
+ interface Extras {
68
+ badges: Map<string, Chip[]>; following: Set<string> | undefined;
69
+ /** "Active 4h ago" / "Last seen …" and the role word per member from the One App members service, and the members it answered for. */
70
+ activity: { texts: Map<string, string>; known: Set<string>; roles: Map<string, string> } | undefined;
71
+ /** The signed-in reader's own member id: their own row has no Follow. "" for a Visitor or when it cannot be read. */
72
+ self: string;
73
+ }
68
74
 
69
75
  export function registerMembersDirectory(serviceName: string, options: MembersDirectoryOptions = {}) {
70
76
  const rail = options.rail;
@@ -98,13 +104,15 @@ export function registerMembersDirectory(serviceName: string, options: MembersDi
98
104
  return badgeCatalog;
99
105
  }
100
106
 
101
- async function extrasFor(members: WixMember[], member: boolean): Promise<Extras> {
107
+ async function extrasFor(members: WixMember[], access: ReadAccess, member: boolean): Promise<Extras> {
102
108
  const ids = members.map((m) => m.id);
103
109
  const badges = new Map<string, Chip[]>();
104
- const [badgeRead, followRead, activityRead] = await Promise.allSettled([
110
+ const [badgeRead, followRead, activityRead, selfRead] = await Promise.allSettled([
105
111
  options.showBadges ? Promise.all([badgeDefinitions(), badgesByMember(ids)]) : Promise.resolve(undefined),
106
112
  options.showFollow && member ? getMyFollowing(ids) : Promise.resolve(undefined),
107
- options.showActivity ? readMemberActivity(ids) : Promise.resolve(undefined),
113
+ // The One App members service answers both the activity line and the role.
114
+ options.showActivity || options.showRole ? readMemberActivity(ids) : Promise.resolve(undefined),
115
+ options.showFollow && member ? ownMemberId(access) : Promise.resolve(""),
108
116
  ]);
109
117
  // A badge or follow read that fails leaves its chips off the rows; the list itself still loads.
110
118
  if (badgeRead.status === "rejected") console.warn("members_directory: the badges could not be read", badgeRead.reason);
@@ -117,12 +125,15 @@ export function registerMembersDirectory(serviceName: string, options: MembersDi
117
125
  if (chips.length) badges.set(memberId, chips);
118
126
  }
119
127
  }
120
- return { badges, following: followRead.status === "fulfilled" ? followRead.value : undefined, activity: activityRead.status === "fulfilled" ? activityRead.value : undefined };
128
+ return { badges, following: followRead.status === "fulfilled" ? followRead.value : undefined, activity: activityRead.status === "fulfilled" ? activityRead.value : undefined,
129
+ self: selfRead.status === "fulfilled" ? selfRead.value : "" };
121
130
  }
122
131
 
123
132
  function row(m: WixMember, extras: Extras, now: number): Row {
124
133
  const n = name(m);
125
- const role = options.showRole ? copyParam("members.roleMember", "Member") : "";
134
+ // The role the One App members service names ("Owner" for the site owner). A member it did not answer for has no known role, and
135
+ // the row says nothing rather than calling the owner a "Member".
136
+ const role = options.showRole ? extras.activity?.roles.get(m.id) ?? "" : "";
126
137
  // The One App members service answers "Active 4h ago" / "Last seen …" for the page. A member it answered for with nothing to say shows no line;
127
138
  // the login date is only for a member it did not answer for (an older native build refuses the route).
128
139
  const activity = !options.showActivity ? "" : extras.activity?.known.has(m.id) ? extras.activity.texts.get(m.id) ?? "" : activityLine(m.lastLoginDate, now);
@@ -133,14 +144,16 @@ export function registerMembersDirectory(serviceName: string, options: MembersDi
133
144
  const slot = (i: number) => ({ label: shown[i]?.label ?? "", token: shown[i]?.token ?? "textSecondary", has: !!shown[i] });
134
145
  const b1 = slot(0);
135
146
  const isFollowing = followed.get(m.id) ?? extras.following?.has(m.id) ?? false;
147
+ // A member never follows themself: the reader's own row has no Follow.
148
+ const follows = !!options.showFollow && m.id !== extras.self;
136
149
  // Login emails are not directory subtitles. Only public profile content is presented.
137
150
  return {
138
151
  id: m.id, name: n, subtitle: "", initial: (n[0] || "#").toUpperCase(), photo: wixMediaUrl(m.profile?.photo?.url, AVATAR_IMAGE) || wixMediaUrl(m.profile?.photo?.id, AVATAR_IMAGE) || "", sectionTitle: "",
139
- role, hasRole: !!role, activity, hasActivity: !!activity, roleLine, hasRoleLine: !!roleLine, noRoleLine: !roleLine,
152
+ role, hasRole: !!role, activity, hasActivity: !!activity, noActivity: !activity, roleLine, hasRoleLine: !!roleLine, noRoleLine: !roleLine,
140
153
  badges: chips, hasBadges: chips.length > 0, noBadges: chips.length === 0, badgeOverflow: overflow, hasOverflow: !!overflow, noOverflow: !overflow,
141
154
  badge1Label: b1.label, badge1Token: b1.token, hasBadge1: b1.has, noBadge1: !b1.has,
142
- canFollow: !!options.showFollow, noFollow: !options.showFollow, isFollowing,
143
- followLabel: options.showFollow ? isFollowing ? copyParam("members.following", "Following") : copyParam("members.follow", "Follow") : "",
155
+ canFollow: follows, noFollow: !follows, isFollowing,
156
+ followLabel: follows ? isFollowing ? copyParam("members.following", "Following") : copyParam("members.follow", "Follow") : "",
144
157
  };
145
158
  }
146
159
 
@@ -191,7 +204,7 @@ export function registerMembersDirectory(serviceName: string, options: MembersDi
191
204
  const next = offset + response.members.length;
192
205
  if (!response.members.length && total !== undefined && total > next) throw new Error("Incomplete member page");
193
206
  signedIn = !!access.member.email;
194
- const extras = await extrasFor(response.members, signedIn);
207
+ const extras = await extrasFor(response.members, access, signedIn);
195
208
  const now = Date.now();
196
209
  const rows = response.members.map(member => row(member, extras, now));
197
210
  // A rail shows the first few matching members of this one page: it never pages, and a badge filter cannot see past the page read.
@@ -4,8 +4,8 @@
4
4
  //
5
5
  // Each duration phrase is ONE plural key per unit, so a translation fits the whole phrase ("por 10 años") instead of
6
6
  // gluing translated words around English ones. Its English fallback is the wording the workers always had. The cadence
7
- // ("one-time", "per month") and the validity ("for 10 years", "Unlimited duration") are separate lines: "one-time" says
8
- // how the plan is paid, never how long it lasts.
7
+ // ("one-time", "per month", "Free plan") and the validity ("for 10 years", "Until canceled") are separate lines: "one-time"
8
+ // says how the plan is paid, never how long it lasts.
9
9
  import type { WixPlan } from "@himalaya/wix-pricing-plans";
10
10
  import { copyParam, copyPlural, copyTemplate } from "./himi-copy.js";
11
11
 
@@ -47,10 +47,19 @@ export function every(count: number, unit: string): string {
47
47
  return copyPlural(`plans.every${unitKey(known)}`, EVERY[known], count);
48
48
  }
49
49
 
50
+ /** The plan states a price, and it is zero. A plan with no price (or one that is not a number) is not called free. */
51
+ export function isFreePlan(plan: WixPlan): boolean {
52
+ const raw = plan.pricing?.price?.value;
53
+ return raw != null && String(raw).trim() !== "" && Number(raw) === 0;
54
+ }
55
+
50
56
  /** How the plan is paid, under its price: "per month" / "every 3 months" for a subscription, "one-time" for a single
51
57
  * payment; "" when the plan names neither. How long access lasts is `planValidityLine`, never this line. */
52
58
  export function planPeriodLine(plan: WixPlan): string {
53
59
  const pricing = plan.pricing;
60
+ // A plan that costs nothing reads "Free plan" beside its price, as the One App card does: a payment cadence would describe a
61
+ // payment the member never makes. How long it lasts is still `planValidityLine`.
62
+ if (isFreePlan(plan)) return copyParam("plans.freePlan", "Free plan");
54
63
  // A single payment wins over a stray `subscription` stub: the pricing kinds are exclusive, and "recurring" beside
55
64
  // "Unlimited duration" would contradict itself.
56
65
  if (pricing?.singlePaymentForDuration || pricing?.singlePaymentUnlimited) return copyParam("plans.oneTimeFact", "one-time");
@@ -62,12 +71,12 @@ export function planPeriodLine(plan: WixPlan): string {
62
71
  return "";
63
72
  }
64
73
 
65
- /** How long the plan's access lasts: "Unlimited duration" (paid once, never ends), "Until canceled" (renews with no end),
66
- * "for 10 years" (a fixed span, or a subscription's cycles × cycle length); "" when the plan does not say. The open-ended
67
- * wording is the plans screen's (`planDuration`); a fixed span keeps the per-unit plural keys. */
74
+ /** How long the plan's access lasts: "Until canceled" (paid once and never ends, or renews with no end), "for 10 years" (a
75
+ * fixed span, or a subscription's cycles × cycle length); "" when the plan does not say. A single payment with unlimited
76
+ * validity reads "Until canceled", as the One App's plan card words it; a fixed span keeps the per-unit plural keys. */
68
77
  export function planValidityLine(plan: WixPlan): string {
69
78
  const pricing = plan.pricing;
70
- if (pricing?.singlePaymentUnlimited) return copyParam("plans.unlimited", "Unlimited duration");
79
+ if (pricing?.singlePaymentUnlimited) return copyParam("plans.untilCanceled", "Until canceled");
71
80
  const single = pricing?.singlePaymentForDuration;
72
81
  const cycle = single ? undefined : pricing?.subscription;
73
82
  if (cycle && !cycle.cycleCount) return copyParam("plans.untilCanceled", "Until canceled");
@@ -1,4 +1,5 @@
1
- // The INLINE plans section: the site's pricing plans as cards (name, pitch, price, cadence, validity, the whole benefits list), hosted by
1
+ // The INLINE plans section: the site's pricing plans as cards (name, pitch, price, cadence, validity, the benefits list or a
2
+ // "Show Benefits" disclosure over it), hosted by
2
3
  // any worker that wants them next to other sections. It is data only and read-only: a card opens the plan's own screen
3
4
  // (`himi_plan`), which is where joining and paying live. The `plans-card` recipe is the card that reads it,
4
5
  // bound as `$service:<serviceName>.*`.
@@ -19,6 +20,9 @@ export interface PlansSectionOptions {
19
20
  showBenefits?: boolean;
20
21
  /** The order of the published plans when none is selected (a selection keeps the source's own order); absent: the site's order. */
21
22
  order?: "oldest-first" | "newest-first";
23
+ /** How the benefits show: listed on the card ("list", the default), or folded under a disclosure the reader opens
24
+ * ("disclosure", the One App paid-plans card's "Show Benefits"). */
25
+ benefits?: "list" | "disclosure";
22
26
  }
23
27
 
24
28
  export interface PlansSectionRow {
@@ -28,10 +32,14 @@ export interface PlansSectionRow {
28
32
  priceLine: string; noPrice: boolean;
29
33
  /** How the plan is paid ("per month", "one-time"). */
30
34
  periodLine: string; noPeriod: boolean;
31
- /** How long access lasts ("Unlimited duration", "for 10 years"), apart from the cadence. */
35
+ /** How long access lasts ("Until canceled", "for 10 years"), apart from the cadence. */
32
36
  validityLine: string; noValidity: boolean;
33
37
  badge: string; noBadge: boolean;
34
38
  perks: string[];
39
+ /** The benefits listed on the card (list layout, the plan has some). */
40
+ noPerkList: boolean;
41
+ /** The benefits folded under the disclosure (disclosure layout, the plan has some), and whether the reader opened it. */
42
+ noPerkDisclosure: boolean; benefitsOpen: boolean;
35
43
  [perk: `perk${number}`]: string;
36
44
  [flag: `noPerk${number}`]: boolean;
37
45
  }
@@ -51,7 +59,7 @@ function money(plan: WixPlan): string {
51
59
  try { return formatCurrency(Number(raw), price?.currency || "USD"); } catch { return `${raw}`; }
52
60
  }
53
61
 
54
- export function plansSectionRow(plan: WixPlan, showBenefits = true): PlansSectionRow {
62
+ export function plansSectionRow(plan: WixPlan, showBenefits = true, benefits: PlansSectionOptions["benefits"] = "list"): PlansSectionRow {
55
63
  const perks = showBenefits
56
64
  ? (plan.perks?.values ?? []).map((perk) => (perk ?? "").trim()).filter(Boolean).slice(0, PLANS_SECTION_MAX_PERKS)
57
65
  : [];
@@ -63,6 +71,7 @@ export function plansSectionRow(plan: WixPlan, showBenefits = true): PlansSectio
63
71
  return {
64
72
  id: plan.id || "", name: (plan.name || copyParam("plans.planFallbackName", "Plan")).trim(),
65
73
  description, noDescription: !description, priceLine, noPrice: !priceLine, periodLine, noPeriod: !periodLine, validityLine, noValidity: !validityLine, badge, noBadge: !badge, perks,
74
+ noPerkList: !perks.length || benefits === "disclosure", noPerkDisclosure: !perks.length || benefits !== "disclosure", benefitsOpen: false,
66
75
  ...planPerkFields(perks),
67
76
  };
68
77
  }
@@ -97,22 +106,39 @@ export function selectPlans(plans: readonly WixPlan[], planIds: readonly string[
97
106
  return live.filter((plan) => rank.has(plan.id)).sort((a, b) => (rank.get(a.id) ?? 0) - (rank.get(b.id) ?? 0));
98
107
  }
99
108
 
109
+ /** The rows with one plan's benefits disclosure opened or closed (the reader's tap); any other row is kept as it is. */
110
+ export function toggleBenefits(rows: readonly PlansSectionRow[], id: unknown): PlansSectionRow[] {
111
+ if (typeof id !== "string" || !id) return [...rows];
112
+ return rows.map((row) => row.id === id && !row.noPerkDisclosure ? { ...row, benefitsOpen: !row.benefitsOpen } : row);
113
+ }
114
+
100
115
  export function registerPlansSection(serviceName: string, options: PlansSectionOptions = {}) {
101
116
  const showBenefits = options.showBenefits !== false;
117
+ const benefits = options.benefits === "disclosure" ? "disclosure" : "list";
102
118
  const planIds = (options.planIds ?? []).filter((id) => typeof id === "string" && id);
103
- return defineService<PlansSectionState, { load: (state: PlansSectionState, arg?: unknown) => Promise<PlansSectionState> }>(serviceName, {
119
+ return defineService<PlansSectionState, {
120
+ load: (state: PlansSectionState, arg?: unknown) => Promise<PlansSectionState>;
121
+ toggleBenefits: (state: PlansSectionState, arg?: unknown) => PlansSectionState;
122
+ }>(serviceName, {
104
123
  state: derive("loading", []),
105
124
  actions: {
106
- load: async (_state, arg) => {
125
+ load: async (state, arg) => {
107
126
  stashCopy(arg);
127
+ // The section reads again each time it reappears (back from a plan): a disclosure the reader opened stays open.
128
+ const open = new Set(state.rows.filter((row) => row.benefitsOpen).map((row) => row.id));
108
129
  try {
109
130
  const response = await listPublicPlans();
110
- return derive("ready", selectPlans(response.plans ?? [], planIds, options.order).map((plan) => plansSectionRow(plan, showBenefits)));
131
+ return derive("ready", selectPlans(response.plans ?? [], planIds, options.order).map((plan) => {
132
+ const row = plansSectionRow(plan, showBenefits, benefits);
133
+ return open.has(row.id) && !row.noPerkDisclosure ? { ...row, benefitsOpen: true } : row;
134
+ }));
111
135
  } catch (error) {
112
136
  console.warn("plans_section: the plans could not be read", error);
113
137
  return derive("error", []);
114
138
  }
115
139
  },
140
+ // The card's "Show Benefits" disclosure: only the tapped plan opens or closes.
141
+ toggleBenefits: (state, arg) => derive(state.status, toggleBenefits(state.rows, (arg as { id?: unknown } | undefined)?.id)),
116
142
  },
117
143
  });
118
144
  }
@@ -6,6 +6,7 @@
6
6
  import { defineService } from "@himalaya/state";
7
7
  import { searchStoreProducts, productImage, productPrice, type StoreProduct } from "./himi-store.js";
8
8
  import { copyParam, stashCopy } from "./himi-copy.js";
9
+ import { ribbonText } from "./store-ribbon.js";
9
10
 
10
11
  export interface ProductsSectionOptions {
11
12
  /** The source collection's id; unset reads the whole catalog. */
@@ -17,6 +18,8 @@ export interface ProductsSectionOptions {
17
18
  export interface ProductRow {
18
19
  id: string; name: string; price: string;
19
20
  image: string; initial: string; hasImage: boolean; noImage: boolean;
21
+ /** The merchant's ribbon on the product ("Best Seller"), on the tile's image; a product without one keeps a plain tile. */
22
+ ribbon: string; noRibbon: boolean;
20
23
  /** The product screen a tile opens; the tile binds `id` as its nav param. */
21
24
  detailScreenId: string;
22
25
  }
@@ -37,9 +40,11 @@ const TILE_IMAGE = { width: 480, height: 480, quality: 85 };
37
40
  function rowOf(product: StoreProduct): ProductRow {
38
41
  const name = (product.name ?? "").trim();
39
42
  const image = productImage(product, TILE_IMAGE);
43
+ const ribbon = ribbonText(product);
40
44
  return {
41
45
  id: product.id ?? "", name, price: productPrice(product),
42
46
  image, initial: (name[0] ?? "#").toUpperCase(), hasImage: !!image, noImage: !image,
47
+ ribbon, noRibbon: !ribbon,
43
48
  detailScreenId: "himi_product",
44
49
  };
45
50
  }
@@ -104,6 +104,8 @@ export interface State {
104
104
  identityLine: string;
105
105
  needsSignIn: boolean;
106
106
  noSignIn: boolean;
107
+ /** The guest's Sign in button on a signed-out "Programs I joined". */
108
+ signInLabel: string;
107
109
  nextCursor: string;
108
110
  noMore: boolean;
109
111
  noPageError: boolean;
@@ -291,10 +293,11 @@ function programContent(o: { program: WixProgram; participant?: WixParticipant;
291
293
  const countFull = capped && o.participants !== undefined && o.participants >= maxParticipants(p);
292
294
  // Not knowing the count of a capped program, or whether an application exists, the card claims neither
293
295
  // "Join" nor "Program is full": View, and the detail screen decides.
294
- // A failed participations read leaves every unjoined-looking card unknown too: the member may be in it.
295
- const standingUnknown = standing === "none" && o.member
296
+ // A failed participations read leaves every unjoined-looking card unknown too: the member may be in it. That holds
297
+ // for a guest as well: a signed-in member whose id is not resolved yet reads as a guest with unknown participations.
298
+ const standingUnknown = standing === "none"
296
299
  && (!!o.applicationUnknown || !!o.participationsUnknown || (capped && o.participants === undefined));
297
- // "Full" only for a member whose own standing is known: an unknown one may already be in it.
300
+ // "Full" only when the viewer's own standing is known: an unknown one may already be in it.
298
301
  const limitReached = countFull && !standingUnknown;
299
302
  const commercePrice = commercePriceOf(p);
300
303
  const descriptionLine = standing === "completed" ? copyParam("memberPrograms.line.completed", "Completed")
@@ -306,9 +309,8 @@ function programContent(o: { program: WixProgram; participant?: WixParticipant;
306
309
  : standing === "suspended" ? copyParam("memberPrograms.line.suspended", "Your participation is paused")
307
310
  : "";
308
311
  // An invitation is accepted on the website (joinProgram cannot accept one), so an invited card's CTA is View.
309
- // A card section invites a guest to join as well: the tap opens the program, which asks them to sign in.
310
- const actionLabel = !o.member && !display.card ? copyParam("memberPrograms.action.view", "View")
311
- : !o.member && standing !== "none" ? copyParam("memberPrograms.action.view", "View")
312
+ // A guest is invited to join as well, as on the source card: the tap opens the program, which asks them to sign in.
313
+ const actionLabel = !o.member && standing !== "none" ? copyParam("memberPrograms.action.view", "View")
312
314
  : display.card && joined ? copyParam("memberPrograms.action.continue", "Continue")
313
315
  : limitReached ? copyParam("memberPrograms.action.full", "Program is full")
314
316
  : joined || over || closed || standing === "pending" || standing === "invited" || standingUnknown ? copyParam("memberPrograms.action.view", "View")
@@ -333,8 +335,8 @@ function programContent(o: { program: WixProgram; participant?: WixParticipant;
333
335
  hasProgress: started, noProgress: !started,
334
336
  pricable: !joined && !over && !closed && !descriptionLine,
335
337
  commercePrice, free: !commercePrice,
336
- // Only a member's CTA is the join action; a guest's "View" stays a navigation.
337
- actionLabel, actionDisabled: limitReached && o.member,
338
+ // A full program offers nobody a join; the card itself still opens the program.
339
+ actionLabel, actionDisabled: limitReached,
338
340
  // A member in the program opens the participant page; everyone else the program page.
339
341
  detailScreenId: programScreenFor(inProgram(standing, o.participant), DETAIL_SCREEN, PARTICIPANT_SCREEN),
340
342
  categoryIds: categoryIdsOf(p),
@@ -617,7 +619,7 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
617
619
 
618
620
  const INITIAL_STATE: State = {
619
621
  status: "loading", rows: [], isLoading: true, notLoading: false, isErrored: false, notErrored: true, noEmpty: true, hideList: true,
620
- emptyText: "", errorText: "", identityLine: "", needsSignIn: false, noSignIn: true, nextCursor: "", noMore: true, noPageError: true, loadingMore: false,
622
+ emptyText: "", errorText: "", identityLine: "", needsSignIn: false, noSignIn: true, signInLabel: "", nextCursor: "", noMore: true, noPageError: true, loadingMore: false,
621
623
  statusFilter: "all", statusOptions: [], hideStatusFilter: true, categoryId: "", categoryChips: [], hideCategoryFilter: true,
622
624
  noSeeAll: true, hidePriceRetry: true, priceRetryText: "", summary: "", hasRows: false, noRows: true,
623
625
  };
@@ -668,19 +670,20 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
668
670
  emptyText,
669
671
  errorText: status === "error" ? (current?.error || copyParam("memberPrograms.errorText", "Programs could not be loaded.")) : "",
670
672
  identityLine: meta.email ? copyTemplate("memberPrograms.identityLine", "Signed in as {email}", { email: meta.email ?? "" }) : "",
671
- needsSignIn, noSignIn: !needsSignIn,
673
+ needsSignIn, noSignIn: !needsSignIn, signInLabel: copyParam("memberPrograms.signInCta", "Sign in"),
672
674
  nextCursor: current && !current.pageError && !current.loadingMore ? current.nextCursor : "",
673
675
  noMore: !current?.nextCursor || current.pageError || current.loadingMore,
674
676
  noPageError: !current?.pageError,
675
677
  loadingMore: !!current?.loadingMore,
676
678
  statusFilter, statusOptions,
677
- // A guest sees the catalog, never a "joined" filter they cannot satisfy — unless they are already on
678
- // it (signed out there), when the control is their way back to the catalog. It stays up while a
679
- // filter switch or a refresh reloads, so the control never flickers away under the finger.
680
- hideStatusFilter: options.filters?.status === false || (!member && statusFilter !== "joined"),
679
+ // The source's filter menu is shown to a guest too, also with one program: "Programs I joined" then asks them
680
+ // to sign in (needsSignIn). It stays up while a filter switch or a refresh reloads, so it never flickers away.
681
+ hideStatusFilter: options.filters?.status === false,
681
682
  categoryId, categoryChips,
682
- // One category chosen in the section is the whole list: choosing among one is not a filter.
683
- hideCategoryFilter: options.filters?.category === false || categoriesFailed || !categories || categories.length === 0 || sectionCategories.length === 1,
683
+ // A site with no categories still shows "All categories", as the source does. A section scoped to categories
684
+ // offers the ones the site still has: one (or none) left is the whole list, and choosing among one is not a
685
+ // filter. Unread categories offer nothing to pick.
686
+ hideCategoryFilter: options.filters?.category === false || categoriesFailed || !categories || (sectionCategories.length > 0 && categories.length <= 1),
684
687
  // See all only for an inline (limited) list that has programs past the cards it shows.
685
688
  noSeeAll: !(inlineLimit && status === "ready" && meta.more === true),
686
689
  hidePriceRetry: status !== "ready" || !views.some((view) => view && view.route !== "disabled" && (scopeIncomplete || view.retryable)),
@@ -0,0 +1,11 @@
1
+ // The merchant's ribbon on a product ("New", "Best Seller"…), on its own so a section that shows only tiles (products-section) reads it
2
+ // without the shop's sort, filter and saved-products code (himi-store-facets re-exports it).
3
+ import type { StoreProduct } from "./himi-store.js";
4
+
5
+ /** The ribbon the merchant set, whichever catalog answered: V3 `{ id, name }`, V1 a plain string. Read through a
6
+ * local type, not a `StoreProduct` member: other workers already extend that type with their own `ribbon`. */
7
+ export function ribbonText(p: StoreProduct): string {
8
+ const ribbon = (p as { ribbon?: unknown }).ribbon;
9
+ const name = typeof ribbon === "string" ? ribbon : typeof (ribbon as { name?: unknown } | null | undefined)?.name === "string" ? (ribbon as { name: string }).name : "";
10
+ return name.trim();
11
+ }
@@ -11,6 +11,7 @@
11
11
  // retitles them like any other worker string.
12
12
  import { normalizeFormattedPrice, productImage, productOptions, productPrice, type StoreProduct } from "./himi-store.js";
13
13
  import { readSavedProducts, toggleSavedProduct } from "./himi-store-saved.js";
14
+ import { ribbonText } from "./store-ribbon.js";
14
15
  import { cleanTitle, initials } from "./himi-text.js";
15
16
  import { copyParam, copyTemplate } from "./himi-copy.js";
16
17
  import { formatCurrency } from "./engine-intl.js";
@@ -185,13 +186,7 @@ function swatchFields(hexes: string[], onSale: boolean) {
185
186
  };
186
187
  }
187
188
 
188
- /** The ribbon the merchant set, whichever catalog answered: V3 `{ id, name }`, V1 a plain string. Read through a
189
- * local type, not a `StoreProduct` member: other workers already extend that type with their own `ribbon`. */
190
- export function ribbonText(p: StoreProduct): string {
191
- const ribbon = (p as { ribbon?: unknown }).ribbon;
192
- const name = typeof ribbon === "string" ? ribbon : typeof (ribbon as { name?: unknown } | null | undefined)?.name === "string" ? (ribbon as { name: string }).name : "";
193
- return name.trim();
194
- }
189
+ export { ribbonText };
195
190
 
196
191
  /** What the tag row (Sale tag, ribbon, swatches) shows. One rule for every screen that rebuilds it, including
197
192
  * after the App Store presentation changes `onSale`: the ribbon wins over the Sale tag, so a product never
@@ -0,0 +1,11 @@
1
+ // The merchant's ribbon on a product ("New", "Best Seller"…), on its own so a section that shows only tiles (products-section) reads it
2
+ // without the shop's sort, filter and saved-products code (himi-store-facets re-exports it).
3
+ import type { StoreProduct } from "./himi-store.js";
4
+
5
+ /** The ribbon the merchant set, whichever catalog answered: V3 `{ id, name }`, V1 a plain string. Read through a
6
+ * local type, not a `StoreProduct` member: other workers already extend that type with their own `ribbon`. */
7
+ export function ribbonText(p: StoreProduct): string {
8
+ const ribbon = (p as { ribbon?: unknown }).ribbon;
9
+ const name = typeof ribbon === "string" ? ribbon : typeof (ribbon as { name?: unknown } | null | undefined)?.name === "string" ? (ribbon as { name: string }).name : "";
10
+ return name.trim();
11
+ }
@@ -11,6 +11,7 @@
11
11
  // retitles them like any other worker string.
12
12
  import { normalizeFormattedPrice, productImage, productOptions, productPrice, type StoreProduct } from "./himi-store.js";
13
13
  import { readSavedProducts, toggleSavedProduct } from "./himi-store-saved.js";
14
+ import { ribbonText } from "./store-ribbon.js";
14
15
  import { cleanTitle, initials } from "./himi-text.js";
15
16
  import { copyParam, copyTemplate } from "./himi-copy.js";
16
17
  import { formatCurrency } from "./engine-intl.js";
@@ -185,13 +186,7 @@ function swatchFields(hexes: string[], onSale: boolean) {
185
186
  };
186
187
  }
187
188
 
188
- /** The ribbon the merchant set, whichever catalog answered: V3 `{ id, name }`, V1 a plain string. Read through a
189
- * local type, not a `StoreProduct` member: other workers already extend that type with their own `ribbon`. */
190
- export function ribbonText(p: StoreProduct): string {
191
- const ribbon = (p as { ribbon?: unknown }).ribbon;
192
- const name = typeof ribbon === "string" ? ribbon : typeof (ribbon as { name?: unknown } | null | undefined)?.name === "string" ? (ribbon as { name: string }).name : "";
193
- return name.trim();
194
- }
189
+ export { ribbonText };
195
190
 
196
191
  /** What the tag row (Sale tag, ribbon, swatches) shows. One rule for every screen that rebuilds it, including
197
192
  * after the App Store presentation changes `onSale`: the ribbon wins over the Sale tag, so a product never
@@ -0,0 +1,11 @@
1
+ // The merchant's ribbon on a product ("New", "Best Seller"…), on its own so a section that shows only tiles (products-section) reads it
2
+ // without the shop's sort, filter and saved-products code (himi-store-facets re-exports it).
3
+ import type { StoreProduct } from "./himi-store.js";
4
+
5
+ /** The ribbon the merchant set, whichever catalog answered: V3 `{ id, name }`, V1 a plain string. Read through a
6
+ * local type, not a `StoreProduct` member: other workers already extend that type with their own `ribbon`. */
7
+ export function ribbonText(p: StoreProduct): string {
8
+ const ribbon = (p as { ribbon?: unknown }).ribbon;
9
+ const name = typeof ribbon === "string" ? ribbon : typeof (ribbon as { name?: unknown } | null | undefined)?.name === "string" ? (ribbon as { name: string }).name : "";
10
+ return name.trim();
11
+ }
@@ -11,6 +11,7 @@
11
11
  // retitles them like any other worker string.
12
12
  import { normalizeFormattedPrice, productImage, productOptions, productPrice, type StoreProduct } from "./himi-store.js";
13
13
  import { readSavedProducts, toggleSavedProduct } from "./himi-store-saved.js";
14
+ import { ribbonText } from "./store-ribbon.js";
14
15
  import { cleanTitle, initials } from "./himi-text.js";
15
16
  import { copyParam, copyTemplate } from "./himi-copy.js";
16
17
  import { formatCurrency } from "./engine-intl.js";
@@ -185,13 +186,7 @@ function swatchFields(hexes: string[], onSale: boolean) {
185
186
  };
186
187
  }
187
188
 
188
- /** The ribbon the merchant set, whichever catalog answered: V3 `{ id, name }`, V1 a plain string. Read through a
189
- * local type, not a `StoreProduct` member: other workers already extend that type with their own `ribbon`. */
190
- export function ribbonText(p: StoreProduct): string {
191
- const ribbon = (p as { ribbon?: unknown }).ribbon;
192
- const name = typeof ribbon === "string" ? ribbon : typeof (ribbon as { name?: unknown } | null | undefined)?.name === "string" ? (ribbon as { name: string }).name : "";
193
- return name.trim();
194
- }
189
+ export { ribbonText };
195
190
 
196
191
  /** What the tag row (Sale tag, ribbon, swatches) shows. One rule for every screen that rebuilds it, including
197
192
  * after the App Store presentation changes `onSale`: the ribbon wins over the Sale tag, so a product never
@@ -0,0 +1,11 @@
1
+ // The merchant's ribbon on a product ("New", "Best Seller"…), on its own so a section that shows only tiles (products-section) reads it
2
+ // without the shop's sort, filter and saved-products code (himi-store-facets re-exports it).
3
+ import type { StoreProduct } from "./himi-store.js";
4
+
5
+ /** The ribbon the merchant set, whichever catalog answered: V3 `{ id, name }`, V1 a plain string. Read through a
6
+ * local type, not a `StoreProduct` member: other workers already extend that type with their own `ribbon`. */
7
+ export function ribbonText(p: StoreProduct): string {
8
+ const ribbon = (p as { ribbon?: unknown }).ribbon;
9
+ const name = typeof ribbon === "string" ? ribbon : typeof (ribbon as { name?: unknown } | null | undefined)?.name === "string" ? (ribbon as { name: string }).name : "";
10
+ return name.trim();
11
+ }