@wix/himalaya-cli 0.1788.0 → 0.1790.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 (79) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/online-programs/src/index.d.ts +18 -0
  2. package/dist/browser-plane/assets.json +5 -5
  3. package/dist/browser-plane/preview-deferred/{bd05b082ca023da46cfeef63687d1ddc10eaed1a03e86c7671ca821954222066.bin → 83e211fe9fba65cca1fac7a0d552fbd3ba2873496f1c6117d5ac561d489ac839.bin} +1 -1
  4. package/dist/browser-plane/sw.js +8 -8
  5. package/dist/cli.mjs +145 -53
  6. package/dist/preview-assets.generated.bin +0 -0
  7. package/guides/himi-json-output.md +8 -1
  8. package/guides/releasing-with-himi-serve.md +5 -5
  9. package/guides/sdk-reference.json +1 -1
  10. package/package.json +2 -2
  11. package/templates/beauty-salon/l10n/en.json +1 -1
  12. package/templates/branded-lite/dev/index.ts +207 -2
  13. package/templates/branded-lite/l10n/ar.json +76 -0
  14. package/templates/branded-lite/l10n/cs.json +76 -0
  15. package/templates/branded-lite/l10n/da.json +76 -0
  16. package/templates/branded-lite/l10n/de.json +76 -0
  17. package/templates/branded-lite/l10n/el.json +76 -0
  18. package/templates/branded-lite/l10n/en.json +43 -1
  19. package/templates/branded-lite/l10n/es.json +76 -0
  20. package/templates/branded-lite/l10n/fi.json +76 -0
  21. package/templates/branded-lite/l10n/fr.json +76 -0
  22. package/templates/branded-lite/l10n/he.json +62 -0
  23. package/templates/branded-lite/l10n/hu.json +76 -0
  24. package/templates/branded-lite/l10n/id.json +76 -0
  25. package/templates/branded-lite/l10n/it.json +76 -0
  26. package/templates/branded-lite/l10n/ja.json +76 -0
  27. package/templates/branded-lite/l10n/ko.json +76 -0
  28. package/templates/branded-lite/l10n/lt.json +76 -0
  29. package/templates/branded-lite/l10n/nl.json +76 -0
  30. package/templates/branded-lite/l10n/no.json +76 -0
  31. package/templates/branded-lite/l10n/pl.json +76 -0
  32. package/templates/branded-lite/l10n/pt.json +76 -0
  33. package/templates/branded-lite/l10n/ru.json +76 -0
  34. package/templates/branded-lite/l10n/sv.json +76 -0
  35. package/templates/branded-lite/l10n/th.json +76 -0
  36. package/templates/branded-lite/l10n/tr.json +76 -0
  37. package/templates/branded-lite/l10n/uk.json +76 -0
  38. package/templates/branded-lite/l10n/vi.json +76 -0
  39. package/templates/branded-lite/l10n/zh.json +76 -0
  40. package/templates/branded-lite/tier5-src/himi-branded-lite-program-participant/index.ts +169 -4
  41. package/templates/branded-lite/tier5-src/himi-branded-lite-program-participant/model.ts +32 -1
  42. package/templates/community-club/l10n/en.json +1 -1
  43. package/templates/events-meetups/l10n/en.json +1 -1
  44. package/templates/gym-fitness/l10n/en.json +1 -1
  45. package/templates/nonprofit-cause/l10n/en.json +1 -1
  46. package/templates/podcast-creator/l10n/en.json +1 -1
  47. package/templates/portfolio-creative/l10n/en.json +1 -1
  48. package/templates/restaurant/l10n/en.json +1 -1
  49. package/templates/retail-store/l10n/en.json +1 -1
  50. package/templates/yoga-studio/dev/index.ts +203 -1
  51. package/templates/yoga-studio/l10n/ar.json +76 -0
  52. package/templates/yoga-studio/l10n/cs.json +76 -0
  53. package/templates/yoga-studio/l10n/da.json +76 -0
  54. package/templates/yoga-studio/l10n/de.json +76 -0
  55. package/templates/yoga-studio/l10n/el.json +76 -0
  56. package/templates/yoga-studio/l10n/en.json +43 -1
  57. package/templates/yoga-studio/l10n/es.json +76 -0
  58. package/templates/yoga-studio/l10n/fi.json +76 -0
  59. package/templates/yoga-studio/l10n/fr.json +76 -0
  60. package/templates/yoga-studio/l10n/he.json +62 -0
  61. package/templates/yoga-studio/l10n/hu.json +76 -0
  62. package/templates/yoga-studio/l10n/id.json +76 -0
  63. package/templates/yoga-studio/l10n/it.json +76 -0
  64. package/templates/yoga-studio/l10n/ja.json +76 -0
  65. package/templates/yoga-studio/l10n/ko.json +76 -0
  66. package/templates/yoga-studio/l10n/lt.json +76 -0
  67. package/templates/yoga-studio/l10n/nl.json +76 -0
  68. package/templates/yoga-studio/l10n/no.json +76 -0
  69. package/templates/yoga-studio/l10n/pl.json +76 -0
  70. package/templates/yoga-studio/l10n/pt.json +76 -0
  71. package/templates/yoga-studio/l10n/ru.json +76 -0
  72. package/templates/yoga-studio/l10n/sv.json +76 -0
  73. package/templates/yoga-studio/l10n/th.json +76 -0
  74. package/templates/yoga-studio/l10n/tr.json +76 -0
  75. package/templates/yoga-studio/l10n/uk.json +76 -0
  76. package/templates/yoga-studio/l10n/vi.json +76 -0
  77. package/templates/yoga-studio/l10n/zh.json +76 -0
  78. package/templates/yoga-studio/tier5-src/himi-branded-lite-program-participant/index.ts +169 -4
  79. package/templates/yoga-studio/tier5-src/himi-branded-lite-program-participant/model.ts +32 -1
