import { a as QueryCtxWithPreferredOrmQueryTable, n as LookupByIdResultByCtx, t as DocByCtx } from "../query-context-CNo9ffvI.js";
import { t as GetAuth } from "../types-BCl8gfGy.js";
import { t as GenericCtx } from "../context-utils-OMkMGhBk.js";
import { S as defineAuth, _ as GenericAuthBeforeResult, a as AuthFunctions, b as GenericAuthTriggerHandlers, c as createApi, d as deleteOneHandler, f as findManyHandler, g as BetterAuthOptionsWithoutDatabase, h as updateOneHandler, i as getGeneratedAuthDisabledReason, l as createHandler, m as updateManyHandler, n as GeneratedAuthDisabledReasonKind, o as Triggers, p as findOneHandler, r as createDisabledAuthRuntime, s as createClient, t as AuthRuntime, u as deleteManyHandler, v as GenericAuthDefinition, x as GenericAuthTriggers, y as GenericAuthTriggerChange } from "../generated-contract-disabled-C_-KWRfT.js";
import * as convex_values0 from "convex/values";
import { Infer } from "convex/values";
import { AuthConfig, DocumentByName, GenericDataModel, GenericMutationCtx, GenericQueryCtx, GenericSchema, PaginationOptions, PaginationResult, SchemaDefinition, TableNamesInDataModel } from "convex/server";
import * as better_auth_adapters0 from "better-auth/adapters";
import { DBAdapterDebugLogOption } from "better-auth/adapters";
import { BetterAuthDBSchema } from "better-auth/db";
import { BetterAuthOptions } from "better-auth/minimal";
import * as better_auth_api0 from "better-auth/api";
import * as better_auth_plugins_oidc_provider0 from "better-auth/plugins/oidc-provider";
import * as jose from "jose";
import * as better_auth0 from "better-auth";
import { Session, User } from "better-auth";
import { Where } from "better-auth/types";
import { SetOptional } from "type-fest";

