{"version":3,"sources":["../src/create-creem-auth-client.ts"],"sourcesContent":["import { createAuthClient } from \"better-auth/react\";\nimport type { CreateCheckoutInput, CreateCheckoutResponse } from \"./checkout-types.js\";\nimport type { CreatePortalInput, CreatePortalResponse } from \"./portal-types.js\";\nimport type {\n  CancelSubscriptionInput,\n  CancelSubscriptionResponse,\n} from \"./cancel-subscription-types.js\";\nimport type { RetrieveSubscriptionInput, SubscriptionData } from \"./retrieve-subscription-types.js\";\nimport type {\n  SearchTransactionsInput,\n  SearchTransactionsResponse,\n} from \"./search-transactions-types.js\";\nimport type { HasAccessGrantedResponse } from \"./has-active-subscription-types.js\";\n\n/**\n * Standard Better-Auth response type\n */\ntype AuthResponse<T> = Promise<{\n  data: T | null;\n  error: { message: string; status?: number } | null;\n}>;\n\n/**\n * Creem client methods with clean, well-documented types\n */\nexport interface CreemClient {\n  /**\n   * Create a checkout session for a product.\n   *\n   * **Required:**\n   * - `productId` - The Creem product ID\n   *\n   * **Optional:**\n   * - `units` - Number of units (default: 1)\n   * - `successUrl` - Redirect URL after checkout\n   * - `discountCode` - Discount code to apply\n   * - `customer` - Customer info (defaults to session user)\n   * - `metadata` - Additional metadata\n   * - `requestId` - Idempotency key\n   * - `customFields` - Up to 3 custom fields for collecting additional info\n   * - `customField` - *(deprecated)* Use `customFields` instead\n   *\n   * @example\n   * ```typescript\n   * const { data } = await authClient.creem.createCheckout({\n   *   productId: \"prod_abc123\",\n   *   units: 1,\n   *   successUrl: \"/success\"\n   * });\n   * if (data?.url) window.location.href = data.url;\n   * ```\n   */\n  createCheckout(input: CreateCheckoutInput): AuthResponse<CreateCheckoutResponse>;\n\n  /**\n   * Create a customer portal session.\n   *\n   * Opens the Creem customer portal where users can manage their subscriptions,\n   * view invoices, and update payment methods.\n   *\n   * **Optional:**\n   * - `customerId` - Override customer ID (defaults to session user's Creem customer ID)\n   *\n   * @param input - Portal parameters (optional)\n   * @returns Promise with portal URL and redirect flag, or error\n   *\n   * @example\n   * ```typescript\n   * // Use default customer from session\n   * const { data } = await authClient.creem.createPortal();\n   *\n   * // Or specify a customer ID\n   * const { data } = await authClient.creem.createPortal({\n   *   customerId: \"cust_abc123\"\n   * });\n   *\n   * if (data?.url) window.location.href = data.url;\n   * ```\n   */\n  createPortal(input?: CreatePortalInput): AuthResponse<CreatePortalResponse>;\n\n  /**\n   * Cancel an active subscription.\n   *\n   * Cancels a subscription immediately or at the end of the current billing period,\n   * depending on your Creem settings.\n   *\n   * **Required:**\n   * - `id` - The subscription ID to cancel\n   *\n   * @param input - Cancellation parameters\n   * @returns Promise with success status and message, or error\n   *\n   * @example\n   * ```typescript\n   * const { data, error } = await authClient.creem.cancelSubscription({\n   *   id: \"sub_abc123\"\n   * });\n   *\n   * if (data?.success) {\n   *   console.log(data.message);\n   * }\n   * ```\n   */\n  cancelSubscription(input: CancelSubscriptionInput): AuthResponse<CancelSubscriptionResponse>;\n\n  /**\n   * Retrieve subscription details.\n   *\n   * Gets detailed information about a subscription including status,\n   * product details, customer information, and billing dates.\n   *\n   * **Required:**\n   * - `id` - The subscription ID\n   *\n   * @param input - Retrieval parameters\n   * @returns Promise with subscription data, or error\n   *\n   * @example\n   * ```typescript\n   * const { data } = await authClient.creem.retrieveSubscription({\n   *   id: \"sub_abc123\"\n   * });\n   *\n   * if (data) {\n   *   console.log(`Status: ${data.status}`);\n   *   console.log(`Product: ${data.product.name}`);\n   *   console.log(`Price: ${data.product.price} ${data.product.currency}`);\n   * }\n   * ```\n   */\n  retrieveSubscription(input: RetrieveSubscriptionInput): AuthResponse<SubscriptionData>;\n\n  /**\n   * Search transaction history.\n   *\n   * Searches for transactions with optional filters for customer, product, or order.\n   * Supports pagination for large result sets.\n   *\n   * **All parameters are optional:**\n   * - `customerId` - Filter by customer ID (defaults to session user)\n   * - `productId` - Filter by product ID\n   * - `orderId` - Filter by order ID\n   * - `pageNumber` - Page number (starts at 1)\n   * - `pageSize` - Number of results per page\n   *\n   * @param input - Search parameters (optional)\n   * @returns Promise with transaction list, or error\n   *\n   * @example\n   * ```typescript\n   * // Get all transactions for current user\n   * const { data } = await authClient.creem.searchTransactions();\n   *\n   * // Search with filters and pagination\n   * const { data } = await authClient.creem.searchTransactions({\n   *   customerId: \"cust_abc123\",\n   *   productId: \"prod_xyz789\",\n   *   pageNumber: 2,\n   *   pageSize: 50\n   * });\n   *\n   * if (data?.items) {\n   *   data.items.forEach(tx => {\n   *     console.log(`${tx.type}: ${tx.amount} ${tx.currency}`);\n   *   });\n   * }\n   * ```\n   */\n  searchTransactions(input?: SearchTransactionsInput): AuthResponse<SearchTransactionsResponse>;\n\n  /**\n   * Check if the current user has access granted.\n   *\n   * Verifies if the authenticated user has an active subscription or access\n   * to your platform based on their Creem subscription status.\n   *\n   * @returns Promise with access status, or error\n   *\n   * @example\n   * ```typescript\n   * const { data } = await authClient.creem.hasAccessGranted();\n   *\n   * if (data?.hasAccess) {\n   *   console.log(\"User has active subscription\");\n   * }\n   * ```\n   */\n  hasAccessGranted(): AuthResponse<HasAccessGrantedResponse>;\n}\n\n/**\n * Helper function to create an auth client with proper Creem types.\n *\n * This function wraps Better-Auth's `createAuthClient` and provides proper\n * TypeScript types for the Creem plugin methods, giving you clean IntelliSense\n * with full documentation.\n *\n * @param config - Better-Auth client configuration with Creem plugin\n * @returns Auth client with properly typed Creem methods\n *\n * @example\n * ```typescript\n * import { createCreemAuthClient, creemClient } from \"./lib/creem-betterauth\";\n *\n * export const authClient = createCreemAuthClient({\n *   plugins: [creemClient()]\n * });\n *\n * // Now you get clean type hints!\n * const { data } = await authClient.creem.createCheckout({\n *   productId: \"prod_abc123\"\n * });\n * ```\n */\nexport function createCreemAuthClient(config: Parameters<typeof createAuthClient>[0]): ReturnType<\n  typeof createAuthClient\n> & {\n  creem: CreemClient;\n} {\n  const baseClient = createAuthClient(config);\n\n  return baseClient as ReturnType<typeof createAuthClient> & {\n    creem: CreemClient;\n  };\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAuN1B,SAAS,sBAAsB,QAIpC;AACA,QAAM,aAAa,iBAAiB,MAAM;AAE1C,SAAO;AAGT;","names":[]}