@@ -4298,6 +4298,42 @@
4298
4298
  "translation": "Đổi ảnh",
4299
4299
  "origin": "machine"
4300
4300
  },
4301
+ "h_09605d5316c8": {
4302
+ "key": "programParticipant.badgesCta",
4303
+ "source": "See badges",
4304
+ "translation": "Xem huy hiệu",
4305
+ "origin": "machine"
4306
+ },
4307
+ "h_877a96132aba": {
4308
+ "key": "programParticipant.shareCta",
4309
+ "source": "Share program",
4310
+ "translation": "Chia sẻ chương trình",
4311
+ "origin": "machine"
4312
+ },
4313
+ "h_9594aa7fb773": {
4314
+ "key": "programParticipant.certificateLine",
4315
+ "source": "You earned a certificate for completing this program.",
4316
+ "translation": "Bạn đã nhận được chứng chỉ vì hoàn thành chương trình này.",
4317
+ "origin": "machine"
4318
+ },
4319
+ "h_f0ab567fcabf": {
4320
+ "key": "programParticipant.certificateCta",
4321
+ "source": "Download certificate",
4322
+ "translation": "Tải chứng chỉ xuống",
4323
+ "origin": "machine"
4324
+ },
4325
+ "h_f57098156f45": {
4326
+ "key": "programParticipant.leaveCta",
4327
+ "source": "Leave program",
4328
+ "translation": "Rời chương trình",
4329
+ "origin": "machine"
4330
+ },
4331
+ "h_8be9b7b4a288": {
4332
+ "key": "programParticipant.rewardsTitle",
4333
+ "source": "Completion rewards",
4334
+ "translation": "Phần thưởng hoàn thành",
4335
+ "origin": "machine"
4336
+ },
4301
4337
  "h_1e9b74b4dda5": {
4302
4338
  "source": "Show all ({count})",
4303
4339
  "translation": "Xem tất cả ({count})",
@@ -9462,6 +9498,46 @@
9462
9498
  "source": "Unblock {name}?",
9463
9499
  "translation": "Bỏ chặn {name}?",
9464
9500
  "origin": "machine"
9501
+ },
9502
+ "h_6afc7c99550a": {
9503
+ "source": "The certificate can't be opened right now. Try again.",
9504
+ "translation": "Hiện không thể mở chứng chỉ. Hãy thử lại.",
9505
+ "origin": "machine"
9506
+ },
9507
+ "h_f253bccee8b9": {
9508
+ "source": "Complete the program to earn its badges.",
9509
+ "translation": "Hoàn thành chương trình để nhận huy hiệu của chương trình.",
9510
+ "origin": "machine"
9511
+ },
9512
+ "h_5c5c12ccef8f": {
9513
+ "source": "You completed the program. See the badges it awards.",
9514
+ "translation": "Bạn đã hoàn thành chương trình. Xem các huy hiệu mà chương trình trao tặng.",
9515
+ "origin": "machine"
9516
+ },
9517
+ "h_f3132d590fe5": {
9518
+ "source": "Leave this program?",
9519
+ "translation": "Rời chương trình này?",
9520
+ "origin": "machine"
9521
+ },
9522
+ "h_5d2962cd6aea": {
9523
+ "source": "You'll lose access to its steps. You can join again from the program page.",
9524
+ "translation": "Bạn sẽ mất quyền truy cập vào các bước của chương trình. Bạn có thể tham gia lại từ trang chương trình.",
9525
+ "origin": "machine"
9526
+ },
9527
+ "h_7e3520a97331": {
9528
+ "source": "Leave",
9529
+ "translation": "Rời",
9530
+ "origin": "machine"
9531
+ },
9532
+ "h_8173f44ffdee": {
9533
+ "source": "We couldn't take you out of the program. Try again.",
9534
+ "translation": "Chúng tôi không thể đưa bạn ra khỏi chương trình. Hãy thử lại.",
9535
+ "origin": "machine"
9536
+ },
9537
+ "h_3f1848b083aa": {
9538
+ "source": "You're offline. Connect to the internet and try again.",
9539
+ "translation": "Bạn đang ngoại tuyến. Hãy kết nối Internet và thử lại.",
9540
+ "origin": "machine"
9465
9541
  }
