UNPKG

@coursebuilder/core

Version:

Core package for Course Builder

525 lines (522 loc) 20.6 kB
import * as ai from 'ai'; import * as inngest from 'inngest'; import { GetFunctionInput, Inngest, EventSchemas, InngestMiddleware, InngestFunction, GetEvents, Handler } from 'inngest'; import { AuthConfig } from '@auth/core'; import { NodemailerConfig } from '@auth/core/providers/nodemailer'; import { c as CourseBuilderAdapter, e as TranscriptionConfig, L as LlmProviderConfig, f as PaymentsProviderConfig } from '../adapters-DK4L3hbS.cjs'; import { PartyProviderConfig } from '../providers/partykit.cjs'; import { NotificationProviderConfig } from '../providers/slack.cjs'; import '@auth/core/adapters'; import '../schemas/coupon-schema.cjs'; import 'zod'; import '../schemas/merchant-coupon-schema.cjs'; import '../schemas/merchant-customer-schema.cjs'; import '../schemas/merchant-product-schema.cjs'; import '../schemas/price-schema.cjs'; import '../schemas/product-schema.cjs'; import '../schemas/purchase-schema.cjs'; import '../schemas/purchase-user-transfer-schema.cjs'; import '../schemas/resource-progress-schema.cjs'; import '../schemas/user-schema.cjs'; import '../schemas/video-resource.cjs'; import '../schemas/upgradable-product-schema.cjs'; import '../schemas/merchant-charge-schema.cjs'; import '../schemas/merchant-price-schema.cjs'; import '../schemas/content-resource-schema.cjs'; import '../schemas/merchant-account-schema.cjs'; import '../schemas/merchant-session.cjs'; import '../schemas/merchant-subscription.cjs'; import '../schemas/organization-member.cjs'; import '../schemas/organization-schema.cjs'; import '../schemas/subscription.cjs'; import 'cookie'; import 'stripe'; import '../lib/utils/logger.cjs'; import '@auth/core/providers'; import '../schemas/subscriber-schema.cjs'; import '../schemas/purchase-info.cjs'; import '../schemas/subscription-info.cjs'; interface CoreInngestContext { db: CourseBuilderAdapter; siteRootUrl: string; transcriptProvider: TranscriptionConfig; openaiProvider: LlmProviderConfig; partyProvider: PartyProviderConfig; paymentProvider?: PaymentsProviderConfig; emailProvider?: NodemailerConfig; notificationProvider?: NotificationProviderConfig; getAuthConfig: () => AuthConfig; mediaUploadProvider: { deleteFiles: (fileKey: string) => Promise<{ success: boolean; }>; }; } type CoreInngestFunctionInput = GetFunctionInput<CoreInngest>; type CoreInngestTrigger = InngestFunction.Trigger<keyof GetEvents<CoreInngest>>; type CoreInngestHandler = Handler.Any; declare const createInngestMiddleware: <TCourseBuilderContext extends CoreInngestContext = CoreInngestContext>(context: TCourseBuilderContext) => InngestMiddleware<{ name: string; init(): { onFunctionRun(): { transformInput(): { ctx: { [K in keyof TCourseBuilderContext]: TCourseBuilderContext[K]; }; }; }; }; }>; declare const coreInngest: Inngest<{ id: string; schemas: EventSchemas<{ "inngest/function.failed": { data: { function_id: string; run_id: string; error: inngest.JsonError; event: inngest.EventPayload<any>; }; name: "inngest/function.failed"; }; "inngest/function.finished": { data: { function_id: string; run_id: string; correlation_id?: string | undefined; } & ({ error: inngest.JsonError; } | { result: unknown; }); name: "inngest/function.finished"; }; "inngest/function.invoked": { id?: string | undefined; user?: any; data?: any; ts?: number | undefined; v?: string | undefined; name: "inngest/function.invoked"; }; "inngest/function.cancelled": { data: { function_id: string; run_id: string; correlation_id?: string | undefined; }; name: "inngest/function.cancelled"; }; "inngest/scheduled.timer": { id: string; user?: any; data: { cron: string; }; ts?: number | undefined; v?: string | undefined; name: "inngest/scheduled.timer"; }; "video/srt-ready": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "video/srt-ready"; data: { videoResourceId: string; }; }; "video/transcript-ready-event": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "video/transcript-ready-event"; data: { videoResourceId: string | null; }; }; "resource/chat-request-event": { id?: string | undefined; ts?: number | undefined; v?: string | undefined; name: "resource/chat-request-event"; data: { resourceId: string; messages: ai.CoreMessage[]; promptId?: string | undefined; selectedWorkflow: string; model?: string | undefined; }; user: Record<string, any>; }; "video/status-check": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "video/status-check"; data: { videoResourceId: string; fileKey: string; }; }; "video/video-uploaded": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "video/video-uploaded"; data: { originalMediaUrl: string; fileName: string; resourceId?: string | undefined; title?: string | undefined; fileKey?: string | undefined; parentResourceId?: string | undefined; resourceType?: string | undefined; }; }; "video-resource/created": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "video-resource/created"; data: { videoResourceId: string; originalMediaUrl: string; moduleSlug?: string | undefined; }; }; "mux/web-hook-event": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "mux/web-hook-event"; data: { muxWebhookEvent: { object: { type: string; id: string; }; type: string; id: string; created_at: string; request_id: string | null; environment: { name: string; id: string; }; attempts: any[]; accessor_source: string | null; accessor: string | null; data?: any; }; }; }; "stripe/checkout-session-completed": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "stripe/checkout-session-completed"; data: { stripeEvent: { type: "checkout.session.completed"; id: string; data: { object: { object: "checkout.session"; id: string; status: string; metadata: Record<string, string>; subscription: null; customer: string; payment_intent: string; created: number; livemode: boolean; currency: string; mode: "payment"; amount_subtotal: number; amount_total: number; custom_fields: unknown[]; customer_details: { name: string | null; email: string | null; address: { state: string | null; city: string | null; country: string | null; line1: string | null; line2: string | null; postal_code: string | null; }; }; payment_method_collection: string; payment_status: string; phone_number_collection: { enabled: boolean; }; success_url: string; total_details: { amount_discount: number; amount_shipping: number; amount_tax: number; }; } | { object: "checkout.session"; id: string; status: string; metadata: Record<string, string>; subscription: string; customer: string; payment_intent: null; created: number; livemode: boolean; currency: string; mode: "subscription"; amount_subtotal: number; amount_total: number; custom_fields: unknown[]; customer_details: { name: string | null; email: string | null; address: { state: string | null; city: string | null; country: string | null; line1: string | null; line2: string | null; postal_code: string | null; }; }; payment_method_collection: string; payment_status: string; phone_number_collection: { enabled: boolean; }; success_url: string; total_details: { amount_discount: number; amount_shipping: number; amount_tax: number; }; } | { object: "checkout.session"; id: string; status: string; metadata: Record<string, string>; subscription: null; customer: string; payment_intent: null; created: number; livemode: boolean; currency: string; mode: "setup"; amount_subtotal: number; amount_total: number; custom_fields: unknown[]; customer_details: { name: string | null; email: string | null; address: { state: string | null; city: string | null; country: string | null; line1: string | null; line2: string | null; postal_code: string | null; }; }; payment_method_collection: string; payment_status: string; phone_number_collection: { enabled: boolean; }; success_url: string; total_details: { amount_discount: number; amount_shipping: number; amount_tax: number; }; }; }; created: number; }; }; }; "stripe/customer-subscription-created": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "stripe/customer-subscription-created"; data: { stripeEvent: { object: "event"; type: "customer.subscription.created"; id: string; data: { object: { object: "subscription"; id: string; status: "active" | "incomplete" | "incomplete_expired" | "trialing" | "past_due" | "canceled" | "unpaid"; customer: string; items: { data: { id: string; price: { id: string; product: string; }; }[]; }; }; }; }; }; }; "stripe/customer-subscription-updated": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "stripe/customer-subscription-updated"; data: { stripeEvent: { object: "event"; type: "customer.subscription.updated"; id: string; data: { object: { object: "subscription"; id: string; status: "active" | "incomplete" | "incomplete_expired" | "trialing" | "past_due" | "canceled" | "unpaid"; customer: string; items: { data: { id: string; price: { id: string; product: string; }; }[]; }; }; previous_attributes?: Record<string, unknown> | undefined; }; }; }; }; "stripe/invoice-payment-succeeded": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "stripe/invoice-payment-succeeded"; data: { stripeEvent: { object: "event"; type: "invoice.payment_succeeded"; id: string; data: { object: { object: "invoice"; id: string; status: "void" | "open" | "paid" | "uncollectible"; customer: string; currency: string; amount_paid: number; subscription?: string | undefined; charge?: string | undefined; }; }; }; }; }; "commerce/update-purchase-status": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "commerce/update-purchase-status"; data: { status: "Valid" | "Restricted" | "Refunded" | "Disputed" | "Banned"; stripeChargeId: string; }; }; "commerce/new-purchase-created": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "commerce/new-purchase-created"; data: { purchaseId: string; checkoutSessionId: string; productType: "live" | "self-paced" | "membership" | "cohort"; }; }; "commerce/new-subscription-created": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "commerce/new-subscription-created"; data: { checkoutSessionId: string; subscriptionId: string; }; }; "commerce/full-price-coupon-redeemed": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "commerce/full-price-coupon-redeemed"; data: { purchaseId: string; productType: "live" | "self-paced" | "membership" | "cohort"; }; }; "commerce/refund-processed": { id?: string | undefined; user?: any; ts?: number | undefined; v?: string | undefined; name: "commerce/refund-processed"; data: { merchantChargeId: string; }; }; }>; middleware: [InngestMiddleware<{ name: string; init(): { onFunctionRun(): { transformInput(): { ctx: { db: CourseBuilderAdapter<any>; siteRootUrl: string; partyKitRootUrl: string; transcriptProvider: TranscriptionConfig; openaiProvider: LlmProviderConfig; partyProvider: PartyProviderConfig; paymentProvider: PaymentsProviderConfig; emailProvider: NodemailerConfig; notificationProvider: NotificationProviderConfig; getAuthConfig: () => AuthConfig; mediaUploadProvider: { deleteFiles: (_: string) => Promise<{ success: true; }>; }; }; }; }; }; }>]; }>; type CoreInngest = typeof coreInngest; export { type CoreInngest, type CoreInngestContext, type CoreInngestFunctionInput, type CoreInngestHandler, type CoreInngestTrigger, coreInngest, createInngestMiddleware };