@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.
- 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 +109 -62
- 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/qa-builds.md +7 -4
- 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,3 +1,6 @@
|
|
|
1
|
+
import { memberAccess } from "../_shared/member-access.js";
|
|
2
|
+
import { planDuration } from "../_shared/pricing-plan-display.js";
|
|
3
|
+
import { detailInputId } from "../_shared/detail-presence.js";
|
|
1
4
|
import { descriptionBody } from "../_shared/rich-body.js";
|
|
2
5
|
import { paymentSetupMessage } from "../_shared/payment-setup.js";
|
|
3
6
|
import { offlineWriteMessage, offlineWritesEnabled, withOnlineWrites } from "../_shared/online-actions.js";
|
|
@@ -44,6 +47,12 @@ interface PlanRow {
|
|
|
44
47
|
periodLine: string;
|
|
45
48
|
/** First 3 benefit strings (also flattened below for `$item.` bindings). */
|
|
46
49
|
perks: string[];
|
|
50
|
+
benefitRows: Array<{ id: string; text: string }>;
|
|
51
|
+
expanded: boolean; benefitsCollapsed: boolean; benefitsState: string;
|
|
52
|
+
validity: string;
|
|
53
|
+
terms: string;
|
|
54
|
+
noTerms: boolean;
|
|
55
|
+
noBenefits: boolean;
|
|
47
56
|
perk1: string;
|
|
48
57
|
perk2: string;
|
|
49
58
|
perk3: string;
|
|
@@ -68,6 +77,8 @@ interface State {
|
|
|
68
77
|
rows: PlanRow[];
|
|
69
78
|
emptyText: string;
|
|
70
79
|
actionMessage: string;
|
|
80
|
+
hideActionNotice: boolean;
|
|
81
|
+
hideOfflineError: boolean;
|
|
71
82
|
isLoading: boolean;
|
|
72
83
|
notLoading: boolean;
|
|
73
84
|
isErrored: boolean;
|
|
@@ -75,6 +86,13 @@ interface State {
|
|
|
75
86
|
hasRows: boolean;
|
|
76
87
|
noRows: boolean;
|
|
77
88
|
noEmpty: boolean;
|
|
89
|
+
detail: PlanRow;
|
|
90
|
+
hideDetail: boolean;
|
|
91
|
+
hideDetailNotFound: boolean;
|
|
92
|
+
paymentUnavailable: boolean;
|
|
93
|
+
paymentAvailable: boolean;
|
|
94
|
+
needsSignIn: boolean;
|
|
95
|
+
noSignIn: boolean;
|
|
78
96
|
}
|
|
79
97
|
|
|
80
98
|
function money(plan: WixPlan): string {
|
|
@@ -82,7 +100,7 @@ function money(plan: WixPlan): string {
|
|
|
82
100
|
const raw = price?.value;
|
|
83
101
|
if (raw == null || raw === "" || Number.isNaN(Number(raw))) return "";
|
|
84
102
|
try {
|
|
85
|
-
return formatCurrency(Number(raw), price
|
|
103
|
+
return price?.currency ? formatCurrency(Number(raw), price.currency) : raw;
|
|
86
104
|
} catch {
|
|
87
105
|
return `${raw}`;
|
|
88
106
|
}
|
|
@@ -102,13 +120,8 @@ function period(plan: WixPlan): string {
|
|
|
102
120
|
const { count, unit } = pricing.subscription.cycleDuration;
|
|
103
121
|
return cycleText(count, unit) || copyParam("plans.periodRecurring", "recurring");
|
|
104
122
|
}
|
|
105
|
-
if (pricing?.singlePaymentForDuration)
|
|
106
|
-
|
|
107
|
-
const n = count ?? 0;
|
|
108
|
-
const u = (unit || "").toLowerCase();
|
|
109
|
-
return n && u ? `for ${n} ${n === 1 ? u.replace(/s$/, "") : u.endsWith("s") ? u : `${u}s`}` : copyParam("plans.periodOneTime", "one-time");
|
|
110
|
-
}
|
|
111
|
-
if (pricing?.singlePaymentUnlimited) return copyParam("plans.periodOneTime", "one-time");
|
|
123
|
+
if (pricing?.singlePaymentForDuration) return copyParam("plans.periodOneTime", "One-time payment");
|
|
124
|
+
if (pricing?.singlePaymentUnlimited) return copyParam("plans.periodOneTime", "One-time payment");
|
|
112
125
|
return "";
|
|
113
126
|
}
|
|
114
127
|
|
|
@@ -126,15 +139,14 @@ function joinUrl(plan: WixPlan): string {
|
|
|
126
139
|
|
|
127
140
|
function isFreePlan(plan: WixPlan): boolean {
|
|
128
141
|
const raw = plan.pricing?.price?.value;
|
|
129
|
-
return raw
|
|
142
|
+
return raw !== undefined && raw !== "" && Number(raw) === 0;
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
function planRow(plan: WixPlan): PlanRow {
|
|
133
146
|
const name = (plan.name || copyParam("plans.planFallbackName", "Plan")).trim();
|
|
134
147
|
const perks = (plan.perks?.values ?? [])
|
|
135
148
|
.map((perk) => (perk ?? "").trim())
|
|
136
|
-
.filter(Boolean)
|
|
137
|
-
.slice(0, 3);
|
|
149
|
+
.filter(Boolean);
|
|
138
150
|
const badge = plan.primary ? copyParam("plans.popularBadge", "Popular") : "";
|
|
139
151
|
const trialDays = plan.pricing?.freeTrialDays ?? 0;
|
|
140
152
|
const trialBadge = trialDays > 0 ? copyTemplate("plans.trialBadge", "{days}-day free trial", { days: trialDays }) : "";
|
|
@@ -147,6 +159,12 @@ function planRow(plan: WixPlan): PlanRow {
|
|
|
147
159
|
priceLine: money(plan),
|
|
148
160
|
periodLine: period(plan),
|
|
149
161
|
perks,
|
|
162
|
+
benefitRows: perks.map((text, index) => ({ id: `${plan.id}.benefit.${index}`, text })),
|
|
163
|
+
noBenefits: perks.length === 0,
|
|
164
|
+
expanded: false, benefitsCollapsed: true, benefitsState: "collapsed",
|
|
165
|
+
validity: planDuration(plan.pricing),
|
|
166
|
+
terms: (plan as WixPlan & { termsAndConditions?: string }).termsAndConditions ?? "",
|
|
167
|
+
noTerms: !(plan as WixPlan & { termsAndConditions?: string }).termsAndConditions,
|
|
150
168
|
perk1: perks[0] ?? "",
|
|
151
169
|
perk2: perks[1] ?? "",
|
|
152
170
|
perk3: perks[2] ?? "",
|
|
@@ -156,7 +174,7 @@ function planRow(plan: WixPlan): PlanRow {
|
|
|
156
174
|
joinUrl: joinUrl(plan),
|
|
157
175
|
free: isFreePlan(plan),
|
|
158
176
|
appleSupported: plan.pricing?.singlePaymentUnlimited === true,
|
|
159
|
-
joined: false, joinLabel: copyParam("plans.joinCta", "
|
|
177
|
+
joined: false, joinLabel: copyParam("plans.joinCta", "Continue"), joinDisabled: true, joinNote: "",
|
|
160
178
|
};
|
|
161
179
|
}
|
|
162
180
|
|
|
@@ -166,6 +184,8 @@ function ready(rows: PlanRow[], actionMessage = ""): State {
|
|
|
166
184
|
rows,
|
|
167
185
|
emptyText: rows.length ? "" : copyParam("plans.emptyText", "No membership plans are published yet."),
|
|
168
186
|
actionMessage,
|
|
187
|
+
hideActionNotice: !actionMessage || actionMessage === offlineWriteMessage || actionMessage === paymentSetupMessage("plans"),
|
|
188
|
+
hideOfflineError: actionMessage !== offlineWriteMessage,
|
|
169
189
|
isLoading: false,
|
|
170
190
|
notLoading: true,
|
|
171
191
|
isErrored: false,
|
|
@@ -173,6 +193,7 @@ function ready(rows: PlanRow[], actionMessage = ""): State {
|
|
|
173
193
|
hasRows: rows.length > 0,
|
|
174
194
|
noRows: rows.length === 0,
|
|
175
195
|
noEmpty: rows.length > 0,
|
|
196
|
+
detail: planRow({ id: "" }), hideDetail: true, hideDetailNotFound: true, paymentUnavailable: false, paymentAvailable: true, needsSignIn: false, noSignIn: true,
|
|
176
197
|
};
|
|
177
198
|
}
|
|
178
199
|
|
|
@@ -182,10 +203,23 @@ function idOf(arg: unknown): string {
|
|
|
182
203
|
return typeof value === "string" ? value : "";
|
|
183
204
|
}
|
|
184
205
|
|
|
206
|
+
/** Detail actions carry no live service binding in their arguments. The worker owns the ID. */
|
|
207
|
+
function joinId(state: State, arg: unknown): string {
|
|
208
|
+
const id = idOf(arg);
|
|
209
|
+
const current = detailInputId();
|
|
210
|
+
// Input changes reach the worker before the next load reducer. An old detail
|
|
211
|
+
// can still be painted in that gap; neither its implicit nor explicit ID may charge it.
|
|
212
|
+
if (current) return state.detail.id === current && (!id || id === current) ? current : "";
|
|
213
|
+
return id;
|
|
214
|
+
}
|
|
215
|
+
|
|
185
216
|
const commerce = createIapCommerce({ adapters: [pricingPlanOrders], onChange: () => { void svc.pricingPublish(); } });
|
|
217
|
+
let detailMember = false;
|
|
218
|
+
const expandedPlans = new Set<string>();
|
|
186
219
|
let rows: PlanRow[] = [];
|
|
187
220
|
let items: IapCatalogItem[] = [];
|
|
188
221
|
let message = "";
|
|
222
|
+
let messagePlanId = "";
|
|
189
223
|
let started = false;
|
|
190
224
|
let loading = 0;
|
|
191
225
|
let contentReady = false;
|
|
@@ -207,22 +241,29 @@ function pricedState(state: State): State {
|
|
|
207
241
|
const apple = purchase.appleRoute;
|
|
208
242
|
const regularReady = regularGeneration === memberSession.current().generation && (!memberSession.identityBound || memberSession.current().kind === "member");
|
|
209
243
|
const joined = apple ? purchase.accessReady : regularReady && regularAccess.has(row.id);
|
|
210
|
-
return { ...row, priceLine: view.route === "disabled" ? row.priceLine : price.priceText,
|
|
244
|
+
return { ...row, expanded: expandedPlans.has(row.id), benefitsCollapsed: !expandedPlans.has(row.id), benefitsState: expandedPlans.has(row.id) ? "expanded" : "collapsed", priceLine: view.route === "disabled" ? row.priceLine : price.priceText,
|
|
211
245
|
periodLine: apple ? price.priceNote : view.route === "regular" || view.route === "disabled" ? row.periodLine : "",
|
|
212
246
|
trialBadge: apple || price.actionDisabled ? "" : row.trialBadge,
|
|
247
|
+
validity: apple ? "" : row.validity,
|
|
213
248
|
noTrialBadge: apple || price.actionDisabled || row.noTrialBadge,
|
|
214
249
|
joined,
|
|
215
250
|
joinLabel: joined ? copyParam("plans.joinedLabel", "Current plan") : apple ? purchase.buyLabel : row.joinLabel,
|
|
216
251
|
joinDisabled: joined || (apple ? purchase.buyDisabled || !row.appleSupported : price.actionDisabled || !regularReady) || joining.has(row.id),
|
|
217
252
|
joinNote: apple ? row.appleSupported ? purchase.buyNote : iapPriceCopy("plans").purchaseUnavailable : price.actionNote };
|
|
218
253
|
});
|
|
219
|
-
const
|
|
254
|
+
const detail = priced.find(row => row.id === detailInputId()) ?? null;
|
|
255
|
+
const owned = detailInputId() ? detail?.joined ? detail : undefined : priced.find(row => row.joined);
|
|
256
|
+
const notice = !detailInputId() || messagePlanId === detailInputId() ? message : "";
|
|
220
257
|
const poll = commerce.pollDirective("himiBrandedPlans.iapPoll");
|
|
221
|
-
return { ...state, ...ready(priced, owned ? copyTemplate("plans.joinedMessage", "You've joined {name}.", { name: owned.name }) :
|
|
258
|
+
return { ...state, ...ready(priced, notice || (owned ? copyTemplate("plans.joinedMessage", "You've joined {name}.", { name: owned.name }) : "")), detail: detail ?? planRow({ id: "" }), hideDetail: !detail, hideDetailNotFound: Boolean(detail), paymentUnavailable: notice === paymentSetupMessage("plans"), paymentAvailable: notice !== paymentSetupMessage("plans"), needsSignIn: Boolean(detailInputId()) && !detailMember, noSignIn: !detailInputId() || detailMember, ...(poll ? { _poll: poll } : {}) };
|
|
222
259
|
}
|
|
223
260
|
|
|
224
261
|
async function regularJoinMessage(row: PlanRow, reference: { kind: string; id: string }): Promise<string> {
|
|
225
262
|
const generation = memberSession.current().generation;
|
|
263
|
+
const sourceDetail = detailInputId();
|
|
264
|
+
const isCurrent = (): boolean => generation === memberSession.current().generation && detailInputId() === sourceDetail;
|
|
265
|
+
const mayContinue = (): boolean => isCurrent() && commerce.pricing.continueCheckoutGuard(reference).allowed;
|
|
266
|
+
if (!mayContinue()) return "";
|
|
226
267
|
if (row.joinUrl) {
|
|
227
268
|
try {
|
|
228
269
|
const result = await openUrl(row.joinUrl, "in_app_browser");
|
|
@@ -230,6 +271,7 @@ async function regularJoinMessage(row: PlanRow, reference: { kind: string; id: s
|
|
|
230
271
|
} catch {
|
|
231
272
|
}
|
|
232
273
|
}
|
|
274
|
+
if (!mayContinue()) return "";
|
|
233
275
|
// Hosted inside a host shell (Spaces) a plan cannot be paid in-app: classic Pricing Plans is not on
|
|
234
276
|
// ecom, so the host's member checkout has no checkout to open, and the redirect session needs a
|
|
235
277
|
// headless OAuth client a hosted app does not have. An online order created here would only be
|
|
@@ -245,11 +287,11 @@ async function regularJoinMessage(row: PlanRow, reference: { kind: string; id: s
|
|
|
245
287
|
let opened: boolean | "withdrawn";
|
|
246
288
|
try {
|
|
247
289
|
opened = await hostedSitePageOpener({ page: "plans", planId: row.id })(
|
|
248
|
-
async () =>
|
|
290
|
+
async () => mayContinue());
|
|
249
291
|
} finally {
|
|
250
292
|
hostedPlanOpenInFlight = false;
|
|
251
293
|
}
|
|
252
|
-
if (
|
|
294
|
+
if (!isCurrent()) return "";
|
|
253
295
|
if (opened === "withdrawn") return "";
|
|
254
296
|
if (opened === true) {
|
|
255
297
|
return copyTemplate("plans.continueOnSiteMessage", "Finish joining {name} on the site.", { name: row.name });
|
|
@@ -257,11 +299,12 @@ async function regularJoinMessage(row: PlanRow, reference: { kind: string; id: s
|
|
|
257
299
|
return copyTemplate("plans.joinOnSiteMessage", "Memberships are purchased on the website — visit the site to join {name}.", { name: row.name });
|
|
258
300
|
}
|
|
259
301
|
// A link may fail to open. Its fallback becomes a write and needs its own preflight.
|
|
302
|
+
if (!mayContinue()) return "";
|
|
260
303
|
if (offlineWritesEnabled && !connectivity().online) return offlineWriteMessage;
|
|
261
304
|
try {
|
|
262
305
|
const created = await createOnlineOrder(row.id);
|
|
263
306
|
const snapshotId = created.purchaseFlowId;
|
|
264
|
-
if (
|
|
307
|
+
if (!isCurrent()) return "";
|
|
265
308
|
if (created.order?.status === "ACTIVE") {
|
|
266
309
|
regularAccess.add(row.id);
|
|
267
310
|
return copyTemplate("plans.joinedMessage", "You've joined {name}.", { name: row.name });
|
|
@@ -270,19 +313,19 @@ async function regularJoinMessage(row: PlanRow, reference: { kind: string; id: s
|
|
|
270
313
|
appId: WIX_PRICING_PLANS_APP_ID,
|
|
271
314
|
snapshotId: snapshotId ?? "",
|
|
272
315
|
msid: await resolveMsid(),
|
|
273
|
-
mayCharge:
|
|
316
|
+
mayCharge: mayContinue,
|
|
274
317
|
cashierUrl: async () => {
|
|
275
|
-
if (!
|
|
318
|
+
if (!mayContinue()) return undefined;
|
|
276
319
|
const redirect = await createRedirectSession({
|
|
277
320
|
paidPlansCheckout: { planId: row.id },
|
|
278
321
|
callbacks: { postFlowUrl: "himalaya-himi-branded-lite://screen/himi_plans" },
|
|
279
322
|
});
|
|
280
|
-
return redirect.redirectSession?.fullUrl;
|
|
323
|
+
return mayContinue() ? redirect.redirectSession?.fullUrl : undefined;
|
|
281
324
|
},
|
|
282
325
|
});
|
|
283
326
|
if (pay.kind === "paid") {
|
|
284
327
|
const access = await entitlement(row.id);
|
|
285
|
-
if (
|
|
328
|
+
if (!isCurrent()) return "";
|
|
286
329
|
if (access.entitled) regularAccess.add(row.id);
|
|
287
330
|
return access.entitled
|
|
288
331
|
? copyTemplate("plans.joinedMessage", "You've joined {name}.", { name: row.name })
|
|
@@ -299,19 +342,22 @@ async function regularJoinMessage(row: PlanRow, reference: { kind: string; id: s
|
|
|
299
342
|
return copyTemplate("plans.joinOnSiteMessage", "Memberships are purchased on the website — visit the site to join {name}.", { name: row.name });
|
|
300
343
|
}
|
|
301
344
|
|
|
302
|
-
const defineService = withOnlineWrites(registerService, ["join"], {
|
|
345
|
+
const defineService = withOnlineWrites<State>(registerService, ["join"], {
|
|
303
346
|
messageFields: ["actionMessage"],
|
|
347
|
+
derive: state => ({ ...state, hideActionNotice: true, hideOfflineError: false }),
|
|
304
348
|
requiresConnectivity: (_action, state: State, arg) => {
|
|
305
|
-
const row = state.rows.find(candidate => candidate.id ===
|
|
349
|
+
const row = state.rows.find(candidate => candidate.id === joinId(state, arg));
|
|
306
350
|
if (!row || commerce.purchaseFields({ kind: "pricingPlan", id: row.id }, iapPurchaseCopy("plans")).appleRoute) return true;
|
|
307
351
|
return !row.joinUrl && !(isHostedWorker() && !row.free);
|
|
308
352
|
},
|
|
309
353
|
});
|
|
310
354
|
const svc = defineService<State, {
|
|
355
|
+
beginDetailLoad: (state: State) => State;
|
|
311
356
|
load: (state: State, arg?: unknown) => Promise<State | undefined>;
|
|
312
357
|
pricingPublish: (state: State) => State;
|
|
313
358
|
pricingRefresh: (state: State) => Promise<undefined>;
|
|
314
359
|
iapPoll: (state: State) => Promise<undefined>;
|
|
360
|
+
toggleBenefits: (state: State, arg?: unknown) => State;
|
|
315
361
|
join: (state: State, arg?: unknown) => Promise<State | undefined>;
|
|
316
362
|
}>("himiBrandedPlans", {
|
|
317
363
|
state: {
|
|
@@ -319,6 +365,8 @@ const svc = defineService<State, {
|
|
|
319
365
|
rows: [],
|
|
320
366
|
emptyText: "",
|
|
321
367
|
actionMessage: "",
|
|
368
|
+
hideActionNotice: true,
|
|
369
|
+
hideOfflineError: true,
|
|
322
370
|
isLoading: true,
|
|
323
371
|
notLoading: false,
|
|
324
372
|
isErrored: false,
|
|
@@ -326,21 +374,35 @@ const svc = defineService<State, {
|
|
|
326
374
|
hasRows: false,
|
|
327
375
|
noRows: true,
|
|
328
376
|
noEmpty: true,
|
|
377
|
+
detail: planRow({ id: "" }), hideDetail: true, hideDetailNotFound: true, paymentUnavailable: false, paymentAvailable: true, needsSignIn: false, noSignIn: true,
|
|
329
378
|
},
|
|
330
|
-
notHydrated: ["rows", "actionMessage"],
|
|
379
|
+
notHydrated: ["rows", "actionMessage", "detail", "hideDetail", "hideDetailNotFound"],
|
|
331
380
|
actions: {
|
|
381
|
+
beginDetailLoad: state => ({ ...state, status: "loading", isLoading: true, notLoading: false,
|
|
382
|
+
notErrored: true, isErrored: false, noEmpty: true, detail: planRow({ id: "" }),
|
|
383
|
+
hideDetail: true, hideDetailNotFound: true, actionMessage: "", hideActionNotice: true, hideOfflineError: true }),
|
|
384
|
+
toggleBenefits: (state, arg) => {
|
|
385
|
+
const id = idOf(arg);
|
|
386
|
+
if (expandedPlans.has(id)) expandedPlans.delete(id); else expandedPlans.add(id);
|
|
387
|
+
return pricedState(state);
|
|
388
|
+
},
|
|
332
389
|
pricingPublish: pricedState,
|
|
333
390
|
pricingRefresh: async () => { await commerce.loadPrices(items); return undefined; },
|
|
334
391
|
iapPoll: async () => { await commerce.poll(); void svc.pricingPublish(); return undefined; },
|
|
335
392
|
load: async (state, arg) => {
|
|
336
393
|
stashCopy(arg);
|
|
337
394
|
const seq = ++loading;
|
|
395
|
+
if (detailInputId() && state.detail.id !== detailInputId()) {
|
|
396
|
+
contentReady = false;
|
|
397
|
+
void svc.beginDetailLoad();
|
|
398
|
+
}
|
|
338
399
|
const generation = memberSession.current().generation;
|
|
339
400
|
regularGeneration = -1;
|
|
340
401
|
regularAccess = new Set();
|
|
341
402
|
try {
|
|
342
|
-
const response = await listPublicPlans();
|
|
343
|
-
if (seq !== loading) return undefined;
|
|
403
|
+
const [response, member] = await Promise.all([listPublicPlans(), detailInputId() ? memberSession.identityBound ? Promise.resolve(memberSession.current().kind === "member") : memberAccess().then(value => Boolean(value.email)) : Promise.resolve(false)]);
|
|
404
|
+
if (seq !== loading || generation !== memberSession.current().generation) return undefined;
|
|
405
|
+
detailMember = member;
|
|
344
406
|
message = "";
|
|
345
407
|
contentReady = true;
|
|
346
408
|
rows = (response.plans ?? []).filter(plan => !plan.archived).map(planRow);
|
|
@@ -369,12 +431,13 @@ const svc = defineService<State, {
|
|
|
369
431
|
isErrored: true,
|
|
370
432
|
notErrored: false,
|
|
371
433
|
noEmpty: true,
|
|
434
|
+
detail: planRow({ id: "" }), hideDetail: true, hideDetailNotFound: true,
|
|
372
435
|
};
|
|
373
436
|
}
|
|
374
437
|
},
|
|
375
438
|
join: async (state, arg) => {
|
|
376
|
-
const row = state.rows.find((candidate) => candidate.id ===
|
|
377
|
-
if (!row || joining.has(row.id)) return undefined;
|
|
439
|
+
const row = state.rows.find((candidate) => candidate.id === joinId(state, arg));
|
|
440
|
+
if ((detailInputId() && !detailMember) || !row || joining.has(row.id)) return undefined;
|
|
378
441
|
const reference = { kind: "pricingPlan", id: row.id };
|
|
379
442
|
const purchase = commerce.purchaseFields(reference, iapPurchaseCopy("plans"));
|
|
380
443
|
if (purchase.accessReady) return undefined;
|
|
@@ -387,8 +450,14 @@ const svc = defineService<State, {
|
|
|
387
450
|
if (regularGeneration !== memberSession.current().generation || (memberSession.identityBound && memberSession.current().kind !== "member") || regularAccess.has(row.id) || !commerce.pricing.checkoutGuard(reference).allowed) return undefined;
|
|
388
451
|
joining.add(row.id);
|
|
389
452
|
void svc.pricingPublish();
|
|
453
|
+
const generation = memberSession.current().generation;
|
|
390
454
|
try {
|
|
391
|
-
|
|
455
|
+
const outcome = await regularJoinMessage(row, reference);
|
|
456
|
+
// An older plan's completion must not replace the current detail's notice.
|
|
457
|
+
if (generation === memberSession.current().generation && (!detailInputId() || detailInputId() === row.id)) {
|
|
458
|
+
message = outcome;
|
|
459
|
+
messagePlanId = row.id;
|
|
460
|
+
}
|
|
392
461
|
return undefined;
|
|
393
462
|
} finally {
|
|
394
463
|
joining.delete(row.id);
|
|
@@ -404,9 +473,10 @@ const svc = defineService<State, {
|
|
|
404
473
|
// loading skeleton indefinitely on iOS. onAppear still fires afterwards and
|
|
405
474
|
// re-loads with the screen's copy pack; it passes no required params here
|
|
406
475
|
// (`appear(..., undefined, "<prefix>.")`), so a param-less first load is safe.
|
|
407
|
-
resetUnhydratedKeysOnOlderRuntime(svc, { ...svc.getState(), rows: [], actionMessage: "" }, ["rows", "actionMessage"]);
|
|
476
|
+
resetUnhydratedKeysOnOlderRuntime(svc, { ...svc.getState(), rows: [], actionMessage: "", detail: planRow({ id: "" }), hideDetail: true, hideDetailNotFound: true }, ["rows", "actionMessage", "detail", "hideDetail", "hideDetailNotFound"]);
|
|
408
477
|
memberSession.subscribe(() => {
|
|
409
478
|
message = "";
|
|
479
|
+
detailMember = false;
|
|
410
480
|
regularGeneration = -1;
|
|
411
481
|
regularAccess = new Set();
|
|
412
482
|
void svc.pricingPublish();
|
|
@@ -1,82 +1,84 @@
|
|
|
1
|
-
// Tier-5 bundle: Wix Spaces clone — My Subscriptions / plan orders (site-scoped).
|
|
2
1
|
import { defineService } from "@himalaya/state";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { listMyPlanOrders, type WixPlanOrder } from "@himalaya/wix-pricing-plans";
|
|
3
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
4
|
+
import { memberAccess, assertMemberAccess, memberAccessDenied, memberChanged } from "../_shared/member-access.js";
|
|
5
|
+
import { orderDate, orderPrice, orderStatus } from "../_shared/pricing-plan-display.js";
|
|
6
|
+
import { descriptionBody } from "../_shared/rich-body.js";
|
|
7
|
+
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
6
8
|
|
|
7
|
-
interface Row { id: string; name: string; subtitle: string }
|
|
9
|
+
interface Row { id: string; name: string; subtitle: string; description: string; price: string; endDate: string; noEndDate: boolean; expired: boolean; dateLabel: string }
|
|
8
10
|
interface S {
|
|
9
|
-
status:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
hideAccountCta: boolean;
|
|
11
|
+
status: string; orders: Row[]; rows: Row[]; allOrders: Row[]; selectedTab: string; nextCursor: string;
|
|
12
|
+
emptyText: string; hideAccountCta: boolean; noOrders: boolean;
|
|
13
|
+
isLoading: boolean; notLoading: boolean; hideError: boolean; denied: boolean;
|
|
14
|
+
hideEmpty: boolean; hideEmptyLoadMore: boolean; hideDeniedError: boolean; hideRetryError: boolean; pageError: boolean; loadingPage: boolean;
|
|
14
15
|
}
|
|
16
|
+
const initial = (): S => ({ status: "loading", orders: [], rows: [], allOrders: [], selectedTab: "active", nextCursor: "", emptyText: "", hideAccountCta: true, noOrders: true, isLoading: true, notLoading: false, hideError: true, denied: false, hideEmpty: true, hideEmptyLoadMore: true, hideDeniedError: true, hideRetryError: true, pageError: false, loadingPage: false });
|
|
17
|
+
let sequence = 0;
|
|
18
|
+
let scope = "";
|
|
19
|
+
let offset = 0;
|
|
20
|
+
let pending = false;
|
|
21
|
+
const session = hostSessionFromGlobal();
|
|
15
22
|
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
function project(state: S): S {
|
|
24
|
+
// Keep the unfiltered `orders` contract for older descriptors without tabs.
|
|
25
|
+
const orders = state.allOrders;
|
|
26
|
+
const rows = orders.filter(row => row.expired === (state.selectedTab === "expired"));
|
|
27
|
+
return { ...state, orders, rows, noOrders: rows.length === 0, hideEmpty: state.status !== "ready" || rows.length > 0 || Boolean(state.nextCursor),
|
|
28
|
+
hideEmptyLoadMore: state.status !== "ready" || rows.length > 0 || !state.nextCursor,
|
|
29
|
+
emptyText: orders.length ? "" : state.selectedTab === "expired" ? copyParam("mySubscriptions.expiredEmpty", "No expired subscriptions") : copyParam("mySubscriptions.activeEmpty", "No active subscriptions") };
|
|
19
30
|
}
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* `{ email: "" }` and a failed lookup proves nothing, so both read as "no member": the
|
|
27
|
-
* plan-orders endpoint is not member-filtered, and calling it for a visitor would list
|
|
28
|
-
* orders that are not theirs. Fail closed. */
|
|
29
|
-
async function sessionEmail(): Promise<string> {
|
|
30
|
-
try {
|
|
31
|
-
const identity = await dispatch("himi.wix.memberIdentity") as unknown;
|
|
32
|
-
const direct = identity as { email?: unknown } | null;
|
|
33
|
-
const wrapped = identity as { payload?: { email?: unknown } } | null;
|
|
34
|
-
const email = direct?.email ?? wrapped?.payload?.email;
|
|
35
|
-
return typeof email === "string" ? email.trim() : "";
|
|
36
|
-
} catch {
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
31
|
+
function norm(order: WixPlanOrder): Row {
|
|
32
|
+
const periodEnd = !order.earliestEndDate && !order.endDate && order.status === "ACTIVE" && (order.pricing?.subscription ?? order.priceDetails?.subscription) ? orderDate(order.currentCycle?.endedDate) : "";
|
|
33
|
+
const endDate = orderDate(order.earliestEndDate ?? order.endDate) || periodEnd;
|
|
34
|
+
return { id: order.id, name: order.planName || copyParam("plans.planFallbackName", "Plan"), subtitle: orderStatus(order),
|
|
35
|
+
description: descriptionBody(order.planDescription).bodyText, price: orderPrice(order), endDate, noEndDate: !endDate, dateLabel: periodEnd ? copyParam("subscriptionDetail.periodEnd", "Current period ends") : order.status === "CANCELED" ? copyParam("subscriptionDetail.endDate", "End date") : order.status === "ENDED" ? copyParam("mySubscriptions.expiredOn", "Expired on") : copyParam("mySubscriptions.validUntil", "Valid until"),
|
|
36
|
+
expired: ["ENDED", "CANCELED"].includes(order.status ?? "") };
|
|
39
37
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
38
|
+
async function readPage(state: S, reset: boolean): Promise<S | undefined> {
|
|
39
|
+
if (!reset && pending) return undefined;
|
|
40
|
+
const seq = reset ? ++sequence : sequence;
|
|
41
|
+
pending = true;
|
|
42
|
+
if (!reset) void svc.beginPage();
|
|
43
|
+
const member = await memberAccess();
|
|
44
|
+
const key = JSON.stringify([member.email, member.scope]);
|
|
45
|
+
if (seq !== sequence) return undefined;
|
|
46
|
+
if (key !== scope) { scope = key; offset = 0; state = initial(); void svc.clear(); }
|
|
47
|
+
if (!member.email) { pending = false; return { ...initial(), status: "guest", emptyText: copyParam("mySubscriptions.guestBody", "Sign in to see your subscriptions."), isLoading: false, notLoading: true, hideAccountCta: false }; }
|
|
48
|
+
try {
|
|
49
|
+
const start = reset ? 0 : offset;
|
|
50
|
+
const result = await listMyPlanOrders({ statuses: ["ACTIVE", "PENDING", "PAUSED", "CANCELED", "ENDED"], limit: 50, offset: start });
|
|
51
|
+
await assertMemberAccess(member);
|
|
52
|
+
if (seq !== sequence) return undefined;
|
|
53
|
+
const raw = result.orders ?? [];
|
|
54
|
+
offset = start + raw.length;
|
|
55
|
+
const rows = raw.filter(order => order.id && order.status !== "DRAFT").map(norm);
|
|
56
|
+
const allOrders = [...new Map([...(reset ? [] : state.allOrders), ...rows].map(row => [row.id, row])).values()];
|
|
57
|
+
return project({ ...state, status: "ready", allOrders, isLoading: false, notLoading: true, hideError: true, denied: false, hideAccountCta: true,
|
|
58
|
+
selectedTab: svc.getState().selectedTab, hideDeniedError: true, hideRetryError: true, nextCursor: raw.length === 50 ? String(offset) : "", pageError: false, loadingPage: false });
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (seq !== sequence) return undefined;
|
|
61
|
+
if (await memberChanged(member, error)) { scope = ""; void svc.clear(); void svc.load(); return undefined; }
|
|
62
|
+
state = project({ ...state, selectedTab: svc.getState().selectedTab });
|
|
63
|
+
const denied = memberAccessDenied(error);
|
|
64
|
+
if (denied) return { ...initial(), selectedTab: state.selectedTab, status: "error", emptyText: copyParam("mySubscriptions.accessDenied", "Subscriptions are unavailable for this account."), isLoading: false, notLoading: true, hideError: false, denied: true, hideDeniedError: false, hideRetryError: true };
|
|
65
|
+
return { ...state, status: "error", emptyText: copyParam("mySubscriptions.loadError", "Subscriptions could not be loaded."), isLoading: false, notLoading: true, hideError: false, denied: false, hideDeniedError: true, hideRetryError: false, hideEmpty: true, hideEmptyLoadMore: true, pageError: !reset && state.allOrders.length > 0, loadingPage: false };
|
|
66
|
+
} finally { if (seq === sequence) pending = false; }
|
|
44
67
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
const svc = defineService<S, {
|
|
69
|
+
clear: (s: S) => S; beginPage: (s: S) => S; load: (s: S, arg?: unknown) => Promise<S | undefined>;
|
|
70
|
+
retry: (s: S) => Promise<S | undefined>; nextPage: (s: S) => Promise<S | undefined>; selectTab: (s: S, arg?: unknown) => S;
|
|
71
|
+
}>("spacesMySubscriptions", {
|
|
72
|
+
state: initial(), notHydrated: Object.keys(initial()) as Array<keyof S>,
|
|
48
73
|
actions: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!email) return { status: "ready", orders: [], emptyText: EMPTY_GUEST, hideAccountCta: false };
|
|
56
|
-
try {
|
|
57
|
-
const r = await listPlanOrders();
|
|
58
|
-
const orders = (((r as unknown as { orders?: WixPlanOrder[] }).orders) ?? []).map(norm);
|
|
59
|
-
return {
|
|
60
|
-
status: "ready",
|
|
61
|
-
orders,
|
|
62
|
-
emptyText: orders.length ? "" : EMPTY_MEMBER,
|
|
63
|
-
hideAccountCta,
|
|
64
|
-
};
|
|
65
|
-
} catch (err) {
|
|
66
|
-
// Signed-in members hitting Headless 403 must not see the guest gate
|
|
67
|
-
// (same honesty as orders READ_ORDER_FORBIDDEN → empty).
|
|
68
|
-
if (email) {
|
|
69
|
-
return {
|
|
70
|
-
status: "ready",
|
|
71
|
-
orders: [],
|
|
72
|
-
emptyText: looksForbidden(err) ? EMPTY_FORBIDDEN : EMPTY_MEMBER,
|
|
73
|
-
hideAccountCta: true,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return { status: "ready", orders: [], emptyText: EMPTY_GUEST, hideAccountCta: false };
|
|
77
|
-
}
|
|
78
|
-
},
|
|
74
|
+
clear: () => initial(),
|
|
75
|
+
beginPage: state => ({ ...state, loadingPage: true }),
|
|
76
|
+
load: (state, arg) => { stashCopy(arg); return readPage(state, true); },
|
|
77
|
+
retry: state => readPage(state, !state.pageError),
|
|
78
|
+
nextPage: state => state.nextCursor ? readPage(state, false) : Promise.resolve(undefined),
|
|
79
|
+
selectTab: (state, arg) => { const raw = typeof arg === "string" ? arg : (arg as { selectedId?: string; id?: string; value?: string })?.selectedId ?? (arg as { id?: string })?.id ?? (arg as { value?: string })?.value; return project({ ...state, selectedTab: raw === "expired" ? "expired" : "active" }); },
|
|
79
80
|
},
|
|
80
|
-
}
|
|
81
|
+
});
|
|
82
|
+
session.subscribe(() => { ++sequence; scope = ""; pending = false; void svc.clear(); void svc.load(); });
|
|
81
83
|
svc.load();
|
|
82
84
|
export { svc };
|