@wix/himalaya-cli 0.1662.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 (26) hide show
  1. package/dist/cli.mjs +252 -47
  2. package/guides/one-app-section-mappings.md +3 -4
  3. package/guides/one-app-to-himi-app.md +20 -1
  4. package/package.json +2 -2
  5. package/templates/beauty-salon/recipes/announcement-card.json +72 -0
  6. package/templates/beauty-salon/tier5-src/_shared/announcement-section.ts +122 -0
  7. package/templates/branded-lite/recipes/announcement-card.json +72 -0
  8. package/templates/branded-lite/tier5-src/_shared/announcement-section.ts +122 -0
  9. package/templates/community-club/recipes/announcement-card.json +72 -0
  10. package/templates/community-club/tier5-src/_shared/announcement-section.ts +122 -0
  11. package/templates/events-meetups/recipes/announcement-card.json +72 -0
  12. package/templates/events-meetups/tier5-src/_shared/announcement-section.ts +122 -0
  13. package/templates/gym-fitness/recipes/announcement-card.json +72 -0
  14. package/templates/gym-fitness/tier5-src/_shared/announcement-section.ts +122 -0
  15. package/templates/nonprofit-cause/recipes/announcement-card.json +72 -0
  16. package/templates/nonprofit-cause/tier5-src/_shared/announcement-section.ts +122 -0
  17. package/templates/podcast-creator/recipes/announcement-card.json +72 -0
  18. package/templates/podcast-creator/tier5-src/_shared/announcement-section.ts +122 -0
  19. package/templates/portfolio-creative/recipes/announcement-card.json +72 -0
  20. package/templates/portfolio-creative/tier5-src/_shared/announcement-section.ts +122 -0
  21. package/templates/restaurant/recipes/announcement-card.json +72 -0
  22. package/templates/restaurant/tier5-src/_shared/announcement-section.ts +122 -0
  23. package/templates/retail-store/recipes/announcement-card.json +72 -0
  24. package/templates/retail-store/tier5-src/_shared/announcement-section.ts +122 -0
  25. package/templates/yoga-studio/recipes/announcement-card.json +72 -0
  26. package/templates/yoga-studio/tier5-src/_shared/announcement-section.ts +122 -0
@@ -363,6 +363,10 @@ Verify probe behavior in the service contract, not just its HTTP method. Some
363
363
  legacy GET routes initialize missing records. In particular, announcement
364
364
  latest/list reads can create a default announcement; avoid those during migration
365
365
  collection and validation. A verified read of a referenced, known record is safer.
366
+ The one place the migration does read announcements is the generated app itself: `generate` maps
367
+ `platform_general_announcement_section` to the shared announcement block, whose worker reads the latest announcement at runtime
368
+ with the one read-only call the native app makes (see the section mappings reference). It never calls `AddCurrentMemberAsReader`
369
+ (a write) and never asks for reader data.
366
370
 
367
371
  `source-graph.json` is a basic relationship index, not the completed plan. The
368
372
  agent must still resolve business CTA contracts, toolbar actions and inheritance,
@@ -1349,6 +1353,14 @@ So generate descriptors as data and write them with the CLI:
1349
1353
  himi template screens --upsert --from .himi/one-app/gen/screens.json
1350
1354
  ```
1351
1355
 
1356
+ `generate` owns a few load parameters on three template screens: `categoryId` on `himi_shop`, and `title`, `groupListLabel` and
1357
+ `pageSize` on `himi_groups_feed` / `himi_groups`. The scaffold ships none of them; a run writes the ones a page's source gives and
1358
+ clears the ones no page owns any more, so do not hand-add these keys there.
1359
+
1360
+ `generate` also fills the `route` rows of `ONE-APP-COVERAGE.json` for the source screens it mapped (`target.screenId` is the screen of
1361
+ the source screen's first visible page), creating the ledger when it is absent; `himi one-app validate-topbar` reads them. A source
1362
+ screen none of whose pages became a screen keeps a blank row, which the validator names.
1363
+
1352
1364
  The file is one JSON object, `{ "<screenId>": <ScreenDescriptor>, … }`. Each existing
1353
1365
  id is replaced in place; each new id is added and registered in
1354
1366
  `navigation.linkableScreens`. One invalid entry refuses the batch and restores every
@@ -1378,6 +1390,11 @@ with its filled variant when there is one) and repoints every `linkableScreens`
1378
1390
  - a screen the More tab lists takes the More tab's id (only when there is a More tab);
1379
1391
  - any other screen takes `""`, the default stack.
1380
1392
 
1393
+ A page the source navigation lists (its `navigation-plan.json` tabs, or the bottom tabs of a source that has its own) that
1394
+ `generate` could not turn into a screen is refused with `pages_without_screen`, which names every such page, and nothing is
1395
+ written: a bar that silently lacks a source page is not the source's navigation. Map the sections `generate` reports under
1396
+ `unmapped` and run it again. No placeholder screen is added for them.
1397
+
1381
1398
  A tab for a screen the app does not define is refused with `screen_missing` and nothing is written: write the generated
1382
1399
  screens first, and keep any template screen a tab opens when you trim. A source icon with no catalog match is reported
1383
1400
  under `gaps` and gets a neutral icon; choose a better one in `config.ts`. The drawer is not touched.
@@ -1795,7 +1812,9 @@ evaluates (`svc.load();` at the bottom of the file — the pattern every migrati
1795
1812
  worker uses); the screen descriptor names nothing, but the read runs as soon as the
1796
1813
  screen boots the worker. Each boot path must be a catalogue or directory read.
1797
1814
  Stop if one submits, orders, books, pays, or calls a getter known to mutate on read
1798
- (such as the legacy announcement default getter). Then review the recorded and
1815
+ (such as the legacy announcement default getter) from the migration's own collection or tests. The one expected exception is the
1816
+ generated announcement block's runtime read of the latest announcement (see the section mappings reference), which belongs to the
1817
+ app and runs on a device or live preview, never during collection, validation or `himi test`. Then review the recorded and
1799
1818
  refused requests. Keep actual recordings
1800
1819
  under `.himi/one-app/fixtures/net-mocks.json`. For local test/render discovery,
1801
1820
  make `dev/net-mocks.json` a relative symlink to that private file: the source
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/himalaya-cli",
3
- "version": "0.1662.0",
3
+ "version": "0.1663.0",
4
4
  "type": "module",
5
5
  "description": "himi — the Himalaya authoring CLI. Build a Tier-5 content package on your own machine, push it to the production serve as a draft, preview it on web + Himi Player, and read worker logs back — the remote dev loop. Wraps @himalaya/serve-cli for transport.",
6
6
  "keywords": [
@@ -72,5 +72,5 @@
72
72
  "artifactId": "himalaya-cli"
73
73
  }
74
74
  },
75
- "falconPackageHash": "4d3f3e985b8a80b1afaca3b94bff7fb078c805dbfd5f07c3e5c7a1f7"
75
+ "falconPackageHash": "5d3793aa788edc5337012c130b481b7eb61984c5f1f160b81f7a951e"
76
76
  }
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }