@vexcms/better-auth 0.1.0-alpha.2 → 0.1.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/pluginSchemas.generated.ts","../src/pluginSchemas.ts","../src/collections.ts"],"sourcesContent":["// ⚠️ AUTO-GENERATED — DO NOT EDIT ⚠️\n// Snapshot of every modelled Better Auth plugin's DB schema, harvested from\n// the real plugin factories by `pluginSchemas.test.ts`. Regenerate after a\n// Better Auth upgrade with `pnpm --filter @vexcms/better-auth gen:auth-schemas`;\n// the same test fails when this file and the installed version disagree.\n//\n// It exists so `betterAuthCollections()` can run in a browser bundle: reading\n// these schemas costs ~1 KB, instantiating the plugins that declare them costs\n// ~154 KB gzipped.\n\nimport type { PluginDBSchema } from \"./pluginSchemas\";\n\n/** Declared DB schema per plugin descriptor key. */\nexport const PLUGIN_SCHEMAS: Record<string, PluginDBSchema> = {\n \"admin\": {\n \"user\": {\n \"fields\": {\n \"role\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n },\n \"banned\": {\n \"type\": \"boolean\",\n \"defaultValue\": false,\n \"required\": false,\n \"input\": false\n },\n \"banReason\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n },\n \"banExpires\": {\n \"type\": \"date\",\n \"required\": false,\n \"input\": false\n }\n }\n },\n \"session\": {\n \"fields\": {\n \"impersonatedBy\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n }\n }\n }\n },\n \"anonymous\": {\n \"user\": {\n \"fields\": {\n \"isAnonymous\": {\n \"type\": \"boolean\",\n \"required\": false,\n \"input\": false,\n \"defaultValue\": false\n }\n }\n }\n },\n \"apiKey\": {\n \"apikey\": {\n \"fields\": {\n \"configId\": {\n \"type\": \"string\",\n \"required\": true,\n \"defaultValue\": \"default\",\n \"input\": false,\n \"index\": true\n },\n \"name\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n },\n \"start\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n },\n \"referenceId\": {\n \"type\": \"string\",\n \"required\": true,\n \"input\": false,\n \"index\": true\n },\n \"prefix\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n },\n \"key\": {\n \"type\": \"string\",\n \"required\": true,\n \"input\": false,\n \"index\": true\n },\n \"refillInterval\": {\n \"type\": \"number\",\n \"required\": false,\n \"input\": false\n },\n \"refillAmount\": {\n \"type\": \"number\",\n \"required\": false,\n \"input\": false\n },\n \"lastRefillAt\": {\n \"type\": \"date\",\n \"required\": false,\n \"input\": false\n },\n \"enabled\": {\n \"type\": \"boolean\",\n \"required\": false,\n \"input\": false,\n \"defaultValue\": true\n },\n \"rateLimitEnabled\": {\n \"type\": \"boolean\",\n \"required\": false,\n \"input\": false,\n \"defaultValue\": true\n },\n \"rateLimitTimeWindow\": {\n \"type\": \"number\",\n \"required\": false,\n \"input\": false,\n \"defaultValue\": 86400000\n },\n \"rateLimitMax\": {\n \"type\": \"number\",\n \"required\": false,\n \"input\": false,\n \"defaultValue\": 10\n },\n \"requestCount\": {\n \"type\": \"number\",\n \"required\": false,\n \"input\": false,\n \"defaultValue\": 0\n },\n \"remaining\": {\n \"type\": \"number\",\n \"required\": false,\n \"input\": false\n },\n \"lastRequest\": {\n \"type\": \"date\",\n \"required\": false,\n \"input\": false\n },\n \"expiresAt\": {\n \"type\": \"date\",\n \"required\": false,\n \"input\": false\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true,\n \"input\": false\n },\n \"updatedAt\": {\n \"type\": \"date\",\n \"required\": true,\n \"input\": false\n },\n \"permissions\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n },\n \"metadata\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": true,\n \"transform\": {}\n }\n }\n }\n },\n \"convex\": {\n \"user\": {\n \"fields\": {\n \"userId\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n }\n }\n },\n \"jwks\": {\n \"fields\": {\n \"publicKey\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"privateKey\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"expiresAt\": {\n \"type\": \"date\",\n \"required\": false\n }\n }\n }\n },\n \"deviceAuthorization\": {\n \"deviceCode\": {\n \"fields\": {\n \"deviceCode\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"userCode\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"expiresAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"status\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"lastPolledAt\": {\n \"type\": \"date\",\n \"required\": false\n },\n \"pollingInterval\": {\n \"type\": \"number\",\n \"required\": false\n },\n \"clientId\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"scope\": {\n \"type\": \"string\",\n \"required\": false\n }\n }\n }\n },\n \"jwt\": {\n \"jwks\": {\n \"fields\": {\n \"publicKey\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"privateKey\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"expiresAt\": {\n \"type\": \"date\",\n \"required\": false\n }\n }\n }\n },\n \"mcp\": {\n \"oauthApplication\": {\n \"modelName\": \"oauthApplication\",\n \"fields\": {\n \"name\": {\n \"type\": \"string\"\n },\n \"icon\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"metadata\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"clientId\": {\n \"type\": \"string\",\n \"unique\": true\n },\n \"clientSecret\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"redirectUrls\": {\n \"type\": \"string\"\n },\n \"type\": {\n \"type\": \"string\"\n },\n \"disabled\": {\n \"type\": \"boolean\",\n \"required\": false,\n \"defaultValue\": false\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": false,\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"createdAt\": {\n \"type\": \"date\"\n },\n \"updatedAt\": {\n \"type\": \"date\"\n }\n }\n },\n \"oauthAccessToken\": {\n \"modelName\": \"oauthAccessToken\",\n \"fields\": {\n \"accessToken\": {\n \"type\": \"string\",\n \"unique\": true\n },\n \"refreshToken\": {\n \"type\": \"string\",\n \"unique\": true\n },\n \"accessTokenExpiresAt\": {\n \"type\": \"date\"\n },\n \"refreshTokenExpiresAt\": {\n \"type\": \"date\"\n },\n \"clientId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"oauthApplication\",\n \"field\": \"clientId\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": false,\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"scopes\": {\n \"type\": \"string\"\n },\n \"createdAt\": {\n \"type\": \"date\"\n },\n \"updatedAt\": {\n \"type\": \"date\"\n }\n }\n },\n \"oauthConsent\": {\n \"modelName\": \"oauthConsent\",\n \"fields\": {\n \"clientId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"oauthApplication\",\n \"field\": \"clientId\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"userId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"scopes\": {\n \"type\": \"string\"\n },\n \"createdAt\": {\n \"type\": \"date\"\n },\n \"updatedAt\": {\n \"type\": \"date\"\n },\n \"consentGiven\": {\n \"type\": \"boolean\"\n }\n }\n }\n },\n \"oidcProvider\": {\n \"oauthApplication\": {\n \"modelName\": \"oauthApplication\",\n \"fields\": {\n \"name\": {\n \"type\": \"string\"\n },\n \"icon\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"metadata\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"clientId\": {\n \"type\": \"string\",\n \"unique\": true\n },\n \"clientSecret\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"redirectUrls\": {\n \"type\": \"string\"\n },\n \"type\": {\n \"type\": \"string\"\n },\n \"disabled\": {\n \"type\": \"boolean\",\n \"required\": false,\n \"defaultValue\": false\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": false,\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"createdAt\": {\n \"type\": \"date\"\n },\n \"updatedAt\": {\n \"type\": \"date\"\n }\n }\n },\n \"oauthAccessToken\": {\n \"modelName\": \"oauthAccessToken\",\n \"fields\": {\n \"accessToken\": {\n \"type\": \"string\",\n \"unique\": true\n },\n \"refreshToken\": {\n \"type\": \"string\",\n \"unique\": true\n },\n \"accessTokenExpiresAt\": {\n \"type\": \"date\"\n },\n \"refreshTokenExpiresAt\": {\n \"type\": \"date\"\n },\n \"clientId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"oauthApplication\",\n \"field\": \"clientId\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": false,\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"scopes\": {\n \"type\": \"string\"\n },\n \"createdAt\": {\n \"type\": \"date\"\n },\n \"updatedAt\": {\n \"type\": \"date\"\n }\n }\n },\n \"oauthConsent\": {\n \"modelName\": \"oauthConsent\",\n \"fields\": {\n \"clientId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"oauthApplication\",\n \"field\": \"clientId\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"userId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\",\n \"onDelete\": \"cascade\"\n },\n \"index\": true\n },\n \"scopes\": {\n \"type\": \"string\"\n },\n \"createdAt\": {\n \"type\": \"date\"\n },\n \"updatedAt\": {\n \"type\": \"date\"\n },\n \"consentGiven\": {\n \"type\": \"boolean\"\n }\n }\n }\n },\n \"organization\": {\n \"organization\": {\n \"fields\": {\n \"name\": {\n \"type\": \"string\",\n \"required\": true,\n \"sortable\": true\n },\n \"slug\": {\n \"type\": \"string\",\n \"required\": true,\n \"unique\": true,\n \"sortable\": true,\n \"index\": true\n },\n \"logo\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"metadata\": {\n \"type\": \"string\",\n \"required\": false\n }\n }\n },\n \"member\": {\n \"fields\": {\n \"organizationId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"organization\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"role\": {\n \"type\": \"string\",\n \"required\": true,\n \"sortable\": true,\n \"defaultValue\": \"member\"\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n }\n }\n },\n \"invitation\": {\n \"fields\": {\n \"organizationId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"organization\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"email\": {\n \"type\": \"string\",\n \"required\": true,\n \"sortable\": true,\n \"index\": true\n },\n \"role\": {\n \"type\": \"string\",\n \"required\": false,\n \"sortable\": true\n },\n \"status\": {\n \"type\": \"string\",\n \"required\": true,\n \"sortable\": true,\n \"defaultValue\": \"pending\"\n },\n \"expiresAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"inviterId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\"\n },\n \"required\": true\n }\n }\n },\n \"session\": {\n \"fields\": {\n \"activeOrganizationId\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n }\n }\n }\n },\n \"organization.teams\": {\n \"organization\": {\n \"fields\": {\n \"name\": {\n \"type\": \"string\",\n \"required\": true,\n \"sortable\": true\n },\n \"slug\": {\n \"type\": \"string\",\n \"required\": true,\n \"unique\": true,\n \"sortable\": true,\n \"index\": true\n },\n \"logo\": {\n \"type\": \"string\",\n \"required\": false\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"metadata\": {\n \"type\": \"string\",\n \"required\": false\n }\n }\n },\n \"team\": {\n \"fields\": {\n \"name\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"organizationId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"organization\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"updatedAt\": {\n \"type\": \"date\",\n \"required\": false\n }\n }\n },\n \"teamMember\": {\n \"fields\": {\n \"teamId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"team\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": false\n }\n }\n },\n \"member\": {\n \"fields\": {\n \"organizationId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"organization\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"role\": {\n \"type\": \"string\",\n \"required\": true,\n \"sortable\": true,\n \"defaultValue\": \"member\"\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n }\n }\n },\n \"invitation\": {\n \"fields\": {\n \"organizationId\": {\n \"type\": \"string\",\n \"required\": true,\n \"references\": {\n \"model\": \"organization\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"email\": {\n \"type\": \"string\",\n \"required\": true,\n \"sortable\": true,\n \"index\": true\n },\n \"role\": {\n \"type\": \"string\",\n \"required\": false,\n \"sortable\": true\n },\n \"teamId\": {\n \"type\": \"string\",\n \"required\": false,\n \"sortable\": true\n },\n \"status\": {\n \"type\": \"string\",\n \"required\": true,\n \"sortable\": true,\n \"defaultValue\": \"pending\"\n },\n \"expiresAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n },\n \"inviterId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\"\n },\n \"required\": true\n }\n }\n },\n \"session\": {\n \"fields\": {\n \"activeOrganizationId\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n },\n \"activeTeamId\": {\n \"type\": \"string\",\n \"required\": false,\n \"input\": false\n }\n }\n }\n },\n \"phoneNumber\": {\n \"user\": {\n \"fields\": {\n \"phoneNumber\": {\n \"type\": \"string\",\n \"required\": false,\n \"unique\": true,\n \"sortable\": true,\n \"returned\": true\n },\n \"phoneNumberVerified\": {\n \"type\": \"boolean\",\n \"required\": false,\n \"returned\": true,\n \"input\": false\n }\n }\n }\n },\n \"siwe\": {\n \"walletAddress\": {\n \"fields\": {\n \"userId\": {\n \"type\": \"string\",\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\"\n },\n \"required\": true,\n \"index\": true\n },\n \"address\": {\n \"type\": \"string\",\n \"required\": true\n },\n \"chainId\": {\n \"type\": \"number\",\n \"required\": true\n },\n \"isPrimary\": {\n \"type\": \"boolean\",\n \"defaultValue\": false\n },\n \"createdAt\": {\n \"type\": \"date\",\n \"required\": true\n }\n }\n }\n },\n \"twoFactor\": {\n \"user\": {\n \"fields\": {\n \"twoFactorEnabled\": {\n \"type\": \"boolean\",\n \"required\": false,\n \"defaultValue\": false,\n \"input\": false\n }\n }\n },\n \"twoFactor\": {\n \"fields\": {\n \"secret\": {\n \"type\": \"string\",\n \"required\": true,\n \"returned\": false,\n \"index\": true\n },\n \"backupCodes\": {\n \"type\": \"string\",\n \"required\": true,\n \"returned\": false\n },\n \"userId\": {\n \"type\": \"string\",\n \"required\": true,\n \"returned\": false,\n \"references\": {\n \"model\": \"user\",\n \"field\": \"id\"\n },\n \"index\": true\n },\n \"verified\": {\n \"type\": \"boolean\",\n \"required\": false,\n \"defaultValue\": true,\n \"input\": false\n },\n \"failedVerificationCount\": {\n \"type\": \"number\",\n \"required\": false,\n \"defaultValue\": 0,\n \"input\": false,\n \"returned\": false\n },\n \"lockedUntil\": {\n \"type\": \"date\",\n \"required\": false,\n \"input\": false,\n \"returned\": false\n }\n }\n }\n }\n};\n","import type { DBFieldAttribute } from \"better-auth\";\n// Type-only namespace import: erased entirely by the compiler, so deriving the\n// plugin-name union below costs the client bundle nothing. A value import here\n// would pull every plugin factory (~684 KB) into any graph that touches it.\nimport type * as BetterAuthPlugins from \"better-auth/plugins\";\n\nimport { PLUGIN_SCHEMAS } from \"./pluginSchemas.generated\";\n\n/**\n * A Better Auth plugin's DB schema contribution — one entry per table it adds\n * or extends.\n *\n * Declared structurally rather than imported from `@better-auth/core/db`:\n * that package is a transitive dependency of `better-auth`, not one this\n * package declares, so naming it in a public type would be an undeclared\n * dependency on consumers' resolution.\n */\nexport type PluginDBSchema = Record<\n string,\n {\n fields: Record<string, DBFieldAttribute>;\n modelName?: string | undefined;\n disableMigration?: boolean | undefined;\n }\n>;\n\n/**\n * Every export of `better-auth/plugins` that is a plugin factory — derived\n * from the module's own types, so the union tracks upstream automatically:\n * a Better Auth release that adds a plugin adds a member here with no code\n * change, and {@link UnclassifiedPlugin} turns that into a compile error in\n * this package until the plugin is classified.\n */\nexport type BetterAuthPluginName = {\n [K in keyof typeof BetterAuthPlugins]: (typeof BetterAuthPlugins)[K] extends (\n ...args: never[]\n ) => {\n id: string;\n }\n ? K\n : never;\n}[keyof typeof BetterAuthPlugins];\n\n/**\n * Per-table overrides a plugin's own `schema` option accepts — renaming its\n * table or adding fields to it. Mirrors Better Auth's `schema` option shape so\n * the value can be authored once and passed to both the real plugin factory\n * and {@link betterAuthCollections}.\n */\nexport type PluginSchemaOverride = Record<\n string,\n {\n modelName?: string | undefined;\n /** Column renames, keyed by the plugin's own field name. */\n fields?: Record<string, string> | undefined;\n additionalFields?: Record<string, DBFieldAttribute> | undefined;\n }\n>;\n\n/**\n * Plugins whose DB schema this package models. `true` enables a plugin with\n * its default schema; an object supplies the SCHEMA-AFFECTING options only.\n *\n * Runtime options (`adminRoles`, `sendInvitationEmail`, OAuth secrets, …) are\n * deliberately absent: this descriptor is authored in a client-safe module and\n * accepting a plugin's full option type is how a server callback — and\n * whatever it closes over — would end up in the browser bundle. Options that\n * do not change the schema cannot change what the admin panel renders, so\n * nothing is lost by keeping them on the server's real plugin instances.\n */\nexport interface ModelledPluginDescriptors {\n /** Roles, bans, and impersonation fields on `user`/`session`. */\n admin?: true | { schema?: PluginSchemaOverride };\n /** `isAnonymous` on `user`. */\n anonymous?: true | { schema?: PluginSchemaOverride };\n /** The `apikey` table. */\n apiKey?: true | { schema?: PluginSchemaOverride };\n /** `userId` on `user`, plus the `jwks` table the Convex plugin's JWT half adds. */\n convex?: true | { schema?: PluginSchemaOverride };\n /** The `deviceCode` table. */\n deviceAuthorization?: true | { schema?: PluginSchemaOverride };\n /** The `jwks` table. */\n jwt?: true | { schema?: PluginSchemaOverride };\n /** The OAuth application/access-token/consent tables. */\n mcp?: true | { schema?: PluginSchemaOverride };\n /** The OAuth application/access-token/consent tables. */\n oidcProvider?: true | { schema?: PluginSchemaOverride };\n /**\n * Organizations, members, and invitations — plus `team`/`teamMember` when\n * `teams` is enabled, which is the one option that changes which tables exist.\n */\n organization?: true | { teams?: boolean; schema?: PluginSchemaOverride };\n /** `phoneNumber`/`phoneNumberVerified` on `user`. */\n phoneNumber?: true | { schema?: PluginSchemaOverride };\n /** The `walletAddress` table. */\n siwe?: true | { schema?: PluginSchemaOverride };\n /** The `twoFactor` table and `twoFactorEnabled` on `user`. */\n twoFactor?: true | { schema?: PluginSchemaOverride };\n}\n\n/** A plugin name this package models. */\nexport type ModelledPluginName = keyof ModelledPluginDescriptors;\n\n/**\n * Plugins that exist upstream but contribute no tables, or whose schema this\n * package does not model. Passing one is a type error naming the escape hatch:\n * read its `schema` off your real plugin instance on the server and hand the\n * value to `betterAuthCollections`'s `extraSchema`.\n */\nexport type UnmodelledPluginDescriptor<TName extends string> = {\n readonly __unmodelled_plugin_pass_its_schema_via_extraSchema: TName;\n};\n\n/**\n * Plugin names neither modelled nor explicitly acknowledged as unmodelled.\n * Always `never`; {@link assertEveryPluginClassified} makes a non-`never`\n * value a compile error naming the plugin a Better Auth release just added.\n */\nexport type UnclassifiedPlugin = Exclude<\n BetterAuthPluginName,\n ModelledPluginName | UnmodelledPluginName\n>;\n\n/**\n * Upstream plugins knowingly left unmodelled. Enumerated rather than inferred\n * so adding a plugin upstream breaks this package's typecheck instead of\n * silently widening the accepted descriptor map.\n */\nexport type UnmodelledPluginName =\n | \"backupCode2fa\"\n | \"bearer\"\n | \"captcha\"\n | \"customSession\"\n | \"emailOTP\"\n | \"genericOAuth\"\n | \"haveIBeenPwned\"\n | \"lastLoginMethod\"\n | \"magicLink\"\n | \"multiSession\"\n | \"oAuthProxy\"\n | \"oauthPopup\"\n | \"oneTap\"\n | \"oneTimeToken\"\n | \"openAPI\"\n | \"otp2fa\"\n | \"passkey\"\n | \"sso\"\n | \"testUtils\"\n | \"totp2fa\"\n | \"twoFactorClient\"\n | \"username\";\n\n/**\n * The `plugins` map `betterAuthCollections` accepts: modelled plugins carry a\n * descriptor, every other upstream plugin is rejected with a message pointing\n * at `extraSchema`.\n */\nexport type BetterAuthPluginDescriptors = ModelledPluginDescriptors & {\n [K in UnmodelledPluginName]?: UnmodelledPluginDescriptor<K>;\n};\n\n/**\n * Compile-time proof that every plugin `better-auth/plugins` exports is either\n * modelled or explicitly unmodelled.\n *\n * A Better Auth upgrade that adds a plugin fails this assignment with the new\n * plugin's name in the error — add it to {@link ModelledPluginDescriptors} (and\n * the probe table in `pluginSchemas.test.ts`) or to {@link UnmodelledPluginName}.\n */\nconst assertEveryPluginClassified: UnclassifiedPlugin extends never\n ? true\n : UnclassifiedPlugin = true;\nvoid assertEveryPluginClassified;\n\n/**\n * Resolves a descriptor map into the plain plugin stubs `getAuthTables` reads.\n *\n * Each enabled plugin contributes its generated schema snapshot with the\n * caller's `schema` overrides applied the same way the real plugin applies\n * them: `additionalFields` are spread into the table (plugins do this\n * themselves when building their schema, so the snapshot — generated with no\n * overrides — cannot already contain them), then Better Auth's own\n * the same field renames and `modelName` override Better Auth's `mergeSchema` applies.\n *\n * @param props.plugins - Descriptor map; omitted or `undefined` entries contribute nothing.\n * @param props.extraSchema - Schemas of plugins this package does not model, taken from a real plugin instance's `schema`.\n * @returns One `{ id, schema }` stub per contributing plugin, in descriptor-key order.\n * @throws {Error} When a descriptor names a plugin with no modelled schema.\n */\nexport function resolvePluginStubs(props: {\n plugins?: BetterAuthPluginDescriptors | undefined;\n extraSchema?: PluginDBSchema | PluginDBSchema[] | undefined;\n}): { id: string; schema: PluginDBSchema }[] {\n const stubs: { id: string; schema: PluginDBSchema }[] = [];\n\n for (const [name, descriptor] of Object.entries(props.plugins ?? {})) {\n if (descriptor === undefined || descriptor === false) continue;\n const options = descriptor === true ? {} : (descriptor as Record<string, unknown>);\n const key =\n name === \"organization\" && options.teams === true ? \"organization.teams\" : name;\n const generated = PLUGIN_SCHEMAS[key];\n if (generated === undefined) {\n throw new Error(\n `betterAuthCollections: no schema is modelled for the \"${name}\" plugin. ` +\n `Read \\`schema\\` off your real plugin instance on the server and pass it as \\`extraSchema\\`.`,\n );\n }\n\n // Cloned because the override merge below rewrites `modelName`/`fieldName`\n // and PLUGIN_SCHEMAS is module-level state shared by every call.\n const schema = structuredClone(generated);\n for (const [table, tableOverride] of Object.entries(\n (options.schema ?? {}) as PluginSchemaOverride,\n )) {\n const target = schema[table];\n if (target === undefined || tableOverride === undefined) continue;\n // Plugins spread `additionalFields` into their own schema at build time,\n // so the snapshot — generated without overrides — never carries them.\n if (tableOverride.additionalFields !== undefined) {\n target.fields = { ...target.fields, ...tableOverride.additionalFields };\n }\n // Same semantics as Better Auth's `mergeSchema`, reimplemented rather\n // than imported: pulling it from `better-auth/db` defeats that barrel's\n // tree-shaking and costs the client bundle 77 KB gzipped instead of 1 KB.\n if (tableOverride.modelName !== undefined) {\n target.modelName = tableOverride.modelName;\n }\n for (const [field, fieldName] of Object.entries(tableOverride.fields ?? {})) {\n const attribute = target.fields[field];\n if (attribute !== undefined) attribute.fieldName = fieldName;\n }\n }\n\n stubs.push({ id: name, schema });\n }\n\n const extra = props.extraSchema;\n if (extra !== undefined) {\n for (const [index, schema] of (Array.isArray(extra) ? extra : [extra]).entries()) {\n stubs.push({ id: `extraSchema-${index}`, schema });\n }\n }\n\n return stubs;\n}\n","import type { AuthCollectionConfig } from \"@vexcms/core\";\nimport type { BetterAuthOptions, DBFieldAttribute } from \"better-auth\";\n\nimport { betterAuthAdapter } from \"./adapter\";\nimport type {\n BetterAuthPluginDescriptors,\n PluginDBSchema,\n} from \"./pluginSchemas\";\nimport { resolvePluginStubs } from \"./pluginSchemas\";\n\n/** Schema-affecting settings for one of Better Auth's four core tables. */\nexport interface BetterAuthCoreTableInput {\n /** Table name this model is stored under. Defaults to Better Auth's own (`user`, `session`, …). */\n modelName?: string | undefined;\n /** Renames of Better Auth's built-in columns. */\n fields?: Record<string, string> | undefined;\n /** Extra columns on this table, in Better Auth's `DBFieldAttribute` shape. */\n additionalFields?: Record<string, DBFieldAttribute> | undefined;\n}\n\n/**\n * Client-safe description of a Better Auth setup — everything that determines\n * which collections exist and which fields they carry, and nothing else.\n *\n * Author this once in a module with no server imports (conventionally\n * `src/auth/schema.ts`), spread it into your `authOptions` beside the secret,\n * base URL, and real plugin instances, and pass the whole object to\n * {@link betterAuthCollections} from `vex.config.ts`. `plugins` is ignored by\n * `BetterAuthOptions` — it is a descriptor map, not plugin instances — so\n * `authOptions` drops that one key and overrides it with the real factories.\n *\n * @see {@link betterAuthCollections}\n */\nexport interface BetterAuthSchemaInput {\n /** The user table. */\n user?: BetterAuthCoreTableInput | undefined;\n /** The session table. */\n session?: BetterAuthCoreTableInput | undefined;\n /** The account table. */\n account?: BetterAuthCoreTableInput | undefined;\n /** The verification table. */\n verification?: BetterAuthCoreTableInput | undefined;\n /**\n * Which Better Auth plugins are registered, and their schema-affecting\n * options. `true` takes a plugin's default schema.\n */\n plugins?: BetterAuthPluginDescriptors | undefined;\n /**\n * Schemas of plugins `@vexcms/better-auth` does not model — read `schema`\n * off the real plugin instance on your server and pass the value here.\n */\n extraSchema?: PluginDBSchema | PluginDBSchema[] | undefined;\n}\n\n/**\n * Builds the Vex auth collections a Better Auth setup implies, without\n * instantiating a single Better Auth plugin.\n *\n * Runs Better Auth's own `getAuthTables` over plain `{ id, schema }` plugin\n * stubs resolved from this package's generated schema snapshot, then converts\n * the result with the same pipeline `betterAuthAdapter` uses on the server —\n * so the collections are identical to the live adapter's by construction, and\n * `packages/better-auth/src/pluginSchemas.test.ts` asserts exactly that.\n *\n * Safe to call from `vex.config.ts`: the whole graph is `@vexcms/core` plus\n * `better-auth/db` (~1 KB gzipped). Instantiating real plugin factories here\n * instead would add ~154 KB gzipped to the admin bundle.\n *\n * @param schema - The client-safe description of your Better Auth setup.\n * @returns The auth collections, ready for `defineConfig({ authCollections })`.\n * @throws {Error} When `plugins` names a plugin whose schema is not modelled — use `extraSchema`.\n *\n * @example\n * ```ts\n * // src/auth/schema.ts — no server imports, safe in the browser bundle\n * export const authSchema = {\n * user: { modelName: \"user\", additionalFields: { roles: { type: \"string[]\", required: true } } },\n * plugins: { admin: true, anonymous: true, organization: { teams: true }, convex: true },\n * } satisfies BetterAuthSchemaInput;\n *\n * // src/vex.config.ts\n * export default defineConfig({ authCollections: betterAuthCollections(authSchema) });\n *\n * // src/auth/options.ts — one source of truth for model names and fields\n * const { plugins: _descriptors, ...schemaOptions } = authSchema;\n * export const authOptions: BetterAuthOptions = {\n * ...schemaOptions,\n * secret: process.env.BETTER_AUTH_SECRET,\n * plugins: createPlugins(),\n * };\n * ```\n *\n * @see {@link BetterAuthSchemaInput} for the input shape\n * @see {@link betterAuthAdapter} for the server-side adapter that verifies this result\n */\nexport function betterAuthCollections(\n schema: BetterAuthSchemaInput = {},\n): AuthCollectionConfig[] {\n const { plugins, extraSchema, ...coreTables } = schema;\n const config: BetterAuthOptions = {\n ...coreTables,\n plugins: resolvePluginStubs({ plugins, extraSchema }) as never,\n };\n return betterAuthAdapter({ config }).collections;\n}\n"],"mappings":";;;;;AAaO,IAAM,iBAAiD;AAAA,EAC5D,SAAS;AAAA,IACP,QAAQ;AAAA,MACN,UAAU;AAAA,QACR,QAAQ;AAAA,UACN,QAAQ;AAAA,UACR,YAAY;AAAA,UACZ,SAAS;AAAA,QACX;AAAA,QACA,UAAU;AAAA,UACR,QAAQ;AAAA,UACR,gBAAgB;AAAA,UAChB,YAAY;AAAA,UACZ,SAAS;AAAA,QACX;AAAA,QACA,aAAa;AAAA,UACX,QAAQ;AAAA,UACR,YAAY;AAAA,UACZ,SAAS;AAAA,QACX;AAAA,QACA,cAAc;AAAA,UACZ,QAAQ;AAAA,UACR,YAAY;AAAA,UACZ,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,UAAU;AAAA,QACR,kBAAkB;AAAA,UAChB,QAAQ;AAAA,UACR,YAAY;AAAA,UACZ,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,QAAQ;AAAA,MACN,UAAU;AAAA,QACR,eAAe;AAAA,UACb,QAAQ;AAAA,UACR,YAAY;AAAA,UACZ,SAAS;AAAA,UACT,gBAAgB;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,UAAU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IA,UAAI,cAAc,cAAc,QAAW;AACzC,eAAO,YAAY,cAAc;AAAA,MACnC;AACA,iBAAW,CAAC,OAAO,SAAS,KAAK,OAAO,QAAQ,cAAc,UAAU,CAAC,CAAC,GAAG;AAC3E,cAAM,YAAY,OAAO,OAAO,KAAK;AACrC,YAAI,cAAc,OAAW,WAAU,YAAY;AAAA,MACrD;AAAA,IACF;AAEA,UAAM,KAAK,EAAE,IAAI,MAAM,OAAO,CAAC;AAAA,EACjC;AAEA,QAAM,QAAQ,MAAM;AACpB,MAAI,UAAU,QAAW;AACvB,eAAW,CAAC,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,GAAG,QAAQ,GAAG;AAChF,YAAM,KAAK,EAAE,IAAI,eAAe,KAAK,IAAI,OAAO,CAAC;AAAA,IACnD;AAAA,EACF;AAEA,SAAO;AACT;;;ACrJO,SAAS,sBACd,SAAgC,CAAC,GACT;AACxB,QAAM,EAAE,SAAS,aAAa,GAAG,WAAW,IAAI;AAChD,QAAM,SAA4B;AAAA,IAChC,GAAG;AAAA,IACH,SAAS,mBAAmB,EAAE,SAAS,YAAY,CAAC;AAAA,EACtD;AACA,SAAO,kBAAkB,EAAE,OAAO,CAAC,EAAE;AACvC;","names":[]}
@@ -0,0 +1,88 @@
1
+ import type { AuthCollectionConfig } from "@vexcms/core";
2
+ import type { DBFieldAttribute } from "better-auth";
3
+ import type { BetterAuthPluginDescriptors, PluginDBSchema } from "./pluginSchemas";
4
+ /** Schema-affecting settings for one of Better Auth's four core tables. */
5
+ export interface BetterAuthCoreTableInput {
6
+ /** Table name this model is stored under. Defaults to Better Auth's own (`user`, `session`, …). */
7
+ modelName?: string | undefined;
8
+ /** Renames of Better Auth's built-in columns. */
9
+ fields?: Record<string, string> | undefined;
10
+ /** Extra columns on this table, in Better Auth's `DBFieldAttribute` shape. */
11
+ additionalFields?: Record<string, DBFieldAttribute> | undefined;
12
+ }
13
+ /**
14
+ * Client-safe description of a Better Auth setup — everything that determines
15
+ * which collections exist and which fields they carry, and nothing else.
16
+ *
17
+ * Author this once in a module with no server imports (conventionally
18
+ * `src/auth/schema.ts`), spread it into your `authOptions` beside the secret,
19
+ * base URL, and real plugin instances, and pass the whole object to
20
+ * {@link betterAuthCollections} from `vex.config.ts`. `plugins` is ignored by
21
+ * `BetterAuthOptions` — it is a descriptor map, not plugin instances — so
22
+ * `authOptions` drops that one key and overrides it with the real factories.
23
+ *
24
+ * @see {@link betterAuthCollections}
25
+ */
26
+ export interface BetterAuthSchemaInput {
27
+ /** The user table. */
28
+ user?: BetterAuthCoreTableInput | undefined;
29
+ /** The session table. */
30
+ session?: BetterAuthCoreTableInput | undefined;
31
+ /** The account table. */
32
+ account?: BetterAuthCoreTableInput | undefined;
33
+ /** The verification table. */
34
+ verification?: BetterAuthCoreTableInput | undefined;
35
+ /**
36
+ * Which Better Auth plugins are registered, and their schema-affecting
37
+ * options. `true` takes a plugin's default schema.
38
+ */
39
+ plugins?: BetterAuthPluginDescriptors | undefined;
40
+ /**
41
+ * Schemas of plugins `@vexcms/better-auth` does not model — read `schema`
42
+ * off the real plugin instance on your server and pass the value here.
43
+ */
44
+ extraSchema?: PluginDBSchema | PluginDBSchema[] | undefined;
45
+ }
46
+ /**
47
+ * Builds the Vex auth collections a Better Auth setup implies, without
48
+ * instantiating a single Better Auth plugin.
49
+ *
50
+ * Runs Better Auth's own `getAuthTables` over plain `{ id, schema }` plugin
51
+ * stubs resolved from this package's generated schema snapshot, then converts
52
+ * the result with the same pipeline `betterAuthAdapter` uses on the server —
53
+ * so the collections are identical to the live adapter's by construction, and
54
+ * `packages/better-auth/src/pluginSchemas.test.ts` asserts exactly that.
55
+ *
56
+ * Safe to call from `vex.config.ts`: the whole graph is `@vexcms/core` plus
57
+ * `better-auth/db` (~1 KB gzipped). Instantiating real plugin factories here
58
+ * instead would add ~154 KB gzipped to the admin bundle.
59
+ *
60
+ * @param schema - The client-safe description of your Better Auth setup.
61
+ * @returns The auth collections, ready for `defineConfig({ authCollections })`.
62
+ * @throws {Error} When `plugins` names a plugin whose schema is not modelled — use `extraSchema`.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * // src/auth/schema.ts — no server imports, safe in the browser bundle
67
+ * export const authSchema = {
68
+ * user: { modelName: "user", additionalFields: { roles: { type: "string[]", required: true } } },
69
+ * plugins: { admin: true, anonymous: true, organization: { teams: true }, convex: true },
70
+ * } satisfies BetterAuthSchemaInput;
71
+ *
72
+ * // src/vex.config.ts
73
+ * export default defineConfig({ authCollections: betterAuthCollections(authSchema) });
74
+ *
75
+ * // src/auth/options.ts — one source of truth for model names and fields
76
+ * const { plugins: _descriptors, ...schemaOptions } = authSchema;
77
+ * export const authOptions: BetterAuthOptions = {
78
+ * ...schemaOptions,
79
+ * secret: process.env.BETTER_AUTH_SECRET,
80
+ * plugins: createPlugins(),
81
+ * };
82
+ * ```
83
+ *
84
+ * @see {@link BetterAuthSchemaInput} for the input shape
85
+ * @see {@link betterAuthAdapter} for the server-side adapter that verifies this result
86
+ */
87
+ export declare function betterAuthCollections(schema?: BetterAuthSchemaInput): AuthCollectionConfig[];
88
+ //# sourceMappingURL=collections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAqB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,KAAK,EACV,2BAA2B,EAC3B,cAAc,EACf,MAAM,iBAAiB,CAAC;AAGzB,2EAA2E;AAC3E,MAAM,WAAW,wBAAwB;IACvC,mGAAmG;IACnG,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAC5C,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,SAAS,CAAC;CACjE;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,qBAAqB;IACpC,sBAAsB;IACtB,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;IAC5C,yBAAyB;IACzB,OAAO,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;IAC/C,yBAAyB;IACzB,OAAO,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;IAC/C,8BAA8B;IAC9B,YAAY,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;IACpD;;;OAGG;IACH,OAAO,CAAC,EAAE,2BAA2B,GAAG,SAAS,CAAC;IAClD;;;OAGG;IACH,WAAW,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,GAAG,SAAS,CAAC;CAC7D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,qBAA0B,GACjC,oBAAoB,EAAE,CAOxB"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Builds a `databaseHooks.user.create.before` hook that stamps a distinct
3
+ * role onto every user the Better Auth `anonymous()` plugin creates — lining
4
+ * up `defineAccess({ anonRole })` with a real, inspectable role instead of
5
+ * relying solely on the "roles resolved empty" fallback.
6
+ *
7
+ * Without this, an anonymous-plugin user still goes through the same
8
+ * `additionalFields` default-fill as every other new user (better-auth's
9
+ * adapter factory applies `roles`' configured `defaultValue` to any field the
10
+ * creating call omits), so it silently ends up with the SAME role as a
11
+ * regular signed-up account rather than a distinct anon one — and
12
+ * `hasPermission`'s empty-roles → `anonRole` fallback never fires for it,
13
+ * because its `roles` array is never actually empty.
14
+ *
15
+ * This hook runs before that default-fill (`databaseHooks` `create.before`
16
+ * wins over field defaults) and only touches documents the anonymous plugin
17
+ * created (`user.isAnonymous === true`); every other creation path is left
18
+ * untouched.
19
+ *
20
+ * @param role - The role string to assign. Pass the same value given to
21
+ * `defineAccess({ anonRole })` so the two stay in lockstep by construction.
22
+ * @returns A `databaseHooks.user` value — spread into `authOptions.databaseHooks.user`,
23
+ * or pass directly as `databaseHooks: { user: anonRoleDatabaseHook(role) }` when
24
+ * no other user hooks are configured.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { anonRoleDatabaseHook } from "@vexcms/better-auth";
29
+ *
30
+ * export const authOptions: BetterAuthOptions = {
31
+ * // ...
32
+ * databaseHooks: {
33
+ * user: anonRoleDatabaseHook(USER_ROLES.anon),
34
+ * },
35
+ * };
36
+ * ```
37
+ */
38
+ export declare function anonRoleDatabaseHook(role: string): {
39
+ create: {
40
+ before: (user: Record<string, unknown>) => Promise<{
41
+ data: Record<string, unknown>;
42
+ }>;
43
+ };
44
+ };
45
+ //# sourceMappingURL=anonRole.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anonRole.d.ts","sourceRoot":"","sources":["../../src/convex/anonRole.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG;IAClD,MAAM,EAAE;QACN,MAAM,EAAE,CACN,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,CAAC,CAAC;KACjD,CAAC;CACH,CAQA"}
@@ -9,18 +9,21 @@ import type { CollectionSlug, VexApiAuth } from "@vexcms/core";
9
9
  * `identity.sessionId` (appended to every token by the plugin) → session
10
10
  * document → `session.activeOrganizationId` → organization document.
11
11
  * Documents are read fresh on every request, so role changes and
12
- * `identity.sessionId` (appended to every token by the plugin) → session
13
- * document → `session.activeOrganizationId` → organization document.
14
- * Documents are read fresh on every request, so role changes and
15
12
  * org switches apply immediately — claims are only used as ids, never
16
13
  * as authorization data.
17
14
  *
15
+ * `orgCollectionSlug` is only required when `resolveOrgs` is true — a
16
+ * project with organizations disabled can omit it entirely. Passing
17
+ * `resolveOrgs: true` without an `orgCollectionSlug` skips org resolution
18
+ * (same as `resolveOrgs: false`) rather than throwing, since the omission
19
+ * is a config mistake, not a request-time error worth failing loudly for.
20
+ *
18
21
  * @returns { user, organization }, @see {@link VexApiAuth}
19
22
  *
20
23
  */
21
24
  export declare function createGetAuth<TCollectionSlug extends CollectionSlug = CollectionSlug>(props: {
22
25
  userCollectionSlug: TCollectionSlug;
23
- orgCollectionSlug: TCollectionSlug;
26
+ orgCollectionSlug?: TCollectionSlug;
24
27
  sessionCollectionSlug: TCollectionSlug;
25
28
  resolveOrgs?: boolean;
26
29
  }): <DataModel extends GenericDataModel>(ctx: GenericQueryCtx<DataModel> | GenericMutationCtx<DataModel>) => Promise<VexApiAuth>;
@@ -1 +1 @@
1
- {"version":3,"file":"getAuth.d.ts","sourceRoot":"","sources":["../../src/convex/getAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE3F,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,eAAe,SAAS,cAAc,GAAG,cAAc,EAAE,KAAK,EAAE;IAC5F,kBAAkB,EAAE,eAAe,CAAC;IACpC,iBAAiB,EAAE,eAAe,CAAC;IACnC,qBAAqB,EAAE,eAAe,CAAC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,IACe,SAAS,SAAS,gBAAgB,EAC9C,KAAK,eAAe,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAC,SAAS,CAAC,KAC9D,OAAO,CAAC,UAAU,CAAC,CA0BvB"}
1
+ {"version":3,"file":"getAuth.d.ts","sourceRoot":"","sources":["../../src/convex/getAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE3F,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,eAAe,SAAS,cAAc,GAAG,cAAc,EAAE,KAAK,EAAE;IAC5F,kBAAkB,EAAE,eAAe,CAAC;IACpC,iBAAiB,CAAC,EAAE,eAAe,CAAC;IACpC,qBAAqB,EAAE,eAAe,CAAC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,IACe,SAAS,SAAS,gBAAgB,EAC9C,KAAK,eAAe,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAC,SAAS,CAAC,KAC9D,OAAO,CAAC,UAAU,CAAC,CA2BvB"}
@@ -41,8 +41,8 @@ export type AuthDbApiOptions<DataModel extends GenericDataModel> = {
41
41
  export declare function authDbApi<DataModel extends GenericDataModel>(options: AuthDbApiOptions<DataModel>): {
42
42
  dbCreate: import("convex/server").RegisteredMutation<"internal", {
43
43
  select?: string[] | undefined;
44
- data: any;
45
44
  model: string;
45
+ data: any;
46
46
  betterAuthSchema: string;
47
47
  }, Promise<import("convex/server").GenericDocument | null>>;
48
48
  dbFindOne: import("convex/server").RegisteredQuery<"internal", {
@@ -67,16 +67,16 @@ export declare function authDbApi<DataModel extends GenericDataModel>(options: A
67
67
  betterAuthSchema: string;
68
68
  }, Promise<number>>;
69
69
  dbUpdate: import("convex/server").RegisteredMutation<"internal", {
70
+ update: any;
70
71
  model: string;
71
72
  betterAuthSchema: string;
72
73
  where: any[];
73
- update: any;
74
74
  }, Promise<import("convex/server").GenericDocument | null>>;
75
75
  dbUpdateMany: import("convex/server").RegisteredMutation<"internal", {
76
+ update: any;
76
77
  model: string;
77
78
  betterAuthSchema: string;
78
79
  where: any[];
79
- update: any;
80
80
  }, Promise<number>>;
81
81
  dbDelete: import("convex/server").RegisteredMutation<"internal", {
82
82
  model: string;
@@ -114,4 +114,5 @@ export declare function createBetterAuthAdapter<DataModel extends GenericDataMod
114
114
  export { convexAdapter } from "./adapter";
115
115
  export * from "./types";
116
116
  export * from "./getAuth";
117
+ export * from "./anonRole";
117
118
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/convex/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAGhB,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAIvB;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,SAAS,SAAS,gBAAgB,IAAI;IACjE,0DAA0D;IAC1D,MAAM,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnC,qEAAqE;IACrE,gBAAgB,EAAE,eAAe,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACzD,kEAAkE;IAClE,aAAa,EAAE,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,SAAS,SAAS,gBAAgB,EAC1D,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmFrC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,SAAS,gBAAgB,EACxE,GAAG,EAAE,gBAAgB,CAAC,SAAS,CAAC,0FAGjC;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/convex/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAGhB,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAIvB;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,SAAS,SAAS,gBAAgB,IAAI;IACjE,0DAA0D;IAC1D,MAAM,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnC,qEAAqE;IACrE,gBAAgB,EAAE,eAAe,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACzD,kEAAkE;IAClE,aAAa,EAAE,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,SAAS,SAAS,gBAAgB,EAC1D,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmFrC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,SAAS,gBAAgB,EACxE,GAAG,EAAE,gBAAgB,CAAC,SAAS,CAAC,0FAGjC;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,20 +1,34 @@
1
1
  /**
2
- * @vexcms/better-auth package entry point.
2
+ * Entry point for the `@vexcms/better-auth` package.
3
3
  *
4
- * Integrates [Better Auth](https://better-auth.com/) with VexCMS as the auth backend.
5
- * Call `betterAuthAdapter()` in `vex.config.ts` to register Better Auth collections
6
- * as VexCMS collections. Use `authDbApi()` and `createBetterAuthAdapter()` in your
7
- * Convex schema to wire the DB adapter.
4
+ * Integrates [Better Auth](https://better-auth.com/) with VexCMS as the auth backend. This is
5
+ * the **server-only** half of the package — it re-exports `betterAuthAdapter()`, which closes
6
+ * over your real Better Auth options (plugin factories, secrets), and Convex DB-adapter wiring.
7
+ * Never import this entry point from client code; the browser imports
8
+ * `@vexcms/better-auth/client` instead, which derives the same collections from a plain-data
9
+ * schema description with no plugin factories or environment reads.
10
+ *
11
+ * Call `betterAuthAdapter()` in `vex.config.server.ts` to register Better Auth collections
12
+ * as VexCMS collections — `defineServerConfig()` also uses its `collections` to verify the
13
+ * `authCollections` the client config declared still match, throwing `VexAuthConfigError` on
14
+ * drift. Use `authDbApi()` and `createBetterAuthAdapter()` in your Convex schema to wire the
15
+ * DB adapter.
8
16
  *
9
17
  * @example
10
18
  * ```ts
