@wix/himalaya-cli 0.1656.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.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/pricing-plans/src/index.d.ts +37 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/checkout.mjs +2 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +2 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-pricing-plans.mjs +10 -1
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{3912fa5f6ddb60106c630fb5e48edbf12ebfd57c616d8b7aee0d32088cd3bbdf.bin → c04dd5fc5ad48e6b19678d4313159302e9a513ada94bfe515d8dfd5a54d46f5d.bin} +1 -1
- package/dist/browser-plane/sw.js +5 -5
- package/dist/cli.mjs +46 -45
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/getting-started.md +4 -1
- package/guides/himi-skill.md +4 -1
- package/guides/index.json +12 -0
- package/guides/recipe-auth.md +120 -0
- package/guides/recipe-checkout.md +108 -0
- package/guides/sdk-reference.json +21 -3
- package/package.json +2 -2
- package/templates/beauty-salon/dev/index.ts +2151 -2596
- package/templates/beauty-salon/l10n/en.json +208 -180
- package/templates/beauty-salon/l10n/he.json +300 -138
- package/templates/beauty-salon/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/beauty-salon/tier5-src/himi-branded-lite-plans/index.ts +101 -31
- package/templates/beauty-salon/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
- package/templates/beauty-salon/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
- package/templates/beauty-salon/tokens.json +17 -1
- package/templates/branded-lite/dev/index.ts +2272 -2685
- package/templates/branded-lite/l10n/en.json +225 -52
- package/templates/branded-lite/l10n/he.json +305 -39
- package/templates/branded-lite/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-plans/index.ts +101 -31
- package/templates/branded-lite/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
- package/templates/branded-lite/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
- package/templates/branded-lite/tokens.json +5 -1
- package/templates/community-club/l10n/en.json +6 -1
- package/templates/community-club/l10n/he.json +23 -2
- package/templates/community-club/tokens.json +17 -1
- package/templates/events-meetups/l10n/en.json +6 -1
- package/templates/events-meetups/l10n/he.json +23 -2
- package/templates/events-meetups/tokens.json +17 -1
- package/templates/gym-fitness/dev/index.ts +2149 -2594
- package/templates/gym-fitness/l10n/en.json +215 -77
- package/templates/gym-fitness/l10n/he.json +300 -59
- package/templates/gym-fitness/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/gym-fitness/tier5-src/himi-branded-lite-plans/index.ts +101 -31
- package/templates/gym-fitness/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
- package/templates/gym-fitness/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
- package/templates/gym-fitness/tokens.json +17 -1
- package/templates/nonprofit-cause/dev/index.ts +2163 -2608
- package/templates/nonprofit-cause/l10n/en.json +216 -38
- package/templates/nonprofit-cause/l10n/he.json +300 -30
- package/templates/nonprofit-cause/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/nonprofit-cause/tier5-src/himi-branded-lite-plans/index.ts +101 -31
- package/templates/nonprofit-cause/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
- package/templates/nonprofit-cause/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
- package/templates/nonprofit-cause/tokens.json +17 -1
- package/templates/podcast-creator/dev/index.ts +2147 -2592
- package/templates/podcast-creator/l10n/en.json +216 -38
- package/templates/podcast-creator/l10n/he.json +300 -30
- package/templates/podcast-creator/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/podcast-creator/tier5-src/himi-branded-lite-plans/index.ts +101 -31
- package/templates/podcast-creator/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
- package/templates/podcast-creator/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
- package/templates/podcast-creator/tokens.json +17 -1
- package/templates/portfolio-creative/l10n/en.json +15 -8
- package/templates/portfolio-creative/l10n/he.json +28 -6
- package/templates/portfolio-creative/tokens.json +17 -1
- package/templates/restaurant/l10n/en.json +14 -7
- package/templates/restaurant/l10n/he.json +28 -6
- package/templates/restaurant/tokens.json +17 -1
- package/templates/retail-store/l10n/en.json +15 -8
- package/templates/retail-store/l10n/he.json +28 -6
- package/templates/retail-store/tokens.json +17 -1
- package/templates/yoga-studio/dev/index.ts +2204 -2649
- package/templates/yoga-studio/l10n/en.json +216 -43
- package/templates/yoga-studio/l10n/he.json +300 -30
- package/templates/yoga-studio/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/yoga-studio/tier5-src/himi-branded-lite-plans/index.ts +101 -31
- package/templates/yoga-studio/tier5-src/wix-spaces-my-subscriptions/index.ts +72 -70
- package/templates/yoga-studio/tier5-src/wix-spaces-subscription-detail/index.ts +129 -31
- package/templates/yoga-studio/tokens.json +17 -1
- package/templates/beauty-salon/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
- package/templates/branded-lite/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
- package/templates/gym-fitness/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
- package/templates/nonprofit-cause/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
- package/templates/podcast-creator/tier5-src/wix-spaces-plan-detail/index.ts +0 -63
- 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 {
|
|
4
|
-
import {
|
|
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 {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 };
|
|
@@ -106,9 +106,22 @@
|
|
|
106
106
|
"sm": 8,
|
|
107
107
|
"md": 12,
|
|
108
108
|
"lg": 16,
|
|
109
|
-
"xl": 24
|
|
109
|
+
"xl": 24,
|
|
110
|
+
"pricingScreenMargin": 20
|
|
110
111
|
},
|
|
111
112
|
"typography": {
|
|
113
|
+
"pricingTitle": {
|
|
114
|
+
"size": 24,
|
|
115
|
+
"weight": 700,
|
|
116
|
+
"line": 1.2,
|
|
117
|
+
"letterSpacing": 0
|
|
118
|
+
},
|
|
119
|
+
"pricingSection": {
|
|
120
|
+
"size": 14,
|
|
121
|
+
"weight": 700,
|
|
122
|
+
"line": 1.4,
|
|
123
|
+
"letterSpacing": 0
|
|
124
|
+
},
|
|
112
125
|
"pageTitle": {
|
|
113
126
|
"size": 28,
|
|
114
127
|
"weight": 400,
|
|
@@ -187,6 +200,9 @@
|
|
|
187
200
|
},
|
|
188
201
|
"controls": {
|
|
189
202
|
"button": {
|
|
203
|
+
"md": {
|
|
204
|
+
"text": "bodyEmphasis"
|
|
205
|
+
},
|
|
190
206
|
"variants": {
|
|
191
207
|
"tertiary": {
|
|
192
208
|
"label": "textPrimary"
|