9466
9542
  }
9467
9543
  }
@@ -4298,6 +4298,42 @@
4298
4298
  "translation": "變更相片",
4299
4299
  "origin": "machine"
4300
4300
  },
4301
+ "h_09605d5316c8": {
4302
+ "key": "programParticipant.badgesCta",
4303
+ "source": "See badges",
4304
+ "translation": "查看徽章",
4305
+ "origin": "machine"
4306
+ },
4307
+ "h_877a96132aba": {
4308
+ "key": "programParticipant.shareCta",
4309
+ "source": "Share program",
4310
+ "translation": "分享課程",
4311
+ "origin": "machine"
4312
+ },
4313
+ "h_9594aa7fb773": {
4314
+ "key": "programParticipant.certificateLine",
4315
+ "source": "You earned a certificate for completing this program.",
4316
+ "translation": "你已完成這個課程並獲得證書。",
4317
+ "origin": "machine"
4318
+ },
4319
+ "h_f0ab567fcabf": {
4320
+ "key": "programParticipant.certificateCta",
4321
+ "source": "Download certificate",
4322
+ "translation": "下載證書",
4323
+ "origin": "machine"
4324
+ },
4325
+ "h_f57098156f45": {
4326
+ "key": "programParticipant.leaveCta",
4327
+ "source": "Leave program",
4328
+ "translation": "退出課程",
4329
+ "origin": "machine"
4330
+ },
4331
+ "h_8be9b7b4a288": {
4332
+ "key": "programParticipant.rewardsTitle",
4333
+ "source": "Completion rewards",
4334
+ "translation": "完成獎勵",
4335
+ "origin": "machine"
4336
+ },
4301
4337
  "h_1e9b74b4dda5": {
4302
4338
  "source": "Show all ({count})",
4303
4339
  "translation": "查看全部({count})",
@@ -9462,6 +9498,46 @@
9462
9498
  "source": "Unblock {name}?",
9463
9499
  "translation": "要解除封鎖 {name} 嗎?",
9464
9500
  "origin": "machine"
9501
+ },
9502
+ "h_6afc7c99550a": {
9503
+ "source": "The certificate can't be opened right now. Try again.",
9504
+ "translation": "目前無法開啟證書,請再試一次。",
9505
+ "origin": "machine"
9506
+ },
9507
+ "h_f253bccee8b9": {
9508
+ "source": "Complete the program to earn its badges.",
9509
+ "translation": "完成課程即可獲得課程徽章。",
9510
+ "origin": "machine"
9511
+ },
9512
+ "h_5c5c12ccef8f": {
9513
+ "source": "You completed the program. See the badges it awards.",
9514
+ "translation": "你已完成課程。查看課程頒發的徽章。",
9515
+ "origin": "machine"
9516
+ },
9517
+ "h_f3132d590fe5": {
9518
+ "source": "Leave this program?",
9519
+ "translation": "要退出這個課程嗎?",
9520
+ "origin": "machine"
9521
+ },
9522
+ "h_5d2962cd6aea": {
9523
+ "source": "You'll lose access to its steps. You can join again from the program page.",
9524
+ "translation": "你將無法再存取課程步驟。你可以從課程頁面重新加入。",
9525
+ "origin": "machine"
9526
+ },
9527
+ "h_7e3520a97331": {
9528
+ "source": "Leave",
9529
+ "translation": "退出",
9530
+ "origin": "machine"
9531
+ },
9532
+ "h_8173f44ffdee": {
9533
+ "source": "We couldn't take you out of the program. Try again.",
9534
+ "translation": "無法讓你退出課程,請再試一次。",
9535
+ "origin": "machine"
9536
+ },
9537
+ "h_3f1848b083aa": {
9538
+ "source": "You're offline. Connect to the internet and try again.",
9539
+ "translation": "你目前處於離線狀態。請連上網路後再試一次。",
9540
+ "origin": "machine"
9465
9541
  }
