@wix/himalaya-cli 0.1655.0 → 0.1657.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 (86) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/pricing-plans/src/index.d.ts +37 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/checkout.mjs +2 -1
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +2 -1
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-pricing-plans.mjs +10 -1
  5. package/dist/browser-plane/assets.json +5 -5
  6. package/dist/browser-plane/preview-deferred/{3912fa5f6ddb60106c630fb5e48edbf12ebfd57c616d8b7aee0d32088cd3bbdf.bin → c04dd5fc5ad48e6b19678d4313159302e9a513ada94bfe515d8dfd5a54d46f5d.bin} +1 -1
  7. package/dist/browser-plane/sw.js +5 -5
  8. package/dist/cli.mjs +109 -62
  9. package/dist/preview-assets.generated.bin +0 -0
  10. package/guides/getting-started.md +4 -1
  11. package/guides/himi-skill.md +4 -1
  12. package/guides/index.json +12 -0
  13. package/guides/qa-builds.md +7 -4
  14. package/guides/recipe-auth.md +120 -0
  15. package/guides/recipe-checkout.md +108 -0
  16. package/guides/sdk-reference.json +21 -3
  17. package/package.json +2 -2
  18. package/templates/beauty-salon/dev/index.ts +2151 -2596
  19. package/templates/beauty-salon/l10n/en.json +208 -180
  20. package/templates/beauty-salon/l10n/he.json +300 -138
  21. package/templates/beauty-salon/tier5-src/_shared/pricing-plan-display.ts +64 -0
  22. package/templates/beauty-salon/tier5-src/himi-branded-lite-plans/index.ts +101 -31
  23. package/templates/beauty-salon/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
  24. package/templates/beauty-salon/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
  25. package/templates/beauty-salon/tokens.json +17 -1
  26. package/templates/branded-lite/dev/index.ts +2272 -2685
  27. package/templates/branded-lite/l10n/en.json +225 -52
  28. package/templates/branded-lite/l10n/he.json +305 -39
  29. package/templates/branded-lite/tier5-src/_shared/pricing-plan-display.ts +64 -0
  30. package/templates/branded-lite/tier5-src/himi-branded-lite-plans/index.ts +101 -31
  31. package/templates/branded-lite/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
  32. package/templates/branded-lite/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
  33. package/templates/branded-lite/tokens.json +5 -1
  34. package/templates/community-club/l10n/en.json +6 -1
  35. package/templates/community-club/l10n/he.json +23 -2
  36. package/templates/community-club/tokens.json +17 -1
  37. package/templates/events-meetups/l10n/en.json +6 -1
  38. package/templates/events-meetups/l10n/he.json +23 -2
  39. package/templates/events-meetups/tokens.json +17 -1
  40. package/templates/gym-fitness/dev/index.ts +2149 -2594
  41. package/templates/gym-fitness/l10n/en.json +215 -77
  42. package/templates/gym-fitness/l10n/he.json +300 -59
  43. package/templates/gym-fitness/tier5-src/_shared/pricing-plan-display.ts +64 -0
  44. package/templates/gym-fitness/tier5-src/himi-branded-lite-plans/index.ts +101 -31
  45. package/templates/gym-fitness/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
  46. package/templates/gym-fitness/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
  47. package/templates/gym-fitness/tokens.json +17 -1
  48. package/templates/nonprofit-cause/dev/index.ts +2163 -2608
  49. package/templates/nonprofit-cause/l10n/en.json +216 -38
  50. package/templates/nonprofit-cause/l10n/he.json +300 -30
  51. package/templates/nonprofit-cause/tier5-src/_shared/pricing-plan-display.ts +64 -0
  52. package/templates/nonprofit-cause/tier5-src/himi-branded-lite-plans/index.ts +101 -31
  53. package/templates/nonprofit-cause/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
  54. package/templates/nonprofit-cause/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
  55. package/templates/nonprofit-cause/tokens.json +17 -1
  56. package/templates/podcast-creator/dev/index.ts +2147 -2592
  57. package/templates/podcast-creator/l10n/en.json +216 -38
  58. package/templates/podcast-creator/l10n/he.json +300 -30
  59. package/templates/podcast-creator/tier5-src/_shared/pricing-plan-display.ts +64 -0
  60. package/templates/podcast-creator/tier5-src/himi-branded-lite-plans/index.ts +101 -31
  61. package/templates/podcast-creator/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
  62. package/templates/podcast-creator/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
  63. package/templates/podcast-creator/tokens.json +17 -1
  64. package/templates/portfolio-creative/l10n/en.json +15 -8
  65. package/templates/portfolio-creative/l10n/he.json +28 -6
  66. package/templates/portfolio-creative/tokens.json +17 -1
  67. package/templates/restaurant/l10n/en.json +14 -7
  68. package/templates/restaurant/l10n/he.json +28 -6
  69. package/templates/restaurant/tokens.json +17 -1
  70. package/templates/retail-store/l10n/en.json +15 -8
  71. package/templates/retail-store/l10n/he.json +28 -6
  72. package/templates/retail-store/tokens.json +17 -1
  73. package/templates/yoga-studio/dev/index.ts +2204 -2649
  74. package/templates/yoga-studio/l10n/en.json +216 -43
  75. package/templates/yoga-studio/l10n/he.json +300 -30
  76. package/templates/yoga-studio/tier5-src/_shared/pricing-plan-display.ts +64 -0
  77. package/templates/yoga-studio/tier5-src/himi-branded-lite-plans/index.ts +101 -31
  78. package/templates/yoga-studio/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
  79. package/templates/yoga-studio/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
  80. package/templates/yoga-studio/tokens.json +17 -1
  81. package/templates/beauty-salon/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
  82. package/templates/branded-lite/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
  83. package/templates/gym-fitness/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
  84. package/templates/nonprofit-cause/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
  85. package/templates/podcast-creator/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
  86. package/templates/yoga-studio/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
