@wix/himalaya-cli 0.1661.0 → 0.1663.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 (73) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +17 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/audio-record/src/index.d.ts +4 -1
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +26 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/members-v1/src/index.d.ts +26 -0
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +3 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +8 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-members.mjs +4 -0
  8. package/dist/browser-plane/assets.json +5 -5
  9. package/dist/browser-plane/preview-deferred/{fcafca348b6b973cfc2eadc938ddec3c515c641874cbca1667a43b22e1bf7a39.bin → 5fe817d61d13666ee8e6951d96a873f768ef305462735f6030cce105f1c21488.bin} +1 -1
  10. package/dist/browser-plane/sw.js +8 -8
  11. package/dist/cli.mjs +1147 -731
  12. package/dist/preview-assets.generated.bin +0 -0
  13. package/fixtures/wix-canned.json +1 -0
  14. package/guides/component-reference.json +13 -4
  15. package/guides/component-reference.md +26 -6
  16. package/guides/himi-json-output.md +8 -0
  17. package/guides/index.json +1 -1
  18. package/guides/one-app-section-mappings.md +3 -4
  19. package/guides/one-app-to-himi-app.md +20 -1
  20. package/guides/sdk-reference.json +24 -1
  21. package/package.json +2 -2
  22. package/templates/beauty-salon/recipes/announcement-card.json +72 -0
  23. package/templates/beauty-salon/tier5-src/_shared/announcement-section.ts +122 -0
  24. package/templates/beauty-salon/tier5-src/_shared/engine-intl.ts +8 -0
  25. package/templates/beauty-salon-owner/tier5-src/_shared/engine-intl.ts +8 -0
  26. package/templates/branded-lite/dev/index.ts +791 -169
  27. package/templates/branded-lite/l10n/en.json +46 -13
  28. package/templates/branded-lite/l10n/he.json +59 -7
  29. package/templates/branded-lite/recipes/announcement-card.json +72 -0
  30. package/templates/branded-lite/tier5-src/_shared/announcement-section.ts +122 -0
  31. package/templates/branded-lite/tier5-src/_shared/engine-intl.ts +8 -0
  32. package/templates/branded-lite/tier5-src/wix-spaces-member-detail/index.ts +367 -63
  33. package/templates/community-club/l10n/he.json +2 -2
  34. package/templates/community-club/recipes/announcement-card.json +72 -0
  35. package/templates/community-club/tier5-src/_shared/announcement-section.ts +122 -0
  36. package/templates/community-club/tier5-src/_shared/engine-intl.ts +8 -0
  37. package/templates/community-club-owner/tier5-src/_shared/engine-intl.ts +8 -0
  38. package/templates/conference/tier5-src/_shared/engine-intl.ts +8 -0
  39. package/templates/events-meetups/recipes/announcement-card.json +72 -0
  40. package/templates/events-meetups/tier5-src/_shared/announcement-section.ts +122 -0
  41. package/templates/events-meetups/tier5-src/_shared/engine-intl.ts +8 -0
  42. package/templates/events-meetups-owner/tier5-src/_shared/engine-intl.ts +8 -0
  43. package/templates/gym-fitness/recipes/announcement-card.json +72 -0
  44. package/templates/gym-fitness/tier5-src/_shared/announcement-section.ts +122 -0
  45. package/templates/gym-fitness/tier5-src/_shared/engine-intl.ts +8 -0
  46. package/templates/gym-fitness-owner/tier5-src/_shared/engine-intl.ts +8 -0
  47. package/templates/nonprofit-cause/recipes/announcement-card.json +72 -0
  48. package/templates/nonprofit-cause/tier5-src/_shared/announcement-section.ts +122 -0
  49. package/templates/nonprofit-cause/tier5-src/_shared/engine-intl.ts +8 -0
  50. package/templates/nonprofit-cause-owner/tier5-src/_shared/engine-intl.ts +8 -0
  51. package/templates/owner-lite/tier5-src/_shared/engine-intl.ts +8 -0
  52. package/templates/podcast-creator/recipes/announcement-card.json +72 -0
  53. package/templates/podcast-creator/tier5-src/_shared/announcement-section.ts +122 -0
  54. package/templates/podcast-creator/tier5-src/_shared/engine-intl.ts +8 -0
  55. package/templates/podcast-creator-owner/tier5-src/_shared/engine-intl.ts +8 -0
  56. package/templates/portfolio-creative/recipes/announcement-card.json +72 -0
  57. package/templates/portfolio-creative/tier5-src/_shared/announcement-section.ts +122 -0
  58. package/templates/portfolio-creative/tier5-src/_shared/engine-intl.ts +8 -0
  59. package/templates/portfolio-creative-owner/tier5-src/_shared/engine-intl.ts +8 -0
  60. package/templates/restaurant/recipes/announcement-card.json +72 -0
  61. package/templates/restaurant/tier5-src/_shared/announcement-section.ts +122 -0
  62. package/templates/restaurant/tier5-src/_shared/engine-intl.ts +8 -0
  63. package/templates/restaurant-owner/tier5-src/_shared/engine-intl.ts +8 -0
  64. package/templates/retail-store/recipes/announcement-card.json +72 -0
  65. package/templates/retail-store/tier5-src/_shared/announcement-section.ts +122 -0
  66. package/templates/retail-store/tier5-src/_shared/engine-intl.ts +8 -0
  67. package/templates/retail-store-owner/tier5-src/_shared/engine-intl.ts +8 -0
  68. package/templates/salon-spa/tier5-src/_shared/engine-intl.ts +8 -0
  69. package/templates/wholesale-store/tier5-src/_shared/engine-intl.ts +8 -0
  70. package/templates/yoga-studio/recipes/announcement-card.json +72 -0
  71. package/templates/yoga-studio/tier5-src/_shared/announcement-section.ts +122 -0
  72. package/templates/yoga-studio/tier5-src/_shared/engine-intl.ts +8 -0
  73. package/templates/yoga-studio-owner/tier5-src/_shared/engine-intl.ts +8 -0