9466
9542
  }
9467
9543
  }
@@ -13,9 +13,20 @@
13
13
  //
14
14
  // The next step opens the step screen when the host serves one (the load arg `stepScreen`);
15
15
  // without it the button shows the step in the Content tab, where it is marked "Next step".
16
+ //
17
+ // Rewards, leave and share (B4), on the Overview: the certificate (when the program has one and
18
+ // the member completed it; a time-limited link fetched at the tap, opened in the system browser),
19
+ // a link to the badges list (when the program awards badges and the host serves `badgesScreen`),
20
+ // "Leave program" behind a confirm alert (then the program page, which owns rejoining), and the
21
+ // program's site link in the system share sheet.
16
22
  import { connectivity, defineService, navigate } from "@himalaya/state";
23
+ import { open as openUrl } from "@himalaya/open-url";
24
+ import { share as shareSheet } from "@himalaya/share";
25
+ import { alert } from "@himalaya/ui";
17
26
  import {
27
+ getCertificateDownloadUrl,
18
28
  getProgram,
29
+ leaveProgram,
19
30
  listSections,
20
31
  participationsByProgram,
21
32
  queryParticipantSteps,
@@ -23,7 +34,7 @@ import {
23
34
  queryResolvedSteps,
24
35
  searchMemberParticipation,
25
36
  type WixParticipant,
26
- type WixProgram,
37
+ type WixProgramFull,
27
38
  type WixResolvedStep,
28
39
  type WixStep,
29
40
  } from "@himalaya/wix-online-programs";
@@ -39,7 +50,7 @@ import { inProgram, standingOf, STATUS, type Standing } from "../_shared/program
39
50
  import { assertMemberAccess, memberAccess, memberChanged, type MemberAccess } from "../_shared/member-access.js";
40
51
  import { initials } from "../_shared/himi-text.js";
41
52
  import { copyParam, stashCopy } from "../_shared/himi-copy.js";
42
- import { buildContent, type ContentRow } from "./model.js";
53
+ import { buildContent, rewardsOf, shareUrlOf, type ContentRow } from "./model.js";
43
54
 
44
55
  export const SERVICE = "himiBrandedProgramParticipant";
45
56
  /** The program page a member who is not in the program goes back to. */
@@ -92,6 +103,27 @@ interface State {
92
103
  hideContentEmpty: boolean;
93
104
  /** The Content tab's line when it has no rows: no steps yet, or steps the site will not show this member. */
94
105
  contentEmptyText: string;
106
+ /** The program has a certificate and the member completed it. */
107
+ hasCertificate: boolean;
108
+ /** The program awards badges and the host serves the badges vertical. */
109
+ hasBadges: boolean;
110
+ badgesLine: string;
111
+ hideCertificate: boolean;
112
+ hideBadges: boolean;
113
+ /** The Rewards card: hidden when there is neither a certificate nor badges to show. */
114
+ hideRewards: boolean;
115
+ /** The program's page on the site; "" hides Share. */
116
+ shareUrl: string;
117
+ hideShare: boolean;
118
+ /** The member may leave: in the program and the program has not ended. */
119
+ canLeave: boolean;
120
+ hideLeave: boolean;
121
+ /** A certificate fetch or a leave is in flight: both buttons wait. */
122
+ busy: boolean;
123
+ /** Why the certificate did not open, shown in the Rewards card next to its button; "" when none. */
124
+ certificateMessage: string;
125
+ /** Why a leave did not happen, shown under Leave; "" when none. */
126
+ actionMessage: string;
95
127
  }
96
128
 
97
129
  let rows: ContentRow[] = [];
@@ -99,6 +131,12 @@ let rows: ContentRow[] = [];
99
131
  let shownFor: MemberAccess | undefined;
100
132
  let access: Access = "member";
101
133
  let stepScreen = "";
134
+ /** The badges list; "" when the host has no badges vertical. */
135
+ let badgesScreen = "";
136
+ /** The participation the page on screen was built for: what Leave and the certificate act on. */
137
+ let participantId = "";
138
+ /** A certificate fetch or a leave is running: a second tap waits (the busy flag lands a publish later). */
139
+ let acting = false;
102
140
  let loadSeq = 0;
103
141
 
104
142
  function inputId(): string {
@@ -128,6 +166,11 @@ function derive(state: State): State {
128
166
  hideProgress: !member || state.progressLabel === "",
129
167
  hideNextStep: !member || !state.nextStepId,
130
168
  hideContentEmpty: !member || !content || rows.length > 0,
169
+ hideCertificate: !member || !state.hasCertificate,
170
+ hideBadges: !member || !state.hasBadges,
171
+ hideRewards: !member || (!state.hasCertificate && !state.hasBadges),
172
+ hideShare: !member || !state.shareUrl,
173
+ hideLeave: !member || !state.canLeave,
131
174
  };
132
175
  }
133
176
 
@@ -137,10 +180,12 @@ const INITIAL_STATE: State = derive({
137
180
  progress: 0, progressLabel: "", hideProgress: true, nextStepId: "", nextStepTitle: "", nextStepSection: "", hideNextStep: true,
138
181
  nextLine: "", gateText: "", contentEmptyText: "", isLoading: true, notLoading: false, hideError: true, needsSignIn: false, noSignIn: true,
139
182
  hideNotJoined: true, hideBody: true, hideOverview: true, hideContentEmpty: true,
183
+ hasCertificate: false, hasBadges: false, badgesLine: "", hideCertificate: true, hideBadges: true, hideRewards: true,
184
+ shareUrl: "", hideShare: true, canLeave: false, hideLeave: true, busy: false, certificateMessage: "", actionMessage: "",
140
185
  });
141
186
 
142
187
  /** getProgram first; the programs query is the fallback when the GET path fails (as on himi_program). */
143
- async function fetchProgram(id: string): Promise<WixProgram | undefined> {
188
+ async function fetchProgram(id: string): Promise<WixProgramFull | undefined> {
144
189
  try {
145
190
  return (await getProgram(id)).program;
146
191
  } catch {
@@ -196,6 +241,8 @@ async function load(state: State, arg?: unknown): Promise<undefined> {
196
241
  stashCopy(arg);
197
242
  const asked = (arg as { stepScreen?: unknown } | undefined)?.stepScreen;
198
243
  if (typeof asked === "string") stepScreen = asked;
244
+ const badges = (arg as { badgesScreen?: unknown } | undefined)?.badgesScreen;
245
+ if (typeof badges === "string") badgesScreen = badges;
199
246
  const id = inputId();
200
247
  const seq = ++loadSeq;
201
248
  const current = () => seq === loadSeq && inputId() === id;
@@ -219,6 +266,7 @@ async function load(state: State, arg?: unknown): Promise<undefined> {
219
266
  if (!member.email) {
220
267
  access = "signIn";
221
268
  rows = [];
269
+ participantId = "";
222
270
  shownFor = member;
223
271
  void svc.publish({ programId: id, status: "ready" });
224
272
  return undefined;
@@ -241,6 +289,7 @@ async function load(state: State, arg?: unknown): Promise<undefined> {
241
289
  if (!participant || !inProgram(standing, participant)) {
242
290
  access = "notJoined";
243
291
  rows = [];
292
+ participantId = "";
244
293
  shownFor = member;
245
294
  void svc.publish({ ...header, status: "ready", gateText: gateTextOf(standing, participant) });
246
295
  return undefined;
@@ -261,10 +310,14 @@ async function load(state: State, arg?: unknown): Promise<undefined> {
261
310
  await assertMemberAccess(member);
262
311
  if (!current()) return undefined;
263
312
  const model = buildContent({ sections, steps, resolved, participant, now: Date.now(), locale });
313
+ const rewards = rewardsOf(program);
314
+ const completed = standing === "completed";
264
315
  access = "member";
265
316
  rows = model.rows;
317
+ participantId = participant.id;
266
318
  shownFor = member;
267
319
  const status = STATUS[standing as Exclude<Standing, "none">];
320
+ const hasBadges = !!badgesScreen && rewards.badgeIds.length > 0;
268
321
  void svc.publish({
269
322
  ...header,
270
323
  status: "ready",
@@ -279,6 +332,20 @@ async function load(state: State, arg?: unknown): Promise<undefined> {
279
332
  contentEmptyText: model.contentAvailable
280
333
  ? copyParam("programParticipant.contentEmpty", "This program has no steps yet.")
281
334
  : copyParam("programParticipant.contentUnavailable", "This program's steps can't be shown in the app right now."),
335
+ hasCertificate: rewards.certificate && completed,
336
+ hasBadges,
337
+ badgesLine: !hasBadges ? ""
338
+ : completed ? copyParam("programParticipant.badgesEarnedLine", "You completed the program. See the badges it awards.")
339
+ : copyParam("programParticipant.badgesLine", "Complete the program to earn its badges."),
340
+ shareUrl: shareUrlOf(program),
341
+ // Only a member still working through a running program may leave. A completed member keeps the
342
+ // program and its certificate (leaving deletes the participation the certificate link needs), and an
343
+ // ended program has nothing left to leave. `standingOf` reads "completed" before "ended": both checked.
344
+ canLeave: standing === "joined" && !isProgramEnded(program),
345
+ // A load that works clears what an earlier failed attempt said.
346
+ busy: false,
347
+ certificateMessage: "",
348
+ actionMessage: "",
282
349
  });
283
350
  } catch (error) {
284
351
  if (!current()) return undefined;
@@ -289,8 +356,10 @@ async function load(state: State, arg?: unknown): Promise<undefined> {
289
356
  if (changed) {
290
357
  rows = [];
291
358
  access = "member";
359
+ participantId = "";
292
360
  shownFor = undefined;
293
- void svc.publish({ status: "loading", programId: "", standingLine: "", progress: 0, progressLabel: "", nextStepId: "", nextStepTitle: "", nextStepSection: "", nextLine: "" });
361
+ void svc.publish({ status: "loading", programId: "", standingLine: "", progress: 0, progressLabel: "", nextStepId: "", nextStepTitle: "", nextStepSection: "", nextLine: "",
362
+ hasCertificate: false, hasBadges: false, badgesLine: "", shareUrl: "", canLeave: false, busy: false, certificateMessage: "", actionMessage: "" });
294
363
  void svc.load();
295
364
  return undefined;
296
365
  }
@@ -301,6 +370,86 @@ async function load(state: State, arg?: unknown): Promise<undefined> {
301
370
  return undefined;
302
371
  }
303
372
 
373
+ /** The page on screen is still the one an action started on: same program route, ready, same member and
374
+ * participation. Checked again after every await, before anything is opened, deleted or published. */
375
+ function stillOn(programId: string, forParticipant: string, forMember: MemberAccess): boolean {
376
+ const now = svc.getState();
377
+ return inputId() === programId && now.programId === programId && now.status === "ready"
378
+ && participantId === forParticipant && sameMember(shownFor, forMember);
379
+ }
380
+
381
+ /** The certificate link is time-limited: fetched at the tap, never kept. */
382
+ async function openCertificate(state: State): Promise<undefined> {
383
+ if (acting || !state.hasCertificate || !participantId || !shownFor) return undefined;
384
+ acting = true;
385
+ const forMember = shownFor;
386
+ const forParticipant = participantId;
387
+ const programId = state.programId;
388
+ void svc.publish({ busy: true, certificateMessage: "" });
389
+ try {
390
+ await assertMemberAccess(forMember);
391
+ const { downloadUrl } = await getCertificateDownloadUrl(forParticipant);
392
+ // The link is a bearer URL to this member's certificate: open it only if the same member is still
393
+ // signed in and the same page is still on screen; otherwise drop it and leave the new page alone.
394
+ await assertMemberAccess(forMember);
395
+ if (!stillOn(programId, forParticipant, forMember)) { void svc.publish({ busy: false }); return undefined; }
396
+ if (!downloadUrl || !/^https:\/\//i.test(downloadUrl)) throw new Error("No certificate link");
397
+ const { opened } = await openUrl(downloadUrl, "system_browser");
398
+ if (!stillOn(programId, forParticipant, forMember)) { void svc.publish({ busy: false }); return undefined; }
399
+ void svc.publish({ busy: false, certificateMessage: opened ? "" : copyParam("programParticipant.certificateFailed", "The certificate can't be opened right now. Try again.") });
400
+ } catch (error) {
401
+ if (await memberChanged(forMember, error)) { void svc.publish({ busy: false }); void svc.load(); return undefined; }
402
+ void svc.publish({ busy: false, certificateMessage: failedLine("programParticipant.certificateFailed", "The certificate can't be opened right now. Try again.") });
403
+ } finally {
404
+ acting = false;
405
+ }
406
+ return undefined;
407
+ }
408
+
409
+ function failedLine(key: string, fallback: string): string {
410
+ return connectivity().online ? copyParam(key, fallback) : copyParam("programParticipant.offlineAction", "You're offline. Connect to the internet and try again.");
411
+ }
412
+
413
+ /** Leave after the member confirms; then the program page, which owns rejoining. Every outcome but the
414
+ * navigation is a publish, so nothing that loaded while the alert was open is rolled back. */
415
+ async function leave(state: State): Promise<State | undefined> {
416
+ if (acting || !state.canLeave || !participantId || !shownFor) return undefined;
417
+ const forMember = shownFor;
418
+ const forParticipant = participantId;
419
+ const programId = state.programId;
420
+ // No alert host (or another alert is open, e.g. a second tap) counts as "not confirmed": never leave
421
+ // without the member's yes.
422
+ const { confirmed } = await alert({
423
+ title: copyParam("programParticipant.leaveTitle", "Leave this program?"),
424
+ message: copyParam("programParticipant.leaveMessage", "You'll lose access to its steps. You can join again from the program page."),
425
+ confirmLabel: copyParam("programParticipant.leaveConfirm", "Leave"),
426
+ cancelLabel: copyParam("common.cancelCta", "Cancel"),
427
+ destructive: true,
428
+ }).catch(() => ({ confirmed: false }));
429
+ // The page may have moved on while the alert was open: another program or member, or a refresh that
430
+ // ended the program or completed it (no Leave any more).
431
+ if (!confirmed || acting || !stillOn(programId, forParticipant, forMember) || !svc.getState().canLeave) return undefined;
432
+ acting = true;
433
+ try {
434
+ void svc.publish({ busy: true, actionMessage: "" });
435
+ try {
436
+ await assertMemberAccess(forMember);
437
+ // A refresh or route change during the member check (one that completed or ended the program too):
438
+ // delete nothing.
439
+ if (!stillOn(programId, forParticipant, forMember) || !svc.getState().canLeave) { void svc.publish({ busy: false }); return undefined; }
440
+ await leaveProgram(forParticipant);
441
+ } catch (error) {
442
+ if (await memberChanged(forMember, error)) { void svc.publish({ busy: false }); void svc.load(); return undefined; }
443
+ void svc.publish({ busy: false, actionMessage: failedLine("programParticipant.leaveFailed", "We couldn't take you out of the program. Try again.") });
444
+ return undefined;
445
+ }
446
+ participantId = "";
447
+ return navigate(derive({ ...svc.getState(), busy: false, canLeave: false }), { screenId: PROGRAM_SCREEN, args: { id: programId }, presentation: "replace" });
448
+ } finally {
449
+ acting = false;
450
+ }
451
+ }
452
+
304
453
  type Actions = {
305
454
  load: (state: State, arg?: unknown) => Promise<undefined>;
306
455
  refresh: (state: State) => Promise<undefined>;
@@ -308,6 +457,10 @@ type Actions = {
308
457
  selectTab: (state: State, arg?: unknown) => State;
309
458
  openStep: (state: State) => State;
310
459
  openLink: (state: State, arg?: unknown) => Promise<undefined>;
460
+ openCertificate: (state: State) => Promise<undefined>;
461
+ openBadges: (state: State) => State;
462
+ shareProgram: (state: State) => Promise<undefined>;
463
+ leave: (state: State) => Promise<State | undefined>;
311
464
  };
312
465
 
313
466
  const svc = defineService<State, Actions>(SERVICE, {
@@ -329,6 +482,18 @@ const svc = defineService<State, Actions>(SERVICE, {
329
482
  return derive({ ...state, tab: "content" });
330
483
  },
331
484
  openLink: async (_state, arg) => { await openRichLink(arg); return undefined; },
485
+ openCertificate,
486
+ openBadges: (state) => {
487
+ // The badges list: one badge's page shows only what its caller passes, which this page does not read.
488
+ if (!state.hasBadges || !badgesScreen) return state;
489
+ return navigate(state, { screenId: badgesScreen });
490
+ },
491
+ shareProgram: async (state) => {
492
+ if (!state.shareUrl) return undefined;
493
+ try { await shareSheet({ subject: state.name, text: state.name, url: state.shareUrl }); } catch { /* the sheet is best-effort */ }
494
+ return undefined;
495
+ },
496
+ leave,
332
497
  },
333
498
  });
334
499
 
@@ -2,7 +2,7 @@
2
2
  // flat row list (a section header, then its steps) plus the Overview's progress and next step.
3
3
  // Pure — the worker reads the program, the participation and the content; this file only decides
4
4
  // what the member sees.
5
- import type { WixParticipant, WixResolvedStep, WixSection, WixStep } from "@himalaya/wix-online-programs";
5
+ import type { WixParticipant, WixProgramFull, WixResolvedStep, WixSection, WixStep } from "@himalaya/wix-online-programs";
6
6
  import { copyParam, copyTemplate } from "../_shared/himi-copy.js";
7
7
  import { formatDateMedium } from "../_shared/engine-intl.js";
8
8
 
@@ -204,3 +204,34 @@ export function buildContent(input: {
204
204
  contentAvailable,
205
205
  };
206
206
  }
207
+
208
+ /** What the program awards on completion (rewards with another trigger are not shown), as the participant page shows it. */
209
+ export interface Rewards {
210
+ /** The program has a certificate connected. */
211
+ certificate: boolean;
212
+ /** Distinct badge ids the program awards, in the order the site lists them. */
213
+ badgeIds: string[];
214
+ }
215
+
216
+ export function rewardsOf(program: Pick<WixProgramFull, "rewards"> | undefined): Rewards {
217
+ const badgeIds: string[] = [];
218
+ let certificate = false;
219
+ for (const reward of program?.rewards ?? []) {
220
+ // Only what completing the program earns: the page promises these "when you complete the program".
221
+ const trigger = String(reward?.trigger ?? "ALL_STEPS_COMPLETED").toUpperCase();
222
+ if (trigger !== "ALL_STEPS_COMPLETED") continue;
223
+ if (reward?.certificate?.id) certificate = true;
224
+ for (const id of reward?.badgeIds ?? []) if (typeof id === "string" && id && !badgeIds.includes(id)) badgeIds.push(id);
225
+ }
226
+ return { certificate, badgeIds };
227
+ }
228
+
229
+ /** The program's page on the live site, for the share sheet; "" when the site gives no https link. */
230
+ export function shareUrlOf(program: Pick<WixProgramFull, "seo"> | undefined): string {
231
+ const base = program?.seo?.url?.base ?? "";
232
+ const path = program?.seo?.url?.path ?? "";
233
+ // No `URL` in every worker engine: join by hand. A base with a query or a fragment is not a page base.
234
+ if (!/^https:\/\/[^/?#\s]+(\/[^?#\s]*)?$/i.test(base) || /[\s]/.test(path)) return "";
235
+ const tail = path.replace(/^\/+/, "");
236
+ return tail ? `${base.replace(/\/+$/, "")}/${tail}` : base;
237
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$source": "en",
3
- "$generated": "2026-11-19T10:08:02.426Z",
3
+ "$generated": "2026-11-19T15:47:24.661Z",
4
4
  "messages": {
5
5
  "h_009bd0adf237": {
6
6
  "source": "Custom collections published by this business.",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$source": "en",
3
- "$generated": "2026-11-19T10:08:02.426Z",
3
+ "$generated": "2026-11-19T15:47:24.661Z",
4
4
  "messages": {
5
5
  "h_01ca4c21ba7d": {
6
6
  "source": "Continue with Apple",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$source": "en",
3
- "$generated": "2026-11-19T10:08:02.426Z",
3
+ "$generated": "2026-11-19T15:47:24.661Z",
4
4
  "messages": {
5
5
  "h_0028d743eb44": {
6
6
  "source": "Sale",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$source": "en",
3
- "$generated": "2026-11-19T10:08:02.426Z",
3
+ "$generated": "2026-11-19T15:47:24.661Z",
4
4
  "messages": {
5
5
  "h_01ca4c21ba7d": {
6
6
  "source": "Continue with Apple",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$source": "en",
3
- "$generated": "2026-11-19T10:08:02.426Z",
3
+ "$generated": "2026-11-19T15:47:24.661Z",
4
4
  "messages": {
5
5
  "h_01ca4c21ba7d": {
6
6
  "source": "Continue with Apple",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$source": "en",
3
- "$generated": "2026-11-19T10:08:02.426Z",
3
+ "$generated": "2026-11-19T15:47:24.661Z",
4
4
  "messages": {
5
5
  "h_0028d743eb44": {
6
6
  "source": "Sale",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$source": "en",
3
- "$generated": "2026-11-19T10:08:02.426Z",
3
+ "$generated": "2026-11-19T15:47:24.661Z",
4
4
  "messages": {
5
5
  "h_01ca4c21ba7d": {
6
6
  "source": "Continue with Apple",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$source": "en",
3
- "$generated": "2026-11-19T10:08:02.426Z",
3
+ "$generated": "2026-11-19T15:47:24.661Z",
4
4
  "messages": {
5
5
  "h_0028d743eb44": {
6
6
  "source": "Sale",