@@ -1,41 +1,139 @@
1
- // Tier-5 bundle: Wix Spaces clone — Subscription / plan-order detail (site-scoped).
2
1
  import { defineService } from "@himalaya/state";
3
- import { getPlanOrder, type WixPlanOrder } from "@himalaya/wix-pricing-plans";
4
- import { formatDateMedium } from "../_shared/engine-intl.js";
2
+ import { getMyPlanOrder, requestCancellation, type WixPlanOrder } from "@himalaya/wix-pricing-plans";
3
+ import { hostSessionFromGlobal } from "@himalaya/iap";
4
+ import { memberAccess, assertMemberAccess, memberAccessDenied, memberChanged, type MemberAccess } from "../_shared/member-access.js";
5
+ import { orderDate, orderPrice, orderStatus, orderFacts } from "../_shared/pricing-plan-display.js";
5
6
  import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
7
+ import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
6
8
 
7
- interface S extends PresenceFlags { status: "loading" | "ready"; name: string; subtitle: string; price: string; validity: string }
8
-
9
-
10
- // Shown by hosts without the shared not-found state (the Spaces clone renders `subtitle`
11
- // directly); branded-lite hides the whole content block behind `notFound`.
12
- const EMPTY_DETAIL = "Open a subscription from My Subscriptions — detail needs a plan-order id.";
13
- const LOAD_FAILED = "This subscription could not be loaded. Try again from My Subscriptions.";
14
-
15
- const svc = defineService<S, { load: (s: S) => Promise<S> }>("spacesSubscriptionDetail", {
16
- state: { status: "loading", name: "", subtitle: "", price: "", validity: "", ...presence("loading") },
9
+ interface S extends PresenceFlags {
10
+ denied: boolean; hideDeniedError: boolean; notActive: boolean; isActive: boolean;
11
+ status: string; name: string; subtitle: string; price: string; validity: string;
12
+ facts: ReturnType<typeof orderFacts>; hideAccountCta: boolean;
13
+ hideCancel: boolean; hideConfirmation: boolean; showConfirmation: boolean; busy: boolean; noScheduledOption: boolean;
14
+ effectiveAt: string; confirmation: string; actionMessage: string; actionError: string; hasActionError: boolean; noActionError: boolean;
15
+ }
16
+ const initial = (): S => ({ denied: false, hideDeniedError: true, notActive: true, isActive: false, status: "loading", name: "", subtitle: "", price: "", validity: "", facts: [], hideAccountCta: true,
17
+ hideCancel: true, hideConfirmation: true, showConfirmation: false, busy: false, noScheduledOption: true, effectiveAt: "IMMEDIATELY", confirmation: "", actionMessage: "", actionError: "none", hasActionError: false, noActionError: true, ...presence("loading") });
18
+ let order: WixPlanOrder | null = null;
19
+ let sequence = 0;
20
+ let cancelInFlight = false;
21
+ const cancellationsSent = new Set<string>();
22
+ let orderMemberKey = "";
23
+ const memberKey = (member: MemberAccess): string => JSON.stringify([member.scope, member.email]);
24
+ const cancellationKey = (id: string, owner = orderMemberKey): string => JSON.stringify([owner, id]);
25
+ const session = hostSessionFromGlobal();
26
+ function canCancel(o: WixPlanOrder): boolean {
27
+ // The member API enforces the PURCHASED policy. Current public plan settings are not the
28
+ // historical policy, and an archived plan must not prevent canceling an existing order.
29
+ return Boolean(o.id) && ["ACTIVE", "PENDING", "PAUSED"].includes(o.status ?? "") && o.type !== "EXTERNAL"
30
+ && !o.autoRenewCanceled && o.cancellation?.effectiveAt !== "NEXT_PAYMENT_DATE";
31
+ }
32
+ function project(o: WixPlanOrder, message = ""): S {
33
+ const end = orderDate(o.earliestEndDate ?? o.endDate ?? o.currentCycle?.endedDate);
34
+ const scheduled = Boolean((o.pricing?.subscription ?? o.priceDetails?.subscription) && o.currentCycle?.endedDate && Date.parse(o.currentCycle.endedDate) > Date.now());
35
+ const renews = o.status === "ACTIVE" && scheduled ? orderDate(o.currentCycle?.endedDate) : "";
36
+ return { ...initial(), ...presence("found"), status: "ready", notActive: o.status !== "ACTIVE", isActive: o.status === "ACTIVE", name: o.planName || copyParam("subscriptionDetail.fallbackName", "Subscription"), subtitle: orderStatus(o), price: orderPrice(o),
37
+ validity: (o.earliestEndDate || o.autoRenewCanceled || o.cancellation?.effectiveAt === "NEXT_PAYMENT_DATE") && end ? copyTemplate("subscriptionDetail.scheduledEndMessage", "Your subscription ends on {date}.", { date: end }) : renews ? copyTemplate("placeSummary.planRenews", "Renews {date}", { date: renews }) : "",
38
+ facts: orderFacts(o), hideCancel: !canCancel(o) || cancellationsSent.has(cancellationKey(o.id)), noScheduledOption: !scheduled,
39
+ effectiveAt: scheduled ? "NEXT_PAYMENT_DATE" : "IMMEDIATELY", actionMessage: message };
40
+ }
41
+ function confirmation(effectiveAt: string): string {
42
+ const end = orderDate(order?.currentCycle?.endedDate);
43
+ return effectiveAt === "NEXT_PAYMENT_DATE" && end
44
+ ? copyTemplate("subscriptionDetail.cancelAtPeriodEndBody", "Request cancellation at the next payment date, {date}?", { date: end })
45
+ : copyParam("subscriptionDetail.cancelImmediatelyBody", "Request cancellation now? Your access can end immediately.");
46
+ }
47
+ async function load(_state: S, arg?: unknown): Promise<S | undefined> {
48
+ stashCopy(arg);
49
+ const seq = ++sequence;
50
+ if (order && order.id !== detailInputId()) { order = null; void svc.clear(); }
51
+ const member = await memberAccess();
52
+ if (seq !== sequence) return undefined;
53
+ if (!member.email) { order = null; return { ...initial(), status: "guest", subtitle: copyParam("mySubscriptions.guestBody", "Sign in to see your subscriptions."), hideAccountCta: false, ...presence("missing"), hideNotFound: true }; }
54
+ const id = detailInputId();
55
+ if (!id) return { ...initial(), status: "ready", subtitle: copyParam("subscriptionDetail.missingId", "Open a subscription from My Subscriptions."), ...presence("missing") };
56
+ try {
57
+ const result = await getMyPlanOrder(id);
58
+ await assertMemberAccess(member);
59
+ if (seq !== sequence) return undefined;
60
+ orderMemberKey = memberKey(member);
61
+ order = result.order;
62
+ if (!order?.id || order.status === "DRAFT") { order = null; return { ...initial(), status: "ready", ...presence("missing") }; }
63
+ return project(order, cancellationsSent.has(cancellationKey(order.id)) && canCancel(order) ? copyParam("subscriptionDetail.cancelPending", "Cancellation requested. Refresh to see the latest status.") : "");
64
+ } catch (error) {
65
+ if (seq !== sequence) return undefined;
66
+ order = null;
67
+ if (await memberChanged(member, error)) { void svc.clear(); void svc.load(); return undefined; }
68
+ const denied = memberAccessDenied(error);
69
+ const flags = presenceAfterError(error);
70
+ return { ...initial(), status: "ready", subtitle: copyParam("subscriptionDetail.loadError", "This subscription could not be loaded."), ...flags, denied, hideLoadError: denied || flags.hideLoadError, hideDeniedError: !denied };
71
+ }
72
+ }
73
+ type SubscriptionActions = {
74
+ beginCancel: (s: S) => S; clear: (s: S) => S; load: typeof load; requestCancel: (s: S) => S;
75
+ dismissCancel: (s: S) => S; chooseEffectiveAt: (s: S, arg?: unknown) => S;
76
+ confirmCancel: (s: S) => Promise<S | undefined>;
77
+ };
78
+ const svc: ReturnType<typeof defineService<S, SubscriptionActions>> = defineService<S, SubscriptionActions>("spacesSubscriptionDetail", {
79
+ state: initial(), notHydrated: Object.keys(initial()) as Array<keyof S>,
17
80
  actions: {
18
- load: async (s) => {
19
- const id = detailInputId();
20
- // No order id (a stale link, a route opened directly) → the shared not-found state.
21
- if (!id) return { status: "ready", name: "", subtitle: EMPTY_DETAIL, price: "", validity: "", ...presence("missing") };
81
+ beginCancel: state => ({ ...state, busy: true }),
82
+ clear: () => initial(), load,
83
+ requestCancel: state => !order || order.id !== detailInputId() || state.hideCancel || cancelInFlight ? state : { ...state, hideConfirmation: false, showConfirmation: true, actionMessage: "", actionError: "none", hasActionError: false, noActionError: true, confirmation: confirmation(state.effectiveAt) },
84
+ dismissCancel: state => cancelInFlight ? state : { ...state, hideConfirmation: true, showConfirmation: false },
85
+ chooseEffectiveAt: (state, arg) => {
86
+ if (cancelInFlight || state.hideConfirmation) return state;
87
+ const value = typeof arg === "string" ? arg : (arg as { value?: string; selectedId?: string })?.value ?? (arg as { selectedId?: string })?.selectedId;
88
+ const effectiveAt = value === "NEXT_PAYMENT_DATE" && !state.noScheduledOption ? value : "IMMEDIATELY";
89
+ return { ...state, effectiveAt, confirmation: confirmation(effectiveAt) };
90
+ },
91
+ confirmCancel: async (state): Promise<S | undefined> => {
92
+ if (state.hideConfirmation || state.hideCancel || !order || order.id !== detailInputId() || !canCancel(order) || cancelInFlight || cancellationsSent.has(cancellationKey(order.id))) return undefined;
93
+ cancelInFlight = true;
94
+ void svc.beginCancel();
95
+ const seq = sequence;
96
+ const id = order.id;
97
+ const isCurrent = (): boolean => seq === sequence && detailInputId() === id;
98
+ const member = await memberAccess();
99
+ const requestKey = cancellationKey(id, memberKey(member));
22
100
  try {
23
- const res = await getPlanOrder(id);
24
- const o = (((res as unknown as { order?: WixPlanOrder }).order) ?? (res as unknown as WixPlanOrder)) as unknown as {
25
- planName?: string; status?: string;
26
- pricing?: { prices?: Array<{ price?: { formattedTotal?: string } }> };
27
- currentCycle?: { endedDate?: string };
28
- };
29
- const price = o.pricing?.prices?.[0]?.price?.formattedTotal || "";
30
- const end = o.currentCycle?.endedDate ? `Renews ${formatDateMedium(new Date(o.currentCycle.endedDate))}` : "";
31
- return { status: "ready", name: o.planName || "Subscription",
32
- subtitle: o.status ? o.status.charAt(0) + o.status.slice(1).toLowerCase() : "", price, validity: end, ...presence("found") };
33
- } catch (e) {
34
- const flags = presenceAfterError(e);
35
- return { status: "ready", name: "", subtitle: flags.notFound ? "" : LOAD_FAILED, price: "", validity: "", ...flags };
36
- }
101
+ if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
102
+ await assertMemberAccess(member);
103
+ if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
104
+ // Refresh policy/lifecycle facts before writing; never cancel a stale/other member order.
105
+ const latest = (await getMyPlanOrder(id)).order;
106
+ await assertMemberAccess(member);
107
+ if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
108
+ if (!latest || !canCancel(latest)) { order = latest; return latest ? project(latest) : { ...initial(), ...presence("missing") }; }
109
+ if (state.effectiveAt === "NEXT_PAYMENT_DATE" && (!latest.currentCycle?.endedDate || Date.parse(latest.currentCycle.endedDate) <= Date.now())) {
110
+ order = latest; return { ...project(latest), actionMessage: copyParam("subscriptionDetail.changedBeforeCancel", "Your subscription changed. Review the details before canceling.") };
111
+ }
112
+ await requestCancellation(id, state.effectiveAt === "NEXT_PAYMENT_DATE" ? "NEXT_PAYMENT_DATE" : "IMMEDIATELY");
113
+ // An accepted write remains fenced for its original member even when a session
114
+ // change overtakes its response. Check ownership before publishing, not before
115
+ // remembering the acknowledgement; reads can still report ACTIVE afterward.
116
+ cancellationsSent.add(requestKey);
117
+ if (!isCurrent()) return load(svc.getState());
118
+ await assertMemberAccess(member);
119
+ if (!isCurrent()) return load(svc.getState());
120
+ const refreshed = (await getMyPlanOrder(id)).order;
121
+ await assertMemberAccess(member);
122
+ if (!isCurrent()) return load(svc.getState());
123
+ order = refreshed;
124
+ return project(refreshed, canCancel(refreshed) ? copyParam("subscriptionDetail.cancelPending", "Cancellation requested. Refresh to see the latest status.") : "");
125
+ } catch (error) {
126
+ if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
127
+ if (await memberChanged(member, error)) { order = null; orderMemberKey = ""; void svc.clear(); void svc.load(); return undefined; }
128
+ if (!isCurrent()) return seq === sequence ? load(svc.getState()) : undefined;
129
+ return { ...state, busy: false, hideConfirmation: true, showConfirmation: false, actionError: cancellationsSent.has(requestKey) ? "cancelRefreshFailed" : memberAccessDenied(error) ? "cancelDenied" : "cancelFailed", hasActionError: true, noActionError: false, hideCancel: cancellationsSent.has(requestKey) || memberAccessDenied(error) || state.hideCancel,
130
+ actionMessage: cancellationsSent.has(requestKey) ? copyParam("subscriptionDetail.cancelRefreshFailed", "Cancellation requested, but the latest status could not be loaded. Refresh the details.")
131
+ : memberAccessDenied(error) ? copyParam("subscriptionDetail.cancelDenied", "This subscription cannot be canceled from this account. Contact the business for help.")
132
+ : copyParam("subscriptionDetail.cancelFailed", "Cancellation failed. Try again.") };
133
+ } finally { cancelInFlight = false; }
37
134
  },
38
135
  },
39
136
  });
137
+ session.subscribe(() => { ++sequence; order = null; orderMemberKey = ""; void svc.clear(); void svc.load(); });
40
138
  svc.load();
41
139
  export { svc };
@@ -114,9 +114,22 @@
114
114
  "sm": 8,
115
115
  "md": 12,
116
116
  "lg": 16,
117
- "xl": 24
117
+ "xl": 24,
118
+ "pricingScreenMargin": 20
118
119
  },
119
120
  "typography": {
121
+ "pricingTitle": {
122
+ "size": 24,
123
+ "weight": 700,
124
+ "line": 1.2,
125
+ "letterSpacing": 0
126
+ },
127
+ "pricingSection": {
128
+ "size": 14,
129
+ "weight": 700,
130
+ "line": 1.4,
131
+ "letterSpacing": 0
132
+ },
120
133
  "pageTitle": {
121
134
  "size": 28,
122
135
  "weight": 400,
@@ -195,6 +208,9 @@
195
208
  },
196
209
  "controls": {
197
210
  "button": {
211
+ "md": {
212
+ "text": "bodyEmphasis"
213
+ },
198
214
  "variants": {
199
215
  "tertiary": {
200
216
  "label": "textPrimary"
@@ -1,63 +0,0 @@
1
- import { descriptionBody } from "../_shared/rich-body.js";
2
- // Tier-5 bundle: Wix Spaces clone — Pricing plan detail (ON-DEVICE, site-scoped).
3
- // himalaya.input.id carries the plan id.
4
- //
5
- // Read from the PUBLIC plans (GET /pricing-plans/v2/plans/public — what the plans list
6
- // shows), not from getPlan: GET /pricing-plans/v2/plans/{id} is the management read, and a
7
- // hosted site's member or visitor gets a 403 from it, which rendered "couldn't be loaded"
8
- // for every plan the list had just shown. getPlan stays as the fallback for a plan that is
9
- // not public, for a caller that may read it (an owner-scope host).
10
- import { withIapPresentation } from "../_shared/iap-presentation.js";
11
- import { getPlan, listPublicPlans, type WixPlan } from "@himalaya/wix-pricing-plans";
12
- import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
13
-
14
- interface S extends PresenceFlags { status: "loading" | "ready"; name: string; price: string; description: string; perks: string }
15
-
16
- function priceOf(p: WixPlan): string {
17
- const m = p.pricing?.price as unknown as { formattedAmount?: string; amount?: string; value?: string; currency?: string } | undefined;
18
- if (!m) return p.pricing?.freeTrialDays ? "Free trial" : "";
19
- return m.formattedAmount || [m.amount ?? m.value, m.currency].filter(Boolean).join(" ");
20
- }
21
-
22
- /** The plan, or null when it is not public and the caller may not read it otherwise. */
23
- async function readPlan(id: string): Promise<WixPlan | null> {
24
- let publicRead = false;
25
- try {
26
- const listed = await listPublicPlans();
27
- publicRead = true;
28
- const hit = (listed?.plans ?? []).find((plan) => plan?.id === id);
29
- if (hit) return hit;
30
- } catch (e) { void e; }
31
- try {
32
- const res = await getPlan(id);
33
- return ((res as unknown as { plan?: WixPlan }).plan) ?? (res as unknown as WixPlan);
34
- } catch (e) {
35
- // The public read worked, so the device is online: a refused or empty management
36
- // read means this plan is not one the viewer can see — not-found, not offline.
37
- if (publicRead) return null;
38
- throw e;
39
- }
40
- }
41
-
42
- const defineService = withIapPresentation<S>({
43
- prefix: "plans", transientKeys: ["price"], contentActions: ["load"],
44
- items: state => detailInputId() ? [{ reference: { kind: "pricingPlan", id: detailInputId() }, commerceDisplayPrice: state.price }] : [],
45
- present: (state, price) => ({ ...state, price: price(detailInputId()) }),
46
- });
47
- const svc = defineService<S, { load: (s: S) => Promise<S> }>("spacesPlanDetail", {
48
- state: { status: "loading", name: "", price: "", description: "", perks: "", ...presence("loading") },
49
- actions: {
50
- load: async (s) => {
51
- const id = detailInputId();
52
- if (!id) return { ...s, status: "ready", ...presence("missing") };
53
- try {
54
- const p = await readPlan(id);
55
- if (!p) return { ...s, status: "ready", ...presence("missing") };
56
- const perks = (p.perks?.values ?? []).map((v) => `• ${v}`).join("\n");
57
- return { status: "ready", name: p.name || "Plan", price: priceOf(p), description: descriptionBody(p.description).bodyText, perks, ...presence("found") };
58
- } catch (e) { return { ...s, status: "ready", ...presenceAfterError(e) }; }
59
- },
60
- },
61
- });
62
- svc.load();
63
- export { svc };
@@ -1,63 +0,0 @@
1
- import { descriptionBody } from "../_shared/rich-body.js";
2
- // Tier-5 bundle: Wix Spaces clone — Pricing plan detail (ON-DEVICE, site-scoped).
3
- // himalaya.input.id carries the plan id.
4
- //
5
- // Read from the PUBLIC plans (GET /pricing-plans/v2/plans/public — what the plans list
6
- // shows), not from getPlan: GET /pricing-plans/v2/plans/{id} is the management read, and a
7
- // hosted site's member or visitor gets a 403 from it, which rendered "couldn't be loaded"
8
- // for every plan the list had just shown. getPlan stays as the fallback for a plan that is
9
- // not public, for a caller that may read it (an owner-scope host).
10
- import { withIapPresentation } from "../_shared/iap-presentation.js";
11
- import { getPlan, listPublicPlans, type WixPlan } from "@himalaya/wix-pricing-plans";
12
- import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
13
-
14
- interface S extends PresenceFlags { status: "loading" | "ready"; name: string; price: string; description: string; perks: string }
15
-
16
- function priceOf(p: WixPlan): string {
17
- const m = p.pricing?.price as unknown as { formattedAmount?: string; amount?: string; value?: string; currency?: string } | undefined;
18
- if (!m) return p.pricing?.freeTrialDays ? "Free trial" : "";
19
- return m.formattedAmount || [m.amount ?? m.value, m.currency].filter(Boolean).join(" ");
20
- }
21
-
22
- /** The plan, or null when it is not public and the caller may not read it otherwise. */
23
- async function readPlan(id: string): Promise<WixPlan | null> {
24
- let publicRead = false;
25
- try {
26
- const listed = await listPublicPlans();
27
- publicRead = true;
28
- const hit = (listed?.plans ?? []).find((plan) => plan?.id === id);
29
- if (hit) return hit;
30
- } catch (e) { void e; }
31
- try {
32
- const res = await getPlan(id);
33
- return ((res as unknown as { plan?: WixPlan }).plan) ?? (res as unknown as WixPlan);
34
- } catch (e) {
35
- // The public read worked, so the device is online: a refused or empty management
36
- // read means this plan is not one the viewer can see — not-found, not offline.
37
- if (publicRead) return null;
38
- throw e;
39
- }
40
- }
41
-
42
- const defineService = withIapPresentation<S>({
43
- prefix: "plans", transientKeys: ["price"], contentActions: ["load"],
44
- items: state => detailInputId() ? [{ reference: { kind: "pricingPlan", id: detailInputId() }, commerceDisplayPrice: state.price }] : [],
45
- present: (state, price) => ({ ...state, price: price(detailInputId()) }),
46
- });
47
- const svc = defineService<S, { load: (s: S) => Promise<S> }>("spacesPlanDetail", {
48
- state: { status: "loading", name: "", price: "", description: "", perks: "", ...presence("loading") },
49
- actions: {
50
- load: async (s) => {
51
- const id = detailInputId();
52
- if (!id) return { ...s, status: "ready", ...presence("missing") };
53
- try {
54
- const p = await readPlan(id);
55
- if (!p) return { ...s, status: "ready", ...presence("missing") };
56
- const perks = (p.perks?.values ?? []).map((v) => `• ${v}`).join("\n");
57
- return { status: "ready", name: p.name || "Plan", price: priceOf(p), description: descriptionBody(p.description).bodyText, perks, ...presence("found") };
58
- } catch (e) { return { ...s, status: "ready", ...presenceAfterError(e) }; }
59
- },
60
- },
61
- });
62
- svc.load();
63
- export { svc };
@@ -1,63 +0,0 @@
1
- import { descriptionBody } from "../_shared/rich-body.js";
2
- // Tier-5 bundle: Wix Spaces clone — Pricing plan detail (ON-DEVICE, site-scoped).
3
- // himalaya.input.id carries the plan id.
4
- //
5
- // Read from the PUBLIC plans (GET /pricing-plans/v2/plans/public — what the plans list
6
- // shows), not from getPlan: GET /pricing-plans/v2/plans/{id} is the management read, and a
7
- // hosted site's member or visitor gets a 403 from it, which rendered "couldn't be loaded"
8
- // for every plan the list had just shown. getPlan stays as the fallback for a plan that is
9
- // not public, for a caller that may read it (an owner-scope host).
10
- import { withIapPresentation } from "../_shared/iap-presentation.js";
11
- import { getPlan, listPublicPlans, type WixPlan } from "@himalaya/wix-pricing-plans";
12
- import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
13
-
14
- interface S extends PresenceFlags { status: "loading" | "ready"; name: string; price: string; description: string; perks: string }
15
-
16
- function priceOf(p: WixPlan): string {
17
- const m = p.pricing?.price as unknown as { formattedAmount?: string; amount?: string; value?: string; currency?: string } | undefined;
18
- if (!m) return p.pricing?.freeTrialDays ? "Free trial" : "";
19
- return m.formattedAmount || [m.amount ?? m.value, m.currency].filter(Boolean).join(" ");
20
- }
21
-
22
- /** The plan, or null when it is not public and the caller may not read it otherwise. */
23
- async function readPlan(id: string): Promise<WixPlan | null> {
24
- let publicRead = false;
25
- try {
26
- const listed = await listPublicPlans();
27
- publicRead = true;
28
- const hit = (listed?.plans ?? []).find((plan) => plan?.id === id);
29
- if (hit) return hit;
30
- } catch (e) { void e; }
31
- try {
32
- const res = await getPlan(id);
33
- return ((res as unknown as { plan?: WixPlan }).plan) ?? (res as unknown as WixPlan);
34
- } catch (e) {
35
- // The public read worked, so the device is online: a refused or empty management
36
- // read means this plan is not one the viewer can see — not-found, not offline.
37
- if (publicRead) return null;
38
- throw e;
39
- }
40
- }
41
-
42
- const defineService = withIapPresentation<S>({
43
- prefix: "plans", transientKeys: ["price"], contentActions: ["load"],
44
- items: state => detailInputId() ? [{ reference: { kind: "pricingPlan", id: detailInputId() }, commerceDisplayPrice: state.price }] : [],
45
- present: (state, price) => ({ ...state, price: price(detailInputId()) }),
46
- });
47
- const svc = defineService<S, { load: (s: S) => Promise<S> }>("spacesPlanDetail", {
48
- state: { status: "loading", name: "", price: "", description: "", perks: "", ...presence("loading") },
49
- actions: {
50
- load: async (s) => {
51
- const id = detailInputId();
52
- if (!id) return { ...s, status: "ready", ...presence("missing") };
53
- try {
54
- const p = await readPlan(id);
55
- if (!p) return { ...s, status: "ready", ...presence("missing") };
56
- const perks = (p.perks?.values ?? []).map((v) => `• ${v}`).join("\n");
57
- return { status: "ready", name: p.name || "Plan", price: priceOf(p), description: descriptionBody(p.description).bodyText, perks, ...presence("found") };
58
- } catch (e) { return { ...s, status: "ready", ...presenceAfterError(e) }; }
59
- },
60
- },
61
- });
62
- svc.load();
63
- export { svc };
@@ -1,63 +0,0 @@
1
- import { descriptionBody } from "../_shared/rich-body.js";
2
- // Tier-5 bundle: Wix Spaces clone — Pricing plan detail (ON-DEVICE, site-scoped).
3
- // himalaya.input.id carries the plan id.
4
- //
5
- // Read from the PUBLIC plans (GET /pricing-plans/v2/plans/public — what the plans list
6
- // shows), not from getPlan: GET /pricing-plans/v2/plans/{id} is the management read, and a
7
- // hosted site's member or visitor gets a 403 from it, which rendered "couldn't be loaded"
8
- // for every plan the list had just shown. getPlan stays as the fallback for a plan that is
9
- // not public, for a caller that may read it (an owner-scope host).
10
- import { withIapPresentation } from "../_shared/iap-presentation.js";
11
- import { getPlan, listPublicPlans, type WixPlan } from "@himalaya/wix-pricing-plans";
12
- import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
13
-
14
- interface S extends PresenceFlags { status: "loading" | "ready"; name: string; price: string; description: string; perks: string }
15
-
16
- function priceOf(p: WixPlan): string {
17
- const m = p.pricing?.price as unknown as { formattedAmount?: string; amount?: string; value?: string; currency?: string } | undefined;
18
- if (!m) return p.pricing?.freeTrialDays ? "Free trial" : "";
19
- return m.formattedAmount || [m.amount ?? m.value, m.currency].filter(Boolean).join(" ");
20
- }
21
-
22
- /** The plan, or null when it is not public and the caller may not read it otherwise. */
23
- async function readPlan(id: string): Promise<WixPlan | null> {
24
- let publicRead = false;
25
- try {
26
- const listed = await listPublicPlans();
27
- publicRead = true;
28
- const hit = (listed?.plans ?? []).find((plan) => plan?.id === id);
29
- if (hit) return hit;
30
- } catch (e) { void e; }
31
- try {
32
- const res = await getPlan(id);
33
- return ((res as unknown as { plan?: WixPlan }).plan) ?? (res as unknown as WixPlan);
34
- } catch (e) {
35
- // The public read worked, so the device is online: a refused or empty management
36
- // read means this plan is not one the viewer can see — not-found, not offline.
37
- if (publicRead) return null;
38
- throw e;
39
- }
40
- }
41
-
42
- const defineService = withIapPresentation<S>({
43
- prefix: "plans", transientKeys: ["price"], contentActions: ["load"],
44
- items: state => detailInputId() ? [{ reference: { kind: "pricingPlan", id: detailInputId() }, commerceDisplayPrice: state.price }] : [],
45
- present: (state, price) => ({ ...state, price: price(detailInputId()) }),
46
- });
47
- const svc = defineService<S, { load: (s: S) => Promise<S> }>("spacesPlanDetail", {
48
- state: { status: "loading", name: "", price: "", description: "", perks: "", ...presence("loading") },
49
- actions: {
50
- load: async (s) => {
51
- const id = detailInputId();
52
- if (!id) return { ...s, status: "ready", ...presence("missing") };
53
- try {
54
- const p = await readPlan(id);
55
- if (!p) return { ...s, status: "ready", ...presence("missing") };
56
- const perks = (p.perks?.values ?? []).map((v) => `• ${v}`).join("\n");
57
- return { status: "ready", name: p.name || "Plan", price: priceOf(p), description: descriptionBody(p.description).bodyText, perks, ...presence("found") };
58
- } catch (e) { return { ...s, status: "ready", ...presenceAfterError(e) }; }
59
- },
60
- },
61
- });
62
- svc.load();
63
- export { svc };
@@ -1,63 +0,0 @@
1
- import { descriptionBody } from "../_shared/rich-body.js";
2
- // Tier-5 bundle: Wix Spaces clone — Pricing plan detail (ON-DEVICE, site-scoped).
3
- // himalaya.input.id carries the plan id.
4
- //
5
- // Read from the PUBLIC plans (GET /pricing-plans/v2/plans/public — what the plans list
6
- // shows), not from getPlan: GET /pricing-plans/v2/plans/{id} is the management read, and a
7
- // hosted site's member or visitor gets a 403 from it, which rendered "couldn't be loaded"
8
- // for every plan the list had just shown. getPlan stays as the fallback for a plan that is
9
- // not public, for a caller that may read it (an owner-scope host).
10
- import { withIapPresentation } from "../_shared/iap-presentation.js";
11
- import { getPlan, listPublicPlans, type WixPlan } from "@himalaya/wix-pricing-plans";
12
- import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
13
-
14
- interface S extends PresenceFlags { status: "loading" | "ready"; name: string; price: string; description: string; perks: string }
15
-
16
- function priceOf(p: WixPlan): string {
17
- const m = p.pricing?.price as unknown as { formattedAmount?: string; amount?: string; value?: string; currency?: string } | undefined;
18
- if (!m) return p.pricing?.freeTrialDays ? "Free trial" : "";
19
- return m.formattedAmount || [m.amount ?? m.value, m.currency].filter(Boolean).join(" ");
20
- }
21
-
22
- /** The plan, or null when it is not public and the caller may not read it otherwise. */
23
- async function readPlan(id: string): Promise<WixPlan | null> {
24
- let publicRead = false;
25
- try {
26
- const listed = await listPublicPlans();
27
- publicRead = true;
28
- const hit = (listed?.plans ?? []).find((plan) => plan?.id === id);
29
- if (hit) return hit;
30
- } catch (e) { void e; }
31
- try {
32
- const res = await getPlan(id);
33
- return ((res as unknown as { plan?: WixPlan }).plan) ?? (res as unknown as WixPlan);
34
- } catch (e) {
35
- // The public read worked, so the device is online: a refused or empty management
36
- // read means this plan is not one the viewer can see — not-found, not offline.
37
- if (publicRead) return null;
38
- throw e;
39
- }
40
- }
41
-
42
- const defineService = withIapPresentation<S>({
43
- prefix: "plans", transientKeys: ["price"], contentActions: ["load"],
44
- items: state => detailInputId() ? [{ reference: { kind: "pricingPlan", id: detailInputId() }, commerceDisplayPrice: state.price }] : [],
45
- present: (state, price) => ({ ...state, price: price(detailInputId()) }),
46
- });
47
- const svc = defineService<S, { load: (s: S) => Promise<S> }>("spacesPlanDetail", {
48
- state: { status: "loading", name: "", price: "", description: "", perks: "", ...presence("loading") },
49
- actions: {
50
- load: async (s) => {
51
- const id = detailInputId();
52
- if (!id) return { ...s, status: "ready", ...presence("missing") };
53
- try {
54
- const p = await readPlan(id);
55
- if (!p) return { ...s, status: "ready", ...presence("missing") };
56
- const perks = (p.perks?.values ?? []).map((v) => `• ${v}`).join("\n");
57
- return { status: "ready", name: p.name || "Plan", price: priceOf(p), description: descriptionBody(p.description).bodyText, perks, ...presence("found") };
58
- } catch (e) { return { ...s, status: "ready", ...presenceAfterError(e) }; }
59
- },
60
- },
61
- });
62
- svc.load();
63
- export { svc };
@@ -1,63 +0,0 @@
1
- import { descriptionBody } from "../_shared/rich-body.js";
2
- // Tier-5 bundle: Wix Spaces clone — Pricing plan detail (ON-DEVICE, site-scoped).
3
- // himalaya.input.id carries the plan id.
4
- //
5
- // Read from the PUBLIC plans (GET /pricing-plans/v2/plans/public — what the plans list
6
- // shows), not from getPlan: GET /pricing-plans/v2/plans/{id} is the management read, and a
7
- // hosted site's member or visitor gets a 403 from it, which rendered "couldn't be loaded"
8
- // for every plan the list had just shown. getPlan stays as the fallback for a plan that is
9
- // not public, for a caller that may read it (an owner-scope host).
10
- import { withIapPresentation } from "../_shared/iap-presentation.js";
11
- import { getPlan, listPublicPlans, type WixPlan } from "@himalaya/wix-pricing-plans";
12
- import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
13
-
14
- interface S extends PresenceFlags { status: "loading" | "ready"; name: string; price: string; description: string; perks: string }
15
-
16
- function priceOf(p: WixPlan): string {
17
- const m = p.pricing?.price as unknown as { formattedAmount?: string; amount?: string; value?: string; currency?: string } | undefined;
18
- if (!m) return p.pricing?.freeTrialDays ? "Free trial" : "";
19
- return m.formattedAmount || [m.amount ?? m.value, m.currency].filter(Boolean).join(" ");
20
- }
21
-
22
- /** The plan, or null when it is not public and the caller may not read it otherwise. */
23
- async function readPlan(id: string): Promise<WixPlan | null> {
24
- let publicRead = false;
25
- try {
26
- const listed = await listPublicPlans();
27
- publicRead = true;
28
- const hit = (listed?.plans ?? []).find((plan) => plan?.id === id);
29
- if (hit) return hit;
30
- } catch (e) { void e; }
31
- try {
32
- const res = await getPlan(id);
33
- return ((res as unknown as { plan?: WixPlan }).plan) ?? (res as unknown as WixPlan);
34
- } catch (e) {
35
- // The public read worked, so the device is online: a refused or empty management
36
- // read means this plan is not one the viewer can see — not-found, not offline.
37
- if (publicRead) return null;
38
- throw e;
39
- }
40
- }
41
-
42
- const defineService = withIapPresentation<S>({
43
- prefix: "plans", transientKeys: ["price"], contentActions: ["load"],
44
- items: state => detailInputId() ? [{ reference: { kind: "pricingPlan", id: detailInputId() }, commerceDisplayPrice: state.price }] : [],
45
- present: (state, price) => ({ ...state, price: price(detailInputId()) }),
46
- });
47
- const svc = defineService<S, { load: (s: S) => Promise<S> }>("spacesPlanDetail", {
48
- state: { status: "loading", name: "", price: "", description: "", perks: "", ...presence("loading") },
49
- actions: {
50
- load: async (s) => {
51
- const id = detailInputId();
52
- if (!id) return { ...s, status: "ready", ...presence("missing") };
53
- try {
54
- const p = await readPlan(id);
55
- if (!p) return { ...s, status: "ready", ...presence("missing") };
56
- const perks = (p.perks?.values ?? []).map((v) => `• ${v}`).join("\n");
57
- return { status: "ready", name: p.name || "Plan", price: priceOf(p), description: descriptionBody(p.description).bodyText, perks, ...presence("found") };
58
- } catch (e) { return { ...s, status: "ready", ...presenceAfterError(e) }; }
59
- },
60
- },
61
- });
62
- svc.load();
63
- export { svc };