@@ -0,0 +1,122 @@
1
+ // The INLINE announcement section: the business's latest announcement, read at RUNTIME (never baked at migration time) and
2
+ // shown next to other sections. It is the call the native Branded app's announcement section makes
3
+ // (wix-one-app-member-view, Announcement/serverApiService.ts `fetchLatestAnnouncement`): one GET of the latest announcement with the
4
+ // app's own signed instance (Member when signed in, else Visitor), which the `wixApi` bridge attaches.
5
+ //
6
+ // READ-ONLY, ALWAYS: `includeReaderData` stays false (true needs the One App manage permission and answers 403), and nothing here
7
+ // ever marks an announcement as seen (`AddCurrentMemberAsReader` is a write). Known server behaviour, shared with the native app: a
8
+ // site that has no announcement yet gets its default welcome text saved once, by this very read.
9
+ // A phone sends the signed instance to this URL only because the native hosts (Android and Swift `WixApiCapability`) allow exactly this
10
+ // GET (host, path, method and the reader-data-off query) for the consumer providers; a build without that entry refuses the read and the
11
+ // section shows nothing. The local web preview has no such list.
12
+ // The `announcement-card` recipe is the card that reads it, bound as `$service:<serviceName>.*`.
13
+ import { defineService } from "@himalaya/state";
14
+ import { richBody } from "./rich-body.js";
15
+ import { formatDateMedium } from "./engine-intl.js";
16
+ import { openRichLink } from "./rich-content-link.js";
17
+
18
+ /** The one call: the latest announcement, without the reader data. */
19
+ export const LATEST_ANNOUNCEMENT_URL = "https://manage.wix.com/_api/mobile-apps-announcements/v1/announcements/latest?includeReaderData=false";
20
+
21
+ interface LatestAnnouncementResponse {
22
+ announcement?: {
23
+ title?: unknown;
24
+ /** The announcement's content: a DraftJS raw state for announcements written in the app, or a Ricos document (as a Struct). */
25
+ content?: unknown;
26
+ createdDate?: unknown;
27
+ creatorMemberProfileData?: { nickname?: unknown; imageUrl?: unknown };
28
+ };
29
+ }
30
+
31
+ export interface AnnouncementState {
32
+ status: "loading" | "ready" | "error";
33
+ hasAnnouncement: boolean; noAnnouncement: boolean;
34
+ title: string; noTitle: boolean;
35
+ /** The rich body as one document string (RichContent draws nothing for ""), and its plain text, shown when there is no document. */
36
+ bodyJson: string; hasBodyJson: boolean; noBodyJson: boolean;
37
+ body: string; noBody: boolean;
38
+ created: string; noCreated: boolean;
39
+ creator: string; noCreator: boolean;
40
+ creatorImage: string; noCreatorImage: boolean;
41
+ isLoading: boolean; notLoading: boolean;
42
+ isErrored: boolean; notErrored: boolean;
43
+ }
44
+
45
+ const text = (value: unknown): string => (typeof value === "string" ? value.trim() : "");
46
+
47
+ /** The plain text of a DraftJS raw state (`{ blocks: [{ text }], entityMap }`), which is what the service's `content` really is for
48
+ * announcements written in the app (observed on a live site, 2026-11-11), or undefined when `content` is not one. Only the blocks' own
49
+ * text is read: the entity map (links, images) is never followed. */
50
+ function draftPlainText(content: unknown): string | undefined {
51
+ let doc = content;
52
+ if (typeof doc === "string") { try { doc = JSON.parse(doc); } catch { return undefined; } }
53
+ const blocks = (doc as { blocks?: unknown } | null | undefined)?.blocks;
54
+ if (!Array.isArray(blocks)) return undefined;
55
+ return blocks.map((block) => text((block as { text?: unknown } | null)?.text)).filter(Boolean).join("\n\n");
56
+ }
57
+
58
+ function derive(status: AnnouncementState["status"], fields: { title?: string; bodyJson?: string; body?: string; created?: string; creator?: string; creatorImage?: string } = {}): AnnouncementState {
59
+ const title = fields.title ?? "", bodyJson = fields.bodyJson ?? "", body = fields.body ?? "", created = fields.created ?? "";
60
+ const creator = fields.creator ?? "", creatorImage = fields.creatorImage ?? "";
61
+ const hasAnnouncement = status === "ready" && !!(title || bodyJson || body);
62
+ return {
63
+ status, hasAnnouncement, noAnnouncement: !hasAnnouncement,
64
+ title, noTitle: !title,
65
+ bodyJson, hasBodyJson: !!bodyJson, noBodyJson: !bodyJson,
66
+ body, noBody: !body,
67
+ created, noCreated: !created,
68
+ creator, noCreator: !creator,
69
+ creatorImage, noCreatorImage: !creatorImage,
70
+ isLoading: status === "loading", notLoading: status !== "loading",
71
+ isErrored: status === "error", notErrored: status !== "error",
72
+ };
73
+ }
74
+
75
+ /** The state for a latest-announcement response: an empty or missing announcement shows nothing, never a placeholder. */
76
+ export function announcementState(response: unknown): AnnouncementState {
77
+ const announcement = (response as LatestAnnouncementResponse | undefined)?.announcement;
78
+ if (!announcement || typeof announcement !== "object") return derive("ready");
79
+ // A DraftJS body shows as its plain text; a Ricos body keeps its rich document.
80
+ const draft = draftPlainText(announcement.content);
81
+ const rich = draft !== undefined ? { bodyJson: "", bodyText: draft } : richBody(announcement.content);
82
+ const when = typeof announcement.createdDate === "string" ? new Date(announcement.createdDate) : undefined;
83
+ const image = text(announcement.creatorMemberProfileData?.imageUrl);
84
+ return derive("ready", {
85
+ title: text(announcement.title),
86
+ bodyJson: rich.bodyJson, body: rich.bodyText,
87
+ created: when && !Number.isNaN(when.getTime()) ? formatDateMedium(when) : "",
88
+ creator: text(announcement.creatorMemberProfileData?.nickname),
89
+ // An avatar is shown only from an https URL.
90
+ creatorImage: /^https:\/\//i.test(image) ? image : "",
91
+ });
92
+ }
93
+
94
+ /** `options` is the generator's uniform second argument; the section has no settings of its own, so nothing is read from it. */
95
+ export function registerAnnouncementSection(serviceName: string, _options: object = {}) {
96
+ // The failure path reads the CURRENT state, not the snapshot the call began with: a refresh that fails after another load already
97
+ // showed an announcement must not erase it.
98
+ let current: () => AnnouncementState = () => derive("loading");
99
+ const handle = defineService<AnnouncementState, { load: (state: AnnouncementState) => Promise<AnnouncementState>; openLink: (state: AnnouncementState, arg?: unknown) => Promise<AnnouncementState> }>(serviceName, {
100
+ state: derive("loading"),
101
+ actions: {
102
+ load: async () => {
103
+ // A failed refresh (offline, a 5xx) keeps an announcement that is already showing: only a screen with nothing to show goes to error.
104
+ const failed = (): AnnouncementState => { const now = current(); return now.hasAnnouncement ? now : derive("error"); };
105
+ try {
106
+ const api = (globalThis as { himalaya?: { wixApi?: { call: (method: string, path: string) => Promise<unknown> } } }).himalaya?.wixApi;
107
+ if (!api) return failed();
108
+ return announcementState(await api.call("GET", LATEST_ANNOUNCEMENT_URL));
109
+ } catch {
110
+ return failed();
111
+ }
112
+ },
113
+ // A link tapped inside the rich body: only http(s), mailto and tel links open (the shared rich-link rule).
114
+ openLink: async (state, arg) => {
115
+ await openRichLink(arg);
116
+ return state;
117
+ },
118
+ },
119
+ });
120
+ current = () => handle.getState() as AnnouncementState;
121
+ return handle;
122
+ }
@@ -94,6 +94,14 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
94
94
  return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
