@fayz-ai/courses 0.7.1 → 0.8.1
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/README.md +2 -0
- package/dist/index.cjs +132 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +132 -29
- package/dist/index.js.map +1 -1
- package/dist/mock-provider.d.ts +3 -1
- package/dist/mock-provider.d.ts.map +1 -1
- package/dist/provider.d.ts +8 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/seed.d.ts.map +1 -1
- package/dist/supabase-provider.d.ts.map +1 -1
- package/dist/tables.d.ts +15 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/index.ts +1 -1
- package/src/mock-provider.ts +14 -1
- package/src/provider.ts +8 -1
- package/src/seed.ts +1 -0
- package/src/supabase-provider.ts +112 -31
- package/src/tables.ts +18 -0
- package/src/types.ts +29 -0
package/dist/tables.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const T: {
|
|
2
|
+
readonly courses: "plg_courses_courses";
|
|
3
|
+
readonly modules: "plg_courses_modules";
|
|
4
|
+
readonly lessons: "plg_courses_lessons";
|
|
5
|
+
readonly offers: "plg_courses_offers";
|
|
6
|
+
readonly customers: "plg_courses_customers";
|
|
7
|
+
readonly enrollments: "plg_courses_enrollments";
|
|
8
|
+
readonly progress: "plg_courses_progress";
|
|
9
|
+
readonly orders: "plg_courses_orders";
|
|
10
|
+
readonly subscriptions: "plg_courses_subscriptions";
|
|
11
|
+
readonly creatorAccounts: "plg_courses_creator_accounts";
|
|
12
|
+
readonly payouts: "plg_courses_payouts";
|
|
13
|
+
readonly paymentEvents: "plg_courses_payment_events";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../src/tables.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,CAAC;;;;;;;;;;;;;CAaJ,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type CourseStatus = 'draft' | 'published' | 'archived';
|
|
2
|
+
/** How the course is delivered — drives scheduling/logistics and the storefront copy. */
|
|
3
|
+
export type CourseDeliveryType = 'online' | 'in_person' | 'hybrid';
|
|
2
4
|
export interface Course {
|
|
3
5
|
id: string;
|
|
4
6
|
slug: string;
|
|
@@ -9,6 +11,8 @@ export interface Course {
|
|
|
9
11
|
price: number;
|
|
10
12
|
currency: string;
|
|
11
13
|
status: CourseStatus;
|
|
14
|
+
/** online (default), presencial, or híbrido. */
|
|
15
|
+
deliveryType: CourseDeliveryType;
|
|
12
16
|
sortOrder: number;
|
|
13
17
|
createdAt: string;
|
|
14
18
|
updatedAt: string;
|
|
@@ -54,6 +58,7 @@ export interface CreateCourseInput {
|
|
|
54
58
|
price?: number;
|
|
55
59
|
currency?: string;
|
|
56
60
|
status?: CourseStatus;
|
|
61
|
+
deliveryType?: CourseDeliveryType;
|
|
57
62
|
sortOrder?: number;
|
|
58
63
|
}
|
|
59
64
|
export type UpdateCourseInput = Partial<CreateCourseInput>;
|
|
@@ -137,6 +142,27 @@ export interface Order {
|
|
|
137
142
|
financialStatus: FinancialStatus;
|
|
138
143
|
stripePaymentIntentId: string | null;
|
|
139
144
|
createdAt: string;
|
|
145
|
+
/** Number of installments (parcelas), from the receivable. Defaults to 1. */
|
|
146
|
+
installmentCount?: number;
|
|
147
|
+
}
|
|
148
|
+
/** One installment (bill) of an order's receivable, with its settlement. */
|
|
149
|
+
export interface OrderInstallment {
|
|
150
|
+
installmentNumber: number;
|
|
151
|
+
amount: number;
|
|
152
|
+
paidAmount: number;
|
|
153
|
+
status: string;
|
|
154
|
+
dueDate: string | null;
|
|
155
|
+
paymentDate: string | null;
|
|
156
|
+
cardBrand: string | null;
|
|
157
|
+
cardInstallments: number | null;
|
|
158
|
+
}
|
|
159
|
+
/** Full order for the detail page — order + course/offer + receivable schedule. */
|
|
160
|
+
export interface OrderDetail extends Order {
|
|
161
|
+
courseTitle: string | null;
|
|
162
|
+
offerName: string | null;
|
|
163
|
+
paidAmount: number;
|
|
164
|
+
balance: number;
|
|
165
|
+
installments: OrderInstallment[];
|
|
140
166
|
}
|
|
141
167
|
export type SubscriptionStatus = 'active' | 'canceled' | 'past_due';
|
|
142
168
|
export interface Subscription {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,CAAA;AAE7D,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,YAAY,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,KA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MAAM,GAAG,IAAI,CAAA;IAC9B,cAAc,EAAE,OAAO,CAAA;IACvB,cAAc,EAAE,OAAO,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,iFAAiF;IACjF,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,0DAA0D;AAC1D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,MAAM,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,iCAAiC;IACjC,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAA;IACX,WAAW;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AACD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,kBAAkB,CAAA;CAC5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fayz-ai/courses",
|
|
3
|
-
"
|
|
3
|
+
"fayz": {
|
|
4
|
+
"status": "beta"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.8.1",
|
|
4
7
|
"description": "Fayz SDK education domain — courses, modules, lessons, enrollments, progress",
|
|
5
8
|
"type": "module",
|
|
6
9
|
"main": "./dist/index.cjs",
|
|
@@ -19,7 +22,7 @@
|
|
|
19
22
|
"src"
|
|
20
23
|
],
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@fayz-ai/core": "^0.
|
|
25
|
+
"@fayz-ai/core": "^0.8.4"
|
|
23
26
|
},
|
|
24
27
|
"peerDependencies": {
|
|
25
28
|
"react": "^18.0.0 || ^19.0.0"
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type {
|
|
|
7
7
|
ListCoursesOptions,
|
|
8
8
|
// Commerce layer
|
|
9
9
|
Offer, OfferKind, RecurringInterval, CreateOfferInput, UpdateOfferInput,
|
|
10
|
-
Order, PaymentMethod, FinancialStatus, ListOrdersOptions,
|
|
10
|
+
Order, OrderDetail, OrderInstallment, PaymentMethod, FinancialStatus, ListOrdersOptions,
|
|
11
11
|
Subscription, SubscriptionStatus, ListSubscriptionsOptions,
|
|
12
12
|
Payout, PayoutStatus, CreatorAccount, FinancialSummary,
|
|
13
13
|
} from './types'
|
package/src/mock-provider.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
CreateLessonInput, UpdateLessonInput,
|
|
7
7
|
ListCoursesOptions,
|
|
8
8
|
Offer, CreateOfferInput, UpdateOfferInput,
|
|
9
|
-
Order, ListOrdersOptions,
|
|
9
|
+
Order, OrderDetail, ListOrdersOptions,
|
|
10
10
|
Subscription, ListSubscriptionsOptions,
|
|
11
11
|
Payout, CreatorAccount, FinancialSummary,
|
|
12
12
|
} from './types'
|
|
@@ -134,6 +134,7 @@ export class MockCoursesProvider implements CoursesProvider {
|
|
|
134
134
|
price: input.price ?? 0,
|
|
135
135
|
currency: input.currency ?? 'BRL',
|
|
136
136
|
status: input.status ?? 'draft',
|
|
137
|
+
deliveryType: input.deliveryType ?? 'online',
|
|
137
138
|
sortOrder: input.sortOrder ?? list.length,
|
|
138
139
|
createdAt: now(),
|
|
139
140
|
updatedAt: now(),
|
|
@@ -299,6 +300,18 @@ export class MockCoursesProvider implements CoursesProvider {
|
|
|
299
300
|
return list.slice().sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))
|
|
300
301
|
}
|
|
301
302
|
|
|
303
|
+
// Core-commerce course sales don't exist in the mock layer (no orders/financial).
|
|
304
|
+
async listCoreSales(): Promise<Order[]> {
|
|
305
|
+
return []
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async getOrder(id: string): Promise<OrderDetail | null> {
|
|
309
|
+
const o = this.orders().find((x) => x.id === id)
|
|
310
|
+
if (!o) return null
|
|
311
|
+
const paid = o.financialStatus === 'paid' ? o.total : 0
|
|
312
|
+
return { ...o, courseTitle: null, offerName: null, paidAmount: paid, balance: o.total - paid, installments: [] }
|
|
313
|
+
}
|
|
314
|
+
|
|
302
315
|
// Subscriptions -----------------------------------------------------------
|
|
303
316
|
async listSubscriptions(opts?: ListSubscriptionsOptions): Promise<Subscription[]> {
|
|
304
317
|
let list = this.subscriptions()
|
package/src/provider.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
CreateLessonInput, UpdateLessonInput,
|
|
6
6
|
ListCoursesOptions,
|
|
7
7
|
Offer, CreateOfferInput, UpdateOfferInput,
|
|
8
|
-
Order, ListOrdersOptions,
|
|
8
|
+
Order, OrderDetail, ListOrdersOptions,
|
|
9
9
|
Subscription, ListSubscriptionsOptions,
|
|
10
10
|
Payout, CreatorAccount, FinancialSummary,
|
|
11
11
|
} from './types'
|
|
@@ -49,6 +49,13 @@ export interface CoursesProvider {
|
|
|
49
49
|
|
|
50
50
|
// Sales ledger
|
|
51
51
|
listOrders(options?: ListOrdersOptions): Promise<Order[]>
|
|
52
|
+
/** Course sales made through the CORE commerce (approved CRM quotes + direct
|
|
53
|
+
* financial receivables that reference a course). Mapped into the Order shape
|
|
54
|
+
* so the Sales screen shows the same money as Financeiro > Receber. */
|
|
55
|
+
listCoreSales(): Promise<Order[]>
|
|
56
|
+
/** Full detail for one order (canonical public.orders) + course/offer +
|
|
57
|
+
* the receivable's installment schedule. Powers the order-detail page. */
|
|
58
|
+
getOrder(id: string): Promise<OrderDetail | null>
|
|
52
59
|
|
|
53
60
|
// Recurring subscriptions
|
|
54
61
|
listSubscriptions(options?: ListSubscriptionsOptions): Promise<Subscription[]>
|
package/src/seed.ts
CHANGED
package/src/supabase-provider.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getSupabaseClientOptional } from '@fayz-ai/core'
|
|
2
2
|
import type { CoursesProvider } from './provider'
|
|
3
3
|
import { getCoursesTenantId } from './tenant'
|
|
4
|
+
import { T } from './tables'
|
|
4
5
|
import type {
|
|
5
6
|
Course, Module, Lesson, Enrollment, Progress,
|
|
6
7
|
CreateCourseInput, UpdateCourseInput,
|
|
@@ -8,7 +9,7 @@ import type {
|
|
|
8
9
|
CreateLessonInput, UpdateLessonInput,
|
|
9
10
|
ListCoursesOptions,
|
|
10
11
|
Offer, CreateOfferInput, UpdateOfferInput,
|
|
11
|
-
Order, ListOrdersOptions,
|
|
12
|
+
Order, OrderDetail, OrderInstallment, PaymentMethod, ListOrdersOptions, FinancialStatus,
|
|
12
13
|
Subscription, ListSubscriptionsOptions,
|
|
13
14
|
Payout, CreatorAccount, FinancialSummary,
|
|
14
15
|
} from './types'
|
|
@@ -38,6 +39,7 @@ function rowToCourse(r: any): Course {
|
|
|
38
39
|
id: r.id, slug: r.slug, title: r.title, subtitle: r.subtitle ?? null,
|
|
39
40
|
description: r.description ?? null, thumbnailUrl: r.thumbnail_url ?? null,
|
|
40
41
|
price: r.price ?? 0, currency: r.currency ?? 'BRL', status: r.status ?? 'draft',
|
|
42
|
+
deliveryType: r.delivery_type ?? 'online',
|
|
41
43
|
sortOrder: r.sort_order ?? 0, createdAt: r.created_at, updatedAt: r.updated_at,
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -103,7 +105,7 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
103
105
|
return {
|
|
104
106
|
// Courses ---------------------------------------------------------------
|
|
105
107
|
async listCourses(opts?: ListCoursesOptions): Promise<Course[]> {
|
|
106
|
-
let q = scoped(getDb().from(
|
|
108
|
+
let q = scoped(getDb().from(T.courses).select('*'))
|
|
107
109
|
if (opts?.status) q = q.eq('status', opts.status)
|
|
108
110
|
if (opts?.slug) q = q.eq('slug', opts.slug)
|
|
109
111
|
if (opts?.search) q = q.ilike('title', `%${opts.search}%`)
|
|
@@ -113,17 +115,18 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
113
115
|
},
|
|
114
116
|
async getCourse(idOrSlug: string): Promise<Course | null> {
|
|
115
117
|
const col = /^[0-9a-f-]{36}$/i.test(idOrSlug) ? 'id' : 'slug'
|
|
116
|
-
const { data, error } = await scoped(getDb().from(
|
|
118
|
+
const { data, error } = await scoped(getDb().from(T.courses).select('*').eq(col, idOrSlug)).maybeSingle()
|
|
117
119
|
if (error) throw error
|
|
118
120
|
return data ? rowToCourse(data) : null
|
|
119
121
|
},
|
|
120
122
|
async createCourse(input: CreateCourseInput): Promise<Course> {
|
|
121
|
-
const { data, error } = await getDb().from(
|
|
123
|
+
const { data, error } = await getDb().from(T.courses).insert({
|
|
122
124
|
tenant_id: getTenantId(),
|
|
123
125
|
slug: input.slug ?? slugify(input.title),
|
|
124
126
|
title: input.title, subtitle: input.subtitle ?? null, description: input.description ?? null,
|
|
125
127
|
thumbnail_url: input.thumbnailUrl ?? null, price: input.price ?? 0,
|
|
126
|
-
currency: input.currency ?? 'BRL', status: input.status ?? 'draft',
|
|
128
|
+
currency: input.currency ?? 'BRL', status: input.status ?? 'draft',
|
|
129
|
+
delivery_type: input.deliveryType ?? 'online', sort_order: input.sortOrder ?? 0,
|
|
127
130
|
}).select('*').single()
|
|
128
131
|
if (error) throw error
|
|
129
132
|
return rowToCourse(data)
|
|
@@ -138,24 +141,25 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
138
141
|
if (input.price !== undefined) patch.price = input.price
|
|
139
142
|
if (input.currency !== undefined) patch.currency = input.currency
|
|
140
143
|
if (input.status !== undefined) patch.status = input.status
|
|
144
|
+
if (input.deliveryType !== undefined) patch.delivery_type = input.deliveryType
|
|
141
145
|
if (input.sortOrder !== undefined) patch.sort_order = input.sortOrder
|
|
142
|
-
const { data, error } = await scoped(getDb().from(
|
|
146
|
+
const { data, error } = await scoped(getDb().from(T.courses).update(patch).eq('id', id)).select('*').single()
|
|
143
147
|
if (error) throw error
|
|
144
148
|
return rowToCourse(data)
|
|
145
149
|
},
|
|
146
150
|
async deleteCourse(id: string): Promise<void> {
|
|
147
|
-
const { error } = await scoped(getDb().from(
|
|
151
|
+
const { error } = await scoped(getDb().from(T.courses).delete().eq('id', id))
|
|
148
152
|
if (error) throw error
|
|
149
153
|
},
|
|
150
154
|
|
|
151
155
|
// Modules ---------------------------------------------------------------
|
|
152
156
|
async listModules(courseId: string): Promise<Module[]> {
|
|
153
|
-
const { data, error } = await scoped(getDb().from(
|
|
157
|
+
const { data, error } = await scoped(getDb().from(T.modules).select('*').eq('course_id', courseId)).order('sort_order', { ascending: true })
|
|
154
158
|
if (error) throw error
|
|
155
159
|
return (data ?? []).map(rowToModule)
|
|
156
160
|
},
|
|
157
161
|
async createModule(input: CreateModuleInput): Promise<Module> {
|
|
158
|
-
const { data, error } = await getDb().from(
|
|
162
|
+
const { data, error } = await getDb().from(T.modules).insert({
|
|
159
163
|
tenant_id: getTenantId(), course_id: input.courseId, title: input.title, sort_order: input.sortOrder ?? 0,
|
|
160
164
|
}).select('*').single()
|
|
161
165
|
if (error) throw error
|
|
@@ -165,28 +169,28 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
165
169
|
const patch: any = {}
|
|
166
170
|
if (input.title !== undefined) patch.title = input.title
|
|
167
171
|
if (input.sortOrder !== undefined) patch.sort_order = input.sortOrder
|
|
168
|
-
const { data, error } = await scoped(getDb().from(
|
|
172
|
+
const { data, error } = await scoped(getDb().from(T.modules).update(patch).eq('id', id)).select('*').single()
|
|
169
173
|
if (error) throw error
|
|
170
174
|
return rowToModule(data)
|
|
171
175
|
},
|
|
172
176
|
async deleteModule(id: string): Promise<void> {
|
|
173
|
-
const { error } = await scoped(getDb().from(
|
|
177
|
+
const { error } = await scoped(getDb().from(T.modules).delete().eq('id', id))
|
|
174
178
|
if (error) throw error
|
|
175
179
|
},
|
|
176
180
|
|
|
177
181
|
// Lessons ---------------------------------------------------------------
|
|
178
182
|
async listLessons(courseId: string): Promise<Lesson[]> {
|
|
179
|
-
const { data, error } = await scoped(getDb().from(
|
|
183
|
+
const { data, error } = await scoped(getDb().from(T.lessons).select('*').eq('course_id', courseId)).order('sort_order', { ascending: true })
|
|
180
184
|
if (error) throw error
|
|
181
185
|
return (data ?? []).map(rowToLesson)
|
|
182
186
|
},
|
|
183
187
|
async getLesson(id: string): Promise<Lesson | null> {
|
|
184
|
-
const { data, error } = await scoped(getDb().from(
|
|
188
|
+
const { data, error } = await scoped(getDb().from(T.lessons).select('*').eq('id', id)).maybeSingle()
|
|
185
189
|
if (error) throw error
|
|
186
190
|
return data ? rowToLesson(data) : null
|
|
187
191
|
},
|
|
188
192
|
async createLesson(input: CreateLessonInput): Promise<Lesson> {
|
|
189
|
-
const { data, error } = await getDb().from(
|
|
193
|
+
const { data, error } = await getDb().from(T.lessons).insert({
|
|
190
194
|
tenant_id: getTenantId(), course_id: input.courseId, module_id: input.moduleId,
|
|
191
195
|
title: input.title, description: input.description ?? null, video_url: input.videoUrl,
|
|
192
196
|
duration_sec: input.durationSec ?? 600, sort_order: input.sortOrder ?? 0,
|
|
@@ -201,23 +205,23 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
201
205
|
if (input.videoUrl !== undefined) patch.video_url = input.videoUrl
|
|
202
206
|
if (input.durationSec !== undefined) patch.duration_sec = input.durationSec
|
|
203
207
|
if (input.sortOrder !== undefined) patch.sort_order = input.sortOrder
|
|
204
|
-
const { data, error } = await scoped(getDb().from(
|
|
208
|
+
const { data, error } = await scoped(getDb().from(T.lessons).update(patch).eq('id', id)).select('*').single()
|
|
205
209
|
if (error) throw error
|
|
206
210
|
return rowToLesson(data)
|
|
207
211
|
},
|
|
208
212
|
async deleteLesson(id: string): Promise<void> {
|
|
209
|
-
const { error } = await scoped(getDb().from(
|
|
213
|
+
const { error } = await scoped(getDb().from(T.lessons).delete().eq('id', id))
|
|
210
214
|
if (error) throw error
|
|
211
215
|
},
|
|
212
216
|
|
|
213
217
|
// Enrollments + progress ------------------------------------------------
|
|
214
218
|
async listEnrollments(customerId: string): Promise<Enrollment[]> {
|
|
215
|
-
const { data, error } = await getDb().from(
|
|
219
|
+
const { data, error } = await getDb().from(T.enrollments).select('*').eq('customer_id', customerId)
|
|
216
220
|
if (error) throw error
|
|
217
221
|
return (data ?? []).map(rowToEnrollment)
|
|
218
222
|
},
|
|
219
223
|
async enroll(courseId: string, customerId: string): Promise<Enrollment> {
|
|
220
|
-
const { data, error } = await getDb().from(
|
|
224
|
+
const { data, error } = await getDb().from(T.enrollments)
|
|
221
225
|
.upsert({ tenant_id: getTenantId(), course_id: courseId, customer_id: customerId, status: 'active' },
|
|
222
226
|
{ onConflict: 'course_id,customer_id' })
|
|
223
227
|
.select('*').single()
|
|
@@ -225,7 +229,7 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
225
229
|
return rowToEnrollment(data)
|
|
226
230
|
},
|
|
227
231
|
async listProgress(enrollmentId: string): Promise<Progress[]> {
|
|
228
|
-
const { data, error } = await getDb().from(
|
|
232
|
+
const { data, error } = await getDb().from(T.progress).select('*').eq('enrollment_id', enrollmentId)
|
|
229
233
|
if (error) throw error
|
|
230
234
|
return (data ?? []).map(rowToProgress)
|
|
231
235
|
},
|
|
@@ -233,7 +237,7 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
233
237
|
const row: any = { tenant_id: getTenantId(), enrollment_id: enrollmentId, lesson_id: lessonId }
|
|
234
238
|
if (patch.completed !== undefined) { row.completed = patch.completed; row.completed_at = patch.completed ? new Date().toISOString() : null }
|
|
235
239
|
if (patch.lastPositionSec !== undefined) row.last_position_sec = patch.lastPositionSec
|
|
236
|
-
const { data, error } = await getDb().from(
|
|
240
|
+
const { data, error } = await getDb().from(T.progress)
|
|
237
241
|
.upsert(row, { onConflict: 'enrollment_id,lesson_id' }).select('*').single()
|
|
238
242
|
if (error) throw error
|
|
239
243
|
return rowToProgress(data)
|
|
@@ -241,12 +245,12 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
241
245
|
|
|
242
246
|
// Offers ----------------------------------------------------------------
|
|
243
247
|
async listOffers(courseId: string): Promise<Offer[]> {
|
|
244
|
-
const { data, error } = await scoped(getDb().from(
|
|
248
|
+
const { data, error } = await scoped(getDb().from(T.offers).select('*').eq('course_id', courseId)).order('sort_order', { ascending: true })
|
|
245
249
|
if (error) throw error
|
|
246
250
|
return (data ?? []).map(rowToOffer)
|
|
247
251
|
},
|
|
248
252
|
async createOffer(input: CreateOfferInput): Promise<Offer> {
|
|
249
|
-
const { data, error } = await getDb().from(
|
|
253
|
+
const { data, error } = await getDb().from(T.offers).insert({
|
|
250
254
|
tenant_id: getTenantId(), course_id: input.courseId, name: input.name, price: input.price,
|
|
251
255
|
currency: input.currency ?? 'BRL', kind: input.kind ?? 'one_time',
|
|
252
256
|
recurring_interval: input.recurringInterval ?? (input.kind === 'subscription' ? 'month' : null),
|
|
@@ -265,18 +269,18 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
265
269
|
if (input.isDefault !== undefined) patch.is_default = input.isDefault
|
|
266
270
|
if (input.isOrderBump !== undefined) patch.is_order_bump = input.isOrderBump
|
|
267
271
|
if (input.sortOrder !== undefined) patch.sort_order = input.sortOrder
|
|
268
|
-
const { data, error } = await scoped(getDb().from(
|
|
272
|
+
const { data, error } = await scoped(getDb().from(T.offers).update(patch).eq('id', id)).select('*').single()
|
|
269
273
|
if (error) throw error
|
|
270
274
|
return rowToOffer(data)
|
|
271
275
|
},
|
|
272
276
|
async deleteOffer(id: string): Promise<void> {
|
|
273
|
-
const { error } = await scoped(getDb().from(
|
|
277
|
+
const { error } = await scoped(getDb().from(T.offers).delete().eq('id', id))
|
|
274
278
|
if (error) throw error
|
|
275
279
|
},
|
|
276
280
|
|
|
277
281
|
// Sales -----------------------------------------------------------------
|
|
278
282
|
async listOrders(opts?: ListOrdersOptions): Promise<Order[]> {
|
|
279
|
-
let q = scoped(getDb().from(
|
|
283
|
+
let q = scoped(getDb().from(T.orders).select('*'))
|
|
280
284
|
if (opts?.courseId) q = q.eq('course_id', opts.courseId)
|
|
281
285
|
if (opts?.financialStatus) q = q.eq('financial_status', opts.financialStatus)
|
|
282
286
|
if (opts?.search) q = q.or(`customer_name.ilike.%${opts.search}%,customer_email.ilike.%${opts.search}%`)
|
|
@@ -284,10 +288,87 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
284
288
|
if (error) throw error
|
|
285
289
|
return (data ?? []).map(rowToOrder)
|
|
286
290
|
},
|
|
291
|
+
async listCoreSales(): Promise<Order[]> {
|
|
292
|
+
const { data, error } = await scoped(getDb().from('v_plg_course_sales').select('*'))
|
|
293
|
+
.order('created_at', { ascending: false })
|
|
294
|
+
if (error) throw error
|
|
295
|
+
return (data ?? []).map((r: any): Order => ({
|
|
296
|
+
id: r.id,
|
|
297
|
+
courseId: r.course_id ?? '',
|
|
298
|
+
offerId: r.offer_id ?? null,
|
|
299
|
+
customerId: r.party_id ?? null,
|
|
300
|
+
customerName: r.customer_name ?? null,
|
|
301
|
+
customerEmail: r.customer_email ?? null,
|
|
302
|
+
currency: r.currency ?? 'BRL',
|
|
303
|
+
total: Number(r.total ?? 0),
|
|
304
|
+
platformFee: Number(r.platform_fee ?? 0),
|
|
305
|
+
netValue: Number(r.net_value ?? r.total ?? 0),
|
|
306
|
+
paymentMethod: (r.payment_method ?? null) as PaymentMethod | null,
|
|
307
|
+
financialStatus: (r.financial_status ?? 'pending') as FinancialStatus,
|
|
308
|
+
stripePaymentIntentId: null,
|
|
309
|
+
createdAt: r.created_at,
|
|
310
|
+
installmentCount: Number(r.installment_count ?? 1),
|
|
311
|
+
}))
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
async getOrder(id: string): Promise<OrderDetail | null> {
|
|
315
|
+
const db = getDb()
|
|
316
|
+
const { data: v } = await scoped(db.from('v_plg_course_sales').select('*')).eq('id', id).maybeSingle()
|
|
317
|
+
if (!v) return null
|
|
318
|
+
const [{ data: course }, { data: bills }, { data: pays }] = await Promise.all([
|
|
319
|
+
db.from(T.courses).select('title').eq('id', v.course_id).maybeSingle(),
|
|
320
|
+
db.from('plg_financial_movements').select('*').eq('invoice_id', id).eq('movement_kind', 'bill').order('installment_number'),
|
|
321
|
+
db.from('plg_financial_movements').select('*').eq('invoice_id', id).eq('movement_kind', 'payment'),
|
|
322
|
+
])
|
|
323
|
+
let offerName: string | null = null
|
|
324
|
+
if (v.offer_id) {
|
|
325
|
+
const { data: off } = await db.from(T.offers).select('name').eq('id', v.offer_id).maybeSingle()
|
|
326
|
+
offerName = off?.name ?? null
|
|
327
|
+
}
|
|
328
|
+
const paymentsByInst = new Map<number, any>()
|
|
329
|
+
for (const p of pays ?? []) paymentsByInst.set(p.installment_number ?? 0, p)
|
|
330
|
+
const installments: OrderInstallment[] = (bills ?? []).map((b: any) => {
|
|
331
|
+
const p = paymentsByInst.get(b.installment_number ?? 0)
|
|
332
|
+
return {
|
|
333
|
+
installmentNumber: b.installment_number ?? 1,
|
|
334
|
+
amount: Number(b.amount ?? 0),
|
|
335
|
+
paidAmount: Number(b.paid_amount ?? 0),
|
|
336
|
+
status: b.status ?? 'pending',
|
|
337
|
+
dueDate: b.due_date ?? null,
|
|
338
|
+
paymentDate: p?.payment_date ?? b.payment_date ?? null,
|
|
339
|
+
cardBrand: p?.card_brand ?? null,
|
|
340
|
+
cardInstallments: p?.card_installments ?? null,
|
|
341
|
+
}
|
|
342
|
+
})
|
|
343
|
+
const paid = (bills ?? []).reduce((s: number, b: any) => s + Number(b.paid_amount ?? 0), 0)
|
|
344
|
+
const total = Number(v.total ?? 0)
|
|
345
|
+
return {
|
|
346
|
+
id: v.id,
|
|
347
|
+
courseId: v.course_id ?? '',
|
|
348
|
+
offerId: v.offer_id ?? null,
|
|
349
|
+
customerId: v.party_id ?? null,
|
|
350
|
+
customerName: v.customer_name ?? null,
|
|
351
|
+
customerEmail: v.customer_email ?? null,
|
|
352
|
+
currency: v.currency ?? 'BRL',
|
|
353
|
+
total,
|
|
354
|
+
platformFee: Number(v.platform_fee ?? 0),
|
|
355
|
+
netValue: Number(v.net_value ?? total),
|
|
356
|
+
paymentMethod: (v.payment_method ?? null) as PaymentMethod | null,
|
|
357
|
+
financialStatus: (v.financial_status ?? 'pending') as FinancialStatus,
|
|
358
|
+
stripePaymentIntentId: null,
|
|
359
|
+
createdAt: v.created_at,
|
|
360
|
+
installmentCount: Number(v.installment_count ?? installments.length ?? 1),
|
|
361
|
+
courseTitle: course?.title ?? null,
|
|
362
|
+
offerName,
|
|
363
|
+
paidAmount: paid,
|
|
364
|
+
balance: Math.max(0, total - paid),
|
|
365
|
+
installments,
|
|
366
|
+
}
|
|
367
|
+
},
|
|
287
368
|
|
|
288
369
|
// Subscriptions ---------------------------------------------------------
|
|
289
370
|
async listSubscriptions(opts?: ListSubscriptionsOptions): Promise<Subscription[]> {
|
|
290
|
-
let q = scoped(getDb().from(
|
|
371
|
+
let q = scoped(getDb().from(T.subscriptions).select('*'))
|
|
291
372
|
if (opts?.courseId) q = q.eq('course_id', opts.courseId)
|
|
292
373
|
if (opts?.status) q = q.eq('status', opts.status)
|
|
293
374
|
const { data, error } = await q.order('started_at', { ascending: false })
|
|
@@ -298,9 +379,9 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
298
379
|
// Financial -------------------------------------------------------------
|
|
299
380
|
async getFinancialSummary(): Promise<FinancialSummary> {
|
|
300
381
|
const [orders, subs, payouts] = await Promise.all([
|
|
301
|
-
scoped(getDb().from(
|
|
302
|
-
scoped(getDb().from(
|
|
303
|
-
scoped(getDb().from(
|
|
382
|
+
scoped(getDb().from(T.orders).select('total,platform_fee,net_value,financial_status')),
|
|
383
|
+
scoped(getDb().from(T.subscriptions).select('net_value,interval,status')),
|
|
384
|
+
scoped(getDb().from(T.payouts).select('amount,status')),
|
|
304
385
|
])
|
|
305
386
|
const orderRows: any[] = orders.data ?? []
|
|
306
387
|
const paid = orderRows.filter((o) => o.financial_status === 'paid')
|
|
@@ -324,13 +405,13 @@ export function createSupabaseCoursesProvider(): CoursesProvider {
|
|
|
324
405
|
}
|
|
325
406
|
},
|
|
326
407
|
async listPayouts(): Promise<Payout[]> {
|
|
327
|
-
const { data, error } = await scoped(getDb().from(
|
|
408
|
+
const { data, error } = await scoped(getDb().from(T.payouts).select('*')).order('created_at', { ascending: false })
|
|
328
409
|
if (error) throw error
|
|
329
410
|
return (data ?? []).map(rowToPayout)
|
|
330
411
|
},
|
|
331
412
|
async getCreatorAccount(): Promise<CreatorAccount> {
|
|
332
413
|
const tenantId = getTenantId()
|
|
333
|
-
const { data } = await scoped(getDb().from(
|
|
414
|
+
const { data } = await scoped(getDb().from(T.creatorAccounts).select('*')).maybeSingle()
|
|
334
415
|
return {
|
|
335
416
|
tenantId: tenantId ?? '',
|
|
336
417
|
stripeAccountId: data?.stripe_account_id ?? null,
|
package/src/tables.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Physical table names for @fayz-ai/courses. Renamed to the plg_courses_*
|
|
2
|
+
// industry-pool prefix (was course_*) when the core DB moved into the public
|
|
3
|
+
// schema. RPC function names (course_place_order, course_confirm_payment) are
|
|
4
|
+
// unchanged.
|
|
5
|
+
export const T = {
|
|
6
|
+
courses: 'plg_courses_courses',
|
|
7
|
+
modules: 'plg_courses_modules',
|
|
8
|
+
lessons: 'plg_courses_lessons',
|
|
9
|
+
offers: 'plg_courses_offers',
|
|
10
|
+
customers: 'plg_courses_customers',
|
|
11
|
+
enrollments: 'plg_courses_enrollments',
|
|
12
|
+
progress: 'plg_courses_progress',
|
|
13
|
+
orders: 'plg_courses_orders',
|
|
14
|
+
subscriptions: 'plg_courses_subscriptions',
|
|
15
|
+
creatorAccounts: 'plg_courses_creator_accounts',
|
|
16
|
+
payouts: 'plg_courses_payouts',
|
|
17
|
+
paymentEvents: 'plg_courses_payment_events',
|
|
18
|
+
} as const
|
package/src/types.ts
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
export type CourseStatus = 'draft' | 'published' | 'archived'
|
|
9
9
|
|
|
10
|
+
/** How the course is delivered — drives scheduling/logistics and the storefront copy. */
|
|
11
|
+
export type CourseDeliveryType = 'online' | 'in_person' | 'hybrid'
|
|
12
|
+
|
|
10
13
|
export interface Course {
|
|
11
14
|
id: string
|
|
12
15
|
slug: string
|
|
@@ -17,6 +20,8 @@ export interface Course {
|
|
|
17
20
|
price: number
|
|
18
21
|
currency: string
|
|
19
22
|
status: CourseStatus
|
|
23
|
+
/** online (default), presencial, or híbrido. */
|
|
24
|
+
deliveryType: CourseDeliveryType
|
|
20
25
|
sortOrder: number
|
|
21
26
|
createdAt: string
|
|
22
27
|
updatedAt: string
|
|
@@ -69,6 +74,7 @@ export interface CreateCourseInput {
|
|
|
69
74
|
price?: number
|
|
70
75
|
currency?: string
|
|
71
76
|
status?: CourseStatus
|
|
77
|
+
deliveryType?: CourseDeliveryType
|
|
72
78
|
sortOrder?: number
|
|
73
79
|
}
|
|
74
80
|
export type UpdateCourseInput = Partial<CreateCourseInput>
|
|
@@ -168,6 +174,29 @@ export interface Order {
|
|
|
168
174
|
financialStatus: FinancialStatus
|
|
169
175
|
stripePaymentIntentId: string | null
|
|
170
176
|
createdAt: string
|
|
177
|
+
/** Number of installments (parcelas), from the receivable. Defaults to 1. */
|
|
178
|
+
installmentCount?: number
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** One installment (bill) of an order's receivable, with its settlement. */
|
|
182
|
+
export interface OrderInstallment {
|
|
183
|
+
installmentNumber: number
|
|
184
|
+
amount: number
|
|
185
|
+
paidAmount: number
|
|
186
|
+
status: string
|
|
187
|
+
dueDate: string | null
|
|
188
|
+
paymentDate: string | null
|
|
189
|
+
cardBrand: string | null
|
|
190
|
+
cardInstallments: number | null
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Full order for the detail page — order + course/offer + receivable schedule. */
|
|
194
|
+
export interface OrderDetail extends Order {
|
|
195
|
+
courseTitle: string | null
|
|
196
|
+
offerName: string | null
|
|
197
|
+
paidAmount: number
|
|
198
|
+
balance: number
|
|
199
|
+
installments: OrderInstallment[]
|
|
171
200
|
}
|
|
172
201
|
|
|
173
202
|
export type SubscriptionStatus = 'active' | 'canceled' | 'past_due'
|