@vexcms/better-auth 0.1.0-alpha.17 → 0.1.0-alpha.19
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.
- package/README.md +147 -40
- package/dist/adapter.d.ts +17 -5
- package/dist/adapter.d.ts.map +1 -1
- package/dist/chunk-YPIEILO5.js +196 -0
- package/dist/chunk-YPIEILO5.js.map +1 -0
- package/dist/client.d.ts +24 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +997 -0
- package/dist/client.js.map +1 -0
- package/dist/collections.d.ts +88 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/convex/index.d.ts +1 -1
- package/dist/index.d.ts +23 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -203
- package/dist/index.js.map +1 -1
- package/dist/pluginSchemas.d.ts +159 -0
- package/dist/pluginSchemas.d.ts.map +1 -0
- package/dist/pluginSchemas.generated.d.ts +4 -0
- package/dist/pluginSchemas.generated.d.ts.map +1 -0
- package/package.json +12 -4
|
@@ -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,a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S,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"}
|
package/dist/convex/index.d.ts
CHANGED
|
@@ -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", {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
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
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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,6 +53,7 @@
|
|
|
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
59
|
export { authDbApi, createBetterAuthAdapter, convexAdapter, createGetAuth, anonRoleDatabaseHook, type CreateBetterAuthAdapterArgs, type CreateBetterAuthAdapterResult, } from "./convex";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -1,201 +1,13 @@
|
|
|
1
|
-
// src/adapter.ts
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
date,
|
|
6
|
-
defineCollection,
|
|
7
|
-
number,
|
|
8
|
-
select,
|
|
9
|
-
text
|
|
10
|
-
} from "@vexcms/core";
|
|
11
|
-
import { getAuthTables } from "better-auth/db";
|
|
12
|
-
var AUTH_COLLECTION_TYPES = {
|
|
13
|
-
user: "user",
|
|
14
|
-
session: "session",
|
|
15
|
-
account: "account",
|
|
16
|
-
verification: "verification"
|
|
17
|
-
};
|
|
18
|
-
var EDITABLE_FIELDS = /* @__PURE__ */ new Set([
|
|
19
|
-
"name",
|
|
20
|
-
"email",
|
|
21
|
-
"image",
|
|
22
|
-
"role",
|
|
23
|
-
"banned",
|
|
24
|
-
"banReason",
|
|
25
|
-
"banExpires"
|
|
26
|
-
]);
|
|
27
|
-
var HIDDEN_FIELDS = /* @__PURE__ */ new Set([
|
|
28
|
-
"hashedPassword",
|
|
29
|
-
"password",
|
|
30
|
-
"twoFactorSecret",
|
|
31
|
-
"twoFactorBackupCodes",
|
|
32
|
-
"token",
|
|
33
|
-
"secret",
|
|
34
|
-
"code"
|
|
35
|
-
]);
|
|
36
|
-
function betterAuthAdapter(props) {
|
|
37
|
-
const tables = getAuthTables(props?.config ?? {});
|
|
38
|
-
const collections = [];
|
|
39
|
-
const authCollections = [
|
|
40
|
-
{ type: AUTH_COLLECTION_TYPES.user, slug: props?.config?.user?.modelName },
|
|
41
|
-
{
|
|
42
|
-
type: AUTH_COLLECTION_TYPES.session,
|
|
43
|
-
slug: props?.config?.session?.modelName
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
type: AUTH_COLLECTION_TYPES.account,
|
|
47
|
-
slug: props?.config?.account?.modelName
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
type: AUTH_COLLECTION_TYPES.verification,
|
|
51
|
-
slug: props?.config?.verification?.modelName
|
|
52
|
-
}
|
|
53
|
-
];
|
|
54
|
-
for (const [tableKey, tableDef] of Object.entries(tables)) {
|
|
55
|
-
const slug = tableDef.modelName ?? tableKey;
|
|
56
|
-
const fields = {};
|
|
57
|
-
addAuthCollectionFields({
|
|
58
|
-
attributes: tableDef.fields,
|
|
59
|
-
slug,
|
|
60
|
-
fields,
|
|
61
|
-
config: props?.config,
|
|
62
|
-
extractId: true
|
|
63
|
-
});
|
|
64
|
-
const authCollectionType = authCollections.find((ac) => ac.slug === slug)?.type;
|
|
65
|
-
if (authCollectionType) {
|
|
66
|
-
switch (authCollectionType) {
|
|
67
|
-
case "user": {
|
|
68
|
-
const additionalFields = props?.config?.user?.additionalFields;
|
|
69
|
-
addAuthCollectionFields({
|
|
70
|
-
attributes: additionalFields,
|
|
71
|
-
slug,
|
|
72
|
-
fields,
|
|
73
|
-
config: props?.config
|
|
74
|
-
});
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case "session": {
|
|
78
|
-
const additionalFields = props?.config?.session?.additionalFields;
|
|
79
|
-
addAuthCollectionFields({
|
|
80
|
-
attributes: additionalFields,
|
|
81
|
-
slug,
|
|
82
|
-
fields,
|
|
83
|
-
config: props?.config
|
|
84
|
-
});
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case "account": {
|
|
88
|
-
const additionalFields = props?.config?.account?.additionalFields;
|
|
89
|
-
addAuthCollectionFields({
|
|
90
|
-
attributes: additionalFields,
|
|
91
|
-
slug,
|
|
92
|
-
fields,
|
|
93
|
-
config: props?.config
|
|
94
|
-
});
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
case "verification": {
|
|
98
|
-
const additionalFields = props?.config?.verification?.additionalFields;
|
|
99
|
-
addAuthCollectionFields({
|
|
100
|
-
attributes: additionalFields,
|
|
101
|
-
slug,
|
|
102
|
-
fields,
|
|
103
|
-
config: props?.config
|
|
104
|
-
});
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
default:
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const isProtected = slug !== "user" && slug !== "users";
|
|
112
|
-
collections.push(
|
|
113
|
-
defineCollection({
|
|
114
|
-
slug,
|
|
115
|
-
fields,
|
|
116
|
-
admin: {
|
|
117
|
-
icon: "Lock"
|
|
118
|
-
},
|
|
119
|
-
meta: isProtected ? { protected: true } : void 0
|
|
120
|
-
})
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
const userSlug = tables.user?.modelName ?? "user";
|
|
124
|
-
return {
|
|
125
|
-
name: "better-auth",
|
|
126
|
-
collections,
|
|
127
|
-
userCollection: userSlug
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function addAuthCollectionFields(props) {
|
|
131
|
-
if (!props.attributes) return;
|
|
132
|
-
for (const [fieldName, attr] of Object.entries(props.attributes)) {
|
|
133
|
-
if (props.extractId === true && fieldName === "id") continue;
|
|
134
|
-
const field = betterAuthAttrToVexField(fieldName, attr, props.slug, props?.config);
|
|
135
|
-
if (field) props.fields[fieldName] = field;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function betterAuthAttrToVexField(fieldName, attr, tableSlug, authOptions) {
|
|
139
|
-
if (fieldName === "id") return null;
|
|
140
|
-
const isUserTable = tableSlug === authOptions?.user?.modelName || tableSlug === "user" || tableSlug === "users";
|
|
141
|
-
const isEditable = isUserTable && EDITABLE_FIELDS.has(fieldName);
|
|
142
|
-
const isHidden = HIDDEN_FIELDS.has(fieldName);
|
|
143
|
-
const admin = {};
|
|
144
|
-
if (!isEditable) admin.readOnly = true;
|
|
145
|
-
if (isHidden) admin.hidden = true;
|
|
146
|
-
const baseOptions = {
|
|
147
|
-
defaultValue: void 0
|
|
148
|
-
};
|
|
149
|
-
if (Object.keys(admin).length > 0) baseOptions.admin = admin;
|
|
150
|
-
if (!isEditable) baseOptions.meta = { locked: true };
|
|
151
|
-
if (attr.required) baseOptions.required = attr.required;
|
|
152
|
-
if (attr.defaultValue !== void 0 && typeof attr.defaultValue !== "function") {
|
|
153
|
-
baseOptions.defaultValue = attr.defaultValue;
|
|
154
|
-
}
|
|
155
|
-
if (attr.unique || attr.index) {
|
|
156
|
-
baseOptions.index = `by_${fieldName}`;
|
|
157
|
-
}
|
|
158
|
-
if (attr.references) {
|
|
159
|
-
return text(baseOptions);
|
|
160
|
-
}
|
|
161
|
-
if (Array.isArray(attr.type)) {
|
|
162
|
-
return select({
|
|
163
|
-
options: attr.type.map((v2) => ({ value: v2, label: v2 })),
|
|
164
|
-
...baseOptions
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
switch (attr.type) {
|
|
168
|
-
case "string":
|
|
169
|
-
return text(baseOptions);
|
|
170
|
-
case "string[]":
|
|
171
|
-
return array({
|
|
172
|
-
...baseOptions,
|
|
173
|
-
items: text(baseOptions)
|
|
174
|
-
});
|
|
175
|
-
case "boolean":
|
|
176
|
-
return checkbox(baseOptions);
|
|
177
|
-
case "number":
|
|
178
|
-
return number(baseOptions);
|
|
179
|
-
case "number[]":
|
|
180
|
-
return array({
|
|
181
|
-
...baseOptions,
|
|
182
|
-
items: number(baseOptions)
|
|
183
|
-
});
|
|
184
|
-
case "date":
|
|
185
|
-
return date(baseOptions);
|
|
186
|
-
case "json":
|
|
187
|
-
return text(baseOptions);
|
|
188
|
-
default:
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
2
|
+
betterAuthAdapter
|
|
3
|
+
} from "./chunk-YPIEILO5.js";
|
|
192
4
|
|
|
193
5
|
// src/convex/adapter.ts
|
|
194
6
|
import { anyApi } from "convex/server";
|
|
195
7
|
import {
|
|
196
8
|
createAdapterFactory
|
|
197
9
|
} from "better-auth/adapters";
|
|
198
|
-
import { getAuthTables
|
|
10
|
+
import { getAuthTables } from "better-auth/db";
|
|
199
11
|
var parseWhere = (where) => {
|
|
200
12
|
return where?.map((where2) => {
|
|
201
13
|
if (where2.value instanceof Date) {
|
|
@@ -208,25 +20,25 @@ function convexAdapter(ctx, config = {}) {
|
|
|
208
20
|
return createAdapterFactory({
|
|
209
21
|
adapter: ({ options }) => {
|
|
210
22
|
options.telemetry = { enabled: false };
|
|
211
|
-
const betterAuthSchema =
|
|
23
|
+
const betterAuthSchema = getAuthTables(options);
|
|
212
24
|
const betterAuthSchemaJson = JSON.stringify(betterAuthSchema);
|
|
213
25
|
return {
|
|
214
26
|
id: "convex",
|
|
215
27
|
options: { isRunMutationCtx: "runMutation" in ctx },
|
|
216
28
|
// Use anyApi to reference db operations, call via ctx.runMutation/ctx.runQuery
|
|
217
|
-
create: async ({ data, model, select
|
|
29
|
+
create: async ({ data, model, select }) => {
|
|
218
30
|
return await ctx.runMutation(anyApi.auth.db.dbCreate, {
|
|
219
31
|
betterAuthSchema: betterAuthSchemaJson,
|
|
220
32
|
data,
|
|
221
33
|
model,
|
|
222
|
-
select
|
|
34
|
+
select
|
|
223
35
|
});
|
|
224
36
|
},
|
|
225
|
-
findOne: async ({ model, select
|
|
37
|
+
findOne: async ({ model, select, where }) => {
|
|
226
38
|
return await ctx.runQuery(anyApi.auth.db.dbFindOne, {
|
|
227
39
|
betterAuthSchema: betterAuthSchemaJson,
|
|
228
40
|
model,
|
|
229
|
-
select
|
|
41
|
+
select,
|
|
230
42
|
where: parseWhere(where)
|
|
231
43
|
});
|
|
232
44
|
},
|
|
@@ -1687,14 +1499,14 @@ var checkUniqueFields = async (ctx, schema, betterAuthSchema, table, input, doc)
|
|
|
1687
1499
|
}
|
|
1688
1500
|
}
|
|
1689
1501
|
};
|
|
1690
|
-
var selectFields = (doc,
|
|
1502
|
+
var selectFields = (doc, select) => {
|
|
1691
1503
|
if (!doc) {
|
|
1692
1504
|
return null;
|
|
1693
1505
|
}
|
|
1694
|
-
if (!
|
|
1506
|
+
if (!select?.length) {
|
|
1695
1507
|
return doc;
|
|
1696
1508
|
}
|
|
1697
|
-
return
|
|
1509
|
+
return select.reduce((acc, field) => {
|
|
1698
1510
|
acc[field] = doc[field];
|
|
1699
1511
|
return acc;
|
|
1700
1512
|
}, {});
|
|
@@ -1956,7 +1768,7 @@ var create = {
|
|
|
1956
1768
|
model: v.string(),
|
|
1957
1769
|
select: v.optional(v.array(v.string()))
|
|
1958
1770
|
},
|
|
1959
|
-
handler: async (ctx, { betterAuthSchema, data, model, select
|
|
1771
|
+
handler: async (ctx, { betterAuthSchema, data, model, select }, schema) => {
|
|
1960
1772
|
const authSchema = getBetterAuthSchema(betterAuthSchema);
|
|
1961
1773
|
await checkUniqueFields(ctx, schema, authSchema, model, data);
|
|
1962
1774
|
const id = await ctx.db.insert(model, data);
|
|
@@ -1964,7 +1776,7 @@ var create = {
|
|
|
1964
1776
|
if (!doc) {
|
|
1965
1777
|
throw new Error(`Failed to create ${model}`);
|
|
1966
1778
|
}
|
|
1967
|
-
return selectFields(doc,
|
|
1779
|
+
return selectFields(doc, select);
|
|
1968
1780
|
}
|
|
1969
1781
|
};
|
|
1970
1782
|
var findOne = {
|
|
@@ -1974,11 +1786,11 @@ var findOne = {
|
|
|
1974
1786
|
select: v.optional(v.array(v.string())),
|
|
1975
1787
|
where: v.array(v.any())
|
|
1976
1788
|
},
|
|
1977
|
-
handler: async (ctx, { betterAuthSchema, model, select
|
|
1789
|
+
handler: async (ctx, { betterAuthSchema, model, select, where }, schema) => {
|
|
1978
1790
|
const authSchema = getBetterAuthSchema(betterAuthSchema);
|
|
1979
1791
|
const result = await listOne(ctx, schema, authSchema, {
|
|
1980
1792
|
model,
|
|
1981
|
-
select
|
|
1793
|
+
select,
|
|
1982
1794
|
where
|
|
1983
1795
|
});
|
|
1984
1796
|
return result;
|