95
  }
96
96
 
97
+ /** `{ month: "short", year: "numeric" }` — "Jan 2026". */
98
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
99
+ if (hasIntl()) {
100
+ return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ }
102
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
103
+ }
104
+
97
105
  /** `{ month: "short", day: "numeric" }` — "Jan 5". */
98
106
  export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
99
107
  if (hasIntl()) {
@@ -94,6 +94,14 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
94
94
  return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
95
  }
96
96
 
97
+ /** `{ month: "short", year: "numeric" }` — "Jan 2026". */
98
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
99
+ if (hasIntl()) {
100
+ return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ }
102
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
103
+ }
104
+
97
105
  /** `{ month: "short", day: "numeric" }` — "Jan 5". */
98
106
  export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
99
107
  if (hasIntl()) {
@@ -0,0 +1,72 @@
1
+ {
2
+ "_recipe": "The business's latest announcement (title, rich body, creator and date), read at runtime. Service: registerAnnouncementSection(svc). Hidden whole while there is nothing to show.",
3
+ "_placeholders": {
4
+ "svc": "service name the page worker registered with registerAnnouncementSection",
5
+ "id": "unique node id prefix (e.g. the screen id)",
6
+ "heading": "the source section's own title when it shows one, else an empty string"
7
+ },
8
+ "node": {
9
+ "id": "{{id}}.announcement",
10
+ "body": {
11
+ "package": "himalaya",
12
+ "type": "VStack",
13
+ "props": {
14
+ "spacing": 8,
15
+ "alignment": "leading",
16
+ "children": [
17
+ {
18
+ "id": "{{id}}.heading",
19
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "{{heading}}", "style": "title3", "collapseWhenEmpty": true } }
20
+ },
21
+ {
22
+ "id": "{{id}}.title",
23
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.title", "style": "bodyEmphasis", "collapseWhenEmpty": true } },
24
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noTitle" }
25
+ },
26
+ {
27
+ "id": "{{id}}.body_rich",
28
+ "body": {
29
+ "package": "himalaya",
30
+ "type": "RichContent",
31
+ "props": {
32
+ "documentJsonPath": "$service:{{svc}}.bodyJson",
33
+ "onLink": { "actionId": "tier5.{{svc}}.openLink" },
34
+ "fallback": { "id": "{{id}}.body_rich_fallback", "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.body", "style": "body", "color": "textSecondary" } } }
35
+ }
36
+ },
37
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noBodyJson" }
38
+ },
39
+ {
40
+ "id": "{{id}}.body",
41
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.body", "style": "body", "color": "textSecondary", "collapseWhenEmpty": true } },
42
+ "modifiers": { "hiddenPath": "$service:{{svc}}.hasBodyJson" }
43
+ },
44
+ {
45
+ "id": "{{id}}.meta",
46
+ "body": {
47
+ "package": "himalaya",
48
+ "type": "HStack",
49
+ "props": {
50
+ "spacing": 8,
51
+ "alignment": "center",
52
+ "children": [
53
+ {
54
+ "id": "{{id}}.creator",
55
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.creator", "style": "caption", "color": "textSecondary", "collapseWhenEmpty": true } },
56
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noCreator" }
57
+ },
58
+ {
59
+ "id": "{{id}}.created",
60
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.created", "style": "caption", "color": "textSecondary", "collapseWhenEmpty": true } },
61
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noCreated" }
62
+ }
63
+ ]
64
+ }
65
+ }
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noAnnouncement", "padding": { "leading": 16, "trailing": 16, "top": 16, "bottom": 16 } }
71
+ }
72
+ }
@@ -0,0 +1,122 @@
1
+ // The INLINE announcement section: the business's latest announcement, read at RUNTIME (never baked at migration time) and
2
+ // shown next to other sections. It is the call the native Branded app's announcement section makes
3
+ // (wix-one-app-member-view, Announcement/serverApiService.ts `fetchLatestAnnouncement`): one GET of the latest announcement with the
4
+ // app's own signed instance (Member when signed in, else Visitor), which the `wixApi` bridge attaches.
5
+ //
6
+ // READ-ONLY, ALWAYS: `includeReaderData` stays false (true needs the One App manage permission and answers 403), and nothing here
7
+ // ever marks an announcement as seen (`AddCurrentMemberAsReader` is a write). Known server behaviour, shared with the native app: a
8
+ // site that has no announcement yet gets its default welcome text saved once, by this very read.
9
+ // A phone sends the signed instance to this URL only because the native hosts (Android and Swift `WixApiCapability`) allow exactly this
10
+ // GET (host, path, method and the reader-data-off query) for the consumer providers; a build without that entry refuses the read and the
11
+ // section shows nothing. The local web preview has no such list.
12
+ // The `announcement-card` recipe is the card that reads it, bound as `$service:<serviceName>.*`.
13
+ import { defineService } from "@himalaya/state";
14
+ import { richBody } from "./rich-body.js";
15
+ import { formatDateMedium } from "./engine-intl.js";
16
+ import { openRichLink } from "./rich-content-link.js";
17
+
18
+ /** The one call: the latest announcement, without the reader data. */
19
+ export const LATEST_ANNOUNCEMENT_URL = "https://manage.wix.com/_api/mobile-apps-announcements/v1/announcements/latest?includeReaderData=false";
20
+
21
+ interface LatestAnnouncementResponse {
22
+ announcement?: {
23
+ title?: unknown;
24
+ /** The announcement's content: a DraftJS raw state for announcements written in the app, or a Ricos document (as a Struct). */
25
+ content?: unknown;
26
+ createdDate?: unknown;
27
+ creatorMemberProfileData?: { nickname?: unknown; imageUrl?: unknown };
28
+ };
29
+ }
30
+
31
+ export interface AnnouncementState {
32
+ status: "loading" | "ready" | "error";
33
+ hasAnnouncement: boolean; noAnnouncement: boolean;
34
+ title: string; noTitle: boolean;
35
+ /** The rich body as one document string (RichContent draws nothing for ""), and its plain text, shown when there is no document. */
36
+ bodyJson: string; hasBodyJson: boolean; noBodyJson: boolean;
37
+ body: string; noBody: boolean;
38
+ created: string; noCreated: boolean;
39
+ creator: string; noCreator: boolean;
40
+ creatorImage: string; noCreatorImage: boolean;
41
+ isLoading: boolean; notLoading: boolean;
42
+ isErrored: boolean; notErrored: boolean;
43
+ }
44
+
45
+ const text = (value: unknown): string => (typeof value === "string" ? value.trim() : "");
46
+
47
+ /** The plain text of a DraftJS raw state (`{ blocks: [{ text }], entityMap }`), which is what the service's `content` really is for
48
+ * announcements written in the app (observed on a live site, 2026-11-11), or undefined when `content` is not one. Only the blocks' own
49
+ * text is read: the entity map (links, images) is never followed. */
50
+ function draftPlainText(content: unknown): string | undefined {
51
+ let doc = content;
52
+ if (typeof doc === "string") { try { doc = JSON.parse(doc); } catch { return undefined; } }
53
+ const blocks = (doc as { blocks?: unknown } | null | undefined)?.blocks;
54
+ if (!Array.isArray(blocks)) return undefined;
55
+ return blocks.map((block) => text((block as { text?: unknown } | null)?.text)).filter(Boolean).join("\n\n");
56
+ }
57
+
58
+ function derive(status: AnnouncementState["status"], fields: { title?: string; bodyJson?: string; body?: string; created?: string; creator?: string; creatorImage?: string } = {}): AnnouncementState {
59
+ const title = fields.title ?? "", bodyJson = fields.bodyJson ?? "", body = fields.body ?? "", created = fields.created ?? "";
60
+ const creator = fields.creator ?? "", creatorImage = fields.creatorImage ?? "";
61
+ const hasAnnouncement = status === "ready" && !!(title || bodyJson || body);
62
+ return {
63
+ status, hasAnnouncement, noAnnouncement: !hasAnnouncement,
64
+ title, noTitle: !title,
65
+ bodyJson, hasBodyJson: !!bodyJson, noBodyJson: !bodyJson,
66
+ body, noBody: !body,
67
+ created, noCreated: !created,
68
+ creator, noCreator: !creator,
69
+ creatorImage, noCreatorImage: !creatorImage,
70
+ isLoading: status === "loading", notLoading: status !== "loading",
71
+ isErrored: status === "error", notErrored: status !== "error",
72
+ };
73
+ }
74
+
75
+ /** The state for a latest-announcement response: an empty or missing announcement shows nothing, never a placeholder. */
76
+ export function announcementState(response: unknown): AnnouncementState {
77
+ const announcement = (response as LatestAnnouncementResponse | undefined)?.announcement;
78
+ if (!announcement || typeof announcement !== "object") return derive("ready");
79
+ // A DraftJS body shows as its plain text; a Ricos body keeps its rich document.
80
+ const draft = draftPlainText(announcement.content);
81
+ const rich = draft !== undefined ? { bodyJson: "", bodyText: draft } : richBody(announcement.content);
82
+ const when = typeof announcement.createdDate === "string" ? new Date(announcement.createdDate) : undefined;
83
+ const image = text(announcement.creatorMemberProfileData?.imageUrl);
84
+ return derive("ready", {
85
+ title: text(announcement.title),
86
+ bodyJson: rich.bodyJson, body: rich.bodyText,
87
+ created: when && !Number.isNaN(when.getTime()) ? formatDateMedium(when) : "",
88
+ creator: text(announcement.creatorMemberProfileData?.nickname),
89
+ // An avatar is shown only from an https URL.
90
+ creatorImage: /^https:\/\//i.test(image) ? image : "",
91
+ });
92
+ }
93
+
94
+ /** `options` is the generator's uniform second argument; the section has no settings of its own, so nothing is read from it. */
95
+ export function registerAnnouncementSection(serviceName: string, _options: object = {}) {
96
+ // The failure path reads the CURRENT state, not the snapshot the call began with: a refresh that fails after another load already
97
+ // showed an announcement must not erase it.
98
+ let current: () => AnnouncementState = () => derive("loading");
99
+ const handle = defineService<AnnouncementState, { load: (state: AnnouncementState) => Promise<AnnouncementState>; openLink: (state: AnnouncementState, arg?: unknown) => Promise<AnnouncementState> }>(serviceName, {
100
+ state: derive("loading"),
101
+ actions: {
102
+ load: async () => {
103
+ // A failed refresh (offline, a 5xx) keeps an announcement that is already showing: only a screen with nothing to show goes to error.
104
+ const failed = (): AnnouncementState => { const now = current(); return now.hasAnnouncement ? now : derive("error"); };
105
+ try {
106
+ const api = (globalThis as { himalaya?: { wixApi?: { call: (method: string, path: string) => Promise<unknown> } } }).himalaya?.wixApi;
107
+ if (!api) return failed();
108
+ return announcementState(await api.call("GET", LATEST_ANNOUNCEMENT_URL));
109
+ } catch {
110
+ return failed();
111
+ }
112
+ },
113
+ // A link tapped inside the rich body: only http(s), mailto and tel links open (the shared rich-link rule).
114
+ openLink: async (state, arg) => {
115
+ await openRichLink(arg);
116
+ return state;
117
+ },
118
+ },
119
+ });
120
+ current = () => handle.getState() as AnnouncementState;
121
+ return handle;
122
+ }
@@ -94,6 +94,14 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
94
94
  return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
95
  }
