@composable-os/pack-courses 0.1.0-beta.8 → 0.1.0-beta.9
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/blocks/courses-my-courses/my-courses.js +1 -0
- package/dist/blocks/courses-native-subscription/subscription-screen.d.ts +4 -0
- package/dist/blocks/courses-native-subscription/subscription-screen.js +17 -0
- package/dist/blocks/courses-subscribe/subscribe.d.ts +28 -0
- package/dist/blocks/courses-subscribe/subscribe.js +146 -0
- package/dist/blocks/courses-subscription/my-subscription.d.ts +6 -0
- package/dist/blocks/courses-subscription/my-subscription.js +50 -0
- package/dist/client/index.d.ts +389 -3
- package/dist/client/index.js +137 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +42 -2
- package/dist/tools.d.ts +12 -0
- package/dist/tools.js +52 -4
- package/package.json +3 -3
|
@@ -6,6 +6,7 @@ const WHY = {
|
|
|
6
6
|
bundle: "In a bundle",
|
|
7
7
|
given: "Given to you",
|
|
8
8
|
imported: "From your old account",
|
|
9
|
+
subscription: "Through your subscription",
|
|
9
10
|
};
|
|
10
11
|
export function MyCourses({ courses, onContinue, }) {
|
|
11
12
|
const { data, isPending, error } = courses.useMyCourses();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { day, isLive, PLAN, subscriptionStatus } from "@composable-os/pack-courses/client";
|
|
3
|
+
import { Text } from "react-native";
|
|
4
|
+
import { List } from "../native-base/list.js";
|
|
5
|
+
import { Row } from "../native-base/row.js";
|
|
6
|
+
import { Screen } from "../native-base/screen.js";
|
|
7
|
+
export function SubscriptionScreen({ courses, }) {
|
|
8
|
+
const { data, isPending, error } = courses.useMySubscriptions();
|
|
9
|
+
const offers = courses.useMyOffers();
|
|
10
|
+
const live = data?.items.filter(isLive) ?? [];
|
|
11
|
+
const offer = offers.data?.offers.find((o) => o.planObject === PLAN);
|
|
12
|
+
return (_jsxs(Screen, { title: "My subscription", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading your subscription\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load your subscription." }) : null, data ? (_jsx(List, { empty: "You have no course subscription.", children: live.map((sub) => (_jsx(Row, { title: `${sub.planTitle}: every course`, detail: subscriptionStatus(sub) }, sub.id))) })) : null, offer && !live.length ? (_jsx(Text, { children: offer.askUs
|
|
13
|
+
? `Your subscription with us is paid up to ${day(offer.freeUntil)}. Ask the studio to continue it.`
|
|
14
|
+
: offer.chargedNow
|
|
15
|
+
? `Your subscription with us was paid up to ${day(offer.freeUntil)}. Continue it on the studio's website.`
|
|
16
|
+
: `Your subscription with us is paid up to ${day(offer.freeUntil)}. Continue it on the studio's website, free until then.` })) : null, live.length ? _jsx(Text, { children: "Manage your subscription on the studio's website." }) : null] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
/**
|
|
3
|
+
* Signing a guest in by an emailed code, as the app does it (the web sign-in block's two calls:
|
|
4
|
+
* the template's `/auth/code` and `/auth/sign-in`). `requestCode` says whether the host took the
|
|
5
|
+
* request (it answers every address the same). `confirm` gives the `account` the host's sign-in
|
|
6
|
+
* answer carries: `ready`, or `needs_attention` while staff sort out the person's record (the
|
|
7
|
+
* session is then not yet a customer's); null when the code was refused.
|
|
8
|
+
*/
|
|
9
|
+
export interface SubscribeSignIn {
|
|
10
|
+
requestCode: (email: string) => Promise<boolean>;
|
|
11
|
+
confirm: (email: string, code: string) => Promise<"ready" | "needs_attention" | null>;
|
|
12
|
+
}
|
|
13
|
+
export declare function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInForTrial, signIn, }: {
|
|
14
|
+
courses: Pick<CoursesHooks, "usePlans" | "useSubscribe" | "useMyOffers">;
|
|
15
|
+
/** Where the provider's page sends the subscriber back to (one of the host's listed origins). */
|
|
16
|
+
returnUrl: string;
|
|
17
|
+
/** A signed-in customer subscribes as themselves; a guest gives their email. */
|
|
18
|
+
signedIn: boolean;
|
|
19
|
+
/** Where a guest signs in: only a signed-in customer gets the free trial, or their offer. */
|
|
20
|
+
signInUrl?: string;
|
|
21
|
+
/** Instead of `signInUrl`: what the app does to sign a guest in for the trial, for that plan. */
|
|
22
|
+
onSignInForTrial?: (planId: string) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Preferred: a guest confirms their address with a code right here, then goes on to the
|
|
25
|
+
* provider's page signed in, with the trial.
|
|
26
|
+
*/
|
|
27
|
+
signIn?: SubscribeSignIn;
|
|
28
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { day, formatPrice, noTrialWords, offerFor, offerWords, PLAN, } from "@composable-os/pack-courses/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
6
|
+
import { Input } from "../ui-input/input.js";
|
|
7
|
+
import { Label } from "../ui-label/label.js";
|
|
8
|
+
export function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInForTrial, signIn, }) {
|
|
9
|
+
const { data, isPending, error } = courses.usePlans();
|
|
10
|
+
const subscribe = courses.useSubscribe();
|
|
11
|
+
const [email, setEmail] = useState("");
|
|
12
|
+
const [problem, setProblem] = useState(null);
|
|
13
|
+
// The host gave no trial on a plan that has one: say why before the provider's page asks for
|
|
14
|
+
// the first payment, so nobody is charged by surprise.
|
|
15
|
+
const [noTrial, setNoTrial] = useState(null);
|
|
16
|
+
// Signed in here, by a code (`signIn`): subscribe as the customer from now on.
|
|
17
|
+
const [confirmed, setConfirmed] = useState(false);
|
|
18
|
+
const [codeSent, setCodeSent] = useState(false);
|
|
19
|
+
const [code, setCode] = useState("");
|
|
20
|
+
const [busy, setBusy] = useState(false);
|
|
21
|
+
// Confirmed, but the account waits for staff to merge people: subscribe as a guest meanwhile.
|
|
22
|
+
const [waiting, setWaiting] = useState(false);
|
|
23
|
+
const asCustomer = signedIn || confirmed;
|
|
24
|
+
// Only a signed-in customer has offers; a guest's call would be refused, so it is not made.
|
|
25
|
+
const offers = courses.useMyOffers({ enabled: asCustomer });
|
|
26
|
+
if (isPending || (asCustomer && offers.isPending)) {
|
|
27
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the plans\u2026" });
|
|
28
|
+
}
|
|
29
|
+
if (error || !data)
|
|
30
|
+
return _jsx("p", { role: "alert", children: "We could not load the plans." });
|
|
31
|
+
if (!data.plans.length)
|
|
32
|
+
return _jsx("p", { children: "No plans are offered yet." });
|
|
33
|
+
// Only offers on the course plan object matter here (another pack's plans are its own).
|
|
34
|
+
const onPlans = (list) => (list ?? []).filter((o) => o.planObject === PLAN);
|
|
35
|
+
const mine = asCustomer ? onPlans(offers.data?.offers) : [];
|
|
36
|
+
const continuing = mine.length > 0;
|
|
37
|
+
const askUs = mine.filter((o) => o.askUs);
|
|
38
|
+
async function onSubscribe(planId, hasTrial, customer = asCustomer, offer, owed = continuing) {
|
|
39
|
+
setProblem(null);
|
|
40
|
+
setNoTrial(null);
|
|
41
|
+
try {
|
|
42
|
+
const started = await subscribe.mutateAsync({
|
|
43
|
+
plan: { object: PLAN, id: planId },
|
|
44
|
+
returnUrl,
|
|
45
|
+
...(customer ? {} : { email }),
|
|
46
|
+
...(offer ? { offerId: offer.id } : {}),
|
|
47
|
+
});
|
|
48
|
+
// Never sent to a page that charges today without a word: the host's reason for no trial,
|
|
49
|
+
// or, for a member with free time owed on another plan, that this one is paid from today.
|
|
50
|
+
if (!offer && (owed || (hasTrial && started.noTrial))) {
|
|
51
|
+
setNoTrial({ planId, started: { ...started, noTrial: started.noTrial ?? "continuation" } });
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
window.location.assign(started.url);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
setProblem(e instanceof Error ? e.message : "We could not start your subscription");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** The code step on the plan: ask for a code, then confirm it and start signed in. */
|
|
61
|
+
async function onCode(event, planId) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
if (!signIn)
|
|
64
|
+
return;
|
|
65
|
+
setBusy(true);
|
|
66
|
+
setProblem(null);
|
|
67
|
+
try {
|
|
68
|
+
if (!codeSent) {
|
|
69
|
+
if (await signIn.requestCode(email))
|
|
70
|
+
setCodeSent(true);
|
|
71
|
+
else
|
|
72
|
+
setProblem("We could not send a code. Try again in a moment.");
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const account = await signIn.confirm(email, code);
|
|
76
|
+
if (account === "ready") {
|
|
77
|
+
setConfirmed(true);
|
|
78
|
+
// Signed in now: if they have a continuation offer, they see it in place of the trial
|
|
79
|
+
// (the plans again), never a trial page opened over it.
|
|
80
|
+
const fresh = onPlans((await offers.refetch()).data?.offers);
|
|
81
|
+
if (fresh.length) {
|
|
82
|
+
setNoTrial(null);
|
|
83
|
+
setCodeSent(false);
|
|
84
|
+
setCode("");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Back to the same plan, now as the customer: the host gives the trial or says why not.
|
|
88
|
+
await onSubscribe(planId, true, true, undefined, false);
|
|
89
|
+
}
|
|
90
|
+
else if (account === "needs_attention") {
|
|
91
|
+
// Signed in, but not yet as a customer: staff are told (the host's merge notice). Back
|
|
92
|
+
// to the plans, where they can subscribe as a guest and pay from today.
|
|
93
|
+
setWaiting(true);
|
|
94
|
+
setCodeSent(false);
|
|
95
|
+
setCode("");
|
|
96
|
+
setNoTrial(null);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
setProblem("That code did not work. Check it, or ask for a new one.");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
setBusy(false);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** A new code, after a wrong or expired one, without leaving the plan. */
|
|
108
|
+
async function onNewCode() {
|
|
109
|
+
if (!signIn)
|
|
110
|
+
return;
|
|
111
|
+
setBusy(true);
|
|
112
|
+
setProblem(null);
|
|
113
|
+
setCode("");
|
|
114
|
+
try {
|
|
115
|
+
if (!(await signIn.requestCode(email))) {
|
|
116
|
+
setProblem("We could not send a code. Try again in a moment.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
setBusy(false);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (noTrial?.started.noTrial) {
|
|
124
|
+
const { planId, started } = noTrial;
|
|
125
|
+
const reason = started.noTrial;
|
|
126
|
+
return (_jsxs("section", { className: "grid max-w-sm gap-3", "aria-label": "Subscribe", "data-no-trial": reason, children: [_jsx("p", { role: "status", children: noTrialWords(reason) }), reason === "sign_in" && signIn ? (_jsxs("form", { className: "grid gap-2", onSubmit: (e) => void onCode(e, planId), children: [codeSent ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm", children: `If ${email} can sign in here, we have emailed it a code.` }), _jsx(Label, { htmlFor: "subscriber-code", children: "The code we emailed you" }), _jsx(Input, { id: "subscriber-code", inputMode: "numeric", autoComplete: "one-time-code", required: true, value: code, onChange: (e) => setCode(e.target.value) })] })) : null, _jsx(Button, { type: "submit", disabled: busy || subscribe.isPending, children: codeSent ? "Confirm and start my free trial" : "Email me a code for the free trial" }), codeSent ? (_jsx(Button, { type: "button", variant: "outline", disabled: busy, onClick: () => void onNewCode(), children: "Send me a new code" })) : null, problem ? _jsx("p", { role: "alert", children: problem }) : null] })) : reason === "sign_in" && (onSignInForTrial || signInUrl) ? (_jsx(Button, { onClick: () => onSignInForTrial ? onSignInForTrial(planId) : window.location.assign(signInUrl ?? ""), children: "Sign in for the free trial" })) : null, _jsx(Button, { variant: "outline", onClick: () => window.location.assign(started.url), children: "Continue and pay from today" })] }));
|
|
127
|
+
}
|
|
128
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-label": "Subscribe", children: [waiting ? (_jsx("p", { role: "status", children: "Your address is confirmed, but we need to sort out your record before you can have the free trial, and we have told the team. You can subscribe now and pay from today." })) : null, askUs.map((o) => (_jsx("p", { role: "status", "data-testid": "continuation-offer", children: offerWords(o) }, o.id))), data.plans.map((plan) => {
|
|
129
|
+
const found = offerFor(mine, plan.id);
|
|
130
|
+
const offer = found && !found.askUs ? found : undefined;
|
|
131
|
+
// A continuation replaces the trial (owner decision 7): a member with an open offer on the
|
|
132
|
+
// course plan object is shown no trial on its plans (the host gives none then).
|
|
133
|
+
const trial = !continuing && plan.trialDays && plan.trialDays > 0 ? plan.trialDays : null;
|
|
134
|
+
return (_jsxs(Card, { "data-offer": offer ? offer.id : undefined, children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: plan.title }), _jsx(CardDescription, { children: `${formatPrice(plan.price, data.currency)} a month · every course` })] }), _jsxs(CardContent, { children: [plan.description ? _jsx("p", { children: plan.description }) : null, offer ? _jsx("p", { "data-testid": "continuation-offer", children: offerWords(offer) }) : null, _jsxs("form", { className: "grid max-w-sm gap-2", onSubmit: (e) => {
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
// While the record waits for staff, no trial can be given: straight to paying.
|
|
137
|
+
void onSubscribe(plan.id, trial !== null && !waiting, asCustomer, offer);
|
|
138
|
+
}, children: [asCustomer ? null : (_jsxs(_Fragment, { children: [trial && !waiting ? (_jsxs("p", { children: [signInUrl ? (_jsx("a", { href: signInUrl, className: "underline", children: `Sign in for your ${trial}-day free trial` })) : (`Sign in for your ${trial}-day free trial`), ", or subscribe now and pay from today."] })) : null, _jsx(Label, { htmlFor: `subscriber-email-${plan.id}`, children: "Your email" }), _jsx(Input, { id: `subscriber-email-${plan.id}`, type: "email", required: true, value: email, onChange: (e) => setEmail(e.target.value) })] })), _jsx(Button, { type: "submit", disabled: subscribe.isPending, children: offer
|
|
139
|
+
? offer.chargedNow
|
|
140
|
+
? "Continue my subscription"
|
|
141
|
+
: `Continue, free until ${day(offer.freeUntil)}`
|
|
142
|
+
: asCustomer && trial
|
|
143
|
+
? `Start your ${trial}-day free trial`
|
|
144
|
+
: "Subscribe" }), offer && !offer.chargedNow ? (_jsx("p", { className: "text-sm", children: `Your card is taken now and first charged on ${day(offer.freeUntil)}, unless you cancel.` })) : null, asCustomer && trial ? (_jsx("p", { className: "text-sm", children: "Your card is taken now and charged when the trial ends, unless you cancel. One free trial per person." })) : null] })] })] }, plan.id));
|
|
145
|
+
}), problem ? _jsx("p", { role: "alert", children: problem }) : null] }));
|
|
146
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
export declare function MySubscription({ courses, returnUrl, }: {
|
|
3
|
+
courses: Pick<CoursesHooks, "useMySubscriptions" | "useCancelSubscription" | "useResumeSubscription" | "useBillingPortal">;
|
|
4
|
+
/** Where the provider's portal's back link goes (one of the host's listed origins). */
|
|
5
|
+
returnUrl: string;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { formatMinor, isLive, subscriptionStatus } from "@composable-os/pack-courses/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
6
|
+
export function MySubscription({ courses, returnUrl, }) {
|
|
7
|
+
const { data, isPending, error } = courses.useMySubscriptions();
|
|
8
|
+
const cancel = courses.useCancelSubscription();
|
|
9
|
+
const resume = courses.useResumeSubscription();
|
|
10
|
+
const portal = courses.useBillingPortal();
|
|
11
|
+
const [said, setSaid] = useState(null);
|
|
12
|
+
const [problem, setProblem] = useState(null);
|
|
13
|
+
if (isPending)
|
|
14
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading your subscription\u2026" });
|
|
15
|
+
if (error || !data)
|
|
16
|
+
return _jsx("p", { role: "alert", children: "We could not load your subscription." });
|
|
17
|
+
const live = data.items.filter(isLive);
|
|
18
|
+
if (!live.length)
|
|
19
|
+
return _jsx("p", { children: "You have no course subscription." });
|
|
20
|
+
async function act(run, done) {
|
|
21
|
+
setProblem(null);
|
|
22
|
+
setSaid(null);
|
|
23
|
+
try {
|
|
24
|
+
await run();
|
|
25
|
+
setSaid(done);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
setProblem(e instanceof Error ? e.message : "That did not work");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function onPortal() {
|
|
32
|
+
setProblem(null);
|
|
33
|
+
try {
|
|
34
|
+
// The provider's portal opens in its own page: it cannot be put in a frame.
|
|
35
|
+
const opened = await portal.mutateAsync({ returnUrl });
|
|
36
|
+
window.location.assign(opened.url);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
setProblem(e instanceof Error ? e.message : "We could not open your billing");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const ending = (sub) => sub.cancelAtPeriodEnd || sub.cancelAt !== null;
|
|
43
|
+
const busy = cancel.isPending || resume.isPending || portal.isPending;
|
|
44
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-label": "My subscription", children: [live.map((sub) => (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: sub.planTitle }), _jsx(CardDescription, { children: `${formatMinor(sub.amount, sub.currency)} a ${sub.interval} · every course` })] }), _jsxs(CardContent, { className: "grid gap-3", children: [_jsx("p", { "data-testid": "subscription-status", children: subscriptionStatus(sub) }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [sub.actionUrl ? (_jsx(Button, { onClick: () => window.location.assign(sub.actionUrl ?? ""), children: "Confirm your payment" })) : null, sub.cancelAtPeriodEnd ? (_jsx(Button, { disabled: busy, onClick: () => void act(() => resume.mutateAsync({ id: sub.id }), "Asked to keep it going. It shows here once the payment provider confirms."), children: "Keep my subscription" })) : ending(sub) ? null : (_jsx(Button, { variant: "outline", disabled: busy, onClick: () => {
|
|
45
|
+
if (!window.confirm("Cancel? You keep every course until the period ends.")) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
void act(() => cancel.mutateAsync({ id: sub.id, reason: "Cancelled by the member" }), "Asked to cancel. It ends when the period does; it shows here once the payment provider confirms.");
|
|
49
|
+
}, children: "Cancel subscription" })), _jsx(Button, { variant: "outline", disabled: busy, onClick: () => void onPortal(), children: "Card and invoices" })] })] })] }, sub.id))), said ? _jsx("p", { role: "status", children: said }) : null, problem ? _jsx("p", { role: "alert", children: problem }) : null] }));
|
|
50
|
+
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ClientHolding, type PackClient } from "@composable-os/client";
|
|
2
2
|
import type { z } from "@composable-os/sdk";
|
|
3
3
|
import { type Lesson, type LessonKind, type Outline, type Section } from "../outline.ts";
|
|
4
|
-
import type { buy, catalogue, course, endEnrolment, enrol, lesson, myCourses, progress, startSession, stats } from "../tools.ts";
|
|
4
|
+
import type { buy, catalogue, course, endEnrolment, enrol, lesson, myCourses, plans, progress, startSession, stats } from "../tools.ts";
|
|
5
5
|
export { completion, findLesson, lessonsOf, nextLesson, watchedToEnd } from "../outline.ts";
|
|
6
6
|
export type { Lesson, LessonKind, Outline, Section };
|
|
7
7
|
type Io<T extends {
|
|
@@ -27,8 +27,130 @@ export interface Playback {
|
|
|
27
27
|
label: string;
|
|
28
28
|
}[];
|
|
29
29
|
}
|
|
30
|
+
export declare const PLAN = "courses.plan";
|
|
31
|
+
/** A subscription as its payer reads it (`subscription.list`, stage 32a). */
|
|
32
|
+
export interface CourseSubscription {
|
|
33
|
+
id: string;
|
|
34
|
+
state: "incomplete" | "expired" | "trialing" | "active" | "past_due" | "unpaid" | "paused" | "ended";
|
|
35
|
+
planObject: string;
|
|
36
|
+
planId: string;
|
|
37
|
+
planTitle: string;
|
|
38
|
+
/** One period's price, in the currency's minor unit, tax included. */
|
|
39
|
+
amount: number;
|
|
40
|
+
currency: string;
|
|
41
|
+
interval: "week" | "month" | "year";
|
|
42
|
+
trialEnd: string | null;
|
|
43
|
+
currentPeriodEnd: string | null;
|
|
44
|
+
cancelAtPeriodEnd: boolean;
|
|
45
|
+
cancelAt: string | null;
|
|
46
|
+
endedAt: string | null;
|
|
47
|
+
/** The provider's page to confirm a renewal on (3D Secure), while one waits. */
|
|
48
|
+
actionUrl: string | null;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
}
|
|
51
|
+
/** Why the host gave no free trial on a plan that has one (subscription.start's `noTrial`). */
|
|
52
|
+
export type NoTrial = "sign_in" | "used" | "permission" | "held" | "unconfirmed" | "continuation";
|
|
53
|
+
/** What a member is told about a trial the host did not give. Display only. */
|
|
54
|
+
export declare function noTrialWords(reason: NoTrial): string;
|
|
55
|
+
/**
|
|
56
|
+
* A continuation offer (stage 32a, ADR 0491): a subscriber moving from another platform continues
|
|
57
|
+
* here, free until the date they had paid up to, then charged. Only its own person, signed in as
|
|
58
|
+
* its address, reads or takes it (`subscription.offer.mine`, `subscription.start { offerId }`).
|
|
59
|
+
*/
|
|
60
|
+
export interface ContinuationOffer {
|
|
61
|
+
id: string;
|
|
62
|
+
planObject: string;
|
|
63
|
+
planId: string;
|
|
64
|
+
/** Free until this moment, then charged. */
|
|
65
|
+
freeUntil: string;
|
|
66
|
+
/** Under 48 hours left: taking it now is charged at once. */
|
|
67
|
+
chargedNow: boolean;
|
|
68
|
+
/** Its plan is no longer on sale and there is no single other: the member asks the company. */
|
|
69
|
+
askUs: boolean;
|
|
70
|
+
}
|
|
71
|
+
/** The member's offer for `planId`, if they have one. */
|
|
72
|
+
export declare function offerFor(offers: readonly ContinuationOffer[] | undefined, planId: string): ContinuationOffer | undefined;
|
|
73
|
+
/** What a member is told about their offer, in words. Display only. */
|
|
74
|
+
export declare function offerWords(offer: ContinuationOffer): string;
|
|
75
|
+
/** What subscription.start answers. */
|
|
76
|
+
export interface StartedSubscription {
|
|
77
|
+
subscriptionId: string;
|
|
78
|
+
url: string;
|
|
79
|
+
amount: number;
|
|
80
|
+
currency: string;
|
|
81
|
+
interval: "week" | "month" | "year";
|
|
82
|
+
trialDays: number | null;
|
|
83
|
+
/** Free until this moment (a continuation offer taken), then charged. */
|
|
84
|
+
freeUntil: string | null;
|
|
85
|
+
noTrial: NoTrial | null;
|
|
86
|
+
expiresAt: string | null;
|
|
87
|
+
}
|
|
30
88
|
/** The operations this entry calls, as the generated client types them. */
|
|
31
89
|
export type CoursesOperations = {
|
|
90
|
+
"x.courses.plans": {
|
|
91
|
+
kind: "query";
|
|
92
|
+
} & Io<typeof plans>;
|
|
93
|
+
"subscription.start": {
|
|
94
|
+
kind: "mutation";
|
|
95
|
+
input: {
|
|
96
|
+
plan: {
|
|
97
|
+
object: string;
|
|
98
|
+
id: string;
|
|
99
|
+
};
|
|
100
|
+
returnUrl: string;
|
|
101
|
+
email?: string;
|
|
102
|
+
offerId?: string;
|
|
103
|
+
};
|
|
104
|
+
output: StartedSubscription;
|
|
105
|
+
};
|
|
106
|
+
"subscription.offer.mine": {
|
|
107
|
+
kind: "query";
|
|
108
|
+
input: Record<string, unknown>;
|
|
109
|
+
output: {
|
|
110
|
+
offers: ContinuationOffer[];
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
"subscription.list": {
|
|
114
|
+
kind: "query";
|
|
115
|
+
input: {
|
|
116
|
+
filter?: unknown;
|
|
117
|
+
limit?: number;
|
|
118
|
+
};
|
|
119
|
+
output: {
|
|
120
|
+
items: CourseSubscription[];
|
|
121
|
+
nextCursor: string | null;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
"subscription.cancel": {
|
|
125
|
+
kind: "mutation";
|
|
126
|
+
input: {
|
|
127
|
+
id: string;
|
|
128
|
+
reason?: string;
|
|
129
|
+
};
|
|
130
|
+
output: {
|
|
131
|
+
id: string;
|
|
132
|
+
requested: true;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
"subscription.resume": {
|
|
136
|
+
kind: "mutation";
|
|
137
|
+
input: {
|
|
138
|
+
id: string;
|
|
139
|
+
};
|
|
140
|
+
output: {
|
|
141
|
+
id: string;
|
|
142
|
+
requested: true;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
"subscription.portal": {
|
|
146
|
+
kind: "mutation";
|
|
147
|
+
input: {
|
|
148
|
+
returnUrl: string;
|
|
149
|
+
};
|
|
150
|
+
output: {
|
|
151
|
+
url: string;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
32
154
|
"x.courses.catalogue": {
|
|
33
155
|
kind: "query";
|
|
34
156
|
} & Io<typeof catalogue>;
|
|
@@ -160,6 +282,20 @@ export declare const PLAYBACK_REFRESH_BEFORE_MS: number;
|
|
|
160
282
|
export declare function refreshInMs(expiresAt: string, now?: number): number;
|
|
161
283
|
/** A price as the host gave it, in its currency (`99.00 AUD`). Display only: never worked out. */
|
|
162
284
|
export declare function formatPrice(price: number | null | undefined, currency: string | null | undefined): string;
|
|
285
|
+
/**
|
|
286
|
+
* An amount the host gave in the currency's minor unit (a subscription's price per period), in
|
|
287
|
+
* that currency: `29.00 AUD`. Display only: the minor unit's digits are the currency's own.
|
|
288
|
+
*/
|
|
289
|
+
export declare function formatMinor(minor: number, currency: string): string;
|
|
290
|
+
/** A date as a reader sees it (`3 Dec 2026`), from the host's ISO timestamp. Display only. */
|
|
291
|
+
export declare function day(iso: string | null | undefined): string;
|
|
292
|
+
/**
|
|
293
|
+
* What a subscription's state means to its member, in words, from what the host reports. Display
|
|
294
|
+
* only: whether it gives access is the host's (the seam), never worked out from this.
|
|
295
|
+
*/
|
|
296
|
+
export declare function subscriptionStatus(sub: CourseSubscription): string;
|
|
297
|
+
/** Whether a subscription is still the member's to cancel, resume or pay (not ended). */
|
|
298
|
+
export declare const isLive: (sub: CourseSubscription) => boolean;
|
|
163
299
|
/** A lesson's length as a reader sees it: `12 min`. Display only. */
|
|
164
300
|
export declare function minutes(duration: number | null | undefined): string;
|
|
165
301
|
/** Where a phone asks the host for a picture (the course cover): as the Content pack's. */
|
|
@@ -233,6 +369,13 @@ export declare const COURSES_HOOKS_CALL: {
|
|
|
233
369
|
readonly useEnrol: readonly ["x.courses.enrol"];
|
|
234
370
|
readonly useEndEnrolment: readonly ["x.courses.endEnrolment"];
|
|
235
371
|
readonly useStats: readonly ["x.courses.stats"];
|
|
372
|
+
readonly usePlans: readonly ["x.courses.plans"];
|
|
373
|
+
readonly useSubscribe: readonly ["subscription.start"];
|
|
374
|
+
readonly useMySubscriptions: readonly ["subscription.list"];
|
|
375
|
+
readonly useMyOffers: readonly ["subscription.offer.mine"];
|
|
376
|
+
readonly useCancelSubscription: readonly ["subscription.cancel"];
|
|
377
|
+
readonly useResumeSubscription: readonly ["subscription.resume"];
|
|
378
|
+
readonly useBillingPortal: readonly ["subscription.portal"];
|
|
236
379
|
readonly useWorkingCopy: readonly ["record.get"];
|
|
237
380
|
readonly useSaveOutline: readonly ["record.update"];
|
|
238
381
|
readonly usePublishCourse: readonly ["record.publish"];
|
|
@@ -419,7 +562,7 @@ export declare function createCoursesHooks<C extends ClientHolding>(react: {
|
|
|
419
562
|
} | null;
|
|
420
563
|
price: number | null;
|
|
421
564
|
lessons: number;
|
|
422
|
-
why: "bought" | "bundle" | "given" | "imported";
|
|
565
|
+
why: "bought" | "bundle" | "given" | "imported" | "subscription";
|
|
423
566
|
done: number;
|
|
424
567
|
counted: number;
|
|
425
568
|
complete: boolean;
|
|
@@ -500,6 +643,124 @@ export declare function createCoursesHooks<C extends ClientHolding>(react: {
|
|
|
500
643
|
isPending: boolean;
|
|
501
644
|
error: unknown;
|
|
502
645
|
};
|
|
646
|
+
/** The course plans on offer, with the host's prices and trial days. */
|
|
647
|
+
usePlans(): {
|
|
648
|
+
data: {
|
|
649
|
+
plans: {
|
|
650
|
+
id: string;
|
|
651
|
+
title: string | null;
|
|
652
|
+
description: string | null;
|
|
653
|
+
price: number | null;
|
|
654
|
+
trialDays: number | null;
|
|
655
|
+
}[];
|
|
656
|
+
currency: string | null;
|
|
657
|
+
} | undefined;
|
|
658
|
+
isPending: boolean;
|
|
659
|
+
error: unknown;
|
|
660
|
+
};
|
|
661
|
+
/**
|
|
662
|
+
* Start a course subscription: the host opens the provider's page (web only). Whether the
|
|
663
|
+
* trial is given is the host's (`noTrial` says why not).
|
|
664
|
+
*/
|
|
665
|
+
useSubscribe(): {
|
|
666
|
+
mutate(input: {
|
|
667
|
+
plan: {
|
|
668
|
+
object: string;
|
|
669
|
+
id: string;
|
|
670
|
+
};
|
|
671
|
+
returnUrl: string;
|
|
672
|
+
email?: string;
|
|
673
|
+
offerId?: string;
|
|
674
|
+
}): void;
|
|
675
|
+
mutateAsync(input: {
|
|
676
|
+
plan: {
|
|
677
|
+
object: string;
|
|
678
|
+
id: string;
|
|
679
|
+
};
|
|
680
|
+
returnUrl: string;
|
|
681
|
+
email?: string;
|
|
682
|
+
offerId?: string;
|
|
683
|
+
}): Promise<StartedSubscription>;
|
|
684
|
+
data: StartedSubscription | undefined;
|
|
685
|
+
isPending: boolean;
|
|
686
|
+
error: unknown;
|
|
687
|
+
};
|
|
688
|
+
/** The signed-in customer's own course subscriptions, newest first. */
|
|
689
|
+
useMySubscriptions(): {
|
|
690
|
+
data: {
|
|
691
|
+
items: CourseSubscription[];
|
|
692
|
+
nextCursor: string | null;
|
|
693
|
+
} | undefined;
|
|
694
|
+
isPending: boolean;
|
|
695
|
+
error: unknown;
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* The signed-in customer's own continuation offers (moving from another platform): free until
|
|
699
|
+
* their paid-up date. Read only; taking one is `useSubscribe` with `offerId` (web only).
|
|
700
|
+
*/
|
|
701
|
+
useMyOffers(options?: {
|
|
702
|
+
enabled?: boolean;
|
|
703
|
+
}): {
|
|
704
|
+
data: {
|
|
705
|
+
offers: ContinuationOffer[];
|
|
706
|
+
} | undefined;
|
|
707
|
+
isPending: boolean;
|
|
708
|
+
error: unknown;
|
|
709
|
+
};
|
|
710
|
+
/** End their own subscription when its period ends (web only). */
|
|
711
|
+
useCancelSubscription(): {
|
|
712
|
+
mutate(input: {
|
|
713
|
+
id: string;
|
|
714
|
+
reason?: string;
|
|
715
|
+
}): void;
|
|
716
|
+
mutateAsync(input: {
|
|
717
|
+
id: string;
|
|
718
|
+
reason?: string;
|
|
719
|
+
}): Promise<{
|
|
720
|
+
id: string;
|
|
721
|
+
requested: true;
|
|
722
|
+
}>;
|
|
723
|
+
data: {
|
|
724
|
+
id: string;
|
|
725
|
+
requested: true;
|
|
726
|
+
} | undefined;
|
|
727
|
+
isPending: boolean;
|
|
728
|
+
error: unknown;
|
|
729
|
+
};
|
|
730
|
+
/** Undo that, before the period ends (web only). */
|
|
731
|
+
useResumeSubscription(): {
|
|
732
|
+
mutate(input: {
|
|
733
|
+
id: string;
|
|
734
|
+
}): void;
|
|
735
|
+
mutateAsync(input: {
|
|
736
|
+
id: string;
|
|
737
|
+
}): Promise<{
|
|
738
|
+
id: string;
|
|
739
|
+
requested: true;
|
|
740
|
+
}>;
|
|
741
|
+
data: {
|
|
742
|
+
id: string;
|
|
743
|
+
requested: true;
|
|
744
|
+
} | undefined;
|
|
745
|
+
isPending: boolean;
|
|
746
|
+
error: unknown;
|
|
747
|
+
};
|
|
748
|
+
/** The provider's portal for their card and past invoices (web only, never in a frame). */
|
|
749
|
+
useBillingPortal(): {
|
|
750
|
+
mutate(input: {
|
|
751
|
+
returnUrl: string;
|
|
752
|
+
}): void;
|
|
753
|
+
mutateAsync(input: {
|
|
754
|
+
returnUrl: string;
|
|
755
|
+
}): Promise<{
|
|
756
|
+
url: string;
|
|
757
|
+
}>;
|
|
758
|
+
data: {
|
|
759
|
+
url: string;
|
|
760
|
+
} | undefined;
|
|
761
|
+
isPending: boolean;
|
|
762
|
+
error: unknown;
|
|
763
|
+
};
|
|
503
764
|
/** Staff: a course's working copy, as the builder edits it. */
|
|
504
765
|
useWorkingCopy(courseId: string): {
|
|
505
766
|
data: {
|
|
@@ -589,6 +850,13 @@ export declare function createCoursesHooks<C extends ClientHolding>(react: {
|
|
|
589
850
|
readonly useEnrol: readonly ["x.courses.enrol"];
|
|
590
851
|
readonly useEndEnrolment: readonly ["x.courses.endEnrolment"];
|
|
591
852
|
readonly useStats: readonly ["x.courses.stats"];
|
|
853
|
+
readonly usePlans: readonly ["x.courses.plans"];
|
|
854
|
+
readonly useSubscribe: readonly ["subscription.start"];
|
|
855
|
+
readonly useMySubscriptions: readonly ["subscription.list"];
|
|
856
|
+
readonly useMyOffers: readonly ["subscription.offer.mine"];
|
|
857
|
+
readonly useCancelSubscription: readonly ["subscription.cancel"];
|
|
858
|
+
readonly useResumeSubscription: readonly ["subscription.resume"];
|
|
859
|
+
readonly useBillingPortal: readonly ["subscription.portal"];
|
|
592
860
|
readonly useWorkingCopy: readonly ["record.get"];
|
|
593
861
|
readonly useSaveOutline: readonly ["record.update"];
|
|
594
862
|
readonly usePublishCourse: readonly ["record.publish"];
|
|
@@ -770,7 +1038,7 @@ declare function allCoursesHooks(react: {
|
|
|
770
1038
|
} | null;
|
|
771
1039
|
price: number | null;
|
|
772
1040
|
lessons: number;
|
|
773
|
-
why: "bought" | "bundle" | "given" | "imported";
|
|
1041
|
+
why: "bought" | "bundle" | "given" | "imported" | "subscription";
|
|
774
1042
|
done: number;
|
|
775
1043
|
counted: number;
|
|
776
1044
|
complete: boolean;
|
|
@@ -851,6 +1119,124 @@ declare function allCoursesHooks(react: {
|
|
|
851
1119
|
isPending: boolean;
|
|
852
1120
|
error: unknown;
|
|
853
1121
|
};
|
|
1122
|
+
/** The course plans on offer, with the host's prices and trial days. */
|
|
1123
|
+
usePlans(): {
|
|
1124
|
+
data: {
|
|
1125
|
+
plans: {
|
|
1126
|
+
id: string;
|
|
1127
|
+
title: string | null;
|
|
1128
|
+
description: string | null;
|
|
1129
|
+
price: number | null;
|
|
1130
|
+
trialDays: number | null;
|
|
1131
|
+
}[];
|
|
1132
|
+
currency: string | null;
|
|
1133
|
+
} | undefined;
|
|
1134
|
+
isPending: boolean;
|
|
1135
|
+
error: unknown;
|
|
1136
|
+
};
|
|
1137
|
+
/**
|
|
1138
|
+
* Start a course subscription: the host opens the provider's page (web only). Whether the
|
|
1139
|
+
* trial is given is the host's (`noTrial` says why not).
|
|
1140
|
+
*/
|
|
1141
|
+
useSubscribe(): {
|
|
1142
|
+
mutate(input: {
|
|
1143
|
+
plan: {
|
|
1144
|
+
object: string;
|
|
1145
|
+
id: string;
|
|
1146
|
+
};
|
|
1147
|
+
returnUrl: string;
|
|
1148
|
+
email?: string;
|
|
1149
|
+
offerId?: string;
|
|
1150
|
+
}): void;
|
|
1151
|
+
mutateAsync(input: {
|
|
1152
|
+
plan: {
|
|
1153
|
+
object: string;
|
|
1154
|
+
id: string;
|
|
1155
|
+
};
|
|
1156
|
+
returnUrl: string;
|
|
1157
|
+
email?: string;
|
|
1158
|
+
offerId?: string;
|
|
1159
|
+
}): Promise<StartedSubscription>;
|
|
1160
|
+
data: StartedSubscription | undefined;
|
|
1161
|
+
isPending: boolean;
|
|
1162
|
+
error: unknown;
|
|
1163
|
+
};
|
|
1164
|
+
/** The signed-in customer's own course subscriptions, newest first. */
|
|
1165
|
+
useMySubscriptions(): {
|
|
1166
|
+
data: {
|
|
1167
|
+
items: CourseSubscription[];
|
|
1168
|
+
nextCursor: string | null;
|
|
1169
|
+
} | undefined;
|
|
1170
|
+
isPending: boolean;
|
|
1171
|
+
error: unknown;
|
|
1172
|
+
};
|
|
1173
|
+
/**
|
|
1174
|
+
* The signed-in customer's own continuation offers (moving from another platform): free until
|
|
1175
|
+
* their paid-up date. Read only; taking one is `useSubscribe` with `offerId` (web only).
|
|
1176
|
+
*/
|
|
1177
|
+
useMyOffers(options?: {
|
|
1178
|
+
enabled?: boolean;
|
|
1179
|
+
}): {
|
|
1180
|
+
data: {
|
|
1181
|
+
offers: ContinuationOffer[];
|
|
1182
|
+
} | undefined;
|
|
1183
|
+
isPending: boolean;
|
|
1184
|
+
error: unknown;
|
|
1185
|
+
};
|
|
1186
|
+
/** End their own subscription when its period ends (web only). */
|
|
1187
|
+
useCancelSubscription(): {
|
|
1188
|
+
mutate(input: {
|
|
1189
|
+
id: string;
|
|
1190
|
+
reason?: string;
|
|
1191
|
+
}): void;
|
|
1192
|
+
mutateAsync(input: {
|
|
1193
|
+
id: string;
|
|
1194
|
+
reason?: string;
|
|
1195
|
+
}): Promise<{
|
|
1196
|
+
id: string;
|
|
1197
|
+
requested: true;
|
|
1198
|
+
}>;
|
|
1199
|
+
data: {
|
|
1200
|
+
id: string;
|
|
1201
|
+
requested: true;
|
|
1202
|
+
} | undefined;
|
|
1203
|
+
isPending: boolean;
|
|
1204
|
+
error: unknown;
|
|
1205
|
+
};
|
|
1206
|
+
/** Undo that, before the period ends (web only). */
|
|
1207
|
+
useResumeSubscription(): {
|
|
1208
|
+
mutate(input: {
|
|
1209
|
+
id: string;
|
|
1210
|
+
}): void;
|
|
1211
|
+
mutateAsync(input: {
|
|
1212
|
+
id: string;
|
|
1213
|
+
}): Promise<{
|
|
1214
|
+
id: string;
|
|
1215
|
+
requested: true;
|
|
1216
|
+
}>;
|
|
1217
|
+
data: {
|
|
1218
|
+
id: string;
|
|
1219
|
+
requested: true;
|
|
1220
|
+
} | undefined;
|
|
1221
|
+
isPending: boolean;
|
|
1222
|
+
error: unknown;
|
|
1223
|
+
};
|
|
1224
|
+
/** The provider's portal for their card and past invoices (web only, never in a frame). */
|
|
1225
|
+
useBillingPortal(): {
|
|
1226
|
+
mutate(input: {
|
|
1227
|
+
returnUrl: string;
|
|
1228
|
+
}): void;
|
|
1229
|
+
mutateAsync(input: {
|
|
1230
|
+
returnUrl: string;
|
|
1231
|
+
}): Promise<{
|
|
1232
|
+
url: string;
|
|
1233
|
+
}>;
|
|
1234
|
+
data: {
|
|
1235
|
+
url: string;
|
|
1236
|
+
} | undefined;
|
|
1237
|
+
isPending: boolean;
|
|
1238
|
+
error: unknown;
|
|
1239
|
+
};
|
|
854
1240
|
/** Staff: a course's working copy, as the builder edits it. */
|
|
855
1241
|
useWorkingCopy(courseId: string): {
|
|
856
1242
|
data: {
|
package/dist/client/index.js
CHANGED
|
@@ -9,6 +9,37 @@ import { packHooks } from "@composable-os/client";
|
|
|
9
9
|
import { LESSON_KINDS, } from "../outline.js";
|
|
10
10
|
export { completion, findLesson, lessonsOf, nextLesson, watchedToEnd } from "../outline.js";
|
|
11
11
|
export const COURSE = "courses.course";
|
|
12
|
+
export const PLAN = "courses.plan";
|
|
13
|
+
/** What a member is told about a trial the host did not give. Display only. */
|
|
14
|
+
export function noTrialWords(reason) {
|
|
15
|
+
switch (reason) {
|
|
16
|
+
case "sign_in":
|
|
17
|
+
return "The free trial is for signed-in members. Sign in for it, or continue and pay from today.";
|
|
18
|
+
case "used":
|
|
19
|
+
return "You have had your free trial on this plan, so this one is paid from today.";
|
|
20
|
+
case "held":
|
|
21
|
+
return "A checkout with your free trial is already open. Finish that one, or continue and pay from today.";
|
|
22
|
+
case "unconfirmed":
|
|
23
|
+
return "We could not check your earlier checkout with the payment provider just now, so no free trial can be given yet. Try again in a few minutes, or continue and pay from today.";
|
|
24
|
+
case "permission":
|
|
25
|
+
return "A free trial cannot be given from here; this one is paid from today.";
|
|
26
|
+
case "continuation":
|
|
27
|
+
return "You have free time with us on your continuing subscription, and this plan is not the one it is for: this one is paid from today, with no free trial. Go back to continue free until your date.";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The member's offer for `planId`, if they have one. */
|
|
31
|
+
export function offerFor(offers, planId) {
|
|
32
|
+
return offers?.find((o) => o.planObject === PLAN && o.planId === planId);
|
|
33
|
+
}
|
|
34
|
+
/** What a member is told about their offer, in words. Display only. */
|
|
35
|
+
export function offerWords(offer) {
|
|
36
|
+
if (offer.askUs) {
|
|
37
|
+
return `Your subscription with us is paid up to ${day(offer.freeUntil)}. The plan it continues on is not on sale just now: ask us, and nothing is charged before then.`;
|
|
38
|
+
}
|
|
39
|
+
return offer.chargedNow
|
|
40
|
+
? `Your subscription with us was paid up to ${day(offer.freeUntil)}, which is too soon for free time here: continuing is charged from today.`
|
|
41
|
+
: `Your subscription with us is paid up to ${day(offer.freeUntil)}. Continue it here: nothing is charged until then.`;
|
|
42
|
+
}
|
|
12
43
|
// --- Plain functions ------------------------------------------------------------------------------
|
|
13
44
|
/** A token is asked for again this long before it expires. */
|
|
14
45
|
export const PLAYBACK_REFRESH_BEFORE_MS = 5 * 60_000;
|
|
@@ -35,6 +66,63 @@ export function formatPrice(price, currency) {
|
|
|
35
66
|
return `${price}${currency ? ` ${currency}` : ""}`;
|
|
36
67
|
}
|
|
37
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* An amount the host gave in the currency's minor unit (a subscription's price per period), in
|
|
71
|
+
* that currency: `29.00 AUD`. Display only: the minor unit's digits are the currency's own.
|
|
72
|
+
*/
|
|
73
|
+
export function formatMinor(minor, currency) {
|
|
74
|
+
try {
|
|
75
|
+
const format = new Intl.NumberFormat(undefined, { style: "currency", currency });
|
|
76
|
+
const digits = format.resolvedOptions().maximumFractionDigits ?? 2;
|
|
77
|
+
return format.format(minor / 10 ** digits);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return `${minor} ${currency}`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** A date as a reader sees it (`3 Dec 2026`), from the host's ISO timestamp. Display only. */
|
|
84
|
+
export function day(iso) {
|
|
85
|
+
if (!iso)
|
|
86
|
+
return "";
|
|
87
|
+
const at = new Date(iso);
|
|
88
|
+
return Number.isNaN(at.getTime())
|
|
89
|
+
? ""
|
|
90
|
+
: at.toLocaleDateString(undefined, { day: "numeric", month: "short", year: "numeric" });
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* What a subscription's state means to its member, in words, from what the host reports. Display
|
|
94
|
+
* only: whether it gives access is the host's (the seam), never worked out from this.
|
|
95
|
+
*/
|
|
96
|
+
export function subscriptionStatus(sub) {
|
|
97
|
+
const ends = sub.cancelAtPeriodEnd ? sub.currentPeriodEnd : sub.cancelAt;
|
|
98
|
+
switch (sub.state) {
|
|
99
|
+
case "trialing":
|
|
100
|
+
// A trial, or a continuation's free time until its paid-up date: both are free until then.
|
|
101
|
+
return ends
|
|
102
|
+
? `Free, ending on ${day(ends)}: nothing will be charged`
|
|
103
|
+
: `Free until ${day(sub.trialEnd ?? sub.currentPeriodEnd)}, then charged each ${sub.interval}`;
|
|
104
|
+
case "active":
|
|
105
|
+
return ends
|
|
106
|
+
? `Active until ${day(ends)}, then it ends`
|
|
107
|
+
: `Active: next charge on ${day(sub.currentPeriodEnd)}`;
|
|
108
|
+
case "past_due":
|
|
109
|
+
return sub.actionUrl
|
|
110
|
+
? "A payment needs you to confirm it"
|
|
111
|
+
: "A payment failed: the payment provider will try again";
|
|
112
|
+
case "unpaid":
|
|
113
|
+
return "Unpaid: update your card to keep watching";
|
|
114
|
+
case "paused":
|
|
115
|
+
return "Paused";
|
|
116
|
+
case "incomplete":
|
|
117
|
+
return "Waiting for its first payment";
|
|
118
|
+
case "expired":
|
|
119
|
+
return "Never started: its first payment did not go through";
|
|
120
|
+
case "ended":
|
|
121
|
+
return `Ended${sub.endedAt ? ` on ${day(sub.endedAt)}` : ""}`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Whether a subscription is still the member's to cancel, resume or pay (not ended). */
|
|
125
|
+
export const isLive = (sub) => sub.state !== "ended" && sub.state !== "expired";
|
|
38
126
|
/** A lesson's length as a reader sees it: `12 min`. Display only. */
|
|
39
127
|
export function minutes(duration) {
|
|
40
128
|
return typeof duration === "number" && duration > 0 ? `${duration} min` : "";
|
|
@@ -141,6 +229,15 @@ export const COURSES_HOOKS_CALL = {
|
|
|
141
229
|
useEnrol: ["x.courses.enrol"],
|
|
142
230
|
useEndEnrolment: ["x.courses.endEnrolment"],
|
|
143
231
|
useStats: ["x.courses.stats"],
|
|
232
|
+
// The course subscription (stage 32a). Every billing action is the web's: a native block may
|
|
233
|
+
// read the subscription only (the block lint's noPurchase).
|
|
234
|
+
usePlans: ["x.courses.plans"],
|
|
235
|
+
useSubscribe: ["subscription.start"],
|
|
236
|
+
useMySubscriptions: ["subscription.list"],
|
|
237
|
+
useMyOffers: ["subscription.offer.mine"],
|
|
238
|
+
useCancelSubscription: ["subscription.cancel"],
|
|
239
|
+
useResumeSubscription: ["subscription.resume"],
|
|
240
|
+
useBillingPortal: ["subscription.portal"],
|
|
144
241
|
useWorkingCopy: ["record.get"],
|
|
145
242
|
useSaveOutline: ["record.update"],
|
|
146
243
|
usePublishCourse: ["record.publish"],
|
|
@@ -241,6 +338,46 @@ function allCoursesHooks(react, api) {
|
|
|
241
338
|
useStats(courseId) {
|
|
242
339
|
return useQuery(api.query("x.courses.stats", courseId ? { courseId } : {}));
|
|
243
340
|
},
|
|
341
|
+
/** The course plans on offer, with the host's prices and trial days. */
|
|
342
|
+
usePlans() {
|
|
343
|
+
return useQuery(api.query("x.courses.plans", {}));
|
|
344
|
+
},
|
|
345
|
+
/**
|
|
346
|
+
* Start a course subscription: the host opens the provider's page (web only). Whether the
|
|
347
|
+
* trial is given is the host's (`noTrial` says why not).
|
|
348
|
+
*/
|
|
349
|
+
useSubscribe() {
|
|
350
|
+
return useMutation(api.mutation("subscription.start"));
|
|
351
|
+
},
|
|
352
|
+
/** The signed-in customer's own course subscriptions, newest first. */
|
|
353
|
+
useMySubscriptions() {
|
|
354
|
+
return useQuery(api.query("subscription.list", {
|
|
355
|
+
filter: { field: "planObject", op: "eq", value: PLAN },
|
|
356
|
+
limit: 20,
|
|
357
|
+
}));
|
|
358
|
+
},
|
|
359
|
+
/**
|
|
360
|
+
* The signed-in customer's own continuation offers (moving from another platform): free until
|
|
361
|
+
* their paid-up date. Read only; taking one is `useSubscribe` with `offerId` (web only).
|
|
362
|
+
*/
|
|
363
|
+
useMyOffers(options = {}) {
|
|
364
|
+
return useQuery({
|
|
365
|
+
...api.query("subscription.offer.mine", {}),
|
|
366
|
+
enabled: options.enabled ?? true,
|
|
367
|
+
});
|
|
368
|
+
},
|
|
369
|
+
/** End their own subscription when its period ends (web only). */
|
|
370
|
+
useCancelSubscription() {
|
|
371
|
+
return useMutation(api.mutation("subscription.cancel"));
|
|
372
|
+
},
|
|
373
|
+
/** Undo that, before the period ends (web only). */
|
|
374
|
+
useResumeSubscription() {
|
|
375
|
+
return useMutation(api.mutation("subscription.resume"));
|
|
376
|
+
},
|
|
377
|
+
/** The provider's portal for their card and past invoices (web only, never in a frame). */
|
|
378
|
+
useBillingPortal() {
|
|
379
|
+
return useMutation(api.mutation("subscription.portal"));
|
|
380
|
+
},
|
|
244
381
|
/** Staff: a course's working copy, as the builder edits it. */
|
|
245
382
|
useWorkingCopy(courseId) {
|
|
246
383
|
return useQuery(api.query("record.get", { object: COURSE, id: courseId }));
|
package/dist/index.d.ts
CHANGED
|
@@ -150,6 +150,12 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
150
150
|
readonly via: "courses.enrolment";
|
|
151
151
|
readonly field: "bundle";
|
|
152
152
|
readonly through: "courses";
|
|
153
|
+
}, {
|
|
154
|
+
readonly kind: "subscription";
|
|
155
|
+
readonly options: {
|
|
156
|
+
readonly plans: "courses.plan";
|
|
157
|
+
readonly covers: "all";
|
|
158
|
+
};
|
|
153
159
|
}];
|
|
154
160
|
};
|
|
155
161
|
readonly indexes: readonly [readonly ["theme"]];
|
|
@@ -219,6 +225,52 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
219
225
|
};
|
|
220
226
|
};
|
|
221
227
|
};
|
|
228
|
+
readonly plan: {
|
|
229
|
+
readonly label: "Course plan";
|
|
230
|
+
readonly plural: "Course plans";
|
|
231
|
+
readonly icon: "repeat";
|
|
232
|
+
readonly titleField: "title";
|
|
233
|
+
readonly description: string;
|
|
234
|
+
readonly navigation: "main";
|
|
235
|
+
readonly navigationOrder: 18;
|
|
236
|
+
readonly fields: {
|
|
237
|
+
readonly title: {
|
|
238
|
+
readonly type: "text";
|
|
239
|
+
readonly label: "Title";
|
|
240
|
+
readonly required: true;
|
|
241
|
+
};
|
|
242
|
+
readonly description: {
|
|
243
|
+
readonly type: "text";
|
|
244
|
+
readonly label: "Description";
|
|
245
|
+
};
|
|
246
|
+
readonly price: {
|
|
247
|
+
readonly type: "currency";
|
|
248
|
+
readonly label: "Price per month";
|
|
249
|
+
readonly required: true;
|
|
250
|
+
};
|
|
251
|
+
readonly trialDays: {
|
|
252
|
+
readonly type: "number";
|
|
253
|
+
readonly label: "Free trial (days)";
|
|
254
|
+
readonly min: 0;
|
|
255
|
+
readonly max: 90;
|
|
256
|
+
readonly step: 1;
|
|
257
|
+
readonly description: "Empty or 0: charged from the start. A person gets one trial on any plan.";
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
readonly public: {
|
|
261
|
+
readonly read: readonly ["title", "description", "price", "trialDays"];
|
|
262
|
+
};
|
|
263
|
+
readonly sellable: {
|
|
264
|
+
readonly price: "price";
|
|
265
|
+
readonly tax: {
|
|
266
|
+
readonly code: "txcd_20060158";
|
|
267
|
+
};
|
|
268
|
+
readonly recurring: {
|
|
269
|
+
readonly interval: "month";
|
|
270
|
+
readonly trialDays: "trialDays";
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
};
|
|
222
274
|
readonly enrolment: {
|
|
223
275
|
readonly label: "Enrolment";
|
|
224
276
|
readonly plural: "Enrolments";
|
|
@@ -667,6 +719,7 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
667
719
|
bundle: "bundle";
|
|
668
720
|
given: "given";
|
|
669
721
|
imported: "imported";
|
|
722
|
+
subscription: "subscription";
|
|
670
723
|
}>;
|
|
671
724
|
done: import("zod").ZodNumber;
|
|
672
725
|
counted: import("zod").ZodNumber;
|
|
@@ -674,6 +727,16 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
674
727
|
continueWith: import("zod").ZodNullable<import("zod").ZodString>;
|
|
675
728
|
}, import("zod/v4/core").$strip>>;
|
|
676
729
|
}, import("zod/v4/core").$strip>>;
|
|
730
|
+
readonly plans: import("@composable-os/sdk").ToolSpec<import("zod").ZodObject<{}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
731
|
+
plans: import("zod").ZodArray<import("zod").ZodObject<{
|
|
732
|
+
id: import("zod").ZodString;
|
|
733
|
+
title: import("zod").ZodNullable<import("zod").ZodString>;
|
|
734
|
+
description: import("zod").ZodNullable<import("zod").ZodString>;
|
|
735
|
+
price: import("zod").ZodNullable<import("zod").ZodNumber>;
|
|
736
|
+
trialDays: import("zod").ZodNullable<import("zod").ZodNumber>;
|
|
737
|
+
}, import("zod/v4/core").$strip>>;
|
|
738
|
+
currency: import("zod").ZodNullable<import("zod").ZodString>;
|
|
739
|
+
}, import("zod/v4/core").$strip>>;
|
|
677
740
|
readonly buy: import("@composable-os/sdk").ToolSpec<import("zod").ZodObject<{
|
|
678
741
|
courseId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
679
742
|
bundleId: import("zod").ZodOptional<import("zod").ZodString>;
|
package/dist/index.js
CHANGED
|
@@ -12,13 +12,17 @@
|
|
|
12
12
|
// it. The outline's lesson material is for holders (the `holders` flag in outline.ts), so the
|
|
13
13
|
// host removes it for everyone else, and `media.play` plays a lesson's video only to a holder;
|
|
14
14
|
// - an enrolment and a lesson's progress are their student's (`customer`); progress is written
|
|
15
|
-
// only while the student holds access to its course (`requireAccess`, ADR 0478)
|
|
15
|
+
// only while the student holds access to its course (`requireAccess`, ADR 0478);
|
|
16
|
+
// - a course plan is `sellable` with `recurring` (stage 32a, ADR 0485): a subscription to it,
|
|
17
|
+
// which the payment provider charges every month, gives every live course through the host's
|
|
18
|
+
// `subscription` access source (ADR 0488), to its holder, while the host's record says it
|
|
19
|
+
// runs. One free trial per person per plan object is the host's rule (ADR 0489).
|
|
16
20
|
// The tools in tools.ts compose the host's operations and hold no rule of their own.
|
|
17
21
|
import { defineExtension } from "@composable-os/sdk";
|
|
18
22
|
import { coursesAutomations } from "./automations.js";
|
|
19
23
|
import { coursesDashboards } from "./dashboards.js";
|
|
20
24
|
import { OUTLINE_MAX_BYTES, OUTLINE_SCHEMA } from "./outline.js";
|
|
21
|
-
import { buy, catalogue, course, draft, endEnrolment, enrol, lesson, myCourses, progress, startSession, stats, } from "./tools.js";
|
|
25
|
+
import { buy, catalogue, course, draft, endEnrolment, enrol, lesson, myCourses, plans, progress, startSession, stats, } from "./tools.js";
|
|
22
26
|
const ACTIVE = { states: ["active"], until: "until" };
|
|
23
27
|
export default defineExtension({
|
|
24
28
|
id: "courses",
|
|
@@ -150,6 +154,9 @@ export default defineExtension({
|
|
|
150
154
|
sources: [
|
|
151
155
|
{ via: "courses.enrolment", field: "course", ...ACTIVE },
|
|
152
156
|
{ via: "courses.enrolment", field: "bundle", through: "courses", ...ACTIVE },
|
|
157
|
+
// A running course subscription (stage 32a, ADR 0488): every live course, including
|
|
158
|
+
// ones published later, while the host's subscription record says it gives access.
|
|
159
|
+
{ kind: "subscription", options: { plans: "courses.plan", covers: "all" } },
|
|
153
160
|
],
|
|
154
161
|
},
|
|
155
162
|
indexes: [["theme"]],
|
|
@@ -202,6 +209,38 @@ export default defineExtension({
|
|
|
202
209
|
},
|
|
203
210
|
},
|
|
204
211
|
},
|
|
212
|
+
plan: {
|
|
213
|
+
label: "Course plan",
|
|
214
|
+
plural: "Course plans",
|
|
215
|
+
icon: "repeat",
|
|
216
|
+
titleField: "title",
|
|
217
|
+
description: "A subscription to every published course, paid every month, with a free trial when it " +
|
|
218
|
+
"has trial days. One trial per person per plan; the payment provider charges each month.",
|
|
219
|
+
navigation: "main",
|
|
220
|
+
navigationOrder: 18,
|
|
221
|
+
fields: {
|
|
222
|
+
title: { type: "text", label: "Title", required: true },
|
|
223
|
+
description: { type: "text", label: "Description" },
|
|
224
|
+
price: { type: "currency", label: "Price per month", required: true },
|
|
225
|
+
trialDays: {
|
|
226
|
+
type: "number",
|
|
227
|
+
label: "Free trial (days)",
|
|
228
|
+
min: 0,
|
|
229
|
+
max: 90,
|
|
230
|
+
step: 1,
|
|
231
|
+
description: "Empty or 0: charged from the start. A person gets one trial on any plan.",
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
// Every live plan is offered on the site.
|
|
235
|
+
public: { read: ["title", "description", "price", "trialDays"] },
|
|
236
|
+
sellable: {
|
|
237
|
+
price: "price",
|
|
238
|
+
// As its courses (ADR 0479): taxed only once a human admin turns tax on.
|
|
239
|
+
tax: { code: "txcd_20060158" },
|
|
240
|
+
// A plan (ADR 0485): subscribed to with subscription.start, never put on an order.
|
|
241
|
+
recurring: { interval: "month", trialDays: "trialDays" },
|
|
242
|
+
},
|
|
243
|
+
},
|
|
205
244
|
enrolment: {
|
|
206
245
|
label: "Enrolment",
|
|
207
246
|
plural: "Enrolments",
|
|
@@ -384,6 +423,7 @@ export default defineExtension({
|
|
|
384
423
|
lesson,
|
|
385
424
|
progress,
|
|
386
425
|
myCourses,
|
|
426
|
+
plans,
|
|
387
427
|
buy,
|
|
388
428
|
enrol,
|
|
389
429
|
endEnrolment,
|
package/dist/tools.d.ts
CHANGED
|
@@ -50,6 +50,17 @@ export declare const catalogue: import("@composable-os/sdk").ToolSpec<z.ZodObjec
|
|
|
50
50
|
}, z.core.$strip>>;
|
|
51
51
|
currency: z.ZodNullable<z.ZodString>;
|
|
52
52
|
}, z.core.$strip>>;
|
|
53
|
+
export declare const PLAN = "courses.plan";
|
|
54
|
+
export declare const plans: import("@composable-os/sdk").ToolSpec<z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
|
|
55
|
+
plans: z.ZodArray<z.ZodObject<{
|
|
56
|
+
id: z.ZodString;
|
|
57
|
+
title: z.ZodNullable<z.ZodString>;
|
|
58
|
+
description: z.ZodNullable<z.ZodString>;
|
|
59
|
+
price: z.ZodNullable<z.ZodNumber>;
|
|
60
|
+
trialDays: z.ZodNullable<z.ZodNumber>;
|
|
61
|
+
}, z.core.$strip>>;
|
|
62
|
+
currency: z.ZodNullable<z.ZodString>;
|
|
63
|
+
}, z.core.$strip>>;
|
|
53
64
|
export declare const course: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
54
65
|
slug: z.ZodString;
|
|
55
66
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -167,6 +178,7 @@ export declare const myCourses: import("@composable-os/sdk").ToolSpec<z.ZodObjec
|
|
|
167
178
|
bundle: "bundle";
|
|
168
179
|
given: "given";
|
|
169
180
|
imported: "imported";
|
|
181
|
+
subscription: "subscription";
|
|
170
182
|
}>;
|
|
171
183
|
done: z.ZodNumber;
|
|
172
184
|
counted: z.ZodNumber;
|
package/dist/tools.js
CHANGED
|
@@ -178,6 +178,44 @@ export const catalogue = defineTool({
|
|
|
178
178
|
};
|
|
179
179
|
},
|
|
180
180
|
});
|
|
181
|
+
// --- Course plans --------------------------------------------------------------------------------
|
|
182
|
+
export const PLAN = "courses.plan";
|
|
183
|
+
export const plans = defineTool({
|
|
184
|
+
description: "The course plans on offer: a subscription to every published course, paid every month. Each " +
|
|
185
|
+
"plan's title, description, price per month (in the major unit of `currency`) and the days of " +
|
|
186
|
+
"its free trial. Whether a person gets the trial is the host's, when they subscribe " +
|
|
187
|
+
"(subscription.start): one per person, signed in. Read-only.",
|
|
188
|
+
input: z.object({}),
|
|
189
|
+
output: z.object({
|
|
190
|
+
plans: z.array(z.object({
|
|
191
|
+
id: z.string(),
|
|
192
|
+
title: z.string().nullable(),
|
|
193
|
+
description: z.string().nullable(),
|
|
194
|
+
price: z.number().nullable().describe("Per month, in the major unit of `currency`"),
|
|
195
|
+
trialDays: z.number().nullable(),
|
|
196
|
+
})),
|
|
197
|
+
currency,
|
|
198
|
+
}),
|
|
199
|
+
risk: "read",
|
|
200
|
+
audiences: ["customer", "public"],
|
|
201
|
+
async handler(_input, ctx) {
|
|
202
|
+
const page = await ctx.ops.call("public.list", {
|
|
203
|
+
object: PLAN,
|
|
204
|
+
sort: { field: "price", direction: "asc" },
|
|
205
|
+
limit: 20,
|
|
206
|
+
});
|
|
207
|
+
return {
|
|
208
|
+
plans: page.items.map((p) => ({
|
|
209
|
+
id: p.id,
|
|
210
|
+
title: text(p.values.title),
|
|
211
|
+
description: text(p.values.description),
|
|
212
|
+
price: num(p.values.price),
|
|
213
|
+
trialDays: num(p.values.trialDays),
|
|
214
|
+
})),
|
|
215
|
+
currency: page.currency ?? null,
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
});
|
|
181
219
|
// --- One course ----------------------------------------------------------------------------------
|
|
182
220
|
export const course = defineTool({
|
|
183
221
|
description: "One published course by its address (slug): its fields, its description, its outline's " +
|
|
@@ -371,13 +409,13 @@ export const progress = defineTool({
|
|
|
371
409
|
// --- My courses ----------------------------------------------------------------------------------
|
|
372
410
|
export const myCourses = defineTool({
|
|
373
411
|
description: "Every course the signed-in student holds access to and why (bought, in a bundle, given by " +
|
|
374
|
-
"staff, imported), with how far they are (lessons
|
|
375
|
-
"the lesson to continue with. The host says which
|
|
376
|
-
"Read-only.",
|
|
412
|
+
"staff, imported, or through their course subscription), with how far they are (lessons " +
|
|
413
|
+
"done of those that count, complete) and the lesson to continue with. The host says which " +
|
|
414
|
+
"they hold; nothing here decides it. Read-only.",
|
|
377
415
|
input: z.object({}),
|
|
378
416
|
output: z.object({
|
|
379
417
|
courses: z.array(courseCard.extend({
|
|
380
|
-
why: z.enum(["bought", "bundle", "given", "imported"]),
|
|
418
|
+
why: z.enum(["bought", "bundle", "given", "imported", "subscription"]),
|
|
381
419
|
done: z.number(),
|
|
382
420
|
counted: z.number(),
|
|
383
421
|
complete: z.boolean(),
|
|
@@ -421,6 +459,16 @@ export const myCourses = defineTool({
|
|
|
421
459
|
}
|
|
422
460
|
}
|
|
423
461
|
}
|
|
462
|
+
// A course subscription covers every published course (ADR 0488): the published ones the host
|
|
463
|
+
// says they hold that no enrolment of theirs explains are through it.
|
|
464
|
+
const published = await ctx.ops.call("public.list", {
|
|
465
|
+
object: COURSE,
|
|
466
|
+
sort: { field: "title", direction: "asc" },
|
|
467
|
+
limit: 100,
|
|
468
|
+
});
|
|
469
|
+
const others = published.items.map((c) => c.id).filter((c) => !why.has(c));
|
|
470
|
+
for (const c of await held(ctx, others))
|
|
471
|
+
why.set(c, "subscription");
|
|
424
472
|
// Which of these the host says they hold now (live, in its state, inside its until).
|
|
425
473
|
const holding = await held(ctx, [...why.keys()]);
|
|
426
474
|
const out = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/pack-courses",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.9",
|
|
4
4
|
"license": "FSL-1.1-ALv2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"description": "Video courses sold one at a time or in bundles, watched lesson by lesson on the web and in the app, with progress. Requires Programs."
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@composable-os/client": "0.1.0-beta.
|
|
36
|
-
"@composable-os/sdk": "0.1.0-beta.
|
|
35
|
+
"@composable-os/client": "0.1.0-beta.9",
|
|
36
|
+
"@composable-os/sdk": "0.1.0-beta.9"
|
|
37
37
|
}
|
|
38
38
|
}
|