import * as better_auth_client from 'better-auth/client'; import { BetterFetchOption } from 'better-auth/client'; import { PolarEmbedCheckout } from '@polar-sh/checkout/embed'; export { PolarEmbedCheckout } from '@polar-sh/checkout/embed'; import * as better_auth from 'better-auth'; import { User } from 'better-auth'; import { Polar } from '@polar-sh/sdk'; import * as z from 'zod/v4'; import * as _polar_sh_sdk_models_operations_customerportalorderslist_js from '@polar-sh/sdk/models/operations/customerportalorderslist.js'; import * as _polar_sh_sdk_models_operations_customerportalsubscriptionslist_js from '@polar-sh/sdk/models/operations/customerportalsubscriptionslist.js'; import * as _polar_sh_sdk_models_operations_subscriptionslist_js from '@polar-sh/sdk/models/operations/subscriptionslist.js'; import * as _polar_sh_sdk_types_operations_js from '@polar-sh/sdk/types/operations.js'; import * as _polar_sh_sdk_models_operations_customerportalbenefitgrantslist_js from '@polar-sh/sdk/models/operations/customerportalbenefitgrantslist.js'; import * as _polar_sh_sdk_models_components_customerstate_js from '@polar-sh/sdk/models/components/customerstate.js'; import * as _polar_sh_sdk_models_components_eventsingestresponse_js from '@polar-sh/sdk/models/components/eventsingestresponse.js'; import * as _polar_sh_sdk_models_operations_customerportalcustomermeterslist_js from '@polar-sh/sdk/models/operations/customerportalcustomermeterslist.js'; import { WebhookBenefitCreatedPayload } from '@polar-sh/sdk/models/components/webhookbenefitcreatedpayload'; import { WebhookBenefitGrantCreatedPayload } from '@polar-sh/sdk/models/components/webhookbenefitgrantcreatedpayload'; import { WebhookBenefitGrantRevokedPayload } from '@polar-sh/sdk/models/components/webhookbenefitgrantrevokedpayload'; import { WebhookBenefitGrantUpdatedPayload } from '@polar-sh/sdk/models/components/webhookbenefitgrantupdatedpayload'; import { WebhookBenefitUpdatedPayload } from '@polar-sh/sdk/models/components/webhookbenefitupdatedpayload'; import { WebhookCheckoutCreatedPayload } from '@polar-sh/sdk/models/components/webhookcheckoutcreatedpayload'; import { WebhookCheckoutUpdatedPayload } from '@polar-sh/sdk/models/components/webhookcheckoutupdatedpayload'; import { WebhookCustomerCreatedPayload } from '@polar-sh/sdk/models/components/webhookcustomercreatedpayload'; import { WebhookCustomerDeletedPayload } from '@polar-sh/sdk/models/components/webhookcustomerdeletedpayload'; import { WebhookCustomerStateChangedPayload } from '@polar-sh/sdk/models/components/webhookcustomerstatechangedpayload'; import { WebhookCustomerUpdatedPayload } from '@polar-sh/sdk/models/components/webhookcustomerupdatedpayload'; import { WebhookOrderCreatedPayload } from '@polar-sh/sdk/models/components/webhookordercreatedpayload'; import { WebhookOrderPaidPayload } from '@polar-sh/sdk/models/components/webhookorderpaidpayload'; import { WebhookOrderRefundedPayload } from '@polar-sh/sdk/models/components/webhookorderrefundedpayload'; import { WebhookOrderUpdatedPayload } from '@polar-sh/sdk/models/components/webhookorderupdatedpayload'; import { WebhookOrganizationUpdatedPayload } from '@polar-sh/sdk/models/components/webhookorganizationupdatedpayload'; import { WebhookProductCreatedPayload } from '@polar-sh/sdk/models/components/webhookproductcreatedpayload'; import { WebhookProductUpdatedPayload } from '@polar-sh/sdk/models/components/webhookproductupdatedpayload'; import { WebhookRefundCreatedPayload } from '@polar-sh/sdk/models/components/webhookrefundcreatedpayload'; import { WebhookRefundUpdatedPayload } from '@polar-sh/sdk/models/components/webhookrefundupdatedpayload'; import { WebhookSubscriptionActivePayload } from '@polar-sh/sdk/models/components/webhooksubscriptionactivepayload'; import { WebhookSubscriptionCanceledPayload } from '@polar-sh/sdk/models/components/webhooksubscriptioncanceledpayload'; import { WebhookSubscriptionCreatedPayload } from '@polar-sh/sdk/models/components/webhooksubscriptioncreatedpayload'; import { WebhookSubscriptionRevokedPayload } from '@polar-sh/sdk/models/components/webhooksubscriptionrevokedpayload'; import { WebhookSubscriptionUncanceledPayload } from '@polar-sh/sdk/models/components/webhooksubscriptionuncanceledpayload'; import { WebhookSubscriptionUpdatedPayload } from '@polar-sh/sdk/models/components/webhooksubscriptionupdatedpayload'; import { validateEvent } from '@polar-sh/sdk/webhooks'; import * as zod_v4_core from 'zod/v4/core'; interface PortalConfig { returnUrl?: string; /** * Portal theme */ theme?: "light" | "dark"; } declare const portal: ({ returnUrl, theme }?: PortalConfig) => (polar: Polar) => { portal: better_auth.StrictEndpoint<"/customer/portal", { method: ("POST" | "GET")[]; body: z.ZodOptional; }, z.core.$strip>>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, { url: string; redirect: boolean; }>; state: better_auth.StrictEndpoint<"/customer/state", { method: "GET"; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_models_components_customerstate_js.CustomerState>; benefits: better_auth.StrictEndpoint<"/customer/benefits/list", { method: "GET"; query: z.ZodOptional>; limit: z.ZodOptional>; }, z.core.$strip>>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_customerportalbenefitgrantslist_js.CustomerPortalBenefitGrantsListResponse, { page: number; }>>; subscriptions: better_auth.StrictEndpoint<"/customer/subscriptions/list", { method: "GET"; query: z.ZodOptional; page: z.ZodOptional>; limit: z.ZodOptional>; active: z.ZodOptional>; }, z.core.$strip>>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_subscriptionslist_js.SubscriptionsListResponse, { page: number; }> | _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_customerportalsubscriptionslist_js.CustomerPortalSubscriptionsListResponse, { page: number; }>>; orders: better_auth.StrictEndpoint<"/customer/orders/list", { method: "GET"; query: z.ZodOptional>; limit: z.ZodOptional>; productBillingType: z.ZodOptional>; }, z.core.$strip>>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_customerportalorderslist_js.CustomerPortalOrdersListResponse, { page: number; }>>; }; interface UsageOptions { /** * Products to use for topping up credits */ creditProducts?: Product[] | (() => Promise); } declare const usage: (_usageOptions?: UsageOptions) => (polar: Polar) => { meters: better_auth.StrictEndpoint<"/usage/meters/list", { method: "GET"; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; query: z.ZodObject<{ page: z.ZodOptional>; limit: z.ZodOptional>; }, z.core.$strip>; }, _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_customerportalcustomermeterslist_js.CustomerPortalCustomerMetersListResponse, { page: number; }>>; ingestion: better_auth.StrictEndpoint<"/usage/ingest", { method: "POST"; body: z.ZodObject<{ event: z.ZodString; metadata: z.ZodRecord>; }, z.core.$strip>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_models_components_eventsingestresponse_js.EventsIngestResponse>; }; interface WebhooksOptions { /** * Webhook Secret */ secret: string; /** * Generic handler for all webhooks */ onPayload?: (payload: ReturnType) => Promise; /** * Webhook for checkout created */ onCheckoutCreated?: (payload: WebhookCheckoutCreatedPayload) => Promise; /** * Webhook for checkout updated */ onCheckoutUpdated?: (payload: WebhookCheckoutUpdatedPayload) => Promise; /** * Webhook for order created */ onOrderCreated?: (payload: WebhookOrderCreatedPayload) => Promise; /** * Webhook for order refunded */ onOrderRefunded?: (payload: WebhookOrderRefundedPayload) => Promise; /** * Webhook for order paid */ onOrderPaid?: (payload: WebhookOrderPaidPayload) => Promise; /** * Webhook for order updated */ onOrderUpdated?: (payload: WebhookOrderUpdatedPayload) => Promise; /** * Webhook for refund created */ onRefundCreated?: (payload: WebhookRefundCreatedPayload) => Promise; /** * Webhook for refund updated */ onRefundUpdated?: (payload: WebhookRefundUpdatedPayload) => Promise; /** * Webhook for subscription created */ onSubscriptionCreated?: (payload: WebhookSubscriptionCreatedPayload) => Promise; /** * Webhook for subscription updated */ onSubscriptionUpdated?: (payload: WebhookSubscriptionUpdatedPayload) => Promise; /** * Webhook for subscription active */ onSubscriptionActive?: (payload: WebhookSubscriptionActivePayload) => Promise; /** * Webhook for subscription canceled */ onSubscriptionCanceled?: (payload: WebhookSubscriptionCanceledPayload) => Promise; /** * Webhook for subscription revoked */ onSubscriptionRevoked?: (payload: WebhookSubscriptionRevokedPayload) => Promise; /** * Webhook for subscription uncanceled */ onSubscriptionUncanceled?: (payload: WebhookSubscriptionUncanceledPayload) => Promise; /** * Webhook for product created */ onProductCreated?: (payload: WebhookProductCreatedPayload) => Promise; /** * Webhook for product updated */ onProductUpdated?: (payload: WebhookProductUpdatedPayload) => Promise; /** * Webhook for organization updated */ onOrganizationUpdated?: (payload: WebhookOrganizationUpdatedPayload) => Promise; /** * Webhook for benefit created */ onBenefitCreated?: (payload: WebhookBenefitCreatedPayload) => Promise; /** * Webhook for benefit updated */ onBenefitUpdated?: (payload: WebhookBenefitUpdatedPayload) => Promise; /** * Webhook for benefit grant created */ onBenefitGrantCreated?: (payload: WebhookBenefitGrantCreatedPayload) => Promise; /** * Webhook for benefit grant updated */ onBenefitGrantUpdated?: (payload: WebhookBenefitGrantUpdatedPayload) => Promise; /** * Webhook for benefit grant revoked */ onBenefitGrantRevoked?: (payload: WebhookBenefitGrantRevokedPayload) => Promise; /** * Webhook for customer created */ onCustomerCreated?: (payload: WebhookCustomerCreatedPayload) => Promise; /** * Webhook for customer updated */ onCustomerUpdated?: (payload: WebhookCustomerUpdatedPayload) => Promise; /** * Webhook for customer deleted */ onCustomerDeleted?: (payload: WebhookCustomerDeletedPayload) => Promise; /** * Webhook for customer state changed */ onCustomerStateChanged?: (payload: WebhookCustomerStateChangedPayload) => Promise; } declare const webhooks: (options: WebhooksOptions) => (_polar: Polar) => { polarWebhooks: better_auth.StrictEndpoint<"/polar/webhooks", { method: "POST"; metadata: { isAction: false; }; cloneRequest: true; }, { received: boolean; }>; }; type Product = { /** * Product Id from Polar Product */ productId: string; /** * Easily identifiable slug for the product */ slug: string; }; type PolarPlugin = ReturnType | ReturnType | ReturnType | ReturnType; type PolarPlugins = [PolarPlugin, ...PolarPlugin[]]; interface PolarOptions { /** * Polar Client */ client: Polar; /** * Enable customer creation when a user signs up */ createCustomerOnSignUp?: boolean; /** * A custom function to get the customer create * params * @param data - data containing user and session * @returns */ getCustomerCreateParams?: (data: { user: Partial; }, request?: Request) => Promise<{ metadata?: Record; }>; /** * Use Polar plugins */ use: PolarPlugins; } interface CheckoutOptions { /** * Optional list of slug -> productId mappings for easy slug checkouts */ products?: Product[] | (() => Promise); /** * Checkout Success URL */ successUrl?: string; /** * Checkout Return URL */ returnUrl?: string; /** * Only allow authenticated customers to checkout */ authenticatedUsersOnly?: boolean; /** * Checkout theme */ theme?: "light" | "dark"; } declare const CheckoutParams: z.ZodObject<{ products: z.ZodOptional, z.ZodString]>>; slug: z.ZodOptional; referenceId: z.ZodOptional; customFieldData: z.ZodOptional>>; metadata: z.ZodOptional>>; allowDiscountCodes: z.ZodOptional>; discountId: z.ZodOptional; redirect: z.ZodOptional>; embedOrigin: z.ZodOptional; successUrl: z.ZodOptional; returnUrl: z.ZodOptional; allowTrial: z.ZodOptional; trialInterval: z.ZodOptional>; trialIntervalCount: z.ZodOptional; }, z.core.$strip>; type CheckoutParams = z.infer; declare const checkout: (checkoutOptions?: CheckoutOptions) => (polar: Polar) => { checkout: better_auth.StrictEndpoint<"/checkout", { method: "POST"; body: z.ZodObject<{ products: z.ZodOptional, z.ZodString]>>; slug: z.ZodOptional; referenceId: z.ZodOptional; customFieldData: z.ZodOptional>>; metadata: z.ZodOptional>>; allowDiscountCodes: z.ZodOptional>; discountId: z.ZodOptional; redirect: z.ZodOptional>; embedOrigin: z.ZodOptional; successUrl: z.ZodOptional; returnUrl: z.ZodOptional; allowTrial: z.ZodOptional; trialInterval: z.ZodOptional>; trialIntervalCount: z.ZodOptional; }, z.core.$strip>; }, { url: string; redirect: boolean; }>; }; declare const polar: (options: O) => { id: "polar"; endpoints: { checkout: better_auth.StrictEndpoint<"/checkout", { method: "POST"; body: z.ZodObject<{ products: z.ZodOptional, z.ZodString]>>; slug: z.ZodOptional; referenceId: z.ZodOptional; customFieldData: z.ZodOptional>>; metadata: z.ZodOptional>>; allowDiscountCodes: z.ZodOptional>; discountId: z.ZodOptional; redirect: z.ZodOptional>; embedOrigin: z.ZodOptional; successUrl: z.ZodOptional; returnUrl: z.ZodOptional; allowTrial: z.ZodOptional; trialInterval: z.ZodOptional>; trialIntervalCount: z.ZodOptional; }, zod_v4_core.$strip>; }, { url: string; redirect: boolean; }>; } | { meters: better_auth.StrictEndpoint<"/usage/meters/list", { method: "GET"; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; query: z.ZodObject<{ page: z.ZodOptional>; limit: z.ZodOptional>; }, zod_v4_core.$strip>; }, _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_customerportalcustomermeterslist_js.CustomerPortalCustomerMetersListResponse, { page: number; }>>; ingestion: better_auth.StrictEndpoint<"/usage/ingest", { method: "POST"; body: z.ZodObject<{ event: z.ZodString; metadata: z.ZodRecord>; }, zod_v4_core.$strip>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_models_components_eventsingestresponse_js.EventsIngestResponse>; } | { portal: better_auth.StrictEndpoint<"/customer/portal", { method: ("POST" | "GET")[]; body: z.ZodOptional; }, zod_v4_core.$strip>>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, { url: string; redirect: boolean; }>; state: better_auth.StrictEndpoint<"/customer/state", { method: "GET"; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_models_components_customerstate_js.CustomerState>; benefits: better_auth.StrictEndpoint<"/customer/benefits/list", { method: "GET"; query: z.ZodOptional>; limit: z.ZodOptional>; }, zod_v4_core.$strip>>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_customerportalbenefitgrantslist_js.CustomerPortalBenefitGrantsListResponse, { page: number; }>>; subscriptions: better_auth.StrictEndpoint<"/customer/subscriptions/list", { method: "GET"; query: z.ZodOptional; page: z.ZodOptional>; limit: z.ZodOptional>; active: z.ZodOptional>; }, zod_v4_core.$strip>>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_subscriptionslist_js.SubscriptionsListResponse, { page: number; }> | _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_customerportalsubscriptionslist_js.CustomerPortalSubscriptionsListResponse, { page: number; }>>; orders: better_auth.StrictEndpoint<"/customer/orders/list", { method: "GET"; query: z.ZodOptional>; limit: z.ZodOptional>; productBillingType: z.ZodOptional>; }, zod_v4_core.$strip>>; use: ((inputContext: better_auth.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>)[]; }, _polar_sh_sdk_types_operations_js.PageIterator<_polar_sh_sdk_models_operations_customerportalorderslist_js.CustomerPortalOrdersListResponse, { page: number; }>>; } | { polarWebhooks: better_auth.StrictEndpoint<"/polar/webhooks", { method: "POST"; metadata: { isAction: false; }; cloneRequest: true; }, { received: boolean; }>; }; init(): { options: { databaseHooks: { user: { create: { before: (user: Partial, context: better_auth.GenericEndpointContext | null) => Promise; after: (user: better_auth.User, context: better_auth.GenericEndpointContext | null) => Promise; }; update: { after: (user: better_auth.User, context: better_auth.GenericEndpointContext | null) => Promise; }; delete: { after: (user: better_auth.User, context: better_auth.GenericEndpointContext | null) => Promise; }; }; }; }; }; }; declare const polarClient: () => { id: "polar-client"; $InferServerPlugin: ReturnType; getActions: ($fetch: better_auth_client.BetterFetch) => { checkoutEmbed: (data: Omit, fetchOptions?: BetterFetchOption) => Promise; }; }; export { type CheckoutOptions as C, type PortalConfig as P, type UsageOptions as U, type WebhooksOptions as W, portal as a, CheckoutParams as b, checkout as c, polar as p, polarClient, usage as u, webhooks as w };