96
96
 
97
+ /** `{ month: "short", year: "numeric" }` — "Jan 2026". */
98
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
99
+ if (hasIntl()) {
100
+ return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ }
102
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
103
+ }
104
+
97
105
  /** `{ month: "short", day: "numeric" }` — "Jan 5". */
98
106
  export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
99
107
  if (hasIntl()) {
@@ -94,6 +94,14 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
94
94
  return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
95
  }
96
96
 
97
+ /** `{ month: "short", year: "numeric" }` — "Jan 2026". */
98
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
99
+ if (hasIntl()) {
100
+ return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ }
102
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
103
+ }
104
+
97
105
  /** `{ month: "short", day: "numeric" }` — "Jan 5". */
98
106
  export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
99
107
  if (hasIntl()) {
@@ -0,0 +1,72 @@
1
+ {
2
+ "_recipe": "The business's latest announcement (title, rich body, creator and date), read at runtime. Service: registerAnnouncementSection(svc). Hidden whole while there is nothing to show.",
3
+ "_placeholders": {
4
+ "svc": "service name the page worker registered with registerAnnouncementSection",
5
+ "id": "unique node id prefix (e.g. the screen id)",
6
+ "heading": "the source section's own title when it shows one, else an empty string"
7
+ },
8
+ "node": {
9
+ "id": "{{id}}.announcement",
10
+ "body": {
11
+ "package": "himalaya",
12
+ "type": "VStack",
13
+ "props": {
14
+ "spacing": 8,
15
+ "alignment": "leading",
16
+ "children": [
17
+ {
18
+ "id": "{{id}}.heading",
19
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "{{heading}}", "style": "title3", "collapseWhenEmpty": true } }
20
+ },
21
+ {
22
+ "id": "{{id}}.title",
23
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.title", "style": "bodyEmphasis", "collapseWhenEmpty": true } },
24
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noTitle" }
25
+ },
26
+ {
27
+ "id": "{{id}}.body_rich",
28
+ "body": {
29
+ "package": "himalaya",
30
+ "type": "RichContent",
31
+ "props": {
32
+ "documentJsonPath": "$service:{{svc}}.bodyJson",
33
+ "onLink": { "actionId": "tier5.{{svc}}.openLink" },
34
+ "fallback": { "id": "{{id}}.body_rich_fallback", "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.body", "style": "body", "color": "textSecondary" } } }
35
+ }
36
+ },
37
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noBodyJson" }
38
+ },
39
+ {
40
+ "id": "{{id}}.body",
41
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.body", "style": "body", "color": "textSecondary", "collapseWhenEmpty": true } },
42
+ "modifiers": { "hiddenPath": "$service:{{svc}}.hasBodyJson" }
43
+ },
44
+ {
45
+ "id": "{{id}}.meta",
46
+ "body": {
47
+ "package": "himalaya",
48
+ "type": "HStack",
49
+ "props": {
50
+ "spacing": 8,
51
+ "alignment": "center",
52
+ "children": [
53
+ {
54
+ "id": "{{id}}.creator",
55
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.creator", "style": "caption", "color": "textSecondary", "collapseWhenEmpty": true } },
56
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noCreator" }
57
+ },
58
+ {
59
+ "id": "{{id}}.created",
60
+ "body": { "package": "himalaya", "type": "Text", "props": { "text": "$service:{{svc}}.created", "style": "caption", "color": "textSecondary", "collapseWhenEmpty": true } },
61
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noCreated" }
62
+ }
63
+ ]
64
+ }
65
+ }
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ "modifiers": { "hiddenPath": "$service:{{svc}}.noAnnouncement", "padding": { "leading": 16, "trailing": 16, "top": 16, "bottom": 16 } }
71
+ }
72
+ }
@@ -0,0 +1,122 @@
1
+ // The INLINE announcement section: the business's latest announcement, read at RUNTIME (never baked at migration time) and
2
+ // shown next to other sections. It is the call the native Branded app's announcement section makes
3
+ // (wix-one-app-member-view, Announcement/serverApiService.ts `fetchLatestAnnouncement`): one GET of the latest announcement with the
4
+ // app's own signed instance (Member when signed in, else Visitor), which the `wixApi` bridge attaches.
5
+ //
6
+ // READ-ONLY, ALWAYS: `includeReaderData` stays false (true needs the One App manage permission and answers 403), and nothing here
7
+ // ever marks an announcement as seen (`AddCurrentMemberAsReader` is a write). Known server behaviour, shared with the native app: a
8
+ // site that has no announcement yet gets its default welcome text saved once, by this very read.
9
+ // A phone sends the signed instance to this URL only because the native hosts (Android and Swift `WixApiCapability`) allow exactly this
10
+ // GET (host, path, method and the reader-data-off query) for the consumer providers; a build without that entry refuses the read and the
11
+ // section shows nothing. The local web preview has no such list.
12
+ // The `announcement-card` recipe is the card that reads it, bound as `$service:<serviceName>.*`.
13
+ import { defineService } from "@himalaya/state";
14
+ import { richBody } from "./rich-body.js";
15
+ import { formatDateMedium } from "./engine-intl.js";
16
+ import { openRichLink } from "./rich-content-link.js";
17
+
18
+ /** The one call: the latest announcement, without the reader data. */
19
+ export const LATEST_ANNOUNCEMENT_URL = "https://manage.wix.com/_api/mobile-apps-announcements/v1/announcements/latest?includeReaderData=false";
20
+
21
+ interface LatestAnnouncementResponse {
22
+ announcement?: {
23
+ title?: unknown;
24
+ /** The announcement's content: a DraftJS raw state for announcements written in the app, or a Ricos document (as a Struct). */
25
+ content?: unknown;
26
+ createdDate?: unknown;
27
+ creatorMemberProfileData?: { nickname?: unknown; imageUrl?: unknown };
28
+ };
29
+ }
30
+
31
+ export interface AnnouncementState {
32
+ status: "loading" | "ready" | "error";
33
+ hasAnnouncement: boolean; noAnnouncement: boolean;
34
+ title: string; noTitle: boolean;
35
+ /** The rich body as one document string (RichContent draws nothing for ""), and its plain text, shown when there is no document. */
36
+ bodyJson: string; hasBodyJson: boolean; noBodyJson: boolean;
37
+ body: string; noBody: boolean;
38
+ created: string; noCreated: boolean;
39
+ creator: string; noCreator: boolean;
40
+ creatorImage: string; noCreatorImage: boolean;
41
+ isLoading: boolean; notLoading: boolean;
42
+ isErrored: boolean; notErrored: boolean;
43
+ }
44
+
45
+ const text = (value: unknown): string => (typeof value === "string" ? value.trim() : "");
46
+
47
+ /** The plain text of a DraftJS raw state (`{ blocks: [{ text }], entityMap }`), which is what the service's `content` really is for
48
+ * announcements written in the app (observed on a live site, 2026-11-11), or undefined when `content` is not one. Only the blocks' own
49
+ * text is read: the entity map (links, images) is never followed. */
50
+ function draftPlainText(content: unknown): string | undefined {
51
+ let doc = content;
52
+ if (typeof doc === "string") { try { doc = JSON.parse(doc); } catch { return undefined; } }
53
+ const blocks = (doc as { blocks?: unknown } | null | undefined)?.blocks;
54
+ if (!Array.isArray(blocks)) return undefined;
55
+ return blocks.map((block) => text((block as { text?: unknown } | null)?.text)).filter(Boolean).join("\n\n");
56
+ }
57
+
58
+ function derive(status: AnnouncementState["status"], fields: { title?: string; bodyJson?: string; body?: string; created?: string; creator?: string; creatorImage?: string } = {}): AnnouncementState {
59
+ const title = fields.title ?? "", bodyJson = fields.bodyJson ?? "", body = fields.body ?? "", created = fields.created ?? "";
60
+ const creator = fields.creator ?? "", creatorImage = fields.creatorImage ?? "";
61
+ const hasAnnouncement = status === "ready" && !!(title || bodyJson || body);
62
+ return {
63
+ status, hasAnnouncement, noAnnouncement: !hasAnnouncement,
64
+ title, noTitle: !title,
65
+ bodyJson, hasBodyJson: !!bodyJson, noBodyJson: !bodyJson,
66
+ body, noBody: !body,
67
+ created, noCreated: !created,
68
+ creator, noCreator: !creator,
69
+ creatorImage, noCreatorImage: !creatorImage,
70
+ isLoading: status === "loading", notLoading: status !== "loading",
71
+ isErrored: status === "error", notErrored: status !== "error",
72
+ };
73
+ }
74
+
75
+ /** The state for a latest-announcement response: an empty or missing announcement shows nothing, never a placeholder. */
76
+ export function announcementState(response: unknown): AnnouncementState {
77
+ const announcement = (response as LatestAnnouncementResponse | undefined)?.announcement;
78
+ if (!announcement || typeof announcement !== "object") return derive("ready");
79
+ // A DraftJS body shows as its plain text; a Ricos body keeps its rich document.
80
+ const draft = draftPlainText(announcement.content);
81
+ const rich = draft !== undefined ? { bodyJson: "", bodyText: draft } : richBody(announcement.content);
82
+ const when = typeof announcement.createdDate === "string" ? new Date(announcement.createdDate) : undefined;
83
+ const image = text(announcement.creatorMemberProfileData?.imageUrl);
84
+ return derive("ready", {
85
+ title: text(announcement.title),
86
+ bodyJson: rich.bodyJson, body: rich.bodyText,
87
+ created: when && !Number.isNaN(when.getTime()) ? formatDateMedium(when) : "",
88
+ creator: text(announcement.creatorMemberProfileData?.nickname),
89
+ // An avatar is shown only from an https URL.
90
+ creatorImage: /^https:\/\//i.test(image) ? image : "",
91
+ });
92
+ }
93
+
94
+ /** `options` is the generator's uniform second argument; the section has no settings of its own, so nothing is read from it. */
95
+ export function registerAnnouncementSection(serviceName: string, _options: object = {}) {
96
+ // The failure path reads the CURRENT state, not the snapshot the call began with: a refresh that fails after another load already
97
+ // showed an announcement must not erase it.
98
+ let current: () => AnnouncementState = () => derive("loading");
99
+ const handle = defineService<AnnouncementState, { load: (state: AnnouncementState) => Promise<AnnouncementState>; openLink: (state: AnnouncementState, arg?: unknown) => Promise<AnnouncementState> }>(serviceName, {
100
+ state: derive("loading"),
101
+ actions: {
102
+ load: async () => {
103
+ // A failed refresh (offline, a 5xx) keeps an announcement that is already showing: only a screen with nothing to show goes to error.
104
+ const failed = (): AnnouncementState => { const now = current(); return now.hasAnnouncement ? now : derive("error"); };
105
+ try {
106
+ const api = (globalThis as { himalaya?: { wixApi?: { call: (method: string, path: string) => Promise<unknown> } } }).himalaya?.wixApi;
107
+ if (!api) return failed();
108
+ return announcementState(await api.call("GET", LATEST_ANNOUNCEMENT_URL));
109
+ } catch {
110
+ return failed();
111
+ }
112
+ },
113
+ // A link tapped inside the rich body: only http(s), mailto and tel links open (the shared rich-link rule).
114
+ openLink: async (state, arg) => {
115
+ await openRichLink(arg);
116
+ return state;
117
+ },
118
+ },
119
+ });
120
+ current = () => handle.getState() as AnnouncementState;
121
+ return handle;
122
+ }
@@ -94,6 +94,14 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
94
94
  return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
95
  }
