@fayz-ai/courses 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/seed.ts ADDED
@@ -0,0 +1,146 @@
1
+ import type { Course, Module, Lesson } from './types'
2
+
3
+ // Deterministic placeholder thumbnail (gradient SVG data-URI, no network).
4
+ function thumb(label: string, hue: number): string {
5
+ const svg =
6
+ `<svg xmlns="http://www.w3.org/2000/svg" width="640" height="360">` +
7
+ `<defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1">` +
8
+ `<stop offset="0" stop-color="hsl(${hue},65%,55%)"/>` +
9
+ `<stop offset="1" stop-color="hsl(${(hue + 40) % 360},65%,40%)"/>` +
10
+ `</linearGradient></defs><rect width="640" height="360" fill="url(#g)"/>` +
11
+ `<text x="32" y="320" fill="white" font-family="system-ui" font-size="40" font-weight="700">${label}</text>` +
12
+ `</svg>`
13
+ return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`
14
+ }
15
+
16
+ const YT = (id: string) => `https://www.youtube.com/embed/${id}`
17
+ const t0 = '2026-01-01T00:00:00.000Z'
18
+
19
+ // ---------------------------------------------------------------------------
20
+ // Course seed — a tiny education catalog the admin manages and the member area
21
+ // plays. Both apps start from this so admin↔member look consistent.
22
+ // ---------------------------------------------------------------------------
23
+
24
+ export interface CourseSeedInput {
25
+ slug: string
26
+ title: string
27
+ subtitle?: string
28
+ description?: string
29
+ price?: number
30
+ hue?: number
31
+ modules: Array<{
32
+ title: string
33
+ lessons: Array<{ title: string; description?: string; youtubeId: string; durationSec?: number }>
34
+ }>
35
+ }
36
+
37
+ export interface CourseCatalog {
38
+ courses: Course[]
39
+ modules: Module[]
40
+ lessons: Lesson[]
41
+ }
42
+
43
+ /** Build a deterministic CourseCatalog from a terse declarative seed. */
44
+ export function buildCourseCatalog(input: CourseSeedInput[]): CourseCatalog {
45
+ const courses: Course[] = []
46
+ const modules: Module[] = []
47
+ const lessons: Lesson[] = []
48
+
49
+ input.forEach((c, ci) => {
50
+ const courseId = `course-${String(ci + 1).padStart(2, '0')}`
51
+ courses.push({
52
+ id: courseId,
53
+ slug: c.slug,
54
+ title: c.title,
55
+ subtitle: c.subtitle ?? null,
56
+ description: c.description ?? null,
57
+ thumbnailUrl: thumb(c.title, c.hue ?? (ci * 70) % 360),
58
+ price: c.price ?? 197,
59
+ currency: 'BRL',
60
+ status: 'published',
61
+ sortOrder: ci,
62
+ createdAt: t0,
63
+ updatedAt: t0,
64
+ })
65
+ c.modules.forEach((m, mi) => {
66
+ const moduleId = `${courseId}-m${String(mi + 1).padStart(2, '0')}`
67
+ modules.push({ id: moduleId, courseId, title: m.title, sortOrder: mi })
68
+ m.lessons.forEach((l, li) => {
69
+ lessons.push({
70
+ id: `${moduleId}-l${String(li + 1).padStart(2, '0')}`,
71
+ courseId,
72
+ moduleId,
73
+ title: l.title,
74
+ description: l.description ?? null,
75
+ videoUrl: YT(l.youtubeId),
76
+ durationSec: l.durationSec ?? 600,
77
+ sortOrder: li,
78
+ })
79
+ })
80
+ })
81
+ })
82
+
83
+ return { courses, modules, lessons }
84
+ }
85
+
86
+ /** Default seed shared by both example apps. */
87
+ export const DEFAULT_COURSE_CATALOG: CourseCatalog = buildCourseCatalog([
88
+ {
89
+ slug: 'react-do-zero',
90
+ title: 'React do Zero ao Profissional',
91
+ subtitle: 'Construa interfaces modernas com React',
92
+ description: 'Do básico de componentes a hooks avançados e padrões de produção.',
93
+ price: 297,
94
+ hue: 210,
95
+ modules: [
96
+ {
97
+ title: 'Fundamentos',
98
+ lessons: [
99
+ { title: 'Boas-vindas e setup', youtubeId: 'aqz-KE-bpKQ', durationSec: 420 },
100
+ { title: 'JSX e componentes', youtubeId: 'LXb3EKWsInQ', durationSec: 720 },
101
+ ],
102
+ },
103
+ {
104
+ title: 'Hooks',
105
+ lessons: [
106
+ { title: 'useState e useEffect', youtubeId: 'jNQXAC9IVRw', durationSec: 900 },
107
+ { title: 'Hooks customizados', youtubeId: 'aqz-KE-bpKQ', durationSec: 840 },
108
+ ],
109
+ },
110
+ ],
111
+ },
112
+ {
113
+ slug: 'design-de-produto',
114
+ title: 'Design de Produto na Prática',
115
+ subtitle: 'Do problema ao protótipo validado',
116
+ description: 'Pesquisa, fluxos, wireframes e testes de usabilidade.',
117
+ price: 247,
118
+ hue: 320,
119
+ modules: [
120
+ {
121
+ title: 'Descoberta',
122
+ lessons: [
123
+ { title: 'Entrevistas com usuários', youtubeId: 'LXb3EKWsInQ', durationSec: 660 },
124
+ { title: 'Mapeando jornadas', youtubeId: 'jNQXAC9IVRw', durationSec: 540 },
125
+ ],
126
+ },
127
+ ],
128
+ },
129
+ {
130
+ slug: 'marketing-digital',
131
+ title: 'Marketing Digital para Criadores',
132
+ subtitle: 'Audiência, conteúdo e conversão',
133
+ description: 'Estratégias de tráfego, funil e lançamentos.',
134
+ price: 197,
135
+ hue: 30,
136
+ modules: [
137
+ {
138
+ title: 'Fundamentos',
139
+ lessons: [
140
+ { title: 'Posicionamento', youtubeId: 'aqz-KE-bpKQ', durationSec: 480 },
141
+ { title: 'Criando conteúdo que converte', youtubeId: 'LXb3EKWsInQ', durationSec: 600 },
142
+ ],
143
+ },
144
+ ],
145
+ },
146
+ ])
package/src/types.ts ADDED
@@ -0,0 +1,108 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Courses domain — the education counterpart of @fayz-ai/shop. A Course is the
3
+ // sellable unit; Modules group Lessons; a Lesson carries a video (embed URL in
4
+ // this mock layer). Enrollment = a customer owns a course; Progress tracks
5
+ // per-lesson completion.
6
+ // ---------------------------------------------------------------------------
7
+
8
+ export type CourseStatus = 'draft' | 'published' | 'archived'
9
+
10
+ export interface Course {
11
+ id: string
12
+ slug: string
13
+ title: string
14
+ subtitle: string | null
15
+ description: string | null
16
+ thumbnailUrl: string | null
17
+ price: number
18
+ currency: string
19
+ status: CourseStatus
20
+ sortOrder: number
21
+ createdAt: string
22
+ updatedAt: string
23
+ }
24
+
25
+ export interface Module {
26
+ id: string
27
+ courseId: string
28
+ title: string
29
+ sortOrder: number
30
+ }
31
+
32
+ export interface Lesson {
33
+ id: string
34
+ courseId: string
35
+ moduleId: string
36
+ title: string
37
+ description: string | null
38
+ /** Embed URL (YouTube/Vimeo) in the mock layer; a storage URL with a real backend. */
39
+ videoUrl: string
40
+ durationSec: number
41
+ sortOrder: number
42
+ }
43
+
44
+ export interface Enrollment {
45
+ id: string
46
+ courseId: string
47
+ customerId: string
48
+ status: 'active' | 'refunded'
49
+ enrolledAt: string
50
+ }
51
+
52
+ export interface Progress {
53
+ id: string
54
+ enrollmentId: string
55
+ lessonId: string
56
+ completed: boolean
57
+ lastPositionSec: number
58
+ completedAt: string | null
59
+ }
60
+
61
+ // Inputs -------------------------------------------------------------------
62
+
63
+ export interface CreateCourseInput {
64
+ title: string
65
+ slug?: string
66
+ subtitle?: string
67
+ description?: string
68
+ thumbnailUrl?: string
69
+ price?: number
70
+ currency?: string
71
+ status?: CourseStatus
72
+ sortOrder?: number
73
+ }
74
+ export type UpdateCourseInput = Partial<CreateCourseInput>
75
+
76
+ export interface CreateModuleInput {
77
+ courseId: string
78
+ title: string
79
+ sortOrder?: number
80
+ }
81
+ export type UpdateModuleInput = Partial<Omit<CreateModuleInput, 'courseId'>>
82
+
83
+ export interface CreateLessonInput {
84
+ courseId: string
85
+ moduleId: string
86
+ title: string
87
+ description?: string
88
+ videoUrl: string
89
+ durationSec?: number
90
+ sortOrder?: number
91
+ }
92
+ export type UpdateLessonInput = Partial<Omit<CreateLessonInput, 'courseId' | 'moduleId'>>
93
+
94
+ export interface ListCoursesOptions {
95
+ status?: CourseStatus
96
+ slug?: string
97
+ search?: string
98
+ }
99
+
100
+ /** A course plus the customer's enrollment + progress %, for "my courses". */
101
+ export interface EnrolledCourse {
102
+ course: Course
103
+ enrollment: Enrollment
104
+ totalLessons: number
105
+ completedLessons: number
106
+ /** 0..100 */
107
+ progressPercent: number
108
+ }