@fayz-ai/courses 0.8.0 → 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/dist/index.cjs +90 -0
- 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 +90 -0
- 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/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -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 +82 -2
- package/src/types.ts +29 -0
package/dist/index.cjs
CHANGED
|
@@ -81,6 +81,7 @@ function buildCourseCatalog(input) {
|
|
|
81
81
|
price: c.price ?? 197,
|
|
82
82
|
currency: "BRL",
|
|
83
83
|
status: "published",
|
|
84
|
+
deliveryType: "online",
|
|
84
85
|
sortOrder: ci,
|
|
85
86
|
createdAt: t0,
|
|
86
87
|
updatedAt: t0
|
|
@@ -355,6 +356,7 @@ var MockCoursesProvider = class {
|
|
|
355
356
|
price: input.price ?? 0,
|
|
356
357
|
currency: input.currency ?? "BRL",
|
|
357
358
|
status: input.status ?? "draft",
|
|
359
|
+
deliveryType: input.deliveryType ?? "online",
|
|
358
360
|
sortOrder: input.sortOrder ?? list.length,
|
|
359
361
|
createdAt: now(),
|
|
360
362
|
updatedAt: now()
|
|
@@ -513,6 +515,16 @@ var MockCoursesProvider = class {
|
|
|
513
515
|
}
|
|
514
516
|
return list.slice().sort((a, b) => a.createdAt < b.createdAt ? 1 : -1);
|
|
515
517
|
}
|
|
518
|
+
// Core-commerce course sales don't exist in the mock layer (no orders/financial).
|
|
519
|
+
async listCoreSales() {
|
|
520
|
+
return [];
|
|
521
|
+
}
|
|
522
|
+
async getOrder(id) {
|
|
523
|
+
const o = this.orders().find((x) => x.id === id);
|
|
524
|
+
if (!o) return null;
|
|
525
|
+
const paid = o.financialStatus === "paid" ? o.total : 0;
|
|
526
|
+
return { ...o, courseTitle: null, offerName: null, paidAmount: paid, balance: o.total - paid, installments: [] };
|
|
527
|
+
}
|
|
516
528
|
// Subscriptions -----------------------------------------------------------
|
|
517
529
|
async listSubscriptions(opts) {
|
|
518
530
|
let list = this.subscriptions();
|
|
@@ -616,6 +628,7 @@ function rowToCourse(r) {
|
|
|
616
628
|
price: r.price ?? 0,
|
|
617
629
|
currency: r.currency ?? "BRL",
|
|
618
630
|
status: r.status ?? "draft",
|
|
631
|
+
deliveryType: r.delivery_type ?? "online",
|
|
619
632
|
sortOrder: r.sort_order ?? 0,
|
|
620
633
|
createdAt: r.created_at,
|
|
621
634
|
updatedAt: r.updated_at
|
|
@@ -734,6 +747,7 @@ function createSupabaseCoursesProvider() {
|
|
|
734
747
|
price: input.price ?? 0,
|
|
735
748
|
currency: input.currency ?? "BRL",
|
|
736
749
|
status: input.status ?? "draft",
|
|
750
|
+
delivery_type: input.deliveryType ?? "online",
|
|
737
751
|
sort_order: input.sortOrder ?? 0
|
|
738
752
|
}).select("*").single();
|
|
739
753
|
if (error) throw error;
|
|
@@ -749,6 +763,7 @@ function createSupabaseCoursesProvider() {
|
|
|
749
763
|
if (input.price !== void 0) patch.price = input.price;
|
|
750
764
|
if (input.currency !== void 0) patch.currency = input.currency;
|
|
751
765
|
if (input.status !== void 0) patch.status = input.status;
|
|
766
|
+
if (input.deliveryType !== void 0) patch.delivery_type = input.deliveryType;
|
|
752
767
|
if (input.sortOrder !== void 0) patch.sort_order = input.sortOrder;
|
|
753
768
|
const { data, error } = await scoped(getDb().from(T.courses).update(patch).eq("id", id)).select("*").single();
|
|
754
769
|
if (error) throw error;
|
|
@@ -906,6 +921,81 @@ function createSupabaseCoursesProvider() {
|
|
|
906
921
|
if (error) throw error;
|
|
907
922
|
return (data ?? []).map(rowToOrder);
|
|
908
923
|
},
|
|
924
|
+
async listCoreSales() {
|
|
925
|
+
const { data, error } = await scoped(getDb().from("v_plg_course_sales").select("*")).order("created_at", { ascending: false });
|
|
926
|
+
if (error) throw error;
|
|
927
|
+
return (data ?? []).map((r) => ({
|
|
928
|
+
id: r.id,
|
|
929
|
+
courseId: r.course_id ?? "",
|
|
930
|
+
offerId: r.offer_id ?? null,
|
|
931
|
+
customerId: r.party_id ?? null,
|
|
932
|
+
customerName: r.customer_name ?? null,
|
|
933
|
+
customerEmail: r.customer_email ?? null,
|
|
934
|
+
currency: r.currency ?? "BRL",
|
|
935
|
+
total: Number(r.total ?? 0),
|
|
936
|
+
platformFee: Number(r.platform_fee ?? 0),
|
|
937
|
+
netValue: Number(r.net_value ?? r.total ?? 0),
|
|
938
|
+
paymentMethod: r.payment_method ?? null,
|
|
939
|
+
financialStatus: r.financial_status ?? "pending",
|
|
940
|
+
stripePaymentIntentId: null,
|
|
941
|
+
createdAt: r.created_at,
|
|
942
|
+
installmentCount: Number(r.installment_count ?? 1)
|
|
943
|
+
}));
|
|
944
|
+
},
|
|
945
|
+
async getOrder(id) {
|
|
946
|
+
const db = getDb();
|
|
947
|
+
const { data: v } = await scoped(db.from("v_plg_course_sales").select("*")).eq("id", id).maybeSingle();
|
|
948
|
+
if (!v) return null;
|
|
949
|
+
const [{ data: course }, { data: bills }, { data: pays }] = await Promise.all([
|
|
950
|
+
db.from(T.courses).select("title").eq("id", v.course_id).maybeSingle(),
|
|
951
|
+
db.from("plg_financial_movements").select("*").eq("invoice_id", id).eq("movement_kind", "bill").order("installment_number"),
|
|
952
|
+
db.from("plg_financial_movements").select("*").eq("invoice_id", id).eq("movement_kind", "payment")
|
|
953
|
+
]);
|
|
954
|
+
let offerName = null;
|
|
955
|
+
if (v.offer_id) {
|
|
956
|
+
const { data: off } = await db.from(T.offers).select("name").eq("id", v.offer_id).maybeSingle();
|
|
957
|
+
offerName = off?.name ?? null;
|
|
958
|
+
}
|
|
959
|
+
const paymentsByInst = /* @__PURE__ */ new Map();
|
|
960
|
+
for (const p of pays ?? []) paymentsByInst.set(p.installment_number ?? 0, p);
|
|
961
|
+
const installments = (bills ?? []).map((b) => {
|
|
962
|
+
const p = paymentsByInst.get(b.installment_number ?? 0);
|
|
963
|
+
return {
|
|
964
|
+
installmentNumber: b.installment_number ?? 1,
|
|
965
|
+
amount: Number(b.amount ?? 0),
|
|
966
|
+
paidAmount: Number(b.paid_amount ?? 0),
|
|
967
|
+
status: b.status ?? "pending",
|
|
968
|
+
dueDate: b.due_date ?? null,
|
|
969
|
+
paymentDate: p?.payment_date ?? b.payment_date ?? null,
|
|
970
|
+
cardBrand: p?.card_brand ?? null,
|
|
971
|
+
cardInstallments: p?.card_installments ?? null
|
|
972
|
+
};
|
|
973
|
+
});
|
|
974
|
+
const paid = (bills ?? []).reduce((s, b) => s + Number(b.paid_amount ?? 0), 0);
|
|
975
|
+
const total = Number(v.total ?? 0);
|
|
976
|
+
return {
|
|
977
|
+
id: v.id,
|
|
978
|
+
courseId: v.course_id ?? "",
|
|
979
|
+
offerId: v.offer_id ?? null,
|
|
980
|
+
customerId: v.party_id ?? null,
|
|
981
|
+
customerName: v.customer_name ?? null,
|
|
982
|
+
customerEmail: v.customer_email ?? null,
|
|
983
|
+
currency: v.currency ?? "BRL",
|
|
984
|
+
total,
|
|
985
|
+
platformFee: Number(v.platform_fee ?? 0),
|
|
986
|
+
netValue: Number(v.net_value ?? total),
|
|
987
|
+
paymentMethod: v.payment_method ?? null,
|
|
988
|
+
financialStatus: v.financial_status ?? "pending",
|
|
989
|
+
stripePaymentIntentId: null,
|
|
990
|
+
createdAt: v.created_at,
|
|
991
|
+
installmentCount: Number(v.installment_count ?? installments.length ?? 1),
|
|
992
|
+
courseTitle: course?.title ?? null,
|
|
993
|
+
offerName,
|
|
994
|
+
paidAmount: paid,
|
|
995
|
+
balance: Math.max(0, total - paid),
|
|
996
|
+
installments
|
|
997
|
+
};
|
|
998
|
+
},
|
|
909
999
|
// Subscriptions ---------------------------------------------------------
|
|
910
1000
|
async listSubscriptions(opts) {
|
|
911
1001
|
let q = scoped(getDb().from(T.subscriptions).select("*"));
|