96
96
 
97
+ /** `{ month: "short", year: "numeric" }` — "Jan 2026". */
98
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
99
+ if (hasIntl()) {
100
+ return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ }
102
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
103
+ }
104
+
97
105
  /** `{ month: "short", day: "numeric" }` — "Jan 5". */
98
106
  export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
99
107
  if (hasIntl()) {
@@ -94,6 +94,14 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
94
94
  return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
95
  }
96
96
 
97
+ /** `{ month: "short", year: "numeric" }` — "Jan 2026". */
98
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
99
+ if (hasIntl()) {
100
+ return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ }
102
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
103
+ }
104
+
97
105
  /** `{ month: "short", day: "numeric" }` — "Jan 5". */
98
106
  export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
99
107
  if (hasIntl()) {
@@ -94,6 +94,14 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
94
94
  return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
95
  }
96
96
 
97
+ /** `{ month: "short", year: "numeric" }` — "Jan 2026". */
98
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
99
+ if (hasIntl()) {
100
+ return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ }
102
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
103
+ }
104
+
97
105
  /** `{ month: "short", day: "numeric" }` — "Jan 5". */
98
106
  export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
99
107
  if (hasIntl()) {
@@ -94,6 +94,14 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
94
94
  return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
95
  }
96
96
 
97
+ /** `{ month: "short", year: "numeric" }` — "Jan 2026". */
98
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
99
+ if (hasIntl()) {
100
+ return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ }
102
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
103
+ }
104
+
97
105
  /** `{ month: "short", day: "numeric" }` — "Jan 5". */
98
106
  export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
99
107
  if (hasIntl()) {