11
- * // vex.config.ts
19
+ * // vex.config.server.ts
12
20
  * import { betterAuthAdapter } from "@vexcms/better-auth";
21
+ * import { defineServerConfig } from "@vexcms/core";
22
+ *
13
23
  * import { authOptions } from "~/auth/options";
14
24
  *
15
- * export default defineConfig({
16
- * auth: betterAuthAdapter({ config: authOptions }),
17
- * collections: [posts],
25
+ * import vexConfig from "./vex.config";
26
+ *
27
+ * export default defineServerConfig({
28
+ * config: vexConfig,
29
+ * server: {
30
+ * auth: { adapter: betterAuthAdapter({ config: authOptions }) },
31
+ * },
18
32
  * });
19
33
  * ```
20
34
  *
@@ -39,7 +53,8 @@
39
53
  *
40
54
  * @see {@link betterAuthAdapter} for the main Vex auth adapter function
41
55
  * @see {@link authDbApi} for wiring the Convex DB operations
56
+ * @see {@link better-auth/src!betterAuthCollections} for the client-safe half, from `@vexcms/better-auth/client`
42
57
  */
43
58
  export { betterAuthAdapter, type BetterAuthAdapterOptions } from "./adapter";
44
- export { authDbApi, createBetterAuthAdapter, convexAdapter, createGetAuth, type CreateBetterAuthAdapterArgs, type CreateBetterAuthAdapterResult, } from "./convex";
59
+ export { authDbApi, createBetterAuthAdapter, convexAdapter, createGetAuth, anonRoleDatabaseHook, type CreateBetterAuthAdapterArgs, type CreateBetterAuthAdapterResult, } from "./convex";
45
60
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EACL,SAAS,EACT,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,KAAK,2BAA2B,EAChC,KAAK,6BAA6B,GACnC,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EACL,SAAS,EACT,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,KAAK,2BAA2B,EAChC,KAAK,6BAA6B,GACnC,MAAM,UAAU,CAAC"}