@wix/himalaya-cli 0.1105.0 → 0.1107.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 (91) hide show
  1. package/dist/cli.mjs +27 -5
  2. package/fixtures/wix-canned.json +146 -0
  3. package/package.json +2 -2
  4. package/templates/beauty-salon/dev/index.ts +22 -79
  5. package/templates/beauty-salon/tier5-src/_shared/rich-body.ts +28 -0
  6. package/templates/beauty-salon/tier5-src/_shared/rich-content-link.ts +34 -0
  7. package/templates/beauty-salon/tier5-src/himi-blog-post/index.ts +26 -82
  8. package/templates/beauty-salon-owner/dev/index.ts +44 -1
  9. package/templates/beauty-salon-owner/tier5-src/_shared/rich-body.ts +28 -0
  10. package/templates/beauty-salon-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  11. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  12. package/templates/branded-lite/dev/index.ts +22 -79
  13. package/templates/branded-lite/tier5-src/_shared/rich-body.ts +28 -0
  14. package/templates/branded-lite/tier5-src/_shared/rich-content-link.ts +34 -0
  15. package/templates/branded-lite/tier5-src/himi-blog-post/index.ts +26 -82
  16. package/templates/community-club/dev/index.ts +22 -79
  17. package/templates/community-club/tier5-src/_shared/rich-body.ts +28 -0
  18. package/templates/community-club/tier5-src/_shared/rich-content-link.ts +34 -0
  19. package/templates/community-club/tier5-src/himi-blog-post/index.ts +26 -82
  20. package/templates/community-club-owner/dev/index.ts +44 -1
  21. package/templates/community-club-owner/tier5-src/_shared/rich-body.ts +28 -0
  22. package/templates/community-club-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  23. package/templates/community-club-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  24. package/templates/events-meetups/dev/index.ts +22 -79
  25. package/templates/events-meetups/tier5-src/_shared/rich-body.ts +28 -0
  26. package/templates/events-meetups/tier5-src/_shared/rich-content-link.ts +34 -0
  27. package/templates/events-meetups/tier5-src/himi-blog-post/index.ts +26 -82
  28. package/templates/events-meetups-owner/dev/index.ts +44 -1
  29. package/templates/events-meetups-owner/tier5-src/_shared/rich-body.ts +28 -0
  30. package/templates/events-meetups-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  31. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  32. package/templates/gym-fitness/dev/index.ts +22 -79
  33. package/templates/gym-fitness/tier5-src/_shared/rich-body.ts +28 -0
  34. package/templates/gym-fitness/tier5-src/_shared/rich-content-link.ts +34 -0
  35. package/templates/gym-fitness/tier5-src/himi-blog-post/index.ts +26 -82
  36. package/templates/gym-fitness-owner/dev/index.ts +44 -1
  37. package/templates/gym-fitness-owner/tier5-src/_shared/rich-body.ts +28 -0
  38. package/templates/gym-fitness-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  39. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  40. package/templates/nonprofit-cause/dev/index.ts +22 -79
  41. package/templates/nonprofit-cause/tier5-src/_shared/rich-body.ts +28 -0
  42. package/templates/nonprofit-cause/tier5-src/_shared/rich-content-link.ts +34 -0
  43. package/templates/nonprofit-cause/tier5-src/himi-blog-post/index.ts +26 -82
  44. package/templates/nonprofit-cause-owner/dev/index.ts +44 -1
  45. package/templates/nonprofit-cause-owner/tier5-src/_shared/rich-body.ts +28 -0
  46. package/templates/nonprofit-cause-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  47. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  48. package/templates/owner-lite/dev/index.ts +44 -1
  49. package/templates/owner-lite/tier5-src/_shared/rich-body.ts +28 -0
  50. package/templates/owner-lite/tier5-src/_shared/rich-content-link.ts +34 -0
  51. package/templates/owner-lite/tier5-src/himi-owner-lite-post/index.ts +49 -2
  52. package/templates/podcast-creator/dev/index.ts +22 -79
  53. package/templates/podcast-creator/tier5-src/_shared/rich-body.ts +28 -0
  54. package/templates/podcast-creator/tier5-src/_shared/rich-content-link.ts +34 -0
  55. package/templates/podcast-creator/tier5-src/himi-blog-post/index.ts +26 -82
  56. package/templates/podcast-creator-owner/dev/index.ts +44 -1
  57. package/templates/podcast-creator-owner/tier5-src/_shared/rich-body.ts +28 -0
  58. package/templates/podcast-creator-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  59. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  60. package/templates/portfolio-creative/dev/index.ts +22 -79
  61. package/templates/portfolio-creative/tier5-src/_shared/rich-body.ts +28 -0
  62. package/templates/portfolio-creative/tier5-src/_shared/rich-content-link.ts +34 -0
  63. package/templates/portfolio-creative/tier5-src/himi-blog-post/index.ts +26 -82
  64. package/templates/portfolio-creative-owner/dev/index.ts +44 -1
  65. package/templates/portfolio-creative-owner/tier5-src/_shared/rich-body.ts +28 -0
  66. package/templates/portfolio-creative-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  67. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  68. package/templates/restaurant/dev/index.ts +22 -79
  69. package/templates/restaurant/tier5-src/_shared/rich-body.ts +28 -0
  70. package/templates/restaurant/tier5-src/_shared/rich-content-link.ts +34 -0
  71. package/templates/restaurant/tier5-src/himi-blog-post/index.ts +26 -82
  72. package/templates/restaurant-owner/dev/index.ts +44 -1
  73. package/templates/restaurant-owner/tier5-src/_shared/rich-body.ts +28 -0
  74. package/templates/restaurant-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  75. package/templates/restaurant-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  76. package/templates/retail-store/dev/index.ts +22 -79
  77. package/templates/retail-store/tier5-src/_shared/rich-body.ts +28 -0
  78. package/templates/retail-store/tier5-src/_shared/rich-content-link.ts +34 -0
  79. package/templates/retail-store/tier5-src/himi-blog-post/index.ts +26 -82
  80. package/templates/retail-store-owner/dev/index.ts +44 -1
  81. package/templates/retail-store-owner/tier5-src/_shared/rich-body.ts +28 -0
  82. package/templates/retail-store-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  83. package/templates/retail-store-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
  84. package/templates/yoga-studio/dev/index.ts +22 -79
  85. package/templates/yoga-studio/tier5-src/_shared/rich-body.ts +28 -0
  86. package/templates/yoga-studio/tier5-src/_shared/rich-content-link.ts +34 -0
  87. package/templates/yoga-studio/tier5-src/himi-blog-post/index.ts +26 -82
  88. package/templates/yoga-studio-owner/dev/index.ts +44 -1
  89. package/templates/yoga-studio-owner/tier5-src/_shared/rich-body.ts +28 -0
  90. package/templates/yoga-studio-owner/tier5-src/_shared/rich-content-link.ts +34 -0
  91. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-post/index.ts +49 -2
