@composable-os/pack-courses 0.1.0-beta.10 → 0.1.0-beta.13
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/automations.js +1 -2
- package/dist/blocks/courses-builder/course-builder.js +15 -21
- package/dist/blocks/courses-catalogue/catalogue.js +2 -3
- package/dist/blocks/courses-course/course-page.d.ts +6 -1
- package/dist/blocks/courses-course/course-page.js +73 -9
- package/dist/blocks/courses-my-courses/my-courses.d.ts +14 -1
- package/dist/blocks/courses-my-courses/my-courses.js +9 -1
- package/dist/blocks/courses-native-catalogue/catalogue-screen.js +3 -6
- package/dist/blocks/courses-native-course/course-screen.js +2 -2
- package/dist/blocks/courses-native-my-courses/my-courses-screen.d.ts +14 -1
- package/dist/blocks/courses-native-my-courses/my-courses-screen.js +16 -3
- package/dist/blocks/courses-native-player/lesson-screen.d.ts +1 -0
- package/dist/blocks/courses-native-player/lesson-screen.js +2 -2
- package/dist/blocks/courses-native-subscription/subscription-screen.js +2 -2
- package/dist/blocks/courses-player/player.d.ts +1 -1
- package/dist/blocks/courses-subscribe/subscribe.d.ts +6 -1
- package/dist/blocks/courses-subscribe/subscribe.js +80 -9
- package/dist/blocks/courses-subscription/my-subscription.d.ts +6 -4
- package/dist/blocks/courses-subscription/my-subscription.js +14 -49
- package/dist/client/index.d.ts +382 -10
- package/dist/client/index.js +24 -36
- package/dist/dashboards.d.ts +2 -0
- package/dist/dashboards.js +3 -3
- package/dist/index.d.ts +82 -3
- package/dist/index.js +68 -3
- package/dist/outline.d.ts +1 -3
- package/dist/outline.js +25 -16
- package/dist/tools.d.ts +7 -1
- package/dist/tools.js +130 -103
- package/package.json +3 -3
package/dist/client/index.js
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
// Nothing here decides who may watch, what is for sale or what a course costs. A lesson's material
|
|
6
6
|
// arrives only for a holder (the host removes it for everyone else), and a video plays only with a
|
|
7
7
|
// token the host signs in `media.play`, which `usePlayback` asks for again before it expires.
|
|
8
|
-
import { packHooks } from "@composable-os/client";
|
|
8
|
+
import { accountDay, packHooks } from "@composable-os/client";
|
|
9
9
|
import { LESSON_KINDS, } from "../outline.js";
|
|
10
|
-
export {
|
|
10
|
+
export { accountDay as day, formatMinor } from "@composable-os/client";
|
|
11
|
+
export { asOutline, completion, findLesson, lessonsOf, nextLesson, watchedToEnd, } from "../outline.js";
|
|
11
12
|
export const COURSE = "courses.course";
|
|
12
13
|
export const PLAN = "courses.plan";
|
|
13
14
|
/** What a member is told about a trial the host did not give. Display only. */
|
|
@@ -33,12 +34,13 @@ export function offerFor(offers, planId) {
|
|
|
33
34
|
}
|
|
34
35
|
/** What a member is told about their offer, in words. Display only. */
|
|
35
36
|
export function offerWords(offer) {
|
|
37
|
+
const until = accountDay(offer.freeUntil);
|
|
36
38
|
if (offer.askUs) {
|
|
37
|
-
return `Your subscription with us is paid up to ${
|
|
39
|
+
return `Your subscription with us is paid up to ${until}. The plan it continues on is not on sale just now: ask us, and nothing is charged before then.`;
|
|
38
40
|
}
|
|
39
41
|
return offer.chargedNow
|
|
40
|
-
? `Your subscription with us was paid up to ${
|
|
41
|
-
: `Your subscription with us is paid up to ${
|
|
42
|
+
? `Your subscription with us was paid up to ${until}, which is too soon for free time here: continuing is charged from today.`
|
|
43
|
+
: `Your subscription with us is paid up to ${until}. Continue it here: nothing is charged until then.`;
|
|
42
44
|
}
|
|
43
45
|
// --- Plain functions ------------------------------------------------------------------------------
|
|
44
46
|
/** A token is asked for again this long before it expires. */
|
|
@@ -66,29 +68,6 @@ export function formatPrice(price, currency) {
|
|
|
66
68
|
return `${price}${currency ? ` ${currency}` : ""}`;
|
|
67
69
|
}
|
|
68
70
|
}
|
|
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
71
|
/**
|
|
93
72
|
* What a subscription's state means to its member, in words, from what the host reports. Display
|
|
94
73
|
* only: whether it gives access is the host's (the seam), never worked out from this.
|
|
@@ -99,12 +78,12 @@ export function subscriptionStatus(sub) {
|
|
|
99
78
|
case "trialing":
|
|
100
79
|
// A trial, or a continuation's free time until its paid-up date: both are free until then.
|
|
101
80
|
return ends
|
|
102
|
-
? `Free, ending on ${
|
|
103
|
-
: `Free until ${
|
|
81
|
+
? `Free, ending on ${accountDay(ends)}: nothing will be charged`
|
|
82
|
+
: `Free until ${accountDay(sub.trialEnd ?? sub.currentPeriodEnd)}, then charged each ${sub.interval}`;
|
|
104
83
|
case "active":
|
|
105
84
|
return ends
|
|
106
|
-
? `Active until ${
|
|
107
|
-
: `Active: next charge on ${
|
|
85
|
+
? `Active until ${accountDay(ends)}, then it ends`
|
|
86
|
+
: `Active: next charge on ${accountDay(sub.currentPeriodEnd)}`;
|
|
108
87
|
case "past_due":
|
|
109
88
|
return sub.actionUrl
|
|
110
89
|
? "A payment needs you to confirm it"
|
|
@@ -118,11 +97,15 @@ export function subscriptionStatus(sub) {
|
|
|
118
97
|
case "expired":
|
|
119
98
|
return "Never started: its first payment did not go through";
|
|
120
99
|
case "ended":
|
|
121
|
-
return `Ended${sub.endedAt ? ` on ${
|
|
100
|
+
return `Ended${sub.endedAt ? ` on ${accountDay(sub.endedAt)}` : ""}`;
|
|
122
101
|
}
|
|
123
102
|
}
|
|
124
103
|
/** Whether a subscription is still the member's to cancel, resume or pay (not ended). */
|
|
125
104
|
export const isLive = (sub) => sub.state !== "ended" && sub.state !== "expired";
|
|
105
|
+
/** A course's level (1 to 3) as a reader sees it: `Beginner`. Display only. */
|
|
106
|
+
export function levelName(level) {
|
|
107
|
+
return level === 1 ? "Beginner" : level === 2 ? "Intermediate" : level === 3 ? "Advanced" : null;
|
|
108
|
+
}
|
|
126
109
|
/** A lesson's length as a reader sees it: `12 min`. Display only. */
|
|
127
110
|
export function minutes(duration) {
|
|
128
111
|
return typeof duration === "number" && duration > 0 ? `${duration} min` : "";
|
|
@@ -273,7 +256,9 @@ function allCoursesHooks(react, api) {
|
|
|
273
256
|
/** Start an order for a course or a bundle; then `checkout` it (web only). */
|
|
274
257
|
useBuy() {
|
|
275
258
|
return {
|
|
276
|
-
|
|
259
|
+
// A visitor's agreements (a name typed, a signature, health answers) go in this call:
|
|
260
|
+
// not kept in the app's cache once it is over (stage 44, issue #292).
|
|
261
|
+
start: useMutation({ ...api.mutation("x.courses.buy"), gcTime: 0 }),
|
|
277
262
|
checkout: useMutation(api.mutation("order.checkout")),
|
|
278
263
|
};
|
|
279
264
|
},
|
|
@@ -296,7 +281,9 @@ function allCoursesHooks(react, api) {
|
|
|
296
281
|
...(video.field ? { field: video.field } : {}),
|
|
297
282
|
}
|
|
298
283
|
: null;
|
|
299
|
-
const options = input
|
|
284
|
+
const options = input
|
|
285
|
+
? api.query("media.play", input)
|
|
286
|
+
: none("playback");
|
|
300
287
|
return useQuery({
|
|
301
288
|
...options,
|
|
302
289
|
enabled: input !== null,
|
|
@@ -347,7 +334,8 @@ function allCoursesHooks(react, api) {
|
|
|
347
334
|
* trial is given is the host's (`noTrial` says why not).
|
|
348
335
|
*/
|
|
349
336
|
useSubscribe() {
|
|
350
|
-
|
|
337
|
+
// A guest's agreements go in this call: not kept in the app's cache after it (issue #292).
|
|
338
|
+
return useMutation({ ...api.mutation("subscription.start"), gcTime: 0 });
|
|
351
339
|
},
|
|
352
340
|
/** The signed-in customer's own course subscriptions, newest first. */
|
|
353
341
|
useMySubscriptions() {
|
package/dist/dashboards.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { DashboardDeclaration } from "@composable-os/sdk";
|
|
2
|
+
/** The Monday of the week a timestamp column is in, as a date (the stats tool's weeks too). */
|
|
3
|
+
export declare const WEEK: (column: string) => string;
|
|
2
4
|
export declare const courses: DashboardDeclaration;
|
|
3
5
|
export declare const coursesDashboards: {
|
|
4
6
|
courses: DashboardDeclaration;
|
package/dist/dashboards.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const PAID_IN = "o.paid_at >= :paid_from AND o.paid_at < :paid_to";
|
|
2
1
|
const IN = (column) => `${column} >= :paid_from AND ${column} < :paid_to`;
|
|
3
|
-
|
|
2
|
+
/** The Monday of the week a timestamp column is in, as a date (the stats tool's weeks too). */
|
|
3
|
+
export const WEEK = (column) => `date(${column}, '-' || ((strftime('%w', ${column}) + 6) % 7) || ' days')`;
|
|
4
4
|
/** A course's or a bundle's paid lines in the period, with what they sold. */
|
|
5
5
|
const LINES = `FROM rec_order_line l JOIN rec_order o ON o.id = l.order_id
|
|
6
6
|
WHERE l.object_type IN ('courses.course', 'courses.bundle') AND o.state IN ('paid', 'part_paid')
|
|
7
|
-
AND ${
|
|
7
|
+
AND ${IN("o.paid_at")}`;
|
|
8
8
|
export const courses = {
|
|
9
9
|
title: "Courses",
|
|
10
10
|
description: "Revenue by month by course and bundle, enrolments by course, completions, lessons done by " +
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { type AgreementsSpec } from "@composable-os/sdk";
|
|
1
2
|
declare const _default: import("@composable-os/sdk").Extension<{
|
|
2
3
|
readonly id: "courses";
|
|
3
4
|
readonly version: "0.1.0";
|
|
4
5
|
readonly contractVersion: 1;
|
|
5
6
|
readonly label: "Courses";
|
|
6
7
|
readonly description: string;
|
|
7
|
-
readonly requires: readonly ["programs"];
|
|
8
|
+
readonly requires: readonly ["programs", "content"];
|
|
8
9
|
readonly permissions: {
|
|
9
10
|
readonly read: ["person", "programs.program", "programs.assignment", "programs.session"];
|
|
10
11
|
readonly write: ["programs.assignment", "programs.session"];
|
|
@@ -108,7 +109,7 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
108
109
|
readonly outline: {
|
|
109
110
|
readonly type: "document";
|
|
110
111
|
readonly label: "Outline";
|
|
111
|
-
readonly schema:
|
|
112
|
+
readonly schema: import("@composable-os/sdk").DocumentSchema;
|
|
112
113
|
readonly maxBytes: 524288;
|
|
113
114
|
};
|
|
114
115
|
};
|
|
@@ -119,6 +120,7 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
119
120
|
readonly public: {
|
|
120
121
|
readonly read: readonly ["title", "slug", "theme", "level", "summary", "description", "cover", "trailer", "price", "onSaleFrom", "outline"];
|
|
121
122
|
};
|
|
123
|
+
readonly agreements: AgreementsSpec;
|
|
122
124
|
readonly sellable: {
|
|
123
125
|
readonly price: "price";
|
|
124
126
|
readonly saleWindow: {
|
|
@@ -127,6 +129,13 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
127
129
|
readonly tax: {
|
|
128
130
|
readonly code: "txcd_20060158";
|
|
129
131
|
};
|
|
132
|
+
readonly finance: {
|
|
133
|
+
readonly category: {
|
|
134
|
+
readonly key: "courses";
|
|
135
|
+
readonly label: "Courses";
|
|
136
|
+
};
|
|
137
|
+
readonly earned: "at_sale";
|
|
138
|
+
};
|
|
130
139
|
readonly grants: {
|
|
131
140
|
readonly object: "enrolment";
|
|
132
141
|
readonly set: {
|
|
@@ -193,7 +202,22 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
193
202
|
readonly courses: {
|
|
194
203
|
readonly type: "document";
|
|
195
204
|
readonly label: "Courses";
|
|
196
|
-
readonly schema:
|
|
205
|
+
readonly schema: {
|
|
206
|
+
readonly root: {
|
|
207
|
+
readonly type: "object";
|
|
208
|
+
readonly fields: {
|
|
209
|
+
readonly items: {
|
|
210
|
+
readonly type: "array";
|
|
211
|
+
readonly min: 2;
|
|
212
|
+
readonly max: 10;
|
|
213
|
+
readonly of: {
|
|
214
|
+
readonly type: "ref";
|
|
215
|
+
readonly to: "courses.course";
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
};
|
|
197
221
|
};
|
|
198
222
|
readonly price: {
|
|
199
223
|
readonly type: "currency";
|
|
@@ -208,11 +232,19 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
208
232
|
readonly public: {
|
|
209
233
|
readonly read: readonly ["title", "slug", "summary", "description", "cover", "courses", "price"];
|
|
210
234
|
};
|
|
235
|
+
readonly agreements: AgreementsSpec;
|
|
211
236
|
readonly sellable: {
|
|
212
237
|
readonly price: "price";
|
|
213
238
|
readonly tax: {
|
|
214
239
|
readonly code: "txcd_20060158";
|
|
215
240
|
};
|
|
241
|
+
readonly finance: {
|
|
242
|
+
readonly category: {
|
|
243
|
+
readonly key: "courses";
|
|
244
|
+
readonly label: "Courses";
|
|
245
|
+
};
|
|
246
|
+
readonly earned: "at_sale";
|
|
247
|
+
};
|
|
216
248
|
readonly grants: {
|
|
217
249
|
readonly object: "enrolment";
|
|
218
250
|
readonly set: {
|
|
@@ -260,11 +292,19 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
260
292
|
readonly public: {
|
|
261
293
|
readonly read: readonly ["title", "description", "price", "trialDays"];
|
|
262
294
|
};
|
|
295
|
+
readonly agreements: AgreementsSpec;
|
|
263
296
|
readonly sellable: {
|
|
264
297
|
readonly price: "price";
|
|
265
298
|
readonly tax: {
|
|
266
299
|
readonly code: "txcd_20060158";
|
|
267
300
|
};
|
|
301
|
+
readonly finance: {
|
|
302
|
+
readonly category: {
|
|
303
|
+
readonly key: "courses";
|
|
304
|
+
readonly label: "Courses";
|
|
305
|
+
};
|
|
306
|
+
readonly earned: "over_period";
|
|
307
|
+
};
|
|
268
308
|
readonly recurring: {
|
|
269
309
|
readonly interval: "month";
|
|
270
310
|
readonly trialDays: "trialDays";
|
|
@@ -303,6 +343,8 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
303
343
|
readonly order: {
|
|
304
344
|
readonly type: "text";
|
|
305
345
|
readonly label: "Order";
|
|
346
|
+
readonly readOnly: true;
|
|
347
|
+
readonly description: "The order that granted this enrolment, set by the host.";
|
|
306
348
|
};
|
|
307
349
|
readonly source: {
|
|
308
350
|
readonly type: "select";
|
|
@@ -371,6 +413,15 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
371
413
|
readonly final: true;
|
|
372
414
|
}];
|
|
373
415
|
};
|
|
416
|
+
readonly agreements: {
|
|
417
|
+
readonly point: "course";
|
|
418
|
+
readonly label: "Buying a course";
|
|
419
|
+
readonly suggests: readonly ["terms"];
|
|
420
|
+
readonly enter: readonly ["active"];
|
|
421
|
+
readonly person: "holder";
|
|
422
|
+
readonly importMovesOver: true;
|
|
423
|
+
readonly inlineStep: true;
|
|
424
|
+
};
|
|
374
425
|
readonly customer: {
|
|
375
426
|
readonly field: "holder";
|
|
376
427
|
readonly read: readonly ["course", "bundle", "source", "from", "until", "completed", "status"];
|
|
@@ -741,6 +792,7 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
741
792
|
courseId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
742
793
|
bundleId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
743
794
|
email: import("zod").ZodOptional<import("zod").ZodString>;
|
|
795
|
+
agreements: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>>;
|
|
744
796
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
745
797
|
id: import("zod").ZodString;
|
|
746
798
|
state: import("zod").ZodString;
|
|
@@ -805,5 +857,32 @@ declare const _default: import("@composable-os/sdk").Extension<{
|
|
|
805
857
|
programId: import("zod").ZodNullable<import("zod").ZodString>;
|
|
806
858
|
}, import("zod/v4/core").$strip>>;
|
|
807
859
|
};
|
|
860
|
+
readonly screens: {
|
|
861
|
+
readonly builder: {
|
|
862
|
+
readonly label: "Builder";
|
|
863
|
+
readonly block: "courses-builder";
|
|
864
|
+
readonly export: "CourseBuilder";
|
|
865
|
+
readonly writes: readonly ["courses.course"];
|
|
866
|
+
readonly record: {
|
|
867
|
+
readonly object: "courses.course";
|
|
868
|
+
readonly as: "courseId";
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
};
|
|
872
|
+
readonly portal: {
|
|
873
|
+
readonly courses: {
|
|
874
|
+
readonly label: "My courses";
|
|
875
|
+
readonly web: {
|
|
876
|
+
readonly block: "courses-my-courses";
|
|
877
|
+
readonly export: "MyCoursesSection";
|
|
878
|
+
};
|
|
879
|
+
readonly native: {
|
|
880
|
+
readonly block: "courses-native-my-courses";
|
|
881
|
+
readonly export: "MyCoursesSectionScreen";
|
|
882
|
+
};
|
|
883
|
+
readonly order: 30;
|
|
884
|
+
readonly has: readonly ["courses.enrolment"];
|
|
885
|
+
};
|
|
886
|
+
};
|
|
808
887
|
}>;
|
|
809
888
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,16 @@ import { coursesDashboards } from "./dashboards.js";
|
|
|
24
24
|
import { OUTLINE_MAX_BYTES, OUTLINE_SCHEMA } from "./outline.js";
|
|
25
25
|
import { buy, catalogue, course, draft, endEnrolment, enrol, lesson, myCourses, plans, progress, startSession, stats, } from "./tools.js";
|
|
26
26
|
const ACTIVE = { states: ["active"], until: "until" };
|
|
27
|
+
// Where agreement may be needed to buy a course, a bundle or a plan (stage 44, ADR 0641): nothing
|
|
28
|
+
// is attached by default, so each sells as before until the business attaches a document (its
|
|
29
|
+
// terms) to "course". The course page and subscribe blocks show what is due and let the buyer
|
|
30
|
+
// agree on the way (issue #292).
|
|
31
|
+
const BUYING = {
|
|
32
|
+
point: "course",
|
|
33
|
+
label: "Buying a course",
|
|
34
|
+
suggests: ["terms"],
|
|
35
|
+
inlineStep: true,
|
|
36
|
+
};
|
|
27
37
|
export default defineExtension({
|
|
28
38
|
id: "courses",
|
|
29
39
|
version: "0.1.0",
|
|
@@ -31,8 +41,10 @@ export default defineExtension({
|
|
|
31
41
|
label: "Courses",
|
|
32
42
|
description: "Video courses sold one at a time or in bundles, watched lesson by lesson, with progress. " +
|
|
33
43
|
"A lesson can be a training session from Programs.",
|
|
34
|
-
// A session lesson is a Programs program
|
|
35
|
-
|
|
44
|
+
// A session lesson is a Programs program, and a text lesson (and a video's notes) is drawn by
|
|
45
|
+
// Content's rich text blocks (`content-rich-text`, `content-native-rich-text`) in the player:
|
|
46
|
+
// the host installs Courses only beside both, and `cos add` brings Content's block with it.
|
|
47
|
+
requires: ["programs", "content"],
|
|
36
48
|
permissions: {
|
|
37
49
|
// person.get: a student's name in the stats. programs.*: a session lesson's program, its
|
|
38
50
|
// assignment and dated sessions, made by x.programs.assign for the student (step 6).
|
|
@@ -132,11 +144,14 @@ export default defineExtension({
|
|
|
132
144
|
"outline",
|
|
133
145
|
],
|
|
134
146
|
},
|
|
147
|
+
agreements: BUYING,
|
|
135
148
|
sellable: {
|
|
136
149
|
price: "price",
|
|
137
150
|
saleWindow: { from: "onSaleFrom" },
|
|
138
151
|
// On-demand online courses, no place (ADR 0479): taxed only once an admin turns tax on.
|
|
139
152
|
tax: { code: "txcd_20060158" },
|
|
153
|
+
// In the finance reports (ADR 0792): earned when it is bought.
|
|
154
|
+
finance: { category: { key: "courses", label: "Courses" }, earned: "at_sale" },
|
|
140
155
|
grants: {
|
|
141
156
|
object: "enrolment",
|
|
142
157
|
set: { holder: "order.person", course: "item", order: "order", code: "code" },
|
|
@@ -192,9 +207,12 @@ export default defineExtension({
|
|
|
192
207
|
slug: "slug",
|
|
193
208
|
},
|
|
194
209
|
public: { read: ["title", "slug", "summary", "description", "cover", "courses", "price"] },
|
|
210
|
+
agreements: BUYING,
|
|
195
211
|
sellable: {
|
|
196
212
|
price: "price",
|
|
197
213
|
tax: { code: "txcd_20060158" },
|
|
214
|
+
// In the finance reports (ADR 0792): earned when it is bought.
|
|
215
|
+
finance: { category: { key: "courses", label: "Courses" }, earned: "at_sale" },
|
|
198
216
|
grants: {
|
|
199
217
|
object: "enrolment",
|
|
200
218
|
set: { holder: "order.person", bundle: "item", order: "order", code: "code" },
|
|
@@ -226,10 +244,13 @@ export default defineExtension({
|
|
|
226
244
|
},
|
|
227
245
|
// Every live plan is offered on the site.
|
|
228
246
|
public: { read: ["title", "description", "price", "trialDays"] },
|
|
247
|
+
agreements: BUYING,
|
|
229
248
|
sellable: {
|
|
230
249
|
price: "price",
|
|
231
250
|
// As its courses (ADR 0479): taxed only once a human admin turns tax on.
|
|
232
251
|
tax: { code: "txcd_20060158" },
|
|
252
|
+
// In the finance reports (ADR 0792): courses, but a paid month is earned over the month.
|
|
253
|
+
finance: { category: { key: "courses", label: "Courses" }, earned: "over_period" },
|
|
233
254
|
// A plan (ADR 0485): subscribed to with subscription.start, never put on an order.
|
|
234
255
|
recurring: { interval: "month", trialDays: "trialDays" },
|
|
235
256
|
},
|
|
@@ -248,7 +269,13 @@ export default defineExtension({
|
|
|
248
269
|
holder: { type: "relation", label: "Student", to: "person" },
|
|
249
270
|
course: { type: "relation", label: "Course", to: "courses.course" },
|
|
250
271
|
bundle: { type: "relation", label: "Bundle", to: "courses.bundle" },
|
|
251
|
-
order
|
|
272
|
+
// Which order granted it, set by the host's grant (ADR 0590, the fourth review).
|
|
273
|
+
order: {
|
|
274
|
+
type: "text",
|
|
275
|
+
label: "Order",
|
|
276
|
+
readOnly: true,
|
|
277
|
+
description: "The order that granted this enrolment, set by the host.",
|
|
278
|
+
},
|
|
252
279
|
source: {
|
|
253
280
|
type: "select",
|
|
254
281
|
label: "Where it came from",
|
|
@@ -292,6 +319,20 @@ export default defineExtension({
|
|
|
292
319
|
{ from: ["active", "ended"], to: "void", by: ["host"], final: true },
|
|
293
320
|
],
|
|
294
321
|
},
|
|
322
|
+
// An enrolment staff give (`enrol`, or a record made by hand) starts access as buying one
|
|
323
|
+
// does: the same point, asked by the engine when a caller makes one active or makes an ended
|
|
324
|
+
// one active again (stage 44, issue #281). One a paid order grants is the host's, asked when
|
|
325
|
+
// the order started; one the courses import writes is a student moving over, not asked.
|
|
326
|
+
agreements: {
|
|
327
|
+
point: "course",
|
|
328
|
+
label: "Buying a course",
|
|
329
|
+
suggests: ["terms"],
|
|
330
|
+
enter: ["active"],
|
|
331
|
+
person: "holder",
|
|
332
|
+
importMovesOver: true,
|
|
333
|
+
// The same point as buying one, so the course page's step answers it too (issue #292).
|
|
334
|
+
inlineStep: true,
|
|
335
|
+
},
|
|
295
336
|
customer: {
|
|
296
337
|
field: "holder",
|
|
297
338
|
read: ["course", "bundle", "source", "from", "until", "completed", "status"],
|
|
@@ -424,4 +465,28 @@ export default defineExtension({
|
|
|
424
465
|
draft,
|
|
425
466
|
startSession,
|
|
426
467
|
},
|
|
468
|
+
// A staff screen in the product's admin (stage 47, ADR 0660): the course builder, a tab on the
|
|
469
|
+
// course (it builds one course). It saves the course through the host's record writes, so it is
|
|
470
|
+
// gated by writing a course: any member, never a viewer or a pack role.
|
|
471
|
+
screens: {
|
|
472
|
+
builder: {
|
|
473
|
+
label: "Builder",
|
|
474
|
+
block: "courses-builder",
|
|
475
|
+
export: "CourseBuilder",
|
|
476
|
+
writes: ["courses.course"],
|
|
477
|
+
record: { object: "courses.course", as: "courseId" },
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
// Its section of My account (stage 48, ADR 0710): the courses a student holds, shown once they
|
|
481
|
+
// hold one. A child's courses stay the child's.
|
|
482
|
+
portal: {
|
|
483
|
+
courses: {
|
|
484
|
+
label: "My courses",
|
|
485
|
+
// What they hold, then their course subscription (stage 48 step 7).
|
|
486
|
+
web: { block: "courses-my-courses", export: "MyCoursesSection" },
|
|
487
|
+
native: { block: "courses-native-my-courses", export: "MyCoursesSectionScreen" },
|
|
488
|
+
order: 30,
|
|
489
|
+
has: ["courses.enrolment"],
|
|
490
|
+
},
|
|
491
|
+
},
|
|
427
492
|
});
|
package/dist/outline.d.ts
CHANGED
|
@@ -48,15 +48,13 @@ export interface Section {
|
|
|
48
48
|
export interface Outline {
|
|
49
49
|
sections: Section[];
|
|
50
50
|
}
|
|
51
|
-
/** An empty outline. */
|
|
52
|
-
export declare const EMPTY_OUTLINE: Outline;
|
|
53
51
|
/** The value as an outline, or an empty one when it is not one. */
|
|
54
52
|
export declare function asOutline(value: unknown): Outline;
|
|
55
53
|
/** Every lesson in order, with its section's key. */
|
|
56
54
|
export declare function lessonsOf(outline: Outline): (Lesson & {
|
|
57
55
|
section: string;
|
|
58
56
|
})[];
|
|
59
|
-
/** One lesson by its key, or null. */
|
|
57
|
+
/** One lesson by its key, with its section's key, or null. */
|
|
60
58
|
export declare function findLesson(outline: Outline, key: string): (Lesson & {
|
|
61
59
|
section: string;
|
|
62
60
|
}) | null;
|
package/dist/outline.js
CHANGED
|
@@ -21,19 +21,23 @@ export const MAX_SECTIONS = 50;
|
|
|
21
21
|
export const MAX_LESSONS_PER_SECTION = 100;
|
|
22
22
|
/** The most an outline may be, in bytes of its JSON. */
|
|
23
23
|
export const OUTLINE_MAX_BYTES = 524_288;
|
|
24
|
-
const KEY_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
25
24
|
const optional = (node) => ({ ...node, optional: true });
|
|
26
25
|
const richText = { type: "use", def: "richText" };
|
|
26
|
+
/** A section's and a lesson's key and title. */
|
|
27
|
+
const keyNode = {
|
|
28
|
+
type: "text",
|
|
29
|
+
min: 1,
|
|
30
|
+
max: 40,
|
|
31
|
+
chars: "abcdefghijklmnopqrstuvwxyz0123456789-",
|
|
32
|
+
};
|
|
33
|
+
const titleNode = { type: "text", min: 1, max: 200, noMarkup: true };
|
|
27
34
|
/** What every lesson has, whatever its kind. */
|
|
28
35
|
const common = {
|
|
29
36
|
key: {
|
|
30
|
-
|
|
31
|
-
min: 1,
|
|
32
|
-
max: 40,
|
|
33
|
-
chars: KEY_CHARS,
|
|
37
|
+
...keyNode,
|
|
34
38
|
description: "The lesson's name for good: progress is kept by it. Never changed once published.",
|
|
35
39
|
},
|
|
36
|
-
title:
|
|
40
|
+
title: titleNode,
|
|
37
41
|
duration: optional({
|
|
38
42
|
type: "number",
|
|
39
43
|
min: 0,
|
|
@@ -69,8 +73,8 @@ export const OUTLINE_SCHEMA = {
|
|
|
69
73
|
of: {
|
|
70
74
|
type: "object",
|
|
71
75
|
fields: {
|
|
72
|
-
key:
|
|
73
|
-
title:
|
|
76
|
+
key: keyNode,
|
|
77
|
+
title: titleNode,
|
|
74
78
|
lessons: {
|
|
75
79
|
type: "array",
|
|
76
80
|
max: MAX_LESSONS_PER_SECTION,
|
|
@@ -116,24 +120,29 @@ export const OUTLINE_SCHEMA = {
|
|
|
116
120
|
},
|
|
117
121
|
defs: { ...(RICH_TEXT_SCHEMA.defs ?? {}), richText: RICH_TEXT_SCHEMA.root },
|
|
118
122
|
};
|
|
119
|
-
/** An empty outline. */
|
|
120
|
-
export const EMPTY_OUTLINE = { sections: [] };
|
|
121
123
|
/** The value as an outline, or an empty one when it is not one. */
|
|
122
124
|
export function asOutline(value) {
|
|
123
125
|
const v = value;
|
|
124
|
-
return v && Array.isArray(v.sections) ? v :
|
|
126
|
+
return v && Array.isArray(v.sections) ? v : { sections: [] };
|
|
125
127
|
}
|
|
128
|
+
/** Every lesson in order, as the outline holds it (no copies). */
|
|
129
|
+
const allLessons = (outline) => outline.sections.flatMap((section) => section.lessons ?? []);
|
|
126
130
|
/** Every lesson in order, with its section's key. */
|
|
127
131
|
export function lessonsOf(outline) {
|
|
128
132
|
return outline.sections.flatMap((section) => (section.lessons ?? []).map((l) => ({ ...l, section: section.key })));
|
|
129
133
|
}
|
|
130
|
-
/** One lesson by its key, or null. */
|
|
134
|
+
/** One lesson by its key, with its section's key, or null. */
|
|
131
135
|
export function findLesson(outline, key) {
|
|
132
|
-
|
|
136
|
+
for (const section of outline.sections) {
|
|
137
|
+
const found = section.lessons?.find((l) => l.key === key);
|
|
138
|
+
if (found)
|
|
139
|
+
return { ...found, section: section.key };
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
133
142
|
}
|
|
134
143
|
/** The lesson after this one, or null at the end. */
|
|
135
144
|
export function nextLesson(outline, key) {
|
|
136
|
-
const all =
|
|
145
|
+
const all = allLessons(outline);
|
|
137
146
|
const at = all.findIndex((l) => l.key === key);
|
|
138
147
|
return at >= 0 ? (all[at + 1] ?? null) : null;
|
|
139
148
|
}
|
|
@@ -146,7 +155,7 @@ export function lessonVideo(lesson) {
|
|
|
146
155
|
/** The programs a course's session lessons use, each once. */
|
|
147
156
|
export function sessionPrograms(outline) {
|
|
148
157
|
return [
|
|
149
|
-
...new Set(
|
|
158
|
+
...new Set(allLessons(outline)
|
|
150
159
|
.map((l) => (l.kind === "session" ? l.program : undefined))
|
|
151
160
|
.filter((p) => Boolean(p))),
|
|
152
161
|
];
|
|
@@ -157,7 +166,7 @@ export function sessionPrograms(outline) {
|
|
|
157
166
|
* lesson the outline no longer has does not count, whatever its progress row says.
|
|
158
167
|
*/
|
|
159
168
|
export function completion(outline, done, importedComplete = false) {
|
|
160
|
-
const counted =
|
|
169
|
+
const counted = allLessons(outline).filter((l) => l.kind !== "download");
|
|
161
170
|
const doneCount = counted.filter((l) => done.has(l.key)).length;
|
|
162
171
|
return {
|
|
163
172
|
counted: counted.length,
|
package/dist/tools.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ export declare const COURSE = "courses.course";
|
|
|
4
4
|
export declare const BUNDLE = "courses.bundle";
|
|
5
5
|
export declare const ENROLMENT = "courses.enrolment";
|
|
6
6
|
export declare const PROGRESS = "courses.progress";
|
|
7
|
+
export declare const PLAN = "courses.plan";
|
|
8
|
+
export interface RecordShape {
|
|
9
|
+
id: string;
|
|
10
|
+
title?: string | null;
|
|
11
|
+
values: Record<string, unknown>;
|
|
12
|
+
}
|
|
7
13
|
export declare const catalogue: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
8
14
|
theme: z.ZodOptional<z.ZodString>;
|
|
9
15
|
level: z.ZodOptional<z.ZodNumber>;
|
|
@@ -50,7 +56,6 @@ export declare const catalogue: import("@composable-os/sdk").ToolSpec<z.ZodObjec
|
|
|
50
56
|
}, z.core.$strip>>;
|
|
51
57
|
currency: z.ZodNullable<z.ZodString>;
|
|
52
58
|
}, z.core.$strip>>;
|
|
53
|
-
export declare const PLAN = "courses.plan";
|
|
54
59
|
export declare const plans: import("@composable-os/sdk").ToolSpec<z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
|
|
55
60
|
plans: z.ZodArray<z.ZodObject<{
|
|
56
61
|
id: z.ZodString;
|
|
@@ -190,6 +195,7 @@ export declare const buy: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
|
190
195
|
courseId: z.ZodOptional<z.ZodString>;
|
|
191
196
|
bundleId: z.ZodOptional<z.ZodString>;
|
|
192
197
|
email: z.ZodOptional<z.ZodString>;
|
|
198
|
+
agreements: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
193
199
|
}, z.core.$strip>, z.ZodObject<{
|
|
194
200
|
id: z.ZodString;
|
|
195
201
|
state: z.ZodString;
|