@fayz-ai/courses 0.6.0 → 0.7.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.
@@ -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,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,sFAAsF;IACtF,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAA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AAiC;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,6 @@
1
1
  {
2
2
  "name": "@fayz-ai/courses",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Fayz SDK education domain — courses, modules, lessons, enrollments, progress",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -19,7 +19,7 @@
19
19
  "src"
20
20
  ],
21
21
  "dependencies": {
22
- "@fayz-ai/core": "^0.6.0"
22
+ "@fayz-ai/core": "^0.7.0"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "react": "^18.0.0 || ^19.0.0"
package/src/index.ts CHANGED
@@ -5,6 +5,11 @@ export type {
5
5
  CreateModuleInput, UpdateModuleInput,
6
6
  CreateLessonInput, UpdateLessonInput,
7
7
  ListCoursesOptions,
8
+ // Commerce layer
9
+ Offer, OfferKind, RecurringInterval, CreateOfferInput, UpdateOfferInput,
10
+ Order, PaymentMethod, FinancialStatus, ListOrdersOptions,
11
+ Subscription, SubscriptionStatus, ListSubscriptionsOptions,
12
+ Payout, PayoutStatus, CreatorAccount, FinancialSummary,
8
13
  } from './types'
9
14
 
10
15
  export type { CoursesProvider } from './provider'
@@ -13,7 +18,16 @@ export { setCoursesProvider, getCoursesProvider, getCoursesProviderOptional } fr
13
18
  export { MockCoursesProvider, createMockCoursesProvider } from './mock-provider'
14
19
  export type { MockCoursesSeed } from './mock-provider'
15
20
 
16
- export { buildCourseCatalog, DEFAULT_COURSE_CATALOG } from './seed'
17
- export type { CourseCatalog, CourseSeedInput } from './seed'
21
+ // Supabase-backed provider + tenant scoping (the "fayz-course" central DB).
22
+ export { createSupabaseCoursesProvider } from './supabase-provider'
23
+ export { setCoursesTenantResolver, getCoursesTenantId } from './tenant'
24
+ export type { TenantResolver } from './tenant'
25
+ export { createSafeCoursesProvider } from './safe-provider'
26
+
27
+ export {
28
+ buildCourseCatalog, DEFAULT_COURSE_CATALOG,
29
+ buildDemoLedger, DEFAULT_DEMO_LEDGER, DEMO_PLATFORM_FEE_BPS,
30
+ } from './seed'
31
+ export type { CourseCatalog, CourseSeedInput, DemoLedger } from './seed'
18
32
 
19
33
  export { useMyCourses, useCourse, useCourseProgress } from './hooks'
@@ -5,8 +5,15 @@ import type {
5
5
  CreateModuleInput, UpdateModuleInput,
6
6
  CreateLessonInput, UpdateLessonInput,
7
7
  ListCoursesOptions,
8
+ Offer, CreateOfferInput, UpdateOfferInput,
9
+ Order, ListOrdersOptions,
10
+ Subscription, ListSubscriptionsOptions,
11
+ Payout, CreatorAccount, FinancialSummary,
8
12
  } from './types'
9
- import { DEFAULT_COURSE_CATALOG, type CourseCatalog } from './seed'
13
+ import {
14
+ DEFAULT_COURSE_CATALOG, DEFAULT_DEMO_LEDGER, DEMO_PLATFORM_FEE_BPS,
15
+ type CourseCatalog, type DemoLedger,
16
+ } from './seed'
10
17
 
11
18
  function uid() {
12
19
  return Math.random().toString(36).slice(2)
@@ -24,6 +31,10 @@ const K = {
24
31
  lessons: 'fayz.courses.mock.lessons.v1',
25
32
  enrollments: 'fayz.courses.mock.enrollments.v1',
26
33
  progress: 'fayz.courses.mock.progress.v1',
34
+ offers: 'fayz.courses.mock.offers.v1',
35
+ orders: 'fayz.courses.mock.orders.v1',
36
+ subscriptions: 'fayz.courses.mock.subscriptions.v1',
37
+ payouts: 'fayz.courses.mock.payouts.v1',
27
38
  }
28
39
 
29
40
  function load<T>(key: string): T[] | null {
@@ -45,6 +56,8 @@ function save<T>(key: string, value: T[]): void {
45
56
 
46
57
  export interface MockCoursesSeed {
47
58
  catalog?: CourseCatalog
59
+ /** Demo sales/subscriptions/payouts for the admin commerce surfaces. */
60
+ ledger?: DemoLedger
48
61
  /** Customer ids auto-enrolled in all courses (so the member area has data on first run). */
49
62
  enrollAll?: string[]
50
63
  }
@@ -58,10 +71,15 @@ export interface MockCoursesSeed {
58
71
  export class MockCoursesProvider implements CoursesProvider {
59
72
  constructor(seed?: MockCoursesSeed) {
60
73
  const catalog = seed?.catalog ?? DEFAULT_COURSE_CATALOG
74
+ const ledger = seed?.ledger ?? DEFAULT_DEMO_LEDGER
61
75
  if (load<Course>(K.courses) == null) {
62
76
  save(K.courses, catalog.courses)
63
77
  save(K.modules, catalog.modules)
64
78
  save(K.lessons, catalog.lessons)
79
+ save(K.offers, catalog.offers)
80
+ save(K.orders, ledger.orders)
81
+ save(K.subscriptions, ledger.subscriptions)
82
+ save(K.payouts, ledger.payouts)
65
83
  }
66
84
  // Auto-enroll demo customers in every course (idempotent).
67
85
  if (seed?.enrollAll?.length) {
@@ -85,6 +103,10 @@ export class MockCoursesProvider implements CoursesProvider {
85
103
  private lessons() { return load<Lesson>(K.lessons) ?? [] }
86
104
  private enrollments() { return load<Enrollment>(K.enrollments) ?? [] }
87
105
  private progress() { return load<Progress>(K.progress) ?? [] }
106
+ private offers() { return load<Offer>(K.offers) ?? [] }
107
+ private orders() { return load<Order>(K.orders) ?? [] }
108
+ private subscriptions() { return load<Subscription>(K.subscriptions) ?? [] }
109
+ private payouts() { return load<Payout>(K.payouts) ?? [] }
88
110
 
89
111
  // Courses -----------------------------------------------------------------
90
112
  async listCourses(opts?: ListCoursesOptions): Promise<Course[]> {
@@ -228,6 +250,105 @@ export class MockCoursesProvider implements CoursesProvider {
228
250
  save(K.progress, [...list, created])
229
251
  return created
230
252
  }
253
+
254
+ // Offers ------------------------------------------------------------------
255
+ async listOffers(courseId: string): Promise<Offer[]> {
256
+ return this.offers().filter((o) => o.courseId === courseId).sort((a, b) => a.sortOrder - b.sortOrder)
257
+ }
258
+ async createOffer(input: CreateOfferInput): Promise<Offer> {
259
+ const list = this.offers()
260
+ const offer: Offer = {
261
+ id: uid(),
262
+ courseId: input.courseId,
263
+ name: input.name,
264
+ price: input.price,
265
+ currency: input.currency ?? 'BRL',
266
+ kind: input.kind ?? 'one_time',
267
+ recurringInterval: input.recurringInterval ?? (input.kind === 'subscription' ? 'month' : null),
268
+ isDefault: input.isDefault ?? false,
269
+ isOrderBump: input.isOrderBump ?? false,
270
+ sortOrder: input.sortOrder ?? list.filter((o) => o.courseId === input.courseId).length,
271
+ }
272
+ save(K.offers, [...list, offer])
273
+ return offer
274
+ }
275
+ async updateOffer(id: string, input: UpdateOfferInput): Promise<Offer> {
276
+ const list = this.offers()
277
+ const idx = list.findIndex((o) => o.id === id)
278
+ if (idx < 0) throw new Error('Offer not found')
279
+ list[idx] = { ...list[idx], ...input } as Offer
280
+ save(K.offers, list)
281
+ return list[idx]
282
+ }
283
+ async deleteOffer(id: string): Promise<void> {
284
+ save(K.offers, this.offers().filter((o) => o.id !== id))
285
+ }
286
+
287
+ // Sales ledger ------------------------------------------------------------
288
+ async listOrders(opts?: ListOrdersOptions): Promise<Order[]> {
289
+ let list = this.orders()
290
+ if (opts?.courseId) list = list.filter((o) => o.courseId === opts.courseId)
291
+ if (opts?.financialStatus) list = list.filter((o) => o.financialStatus === opts.financialStatus)
292
+ if (opts?.search) {
293
+ const q = opts.search.toLowerCase()
294
+ list = list.filter((o) =>
295
+ (o.customerName ?? '').toLowerCase().includes(q) ||
296
+ (o.customerEmail ?? '').toLowerCase().includes(q),
297
+ )
298
+ }
299
+ return list.slice().sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))
300
+ }
301
+
302
+ // Subscriptions -----------------------------------------------------------
303
+ async listSubscriptions(opts?: ListSubscriptionsOptions): Promise<Subscription[]> {
304
+ let list = this.subscriptions()
305
+ if (opts?.courseId) list = list.filter((s) => s.courseId === opts.courseId)
306
+ if (opts?.status) list = list.filter((s) => s.status === opts.status)
307
+ return list.slice().sort((a, b) => (a.startedAt < b.startedAt ? 1 : -1))
308
+ }
309
+
310
+ // Financial / payouts / connect -------------------------------------------
311
+ async getFinancialSummary(): Promise<FinancialSummary> {
312
+ const paid = this.orders().filter((o) => o.financialStatus === 'paid')
313
+ const refunded = this.orders().filter((o) => o.financialStatus === 'refunded')
314
+ const activeSubs = this.subscriptions().filter((s) => s.status === 'active')
315
+ const totalRevenue = round2(paid.reduce((s, o) => s + o.total, 0))
316
+ const platformFeeTotal = round2(paid.reduce((s, o) => s + o.platformFee, 0))
317
+ const netTotal = round2(paid.reduce((s, o) => s + o.netValue, 0))
318
+ const paidOut = round2(this.payouts().filter((p) => p.status === 'paid').reduce((s, p) => s + p.amount, 0))
319
+ const mrr = round2(activeSubs.reduce((s, sub) => s + (sub.interval === 'year' ? sub.netValue / 12 : sub.netValue), 0))
320
+ const totalCount = paid.length + refunded.length
321
+ return {
322
+ currency: 'BRL',
323
+ availableBalance: round2(Math.max(netTotal - paidOut, 0)),
324
+ pendingBalance: round2(this.orders().filter((o) => o.financialStatus === 'pending').reduce((s, o) => s + o.netValue, 0)),
325
+ totalRevenue,
326
+ platformFeeTotal,
327
+ salesCount: paid.length,
328
+ activeSubscriptions: activeSubs.length,
329
+ mrr,
330
+ refundRate: totalCount > 0 ? refunded.length / totalCount : 0,
331
+ conversionRate: 0,
332
+ }
333
+ }
334
+ async listPayouts(): Promise<Payout[]> {
335
+ return this.payouts().slice().sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))
336
+ }
337
+ async getCreatorAccount(): Promise<CreatorAccount> {
338
+ // Mock account is not connected — the admin sees the "Connect Stripe" CTA.
339
+ return {
340
+ tenantId: 'mock-tenant',
341
+ stripeAccountId: null,
342
+ chargesEnabled: false,
343
+ payoutsEnabled: false,
344
+ defaultCurrency: 'BRL',
345
+ platformFeeBps: DEMO_PLATFORM_FEE_BPS,
346
+ }
347
+ }
348
+ }
349
+
350
+ function round2(n: number): number {
351
+ return Math.round(n * 100) / 100
231
352
  }
232
353
 
233
354
  export function createMockCoursesProvider(seed?: MockCoursesSeed): MockCoursesProvider {
package/src/provider.ts CHANGED
@@ -4,6 +4,10 @@ import type {
4
4
  CreateModuleInput, UpdateModuleInput,
5
5
  CreateLessonInput, UpdateLessonInput,
6
6
  ListCoursesOptions,
7
+ Offer, CreateOfferInput, UpdateOfferInput,
8
+ Order, ListOrdersOptions,
9
+ Subscription, ListSubscriptionsOptions,
10
+ Payout, CreatorAccount, FinancialSummary,
7
11
  } from './types'
8
12
 
9
13
  export interface CoursesProvider {
@@ -36,6 +40,23 @@ export interface CoursesProvider {
36
40
  lessonId: string,
37
41
  patch: { completed?: boolean; lastPositionSec?: number },
38
42
  ): Promise<Progress>
43
+
44
+ // Offers (pricing / order-bumps)
45
+ listOffers(courseId: string): Promise<Offer[]>
46
+ createOffer(input: CreateOfferInput): Promise<Offer>
47
+ updateOffer(id: string, input: UpdateOfferInput): Promise<Offer>
48
+ deleteOffer(id: string): Promise<void>
49
+
50
+ // Sales ledger
51
+ listOrders(options?: ListOrdersOptions): Promise<Order[]>
52
+
53
+ // Recurring subscriptions
54
+ listSubscriptions(options?: ListSubscriptionsOptions): Promise<Subscription[]>
55
+
56
+ // Financial / payouts / Stripe Connect
57
+ getFinancialSummary(): Promise<FinancialSummary>
58
+ listPayouts(): Promise<Payout[]>
59
+ getCreatorAccount(): Promise<CreatorAccount>
39
60
  }
40
61
 
41
62
  // Global provider holder (mirrors @fayz-ai/shop's setShopProvider/getShopProvider).
@@ -0,0 +1,17 @@
1
+ import { createSafeDataProvider } from '@fayz-ai/core'
2
+ import type { CoursesProvider } from './provider'
3
+ import { createSupabaseCoursesProvider } from './supabase-provider'
4
+ import { createMockCoursesProvider } from './mock-provider'
5
+
6
+ /**
7
+ * Picks the Supabase provider when a Supabase client is initialized, else the
8
+ * mock — resolved lazily on first use (mirrors @fayz-ai/plugin-financial's
9
+ * createSafeFinancialProvider). Apps wire this and get real data with a backend,
10
+ * or a seeded demo without one.
11
+ */
12
+ export function createSafeCoursesProvider(): CoursesProvider {
13
+ return createSafeDataProvider<CoursesProvider>(
14
+ () => createSupabaseCoursesProvider(),
15
+ () => createMockCoursesProvider(),
16
+ )
17
+ }
package/src/seed.ts CHANGED
@@ -1,4 +1,7 @@
1
- import type { Course, Module, Lesson } from './types'
1
+ import type {
2
+ Course, Module, Lesson,
3
+ Offer, Order, Subscription, Payout, PaymentMethod,
4
+ } from './types'
2
5
 
3
6
  // Deterministic placeholder thumbnail (gradient SVG data-URI, no network).
4
7
  function thumb(label: string, hue: number): string {
@@ -38,6 +41,8 @@ export interface CourseCatalog {
38
41
  courses: Course[]
39
42
  modules: Module[]
40
43
  lessons: Lesson[]
44
+ /** One default one-time offer per course, plus a recurring "club" offer on the first. */
45
+ offers: Offer[]
41
46
  }
42
47
 
43
48
  /** Build a deterministic CourseCatalog from a terse declarative seed. */
@@ -45,9 +50,52 @@ export function buildCourseCatalog(input: CourseSeedInput[]): CourseCatalog {
45
50
  const courses: Course[] = []
46
51
  const modules: Module[] = []
47
52
  const lessons: Lesson[] = []
53
+ const offers: Offer[] = []
48
54
 
49
55
  input.forEach((c, ci) => {
50
56
  const courseId = `course-${String(ci + 1).padStart(2, '0')}`
57
+ const price = c.price ?? 197
58
+ // Default one-time offer (the course's headline price).
59
+ offers.push({
60
+ id: `${courseId}-offer-01`,
61
+ courseId,
62
+ name: c.title,
63
+ price,
64
+ currency: 'BRL',
65
+ kind: 'one_time',
66
+ recurringInterval: null,
67
+ isDefault: true,
68
+ isOrderBump: false,
69
+ sortOrder: 0,
70
+ })
71
+ // The first course also ships a recurring "club" offer + an order-bump, to
72
+ // exercise subscriptions and bumps (mirrors Kiwify's multi-offer product).
73
+ if (ci === 0) {
74
+ offers.push({
75
+ id: `${courseId}-offer-02`,
76
+ courseId,
77
+ name: `${c.title} + Club (mensal)`,
78
+ price: Math.round(price * 0.24 * 100) / 100,
79
+ currency: 'BRL',
80
+ kind: 'subscription',
81
+ recurringInterval: 'month',
82
+ isDefault: false,
83
+ isOrderBump: false,
84
+ sortOrder: 1,
85
+ })
86
+ offers.push({
87
+ id: `${courseId}-offer-03`,
88
+ courseId,
89
+ name: 'Templates & Bônus (order-bump)',
90
+ price: 47,
91
+ currency: 'BRL',
92
+ kind: 'one_time',
93
+ recurringInterval: null,
94
+ isDefault: false,
95
+ isOrderBump: true,
96
+ sortOrder: 2,
97
+ })
98
+ }
51
99
  courses.push({
52
100
  id: courseId,
53
101
  slug: c.slug,
@@ -80,7 +128,106 @@ export function buildCourseCatalog(input: CourseSeedInput[]): CourseCatalog {
80
128
  })
81
129
  })
82
130
 
83
- return { courses, modules, lessons }
131
+ return { courses, modules, lessons, offers }
132
+ }
133
+
134
+ // ---------------------------------------------------------------------------
135
+ // Demo commerce ledger — deterministic sample orders/subscriptions/payouts so
136
+ // the Sales, Subscriptions, Financial and dashboard surfaces have data on first
137
+ // run (mock layer only; a real backend fills these from Stripe webhooks).
138
+ // ---------------------------------------------------------------------------
139
+
140
+ export interface DemoLedger {
141
+ orders: Order[]
142
+ subscriptions: Subscription[]
143
+ payouts: Payout[]
144
+ }
145
+
146
+ /** Platform markup applied to demo sales (5% = 500 bps). Mirrors CreatorAccount. */
147
+ export const DEMO_PLATFORM_FEE_BPS = 500
148
+
149
+ // Days offset from t0, so dates are deterministic (no Date.now()).
150
+ function daysFromBase(days: number): string {
151
+ return new Date(Date.parse(t0) + days * 86_400_000).toISOString()
152
+ }
153
+
154
+ const DEMO_BUYERS: Array<{ name: string; email: string }> = [
155
+ { name: 'William Ribeiro', email: 'william@example.com' },
156
+ { name: 'Alan Brancalhão', email: 'alan@example.com' },
157
+ { name: 'Luciano Rufatto', email: 'luciano@example.com' },
158
+ { name: 'Gabriel Boni', email: 'gabriel@example.com' },
159
+ { name: 'Leonardo Lorenzoni', email: 'leonardo@example.com' },
160
+ ]
161
+ const DEMO_METHODS: PaymentMethod[] = ['pix', 'card', 'boleto']
162
+
163
+ function feeFor(total: number): number {
164
+ return Math.round((total * DEMO_PLATFORM_FEE_BPS) / 10000 * 100) / 100
165
+ }
166
+
167
+ /** Build a deterministic ledger from a catalog's default (one-time) offers. */
168
+ export function buildDemoLedger(catalog: CourseCatalog): DemoLedger {
169
+ const orders: Order[] = []
170
+ const subscriptions: Subscription[] = []
171
+ const oneTime = catalog.offers.filter((o) => o.kind === 'one_time' && !o.isOrderBump)
172
+
173
+ oneTime.forEach((offer, oi) => {
174
+ // 3 paid sales per course, spread across buyers/methods/dates.
175
+ for (let i = 0; i < 3; i++) {
176
+ const buyer = DEMO_BUYERS[(oi * 3 + i) % DEMO_BUYERS.length]
177
+ const total = offer.price
178
+ const platformFee = feeFor(total)
179
+ orders.push({
180
+ id: `order-${offer.courseId}-${String(i + 1).padStart(2, '0')}`,
181
+ courseId: offer.courseId,
182
+ offerId: offer.id,
183
+ customerId: `cust-${buyer.email}`,
184
+ customerName: buyer.name,
185
+ customerEmail: buyer.email,
186
+ currency: offer.currency,
187
+ total,
188
+ platformFee,
189
+ netValue: Math.round((total - platformFee) * 100) / 100,
190
+ paymentMethod: DEMO_METHODS[(oi + i) % DEMO_METHODS.length],
191
+ financialStatus: 'paid',
192
+ stripePaymentIntentId: null,
193
+ createdAt: daysFromBase(160 + oi * 7 + i * 2),
194
+ })
195
+ }
196
+ })
197
+
198
+ // Two active subscriptions on the first course's recurring offer.
199
+ const sub = catalog.offers.find((o) => o.kind === 'subscription')
200
+ if (sub) {
201
+ for (let i = 0; i < 2; i++) {
202
+ const buyer = DEMO_BUYERS[(3 + i) % DEMO_BUYERS.length]
203
+ subscriptions.push({
204
+ id: `sub-${sub.courseId}-${String(i + 1).padStart(2, '0')}`,
205
+ courseId: sub.courseId,
206
+ offerId: sub.id,
207
+ customerId: `cust-${buyer.email}`,
208
+ customerName: buyer.name,
209
+ customerEmail: buyer.email,
210
+ currency: sub.currency,
211
+ netValue: Math.round((sub.price - feeFor(sub.price)) * 100) / 100,
212
+ interval: sub.recurringInterval ?? 'month',
213
+ status: 'active',
214
+ stripeSubscriptionId: null,
215
+ startedAt: daysFromBase(150 + i * 2),
216
+ canceledAt: null,
217
+ })
218
+ }
219
+ }
220
+
221
+ // A few successful payouts.
222
+ const payouts: Payout[] = [200, 216.33, 196.33, 801.33].map((amount, i) => ({
223
+ id: `payout-${String(i + 1).padStart(2, '0')}`,
224
+ amount,
225
+ currency: 'BRL',
226
+ status: 'paid',
227
+ createdAt: daysFromBase(120 + i * 20),
228
+ }))
229
+
230
+ return { orders, subscriptions, payouts }
84
231
  }
85
232
 
86
233
  /** Default seed shared by both example apps. */
@@ -144,3 +291,6 @@ export const DEFAULT_COURSE_CATALOG: CourseCatalog = buildCourseCatalog([
144
291
  ],
145
292
  },
146
293
  ])
294
+
295
+ /** Default demo ledger shared by the mock provider (sales/subscriptions/payouts). */
296
+ export const DEFAULT_DEMO_LEDGER: DemoLedger = buildDemoLedger(DEFAULT_COURSE_CATALOG)