//#region src/auth/adapter.d.ts
declare const handlePagination: (next: ({
  paginationOpts
}: {
  paginationOpts: PaginationOptions;
}) => Promise<SetOptional<PaginationResult<any>, "page"> & {
  count?: number;
}>, {
  limit,
  numItems
}?: {
  limit?: number;
  numItems?: number;
}) => Promise<{
  count: number;
  cursor: string | null;
  docs: any[];
  isDone: boolean;
}>;
type ConvexCleanedWhere = Where & {
  value: number[] | string[] | boolean | number | string | null;
};
declare const adapterConfig: {
  adapterId: string;
  adapterName: string;
  debugLogs: false;
  disableIdGeneration: true;
  mapKeysTransformInput: {
    id: string;
  };
  mapKeysTransformOutput: {
    _id: string;
  };
  supportsJSON: false;
  supportsNumericIds: false;
  supportsDates: false;
  supportsArrays: true;
  transaction: false;
  usePlural: false;
  customTransformInput: ({
    data,
    fieldAttributes
  }: {
    data: any;
    fieldAttributes: better_auth0.DBFieldAttribute;
    field: string;
    action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "count";
    model: string;
    schema: BetterAuthDBSchema;
    options: BetterAuthOptions;
  }) => any;
  customTransformOutput: ({
    data,
    fieldAttributes
  }: {
    data: any;
    fieldAttributes: better_auth0.DBFieldAttribute;
    field: string;
    select: string[];
    model: string;
    schema: BetterAuthDBSchema;
    options: BetterAuthOptions;
  }) => any;
};
declare const httpAdapter: <DataModel extends GenericDataModel, Schema extends SchemaDefinition<any, any>>(ctx: GenericCtx<DataModel>, {
  authFunctions,
  debugLogs,
  schema
}: {
  authFunctions: AuthFunctions;
  debugLogs?: DBAdapterDebugLogOption;
  schema?: Schema;
}) => better_auth_adapters0.AdapterFactory<BetterAuthOptions>;
declare const dbAdapter: <DataModel extends GenericDataModel, Schema extends SchemaDefinition<any, any>>(ctx: GenericCtx<DataModel>, getAuthOptions: (ctx: any) => BetterAuthOptions, {
  authFunctions,
  debugLogs,
  schema
}: {
  authFunctions: AuthFunctions;
  schema: Schema;
  debugLogs?: DBAdapterDebugLogOption;
}) => better_auth_adapters0.AdapterFactory<BetterAuthOptions>;
//#endregion
//#region src/auth/adapter-utils.d.ts
type AdapterPaginationOptions = PaginationOptions & {
  endCursor?: string | null;
  maximumRowsRead?: number;
};
declare const adapterWhereValidator: convex_values0.VObject<{
  mode?: "sensitive" | "insensitive" | undefined;
  connector?: "AND" | "OR" | undefined;
  operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
  value: string | number | boolean | string[] | number[] | null;
  field: string;
}, {
  connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
  field: convex_values0.VString<string, "required">;
  mode: convex_values0.VUnion<"sensitive" | "insensitive" | undefined, [convex_values0.VLiteral<"sensitive", "required">, convex_values0.VLiteral<"insensitive", "required">], "optional", never>;
  operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
  value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
}, "required", "mode" | "value" | "connector" | "field" | "operator">;
declare const adapterArgsValidator: convex_values0.VObject<{
  select?: string[] | undefined;
  where?: {
    mode?: "sensitive" | "insensitive" | undefined;
    connector?: "AND" | "OR" | undefined;
    operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
    value: string | number | boolean | string[] | number[] | null;
    field: string;
  }[] | undefined;
  limit?: number | undefined;
  offset?: number | undefined;
  sortBy?: {
    field: string;
    direction: "asc" | "desc";
  } | undefined;
  model: string;
}, {
  limit: convex_values0.VFloat64<number | undefined, "optional">;
  model: convex_values0.VString<string, "required">;
  offset: convex_values0.VFloat64<number | undefined, "optional">;
  select: convex_values0.VArray<string[] | undefined, convex_values0.VString<string, "required">, "optional">;
  sortBy: convex_values0.VObject<{
    field: string;
    direction: "asc" | "desc";
  } | undefined, {
    direction: convex_values0.VUnion<"asc" | "desc", [convex_values0.VLiteral<"asc", "required">, convex_values0.VLiteral<"desc", "required">], "required", never>;
    field: convex_values0.VString<string, "required">;
  }, "optional", "field" | "direction">;
  where: convex_values0.VArray<{
    mode?: "sensitive" | "insensitive" | undefined;
    connector?: "AND" | "OR" | undefined;
    operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
    value: string | number | boolean | string[] | number[] | null;
    field: string;
  }[] | undefined, convex_values0.VObject<{
    mode?: "sensitive" | "insensitive" | undefined;
    connector?: "AND" | "OR" | undefined;
    operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
    value: string | number | boolean | string[] | number[] | null;
    field: string;
  }, {
    connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
    field: convex_values0.VString<string, "required">;
    mode: convex_values0.VUnion<"sensitive" | "insensitive" | undefined, [convex_values0.VLiteral<"sensitive", "required">, convex_values0.VLiteral<"insensitive", "required">], "optional", never>;
    operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
    value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
  }, "required", "mode" | "value" | "connector" | "field" | "operator">, "optional">;
}, "required", "model" | "select" | "where" | "limit" | "offset" | "sortBy" | "sortBy.field" | "sortBy.direction">;
declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
declare const checkUniqueFields: <Schema extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => D | null;
declare const paginate: <Doc extends DocumentByName<GenericDataModel, T>, T extends TableNamesInDataModel<GenericDataModel>>(ctx: GenericQueryCtx<GenericDataModel>, schema: SchemaDefinition<any, any>, betterAuthSchema: BetterAuthDBSchema, args: Infer<typeof adapterArgsValidator> & {
  paginationOpts: AdapterPaginationOptions;
}) => Promise<PaginationResult<Doc>>;
declare const listOne: <Doc extends DocumentByName<GenericDataModel, T>, T extends TableNamesInDataModel<GenericDataModel>>(ctx: GenericQueryCtx<GenericDataModel>, schema: SchemaDefinition<any, any>, betterAuthSchema: BetterAuthDBSchema, args: Infer<typeof adapterArgsValidator>) => Promise<Doc | null>;
//#endregion
//#region src/auth/generated-contract.d.ts
type UnknownFn = (...args: never[]) => unknown;
declare const getInvalidAuthDefinitionExportReason: (authDefinitionPath?: string) => string;
type AuthDefinitionModule<GenericCtx, DataModel extends GenericDataModel, Schema extends SchemaDefinition<GenericSchema, true>, AuthOptions extends BetterAuthOptionsWithoutDatabase> = {
  default: GenericAuthDefinition<GenericCtx, DataModel, Schema, AuthOptions>;
};
type AuthDefinitionInput<GenericCtx, DataModel extends GenericDataModel, Schema extends SchemaDefinition<GenericSchema, true>, AuthOptions extends BetterAuthOptionsWithoutDatabase> = GenericAuthDefinition<GenericCtx, DataModel, Schema, AuthOptions> | AuthDefinitionModule<GenericCtx, DataModel, Schema, AuthOptions>;
declare const resolveGeneratedAuthDefinition: <Definition extends UnknownFn>(input: unknown, reason: string) => Definition;
declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema extends SchemaDefinition<GenericSchema, true>, TriggerCtx extends GenericMutationCtx<DataModel> = GenericMutationCtx<DataModel>, GenericCtx = GenericMutationCtx<DataModel>, AuthOptions extends BetterAuthOptionsWithoutDatabase = BetterAuthOptionsWithoutDatabase>(config: {
  internal: unknown;
  moduleName: string;
  schema: Schema;
  auth: AuthDefinitionInput<GenericCtx, DataModel, Schema, AuthOptions>;
  context?: (ctx: GenericMutationCtx<DataModel>) => TriggerCtx | Promise<TriggerCtx>;
}) => AuthRuntime<DataModel, Schema, TriggerCtx, GenericCtx, AuthOptions>;
//#endregion
//#region src/auth/helpers.d.ts
type SessionDoc<TCtx extends GenericQueryCtx<any>> = DocByCtx<TCtx, 'session'>;
type SessionResult<TCtx extends GenericQueryCtx<any>> = LookupByIdResultByCtx<TCtx, 'session'>;
type SessionLookupCtx<TCtx extends GenericQueryCtx<any>> = QueryCtxWithPreferredOrmQueryTable<TCtx, 'session'>;
type SessionClientSignals = {
  ip?: string;
  userAgent?: string;
};
declare const getAuthUserIdentity: <DataModel extends GenericDataModel>(ctx: GenericQueryCtx<DataModel>) => Promise<{
  sessionId: DocumentByName<DataModel, "session">["_id"];
  userId: DocumentByName<DataModel, "user">["_id"];
  tokenIdentifier: string;
  subject: string;
  issuer: string;
  name?: string;
  givenName?: string;
  familyName?: string;
  nickname?: string;
  preferredUsername?: string;
  profileUrl?: string;
  pictureUrl?: string;
  email?: string;
  emailVerified?: boolean;
  gender?: string;
  birthday?: string;
  timezone?: string;
  language?: string;
  phoneNumber?: string;
  phoneNumberVerified?: boolean;
  address?: string;
  updatedAt?: string;
} | null>;
declare const getAuthUserId: <DataModel extends GenericDataModel>(ctx: GenericQueryCtx<DataModel>) => Promise<string | null>;
declare function getSession<TCtx extends GenericQueryCtx<any>>(ctx: TCtx & SessionLookupCtx<TCtx>, _sessionId?: SessionDoc<TCtx>['_id']): Promise<SessionResult<TCtx>>;
declare const getSessionNetworkSignals: <TCtx extends GenericQueryCtx<any>>(ctx: TCtx & QueryCtxWithPreferredOrmQueryTable<TCtx, "session">, session?: SessionResult<TCtx> | null) => Promise<SessionClientSignals>;
declare const getHeaders: <TCtx extends GenericQueryCtx<any>>(ctx: TCtx & QueryCtxWithPreferredOrmQueryTable<TCtx, "session">, session?: SessionResult<TCtx> | null) => Promise<Headers>;
//#endregion
//#region src/auth/internal/convex-plugin.d.ts
declare const convex: (opts: {
  authConfig: AuthConfig;
  jwks?: string;
  jwksRotateOnTokenGenerationError?: boolean;
  jwt?: {
    definePayload?: (session: {
      session: Session & Record<string, any>;
      user: User & Record<string, any>;
    }) => Promise<Record<string, any>> | Record<string, any> | undefined;
    expirationSeconds?: number;
  };
  /**
   * @deprecated Use jwt.expirationSeconds instead.
   */
  jwtExpirationSeconds?: number;
  options?: BetterAuthOptions;
}) => {
  id: "convex";
  init: (ctx: better_auth0.AuthContext) => void;
  hooks: {
    before: ({
      matcher(context: better_auth0.HookEndpointContext): boolean;
      handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<{
        context: {
          headers: Headers;
        };
      } | undefined>;
    } | {
      matcher: (ctx: better_auth0.HookEndpointContext) => boolean;
      handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<{
        context: better_auth0.MiddlewareContext<better_auth0.MiddlewareOptions, {
          returned?: unknown | undefined;
          responseHeaders?: Headers | undefined;
        } & better_auth0.PluginContext<BetterAuthOptions> & better_auth0.InfoContext & {
          options: BetterAuthOptions;
          trustedOrigins: string[];
          trustedProviders: string[];
          isTrustedOrigin: (url: string, settings?: {
            allowRelativePaths: boolean;
          }) => boolean;
          oauthConfig: {
            skipStateCookieCheck?: boolean | undefined;
            storeStateStrategy: "database" | "cookie";
          };
          newSession: {
            session: {
              id: string;
              createdAt: Date;
              updatedAt: Date;
              userId: string;
              expiresAt: Date;
              token: string;
              ipAddress?: string | null | undefined;
              userAgent?: string | null | undefined;
            } & Record<string, any>;
            user: {
              id: string;
              createdAt: Date;
              updatedAt: Date;
              email: string;
              emailVerified: boolean;
              name: string;
              image?: string | null | undefined;
            } & Record<string, any>;
          } | null;
          session: {
            session: {
              id: string;
              createdAt: Date;
              updatedAt: Date;
              userId: string;
              expiresAt: Date;
              token: string;
              ipAddress?: string | null | undefined;
              userAgent?: string | null | undefined;
            } & Record<string, any>;
            user: {
              id: string;
              createdAt: Date;
              updatedAt: Date;
              email: string;
              emailVerified: boolean;
              name: string;
              image?: string | null | undefined;
            } & Record<string, any>;
          } | null;
          setNewSession: (session: {
            session: {
              id: string;
              createdAt: Date;
              updatedAt: Date;
              userId: string;
              expiresAt: Date;
              token: string;
              ipAddress?: string | null | undefined;
              userAgent?: string | null | undefined;
            } & Record<string, any>;
            user: {
              id: string;
              createdAt: Date;
              updatedAt: Date;
              email: string;
              emailVerified: boolean;
              name: string;
              image?: string | null | undefined;
            } & Record<string, any>;
          } | null) => void;
          socialProviders: better_auth0.OAuthProvider[];
          authCookies: better_auth0.BetterAuthCookies;
          logger: ReturnType<(options?: better_auth0.Logger | undefined) => better_auth0.InternalLogger>;
          rateLimit: {
            enabled: boolean;
            window: number;
            max: number;
            storage: "memory" | "database" | "secondary-storage";
          } & Omit<better_auth0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
          adapter: better_auth0.DBAdapter<BetterAuthOptions>;
          internalAdapter: better_auth0.InternalAdapter<BetterAuthOptions>;
          createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_auth0.CookieOptions> | undefined) => better_auth0.BetterAuthCookie;
          secret: string;
          secretConfig: string | better_auth0.SecretConfig;
          sessionConfig: {
            updateAge: number;
            expiresIn: number;
            freshAge: number;
            cookieRefreshCache: false | {
              enabled: true;
              updateAge: number;
            };
          };
          generateId: (options: {
            model: better_auth0.ModelNames;
            size?: number | undefined;
          }) => string | false;
          secondaryStorage: better_auth0.SecondaryStorage | undefined;
          password: {
            hash: (password: string) => Promise<string>;
            verify: (data: {
              password: string;
              hash: string;
            }) => Promise<boolean>;
            config: {
              minPasswordLength: number;
              maxPasswordLength: number;
            };
            checkPassword: (userId: string, ctx: better_auth0.GenericEndpointContext<BetterAuthOptions>) => Promise<boolean>;
          };
          tables: better_auth0.BetterAuthDBSchema;
          runMigrations: () => Promise<void>;
          publishTelemetry: (event: {
            type: string;
            anonymousId?: string | undefined;
            payload: Record<string, any>;
          }) => Promise<void>;
          skipOriginCheck: boolean | string[];
          skipCSRFCheck: boolean;
          runInBackground: (promise: Promise<unknown>) => void;
          runInBackgroundOrAwait: (promise: Promise<unknown> | void) => better_auth0.Awaitable<unknown>;
        }>;
      }>;
    })[];
    after: {
      matcher: (context: better_auth0.HookEndpointContext) => boolean;
      handler: better_auth_api0.AuthMiddleware;
    }[];
  };
  endpoints: {
    getOpenIdConfig: better_auth0.StrictEndpoint<"/convex/.well-known/openid-configuration", {
      method: "GET";
      metadata: {
        isAction: false;
      };
    }, better_auth_plugins_oidc_provider0.OIDCMetadata>;
    getJwks: better_auth0.StrictEndpoint<"/convex/jwks", {
      method: "GET";
      metadata: {
        openapi: {
          description: string;
          responses: {
            '200': {
              description: string;
            };
          };
        };
      };
    }, jose.JSONWebKeySet>;
    getLatestJwks: better_auth0.StrictEndpoint<"/convex/latest-jwks", {
      isAction: boolean;
      method: "POST";
      metadata: {
        SERVER_ONLY: true;
        openapi: {
          description: string;
        };
      };
    }, any[]>;
    rotateKeys: better_auth0.StrictEndpoint<"/convex/rotate-keys", {
      isAction: boolean;
      method: "POST";
      metadata: {
        SERVER_ONLY: true;
        openapi: {
          description: string;
        };
      };
    }, any[]>;
    getToken: better_auth0.StrictEndpoint<"/convex/token", {
      method: "GET";
      requireHeaders: true;
      use: ((inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<{
        session: {
          session: Record<string, any> & {
            id: string;
            createdAt: Date;
            updatedAt: Date;
            userId: string;
            expiresAt: Date;
            token: string;
            ipAddress?: string | null | undefined;
            userAgent?: string | null | undefined;
          };
          user: Record<string, any> & {
            id: string;
            createdAt: Date;
            updatedAt: Date;
            email: string;
            emailVerified: boolean;
            name: string;
            image?: string | null | undefined;
          };
        };
      }>)[];
      metadata: {
        openapi: {
          description: string;
        };
      };
    }, {
      token: string;
    }>;
  };
  schema: {
    jwks: {
      fields: {
        publicKey: {
          type: "string";
          required: true;
        };
        privateKey: {
          type: "string";
          required: true;
        };
        createdAt: {
          type: "date";
          required: true;
        };
        expiresAt: {
          type: "date";
          required: false;
        };
      };
    };
    user: {
      readonly fields: {
        readonly userId: {
          readonly type: "string";
          readonly required: false;
          readonly input: false;
        };
      };
    };
  };
};
//#endregion
export { type AuthFunctions, type AuthRuntime, BetterAuthOptionsWithoutDatabase, ConvexCleanedWhere, type GeneratedAuthDisabledReasonKind, GenericAuthBeforeResult, GenericAuthDefinition, GenericAuthTriggerChange, GenericAuthTriggerHandlers, GenericAuthTriggers, GetAuth, SessionClientSignals, type Triggers, adapterArgsValidator, adapterConfig, adapterWhereValidator, checkUniqueFields, convex, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };