import { Creem } from 'creem'; import { b as CreateCheckoutInput, c as CreateCheckoutResponse, e as CreatePortalResponse, h as SubscriptionData, g as SearchTransactionsResponse } from './search-transactions-types-DJyPIg0H.mjs'; /** * Configuration for server-side Creem operations. */ interface CreemServerConfig { /** Creem API key */ apiKey: string; /** Whether to use test mode */ testMode?: boolean; } /** * Initialize a Creem client for server-side operations. * Use this for direct API calls outside of Better Auth endpoints. * * @param config - Configuration options * @returns Configured Creem client instance * * @example * ```typescript * import { createCreemClient } from "@creem_io/better-auth/server"; * * const creem = createCreemClient({ * apiKey: process.env.CREEM_API_KEY!, * testMode: true * }); * * // Use directly in Server Actions or API routes * const subscription = await creem.subscriptions.get("sub_123"); * ``` */ declare function createCreemClient(config: CreemServerConfig): Creem; /** * Check if a subscription status indicates active access. * * @param status - The subscription status from Creem * @returns True if subscription grants access * * @example * ```typescript * import { isActiveSubscription } from "@creem_io/better-auth/server"; * * if (isActiveSubscription(subscription.status)) { * // User has active access * } * ``` */ declare function isActiveSubscription(status: string): boolean; /** * Format Creem Unix timestamp to JavaScript Date. * * @param timestamp - Unix timestamp from Creem (seconds) * @returns JavaScript Date object * * @example * ```typescript * import { formatCreemDate } from "@creem_io/better-auth/server"; * * const renewalDate = formatCreemDate(subscription.next_billing_date); * console.log(renewalDate.toLocaleDateString()); * ``` */ declare function formatCreemDate(timestamp: number): Date; /** * Calculate days until subscription renewal. * * @param periodEndTimestamp - Unix timestamp of period end * @returns Number of days until renewal (negative if overdue) * * @example * ```typescript * import { getDaysUntilRenewal } from "@creem_io/better-auth/server"; * * const days = getDaysUntilRenewal(subscription.current_period_end_date); * if (days > 0) { * console.log(`Renews in ${days} days`); * } else { * console.log(`Overdue by ${Math.abs(days)} days`); * } * ``` */ declare function getDaysUntilRenewal(periodEndTimestamp: number): number; /** * Validate webhook signature from Creem. * Use this to verify webhook authenticity in custom webhook handlers. * * @param payload - Raw webhook payload string * @param signature - Signature from 'creem-signature' header * @param secret - Your webhook secret * @returns True if signature is valid * * @example * ```typescript * import { validateWebhookSignature } from "@creem_io/better-auth/server"; * * export async function POST(req: Request) { * const payload = await req.text(); * const signature = req.headers.get('creem-signature'); * * if (!await validateWebhookSignature(payload, signature, process.env.CREEM_WEBHOOK_SECRET!)) { * return new Response('Invalid signature', { status: 401 }); * } * * const event = JSON.parse(payload); * // Process webhook * } * ``` */ declare function validateWebhookSignature(payload: string, signature: string | null, secret: string): Promise; /** * Create a checkout session directly (without using Better Auth endpoints). * Useful in Server Components, Server Actions, or custom API routes. * * @param config - Creem configuration * @param input - Checkout parameters * @returns Checkout URL and redirect flag * * @example * ```typescript * import { createCheckout } from "@creem_io/better-auth/server"; * * // Server Action * export async function startCheckout(productId: string) { * const { url } = await createCheckout( * { * apiKey: process.env.CREEM_API_KEY!, * testMode: true * }, * { * productId, * customer: { email: user.email }, * successUrl: "/success", * metadata: { userId: user.id } * } * ); * * redirect(url); * } * ``` * * @example * // With trial abuse prevention (check user.hadTrial from your database) * ```typescript * const { url } = await createCheckout( * config, * { * productId, * customer: { email: user.email }, * successUrl: "/success", * skipTrial: user.hadTrial, // Pass true if user has already used a trial * } * ); * ``` */ declare function createCheckout(config: CreemServerConfig, input: Omit & { customer: { email?: string; id?: string; }; /** * If true, tells Creem to skip the trial period for this checkout. * Use this for trial abuse prevention - pass true if the user has * already used a trial (check user.hadTrial from your database). * * @since 1.1.0 */ skipTrial?: boolean; }): Promise; /** * Create a customer portal session directly. * Useful in Server Components, Server Actions, or custom API routes. * * @param config - Creem configuration * @param customerId - Creem customer ID * @returns Portal URL and redirect flag * * @example * ```typescript * import { createPortal } from "@creem_io/better-auth/server"; * * // Server Component * export default async function BillingPage() { * const session = await getSession(); * * async function openPortal() { * 'use server'; * const { url } = await createPortal( * { * apiKey: process.env.CREEM_API_KEY!, * testMode: true * }, * session.user.creemCustomerId * ); * redirect(url); * } * * return
...
; * } * ``` */ declare function createPortal(config: CreemServerConfig, customerId: string): Promise; /** * Cancel a subscription directly. * Useful in Server Actions or custom API routes. * * @param config - Creem configuration * @param subscriptionId - Subscription ID to cancel * @returns Success status and message * * @example * ```typescript * import { cancelSubscription } from "@creem_io/better-auth/server"; * * // Server Action * export async function handleCancelSubscription(subId: string) { * const result = await cancelSubscription( * { * apiKey: process.env.CREEM_API_KEY!, * testMode: true * }, * subId * ); * * if (result.success) { * revalidatePath('/billing'); * } * } * ``` */ declare function cancelSubscription(config: CreemServerConfig, subscriptionId: string): Promise<{ success: boolean; message: string; }>; /** * Retrieve subscription details directly. * Useful in Server Components, Server Actions, or custom API routes. * * @param config - Creem configuration * @param subscriptionId - Subscription ID to retrieve * @returns Subscription data * * @example * ```typescript * import { retrieveSubscription } from "@creem_io/better-auth/server"; * * // Server Component * export default async function SubscriptionPage({ params }) { * const subscription = await retrieveSubscription( * { * apiKey: process.env.CREEM_API_KEY!, * testMode: true * }, * params.subscriptionId * ); * * return ( *
*

{subscription.product.name}

*

Status: {subscription.status}

*
* ); * } * ``` */ declare function retrieveSubscription(config: CreemServerConfig, subscriptionId: string): Promise; /** * Search transactions directly. * Useful in Server Components, Server Actions, or custom API routes. * * @param config - Creem configuration * @param filters - Search filters * @returns Transaction search results * * @example * ```typescript * import { searchTransactions } from "@creem_io/better-auth/server"; * * // Server Component * export default async function TransactionsPage() { * const { items, pagination } = await searchTransactions( * { * apiKey: process.env.CREEM_API_KEY!, * testMode: true * }, * { * customerId: user.creemCustomerId, * pageSize: 50 * } * ); * * return ; * } * ``` */ declare function searchTransactions(config: CreemServerConfig, filters?: { customerId?: string; productId?: string; orderId?: string; pageNumber?: number; pageSize?: number; }): Promise; /** * Check if user has active subscription with access. * Works in both database-enabled and database-free modes. * * **Database Mode:** Queries local subscription table for fast access checks. * **API Mode:** Queries Creem API directly (requires API call). * * @param config - Creem configuration * @param options - Check options * @returns Access status information * * @example * ```typescript * // Database mode (when persistSubscriptions: true) * import { checkSubscriptionAccess } from "@creem_io/better-auth/server"; * import { auth } from "@/lib/auth"; * * const status = await checkSubscriptionAccess( * { * apiKey: process.env.CREEM_API_KEY!, * testMode: true * }, * { * database: auth.options.database, // Pass database adapter * userId: session.user.id * } * ); * * // API mode (when persistSubscriptions: false or no database) * const status = await checkSubscriptionAccess( * { * apiKey: process.env.CREEM_API_KEY!, * testMode: true * }, * { * customerId: session.user.creemCustomerId * } * ); * * if (!status.hasAccess) { * redirect('/subscribe'); * } * ``` */ declare function checkSubscriptionAccess(config: CreemServerConfig, options: { database: any; userId: string; customerId?: never; } | { customerId: string; database?: never; userId?: never; }): Promise<{ hasAccess: boolean; status?: string; subscriptionId?: string; expiresAt?: Date; productName?: string; }>; /** * Get all active subscriptions for a user or customer. * Works in both database-enabled and database-free modes. * * @param config - Creem configuration * @param options - Query options * @returns List of active subscriptions * * @example * ```typescript * import { getActiveSubscriptions } from "@creem_io/better-auth/server"; * * // Database mode * const subscriptions = await getActiveSubscriptions( * config, * { database: auth.options.database, userId: user.id } * ); * * // API mode * const subscriptions = await getActiveSubscriptions( * config, * { customerId: user.creemCustomerId } * ); * ``` */ declare function getActiveSubscriptions(config: CreemServerConfig, options: { database: any; userId: string; customerId?: never; } | { customerId: string; database?: never; userId?: never; }): Promise>; export { type CreemServerConfig, cancelSubscription, checkSubscriptionAccess, createCheckout, createCreemClient, createPortal, formatCreemDate, getActiveSubscriptions, getDaysUntilRenewal, isActiveSubscription, retrieveSubscription, searchTransactions, validateWebhookSignature };