@@ -74011,6 +74011,48 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
74011
74011
  }
74012
74012
  }
74013
74013
  },
74014
+ {
74015
+ "id": "post_body",
74016
+ "body": {
74017
+ "package": "himalaya",
74018
+ "type": "RichContent",
74019
+ "props": {
74020
+ "documentJsonPath": "$service:himiOwnerLitePost.bodyJson",
74021
+ "onLink": {
74022
+ "actionId": "tier5.himiOwnerLitePost.openLink"
74023
+ },
74024
+ "fallback": {
74025
+ "id": "",
74026
+ "body": {
74027
+ "package": "himalaya",
74028
+ "type": "Text",
74029
+ "props": {
74030
+ "text": "$service:himiOwnerLitePost.bodyText",
74031
+ "style": "body",
74032
+ "color": "textPrimary",
74033
+ "collapseWhenEmpty": true
74034
+ }
74035
+ }
74036
+ }
74037
+ }
74038
+ }
74039
+ },
74040
+ {
74041
+ "id": "post_body_text",
74042
+ "body": {
74043
+ "package": "himalaya",
74044
+ "type": "Text",
74045
+ "props": {
74046
+ "text": "$service:himiOwnerLitePost.bodyText",
74047
+ "style": "body",
74048
+ "color": "textPrimary",
74049
+ "collapseWhenEmpty": true
74050
+ }
74051
+ },
74052
+ "modifiers": {
74053
+ "hiddenPath": "$service:himiOwnerLitePost.hasBodyJson"
74054
+ }
74055
+ },
74014
74056
  {
74015
74057
  "id": "post_info_card",
74016
74058
  "body": {
@@ -74385,7 +74427,8 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
74385
74427
  "contentType": "application/javascript+ts-bundle",
74386
74428
  "declaredCapabilities": [
74387
74429
  "wix_api",
74388
- "local_database"
74430
+ "local_database",
74431
+ "open_url"
74389
74432
  ],
74390
74433
  "minBinaryVersion": "0.1.0",
74391
74434
  "bundleVersion": "0.0.1"
@@ -0,0 +1,28 @@
1
+ // [rico] #3370 — an entity's Ricos body, prepared for a RichContent component and its plain-text fallback.
2
+ // One rule for every worker that renders a body (the blog post and the owner post detail today; #3372's
3
+ // verticals next), so they cannot drift apart.
4
+ // Inside the platform source this import is a relative path, so node test runs resolve it; an app's copy
5
+ // imports "@himalaya/wix-rich-content".
6
+ import { encodeRichContent, parseRicosJson, ricosToPlainText } from "@himalaya/wix-rich-content";
7
+
8
+ /** What a body-rendering worker publishes: `<name>Json` for `documentJsonPath`, and the plain text. */
9
+ export interface RichBody {
10
+ /** The document as ONE JSON string (media sized, disallowed links dropped); "" when there is no document
11
+ * or the encoder rejected it. RichContent draws nothing for "", so a screen gates its plain text on it. */
12
+ bodyJson: string;
13
+ /** The plain text: the document's own text when it has any, else `fallback`. */
14
+ bodyText: string;
15
+ }
16
+
17
+ /** Prepares `richContent` (a Ricos document, as a Wix API returns it, or its JSON string). No document, or one
18
+ * that is not a document, gives `{ bodyJson: "", bodyText: fallback }`. A document past the viewer's limits
19
+ * gives bodyJson "" and its plain text — except one rejected as too deep, which is not walked again (the
20
+ * plain-text walk has no depth limit), so `fallback` stands in for it. */
21
+ export function richBody(richContent: unknown, fallback = ""): RichBody {
22
+ const doc = parseRicosJson(richContent);
23
+ if (!doc) return { bodyJson: "", bodyText: fallback };
24
+ // 1400 px — the detail-image budget, which is also the encoder's maximum.
25
+ const { json, rejected } = encodeRichContent(doc, { imageWidth: 1400 });
26
+ const text = rejected === "too_deep" ? "" : ricosToPlainText(doc);
27
+ return { bodyJson: json, bodyText: text || fallback };
28
+ }
@@ -0,0 +1,34 @@
1
+ // [rico] #3370 — a RichContent `on_link` tap reaches the worker as `{ url }` (the renderers merge the tapped
2
+ // link into the action's args). Only http(s) with a host, mailto and tel ever reach the OS; anything
3
+ // else is dropped here, before any dispatch. The renderers already refuse other schemes, but the action
4
+ // arrives here as plain data, so the worker checks it again rather than trusting whoever sent it.
5
+ import { open, defaultMode } from "@himalaya/open-url";
6
+
7
+ /** The viewer's link rule, verbatim (`LINK` in @himalaya/wix-rich-content's display.ts, which the package does
8
+ * not export); a parity test pins this copy to the original. */
9
+ const LINK = /^(https?:\/\/[^\s/?#]\S*|mailto:\S+|tel:\S+)$/i;
10
+ /** ASCII whitespace only, as the viewer trims a link before applying the rule. */
11
+ const trimAscii = (s: string): string => s.replace(/^[\t\n\v\f\r ]+|[\t\n\v\f\r ]+$/g, "");
12
+
13
+ /** The url of a link tap (`{ url }`, `{ args: { url } }` or a bare string), or "" when it is missing or
14
+ * not an http(s), mailto or tel link. */
15
+ export function richLinkUrl(arg: unknown): string {
16
+ const a = arg as { url?: unknown; args?: { url?: unknown } } | null | undefined;
17
+ const raw = typeof arg === "string" ? arg
18
+ : typeof a?.url === "string" ? a.url
19
+ : typeof a?.args?.url === "string" ? a.args.url : "";
20
+ const url = trimAscii(raw);
21
+ return LINK.test(url) ? url : "";
22
+ }
23
+
24
+ /** Opens a link tap through `capability.open_url` (http(s) in the in-app browser, mailto/tel in the system
25
+ * handler). False when the link is blocked, nothing took it, or the host threw. */
26
+ export async function openRichLink(arg: unknown): Promise<boolean> {
27
+ const url = richLinkUrl(arg);
28
+ if (!url) return false;
29
+ try {
30
+ return (await open(url, defaultMode(url))).opened;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
@@ -7,6 +7,9 @@ import { postCoverUrl } from "../_shared/owner-post-content.js";
7
7
 
8
8
  import { defineService } from "@himalaya/state";
9
9
  import { getPost, getDraftPost, publishDraftPost, revertDraftPost, deleteDraftPost } from "@himalaya/wix-blog";
10
+ import { parseRicosJson } from "@himalaya/wix-rich-content";
11
+ import { openRichLink } from "../_shared/rich-content-link.js";
12
+ import { richBody } from "../_shared/rich-body.js";
10
13
  import { ownerLoadError, isBridgeUnavailable, isOwnerPreviewDemo, shouldQueueOwnerWrite } from "../_shared/owner-load-error.js";
11
14
  import { DEMO_POSTS, DEMO_NOTE, DEMO_SAVE_NOTE } from "../_shared/owner-preview-demo.js";
12
15
  import { stashCopy, copyParam } from "../_shared/himi-copy.js";
@@ -25,6 +28,14 @@ async function cachePut(row: DbEntity): Promise<void> { try { await dbUpsert(ENT
25
28
  async function cacheDrop(id: string): Promise<void> { try { await dbRemove(ENTITY, id); } catch { /* capability not granted */ } }
26
29
  async function cacheGet(id: string): Promise<DbEntity | null> { try { return await dbGet(ENTITY, id); } catch { return null; } }
27
30
  async function queueWrite(actionId: string, params: Record<string, string>): Promise<void> { try { await dbEnqueue(actionId, params); } catch { /* capability not granted */ } }
31
+ /** [rico] #3370 — keep the body's plain text with the post's cached row, so the offline detail shows it. It is
32
+ * merged into the row the posts list wrote rather than replacing it; a later list re-sync writes its own rows
33
+ * and drops it again, until the detail is next opened online. */
34
+ async function cacheBodyText(s: PostState): Promise<void> {
35
+ if (s.status !== "ready" || !s.id) return;
36
+ const prev = await cacheGet(s.id);
37
+ await cachePut(prev ? { ...prev, bodyText: s.bodyText } : cacheRow(s));
38
+ }
28
39
 
29
40
  interface PostState {
30
41
  id: string;
@@ -38,6 +49,14 @@ interface PostState {
38
49
  summary: string;
39
50
  initial: string;
40
51
  image: string;
52
+ // Body ([rico] #3370) — RichContent binds bodyJson; the plain text shows when there is no document.
53
+ /** The body as ONE Ricos document JSON string for RichContent, from the draft when there is one; "" when the post
54
+ * has none, the encoder rejected it, or this is the offline copy. */
55
+ bodyJson: string;
56
+ /** bodyJson !== "" — gates the plain text, because RichContent draws nothing for "". */
57
+ hasBodyJson: boolean;
58
+ /** Plain text of the body: RichContent's `fallback`, and the offline copy's body. */
59
+ bodyText: string;
41
60
  // Info rows
42
61
  postStatus: string;
43
62
  category: string;
@@ -118,6 +137,9 @@ function shape(s: Partial<PostState>): PostState {
118
137
  summary: s.summary ?? "",
119
138
  initial: s.initial ?? "?",
120
139
  image,
140
+ bodyJson: s.bodyJson ?? "",
141
+ hasBodyJson: !!s.bodyJson,
142
+ bodyText: s.bodyText ?? "",
121
143
  postStatus: s.postStatus ?? statusLabel(raw),
122
144
  category: s.category ?? "—",
123
145
  published: s.published ?? "—",
@@ -153,6 +175,8 @@ function demoDetail(s: PostState, id: string): PostState | null {
153
175
  summary: d.excerpt,
154
176
  initial: (d.title[0] || "?").toUpperCase(),
155
177
  image: "",
178
+ bodyJson: "",
179
+ bodyText: d.body,
156
180
  postStatus: d.postStatus,
157
181
  category: d.category,
158
182
  published: d.published,
@@ -173,6 +197,8 @@ function cacheRow(s: PostState): DbEntity {
173
197
  summary: s.summary,
174
198
  initial: s.initial,
175
199
  image: s.image,
200
+ // The plain text only: the offline copy shows it, and a stale document is never drawn from cache.
201
+ bodyText: s.bodyText,
176
202
  postStatus: s.postStatus,
177
203
  category: s.category,
178
204
  published: s.published,
@@ -194,6 +220,10 @@ function cachedDetail(s: PostState, row: DbEntity): PostState {
194
220
  summary: String(row.summary ?? row.excerpt ?? ""),
195
221
  initial: String(row.initial ?? (title[0] || "?")).slice(0, 1).toUpperCase(),
196
222
  image: String(row.image ?? ""),
223
+ bodyJson: "",
224
+ // The post form upserts a whole row with `body` and no `bodyText`; cacheBodyText later merges `bodyText` into it.
225
+ // So a present `bodyText` is the newer value, and an explicit "" (a body cleared online) is kept.
226
+ bodyText: String(row.bodyText ?? row.body ?? ""),
197
227
  postStatus: row.postStatus != null ? String(row.postStatus) : statusLabel(raw),
198
228
  category: String(row.category ?? "—"),
199
229
  published: String(row.published ?? "—"),
@@ -221,6 +251,10 @@ async function refresh(prev: PostState, id: string, actionMessage = ""): Promise
221
251
  const slug = draft?.seoSlug || post?.slug || "";
222
252
  const draftHidesCover = (draft?.media ?? draft?.coverMedia)?.displayed === false;
223
253
  const image = draftHidesCover ? "" : coverUrl(draft) || coverUrl(post);
254
+ // The draft carries the owner's latest edits, so its body wins over the published one. With no usable
255
+ // document, the published post's own plain text (CONTENT_TEXT) is the body.
256
+ const body = richBody(parseRicosJson(draft?.richContent) ? draft?.richContent : post?.richContent,
257
+ typeof post?.contentText === "string" ? post.contentText.trim() : "");
224
258
  return shape({
225
259
  ...prev,
226
260
  id,
@@ -230,6 +264,7 @@ async function refresh(prev: PostState, id: string, actionMessage = ""): Promise
230
264
  summary: (draft?.excerpt || post?.excerpt || "").trim(),
231
265
  initial: (title[0] || "?").toUpperCase(),
232
266
  image,
267
+ ...body,
233
268
  postStatus: statusLabel(raw),
234
269
  category: "—",
235
270
  published: fmtDate(post?.firstPublishedDate),
@@ -247,6 +282,8 @@ const svc = defineService<PostState, {
247
282
  publish: (s: PostState) => Promise<PostState>;
248
283
  unpublish: (s: PostState) => Promise<PostState>;
249
284
  delete: (s: PostState) => Promise<PostState>;
285
+ /** [rico] #3370 — RichContent's on_link: `{ url }` of the tapped link. */
286
+ openLink: (s: PostState, arg?: unknown) => Promise<PostState>;
250
287
  }>("himiOwnerLitePost", {
251
288
  state: shape({ status: "loading" }),
252
289
  actions: {
@@ -261,7 +298,9 @@ const svc = defineService<PostState, {
261
298
  return shape({ ...s, status: "error", error: "Sample item not found." });
262
299
  }
263
300
  try {
264
- return await refresh(shape({ ...s, id, status: "loading" }), id);
301
+ const loaded = await refresh(shape({ ...s, id, status: "loading" }), id);
302
+ await cacheBodyText(loaded);
303
+ return loaded;
265
304
  } catch (e) {
266
305
  // Offline: fall back to the last-synced local row before the demo/error paths.
267
306
  const cached = await cacheGet(id);
@@ -282,7 +321,9 @@ const svc = defineService<PostState, {
282
321
  return shape({ ...s, status: "error", error: "Sample item not found." });
283
322
  }
284
323
  try {
285
- return await refresh(shape({ ...s, status: "loading" }), s.id);
324
+ const loaded = await refresh(shape({ ...s, status: "loading" }), s.id);
325
+ await cacheBodyText(loaded);
326
+ return loaded;
286
327
  } catch (e) {
287
328
  const cached = await cacheGet(s.id);
288
329
  if (cached) return cachedDetail(s, cached);
@@ -347,6 +388,12 @@ const svc = defineService<PostState, {
347
388
  return shape({ ...s, actionMessage: ownerLoadError(e) });
348
389
  }
349
390
  },
391
+ // Only http(s), mailto and tel links reach open_url; a refused link, or one nothing opened, says so, and
392
+ // a link that opens clears that message rather than leaving an earlier failure on screen.
393
+ openLink: async (s, arg) => shape({
394
+ ...s,
395
+ actionMessage: (await openRichLink(arg)) ? "" : copyParam("ownerPost.linkOpenFailed", "This link could not be opened."),
396
+ }),
350
397
  },
351
398
  });
352
399