better-auth 0.0.4 β†’ 0.0.6

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/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli/index.ts","../src/cli/commands/migrate.ts","../src/cli/get-config.ts","../src/utils/logger.ts","../src/adapters/kysely.ts","../src/adapters/get-tables.ts","../src/cli/utils/get-schema.ts","../src/cli/utils/get-migration.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport \"dotenv/config\";\nimport { migrate } from \"./commands/migrate\";\nasync function main() {\n\tconst program = new Command().name(\"better-auth\");\n\tprogram.addCommand(migrate);\n\tprogram.parse();\n}\n\nmain();\n","import { Command } from \"commander\";\nimport { getConfig } from \"../get-config\";\nimport { z } from \"zod\";\nimport { existsSync } from \"fs\";\nimport path from \"path\";\nimport { logger } from \"../../utils/logger\";\nimport { createKyselyAdapter } from \"../../adapters/kysely\";\nimport ora from \"ora\";\nimport chalk from \"chalk\";\nimport prompts from \"prompts\";\nimport { getMigrations } from \"../utils/get-migration\";\n\nexport const migrate = new Command(\"migrate\")\n\t.option(\n\t\t\"-c, --cwd <cwd>\",\n\t\t\"the working directory. defaults to the current directory.\",\n\t\tprocess.cwd(),\n\t)\n\t.option(\n\t\t\"--config <config>\",\n\t\t\"the path to the configuration file. defaults to the first configuration file found.\",\n\t)\n\t.action(async (opts) => {\n\t\tconst options = z\n\t\t\t.object({\n\t\t\t\tcwd: z.string(),\n\t\t\t\tconfig: z.string().optional(),\n\t\t\t})\n\t\t\t.parse(opts);\n\t\tconst cwd = path.resolve(options.cwd);\n\t\tif (!existsSync(cwd)) {\n\t\t\tlogger.error(`The directory \"${cwd}\" does not exist.`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst config = await getConfig({\n\t\t\tcwd,\n\t\t\tconfigPath: options.config,\n\t\t});\n\t\tif (!config) {\n\t\t\tlogger.error(\"No configuration file found.\");\n\t\t\treturn;\n\t\t}\n\t\tconst db = createKyselyAdapter(config);\n\t\tif (!db) {\n\t\t\tlogger.error(\"Invalid database configuration.\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst spinner = ora(\"preparing migration...\").start();\n\n\t\tconst { toBeAdded, toBeCreated, runMigrations } =\n\t\t\tawait getMigrations(config);\n\n\t\tif (!toBeAdded.length && !toBeCreated.length) {\n\t\t\tspinner.stop();\n\t\t\tlogger.success(\"πŸš€ No migrations needed.\");\n\t\t\tprocess.exit(0);\n\t\t}\n\n\t\tspinner.stop();\n\t\tlogger.info(`πŸ”‘ The migration will affect the following:`);\n\n\t\tfor (const table of [...toBeAdded, ...toBeCreated]) {\n\t\t\tlogger.info(\n\t\t\t\t\"->\",\n\t\t\t\tchalk.magenta(Object.keys(table.fields).join(\", \")),\n\t\t\t\tchalk.white(\"fields on\"),\n\t\t\t\tchalk.yellow(`${table.table}`),\n\t\t\t\tchalk.white(\"table.\"),\n\t\t\t);\n\t\t}\n\t\tconst { migrate } = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"migrate\",\n\t\t\tmessage: \"Are you sure you want to run these migrations?\",\n\t\t\tinitial: false,\n\t\t});\n\t\tif (!migrate) {\n\t\t\tlogger.info(\"Migration cancelled.\");\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tspinner?.start(\"migrating...\");\n\t\tawait runMigrations();\n\t\tspinner.stop();\n\t\tlogger.success(\"πŸš€ migration was completed successfully!\");\n\t\tprocess.exit(0);\n\t});\n","import path from \"node:path\";\nimport jiti from \"jiti\";\nimport type { BetterAuthOptions } from \"../types\";\nimport { logger } from \"../utils/logger\";\n\nlet possiblePaths = [\"auth.ts\", \"auth.config.ts\"];\n\npossiblePaths = [\n\t...possiblePaths,\n\t...possiblePaths.map((it) => `lib/${it}`),\n\t...possiblePaths.map((it) => `utils/${it}`),\n];\npossiblePaths = [...possiblePaths, ...possiblePaths.map((it) => `src/${it}`)];\n\nexport async function getConfig({\n\tcwd,\n\tconfigPath,\n}: {\n\tcwd: string;\n\tconfigPath?: string;\n}) {\n\ttry {\n\t\tlet configFile: BetterAuthOptions | null = null;\n\t\tif (configPath) {\n\t\t\tconst config = (await jiti(cwd).import(\n\t\t\t\tpath.join(cwd, configPath),\n\t\t\t\t{},\n\t\t\t)) as {\n\t\t\t\tauth: {\n\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t};\n\t\t\t};\n\t\t\tif (!config) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconfigFile = config.auth.options;\n\t\t}\n\n\t\tfor (const possiblePath of possiblePaths) {\n\t\t\ttry {\n\t\t\t\tconst config = (await jiti(path.join(cwd, possiblePath)).import(\n\t\t\t\t\tpath.join(cwd, possiblePath),\n\t\t\t\t\t{},\n\t\t\t\t)) as {\n\t\t\t\t\tauth?: {\n\t\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t\t};\n\t\t\t\t\tdefault?: {\n\t\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t\tif (config) {\n\t\t\t\t\tconfigFile = config.auth?.options || config.default?.options || null;\n\t\t\t\t\tif (!configFile) {\n\t\t\t\t\t\tlogger.error(\"[#better-auth]: Couldn't read your auth config.\");\n\t\t\t\t\t\tlogger.break();\n\t\t\t\t\t\tlogger.info(\n\t\t\t\t\t\t\t\"[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tprocess.exit(1);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (!(e instanceof Error && e.message.includes(\"Cannot find module\"))) {\n\t\t\t\t\tlogger.error(e);\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn configFile;\n\t} catch (e) {\n\t\treturn null;\n\t}\n}\n\nexport { possiblePaths };\n","import { createConsola } from \"consola\";\n\nconst consola = createConsola({\n\tformatOptions: {\n\t\tdate: false,\n\t},\n});\n\nexport const createLogger = (options?: {\n\tdisabled?: boolean;\n}) => {\n\treturn {\n\t\tlog: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.log(\"\", ...args);\n\t\t},\n\t\terror: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.error(\"\", ...args);\n\t\t},\n\t\twarn: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.warn(\"\", ...args);\n\t\t},\n\t\tinfo: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.info(\"\", ...args);\n\t\t},\n\t\tdebug: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.debug(\"\", ...args);\n\t\t},\n\t\tbox: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.box(\"\", ...args);\n\t\t},\n\t\tsuccess: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.success(\"\", ...args);\n\t\t},\n\t\tbreak: (...args: any[]) => {\n\t\t\t!options?.disabled && console.log(\"\\n\");\n\t\t},\n\t};\n};\n\nexport const logger = createLogger();\n","import Database from \"better-sqlite3\";\nimport { Kysely } from \"kysely\";\nimport {\n\ttype Dialect,\n\tMysqlDialect,\n\tPostgresDialect,\n\tSqliteDialect,\n} from \"kysely\";\nimport { createPool } from \"mysql2\";\nimport pg from \"pg\";\nimport type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\nimport type { Adapter, Where } from \"../types/adapter\";\n\nconst { Pool } = pg;\n\nfunction convertWhere(w?: Where[]) {\n\tif (!w)\n\t\treturn {\n\t\t\tand: null,\n\t\t\tor: null,\n\t\t};\n\tconst and = w\n\t\t?.filter((w) => w.connector === \"AND\" || !w.connector)\n\t\t.reduce(\n\t\t\t(acc, w) =>\n\t\t\t\t({\n\t\t\t\t\t...acc,\n\t\t\t\t\t[w.field]: w.value,\n\t\t\t\t}) as any,\n\t\t\t{},\n\t\t);\n\tconst or = w\n\t\t?.filter((w) => w.connector === \"OR\")\n\t\t.reduce(\n\t\t\t(acc, w) =>\n\t\t\t\t({\n\t\t\t\t\t...acc,\n\t\t\t\t\t[w.field]: w.value,\n\t\t\t\t}) as any,\n\t\t\t{},\n\t\t);\n\treturn {\n\t\tand: Object.keys(and).length ? and : null,\n\t\tor: Object.keys(or).length ? or : null,\n\t};\n}\n\nfunction transformTo(\n\tval: any,\n\tfields: Record<string, FieldAttribute>,\n\ttransform: KyselyAdapterConfig[\"transform\"],\n) {\n\tfor (const key in val) {\n\t\tif (\n\t\t\tval[key] === 0 &&\n\t\t\tfields[key]?.type === \"boolean\" &&\n\t\t\ttransform?.boolean\n\t\t) {\n\t\t\tval[key] = false;\n\t\t}\n\t\tif (\n\t\t\tval[key] === 1 &&\n\t\t\tfields[key]?.type === \"boolean\" &&\n\t\t\ttransform?.boolean\n\t\t) {\n\t\t\tval[key] = true;\n\t\t}\n\t\tif (fields[key]?.type === \"date\") {\n\t\t\tif (!(val[key] instanceof Date)) {\n\t\t\t\tval[key] = new Date(val[key]);\n\t\t\t}\n\t\t}\n\t}\n\treturn val;\n}\n\nfunction transformFrom(val: any, transform: KyselyAdapterConfig[\"transform\"]) {\n\tfor (const key in val) {\n\t\tif (typeof val[key] === \"boolean\" && transform?.boolean) {\n\t\t\tval[key] = val[key] ? 1 : 0;\n\t\t}\n\t\tif (val[key] instanceof Date) {\n\t\t\tval[key] = val[key].toISOString();\n\t\t}\n\t}\n\treturn val;\n}\n\nexport interface KyselyAdapterConfig {\n\t/**\n\t * Transform dates and booleans for sqlite.\n\t */\n\ttransform?: {\n\t\tschema: {\n\t\t\t[table: string]: Record<string, FieldAttribute>;\n\t\t};\n\t\tboolean: boolean;\n\t\tdate: boolean;\n\t};\n}\n\nexport const kyselyAdapter = (\n\tdb: Kysely<any>,\n\tconfig?: KyselyAdapterConfig,\n): Adapter => {\n\treturn {\n\t\tasync create(data) {\n\t\t\tlet { model, data: val, select } = data;\n\t\t\tif (config?.transform) {\n\t\t\t\tval = transformFrom(val, config.transform);\n\t\t\t}\n\t\t\tlet res = await db\n\t\t\t\t.insertInto(model)\n\t\t\t\t.values(val as any)\n\t\t\t\t.returningAll()\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\tres = schema ? transformTo(val, schema, config.transform) : res;\n\t\t\t}\n\n\t\t\tif (select?.length) {\n\t\t\t\tconst data = res\n\t\t\t\t\t? select.reduce((acc, cur) => {\n\t\t\t\t\t\t\tif (res?.[cur]) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t[cur]: res[cur],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t}, {} as any)\n\t\t\t\t\t: null;\n\t\t\t\tres = data;\n\t\t\t}\n\n\t\t\treturn res as any;\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tlet query = db.selectFrom(model).selectAll();\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tlet res = await query.executeTakeFirst();\n\t\t\tif (select?.length) {\n\t\t\t\tconst data = res\n\t\t\t\t\t? select.reduce((acc, cur) => {\n\t\t\t\t\t\t\tif (res?.[cur]) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t[cur]: res[cur],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t}, {} as any)\n\t\t\t\t\t: null;\n\t\t\t\tres = data;\n\t\t\t}\n\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\tres = res && schema ? transformTo(res, schema, config.transform) : res;\n\n\t\t\t\treturn res || null;\n\t\t\t}\n\t\t\treturn (res || null) as any;\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tlet query = db.selectFrom(model);\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tconst res = await query.selectAll().execute();\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\treturn schema\n\t\t\t\t\t? res.map((v) => transformTo(v, schema, config.transform))\n\t\t\t\t\t: res;\n\t\t\t}\n\t\t\treturn res as any;\n\t\t},\n\t\tasync update(data) {\n\t\t\tlet { model, where, update: val } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\n\t\t\tif (config?.transform) {\n\t\t\t\tval = transformFrom(val, config.transform);\n\t\t\t}\n\n\t\t\tlet query = db.updateTable(model).set(val);\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tconst res = await query.returningAll().executeTakeFirst();\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\treturn schema ? transformTo(res, schema, config.transform) : res;\n\t\t\t}\n\t\t\treturn res as any;\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tlet query = db.deleteFrom(model);\n\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\n\t\t\tawait query.execute();\n\t\t},\n\t};\n};\n\nexport const getDialect = (config: BetterAuthOptions) => {\n\tif (!config.database) {\n\t\treturn null;\n\t}\n\tlet dialect: Dialect | null = null;\n\tif (\"provider\" in config.database) {\n\t\tconst provider = config.database.provider;\n\t\tconst connectionString = config.database.url.trim();\n\t\tif (provider === \"postgres\") {\n\t\t\tconst pool = new Pool({\n\t\t\t\tconnectionString,\n\t\t\t});\n\t\t\tdialect = new PostgresDialect({\n\t\t\t\tpool,\n\t\t\t});\n\t\t}\n\t\tif (provider === \"mysql\") {\n\t\t\tconst params = new URL(connectionString);\n\t\t\tconst pool = createPool({\n\t\t\t\thost: params.hostname,\n\t\t\t\tuser: params.username,\n\t\t\t\tpassword: params.password,\n\t\t\t\tdatabase: params.pathname.split(\"/\")[1],\n\t\t\t\tport: Number(params.port),\n\t\t\t});\n\t\t\tdialect = new MysqlDialect({ pool });\n\t\t}\n\n\t\tif (provider === \"sqlite\") {\n\t\t\tconst db = new Database(connectionString);\n\t\t\tdialect = new SqliteDialect({\n\t\t\t\tdatabase: db,\n\t\t\t});\n\t\t}\n\t}\n\treturn dialect;\n};\n\nexport const createKyselyAdapter = (config: BetterAuthOptions) => {\n\tconst dialect = getDialect(config);\n\tif (!dialect) {\n\t\treturn null;\n\t}\n\tconst db = new Kysely<any>({\n\t\tdialect,\n\t});\n\treturn db;\n};\n\nexport const getDatabaseType = (config: BetterAuthOptions) => {\n\tif (\"provider\" in config.database) {\n\t\treturn config.database.provider;\n\t}\n\tif (\"dialect\" in config.database) {\n\t\tif (config.database.dialect instanceof PostgresDialect) {\n\t\t\treturn \"postgres\";\n\t\t}\n\t\tif (config.database.dialect instanceof MysqlDialect) {\n\t\t\treturn \"mysql\";\n\t\t}\n\t\tif (config.database.dialect instanceof SqliteDialect) {\n\t\t\treturn \"sqlite\";\n\t\t}\n\t}\n\treturn \"sqlite\";\n};\n","import type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\n\nexport type BetterAuthDbSchema = Record<\n\tstring,\n\t{\n\t\ttableName: string;\n\t\tfields: Record<string, FieldAttribute>;\n\t\tdisableMigrations?: boolean;\n\t}\n>;\n\nexport const getAuthTables = (options: BetterAuthOptions) => {\n\tconst pluginSchema = options.plugins?.reduce((acc, plugin) => {\n\t\tconst schema = plugin.schema;\n\t\treturn {\n\t\t\t...acc,\n\t\t\t...schema,\n\t\t};\n\t}, {});\n\n\treturn {\n\t\t...pluginSchema,\n\t\tuser: {\n\t\t\ttableName: options.user?.modelName || \"user\",\n\t\t\tfields: {\n\t\t\t\tname: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\temailVerified: {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdefaultValue: () => false,\n\t\t\t\t},\n\t\t\t\timage: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tsession: {\n\t\t\ttableName: options.session?.modelName || \"session\",\n\t\t\tfields: {\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t},\n\t\t\t\tipAddress: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tuserAgent: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\taccount: {\n\t\t\ttableName: options.account?.modelName || \"account\",\n\t\t\tfields: {\n\t\t\t\taccountId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\tproviderId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\taccessToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tidToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\taccessTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\trefreshTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t} satisfies BetterAuthDbSchema;\n};\n","import {\n\tgetAuthTables,\n\ttype BetterAuthDbSchema,\n} from \"../../adapters/get-tables\";\nimport type { FieldAttribute } from \"../../db\";\nimport type { BetterAuthOptions } from \"../../types\";\n\nexport function getPluginTable(config: BetterAuthOptions) {\n\tconst pluginsMigrations =\n\t\tconfig.plugins?.flatMap((plugin) =>\n\t\t\tObject.keys(plugin.schema || {})\n\t\t\t\t.map((key) => {\n\t\t\t\t\tconst schema = plugin.schema || {};\n\t\t\t\t\tconst table = schema[key]!;\n\t\t\t\t\tif (table?.disableMigration) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttableName: key,\n\t\t\t\t\t\tfields: table?.fields as Record<string, FieldAttribute>,\n\t\t\t\t\t};\n\t\t\t\t})\n\t\t\t\t.filter((value) => value !== undefined),\n\t\t) || [];\n\treturn pluginsMigrations;\n}\nexport function getSchema(config: BetterAuthOptions) {\n\tconst baseSchema = getAuthTables(config);\n\tconst pluginSchema = getPluginTable(config);\n\tconst schema = [\n\t\t...pluginSchema,\n\t\tbaseSchema.user,\n\t\tbaseSchema.session,\n\t\tbaseSchema.account,\n\t].reduce((acc, curr) => {\n\t\t//@ts-expect-error\n\t\tacc[curr.tableName] = {\n\t\t\tfields: {\n\t\t\t\t...acc[curr.tableName]?.fields,\n\t\t\t\t...curr.fields,\n\t\t\t},\n\t\t};\n\t\treturn acc;\n\t}, {} as BetterAuthDbSchema);\n\treturn schema;\n}\n","import type {\n\tAlterTableColumnAlteringBuilder,\n\tCreateTableBuilder,\n} from \"kysely\";\nimport type { FieldAttribute, FieldType } from \"../../db\";\nimport { logger } from \"../../utils/logger\";\nimport type { BetterAuthOptions } from \"../../types\";\nimport { getSchema } from \"./get-schema\";\nimport { createKyselyAdapter, getDatabaseType } from \"../../adapters/kysely\";\n\nconst postgresMap = {\n\tstring: [\"character varying\", \"text\"],\n\tnumber: [\n\t\t\"integer\",\n\t\t\"bigint\",\n\t\t\"smallint\",\n\t\t\"numeric\",\n\t\t\"real\",\n\t\t\"double precision\",\n\t],\n\tboolean: [\"boolean\"],\n\tdate: [\"timestamp\", \"date\"],\n};\nconst mysqlMap = {\n\tstring: [\"varchar\", \"text\"],\n\tnumber: [\n\t\t\"integer\",\n\t\t\"int\",\n\t\t\"bigint\",\n\t\t\"smallint\",\n\t\t\"decimal\",\n\t\t\"float\",\n\t\t\"double\",\n\t],\n\tboolean: [\"boolean\"],\n\tdate: [\"date\", \"datetime\"],\n};\n\nconst sqliteMap = {\n\tstring: [\"TEXT\"],\n\tnumber: [\"INTEGER\", \"REAL\"],\n\tboolean: [\"INTEGER\", \"BOOLEAN\"], // 0 or 1\n\tdate: [\"DATE\", \"INTEGER\"],\n};\n\nconst map = {\n\tpostgres: postgresMap,\n\tmysql: mysqlMap,\n\tsqlite: sqliteMap,\n};\n\nexport function matchType(\n\tcolumnDataType: string,\n\tfieldType: FieldType,\n\tdbType: \"postgres\" | \"sqlite\" | \"mysql\",\n) {\n\tconst types = map[dbType];\n\tconst type = types[fieldType].map((t) => t.toLowerCase());\n\tconst matches = type.includes(columnDataType.toLowerCase());\n\treturn matches;\n}\n\nexport async function getMigrations(config: BetterAuthOptions) {\n\tconst betterAuthSchema = getSchema(config);\n\tconst dbType = getDatabaseType(config);\n\tconst db = createKyselyAdapter(config);\n\tif (!db) {\n\t\tlogger.error(\"Invalid database configuration.\");\n\t\tprocess.exit(1);\n\t}\n\tconst tableMetadata = await db.introspection.getTables();\n\tconst toBeCreated: {\n\t\ttable: string;\n\t\tfields: Record<string, FieldAttribute>;\n\t}[] = [];\n\tconst toBeAdded: {\n\t\ttable: string;\n\t\tfields: Record<string, FieldAttribute>;\n\t}[] = [];\n\tfor (const [key, value] of Object.entries(betterAuthSchema)) {\n\t\tconst table = tableMetadata.find((t) => t.name === key);\n\t\tif (!table) {\n\t\t\tconst tIndex = toBeCreated.findIndex((t) => t.table === key);\n\t\t\tif (tIndex === -1) {\n\t\t\t\ttoBeCreated.push({\n\t\t\t\t\ttable: key,\n\t\t\t\t\tfields: value.fields,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\ttoBeCreated[tIndex].fields = {\n\t\t\t\t\t...toBeCreated[tIndex].fields,\n\t\t\t\t\t...value.fields,\n\t\t\t\t};\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tlet toBeAddedFields: Record<string, FieldAttribute> = {};\n\t\tfor (const [fieldName, field] of Object.entries(value.fields)) {\n\t\t\tconst column = table.columns.find((c) => c.name === fieldName);\n\t\t\tif (!column) {\n\t\t\t\ttoBeAddedFields[fieldName] = field;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (matchType(column.dataType, field.type, dbType)) {\n\t\t\t\tcontinue;\n\t\t\t} else {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Field ${fieldName} in table ${key} has a different type in the database. Expected ${field.type} but got ${column.dataType}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (Object.keys(toBeAddedFields).length > 0) {\n\t\t\ttoBeAdded.push({\n\t\t\t\ttable: key,\n\t\t\t\tfields: toBeAddedFields,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst typeMap = {\n\t\tstring: \"text\",\n\t\tboolean: \"boolean\",\n\t\tnumber: \"integer\",\n\t\tdate: \"date\",\n\t} as const;\n\tconst migrations: (\n\t\t| AlterTableColumnAlteringBuilder\n\t\t| CreateTableBuilder<string, string>\n\t)[] = [];\n\n\tif (toBeAdded.length) {\n\t\tfor (const table of toBeAdded) {\n\t\t\tlogger.info(`Adding fields to table ${table.table}`);\n\t\t\tfor (const [fieldName, field] of Object.entries(table.fields)) {\n\t\t\t\tlogger.info(`Adding field ${fieldName} with type ${field.type}`);\n\n\t\t\t\tconst type = typeMap[field.type];\n\t\t\t\tconst exec = db.schema\n\t\t\t\t\t.alterTable(table.table)\n\t\t\t\t\t.addColumn(fieldName, type, (col) => {\n\t\t\t\t\t\tcol = field.required !== false ? col.notNull() : col;\n\t\t\t\t\t\tif (field.references) {\n\t\t\t\t\t\t\tcol = col.references(\n\t\t\t\t\t\t\t\t`${field.references.model}.${field.references.field}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn col;\n\t\t\t\t\t});\n\t\t\t\tmigrations.push(exec);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (toBeCreated.length) {\n\t\tfor (const table of toBeCreated) {\n\t\t\tlet dbT = db.schema\n\t\t\t\t.createTable(table.table)\n\t\t\t\t.addColumn(\"id\", \"text\", (col) => col.primaryKey());\n\t\t\tfor (const [fieldName, field] of Object.entries(table.fields)) {\n\t\t\t\tconst type = typeMap[field.type];\n\t\t\t\tdbT = dbT.addColumn(fieldName, type, (col) => {\n\t\t\t\t\tcol = field.required !== false ? col.notNull() : col;\n\t\t\t\t\tif (field.references) {\n\t\t\t\t\t\tcol = col.references(\n\t\t\t\t\t\t\t`${field.references.model}.${field.references.field}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn col;\n\t\t\t\t});\n\t\t\t}\n\t\t\tmigrations.push(dbT);\n\t\t}\n\t}\n\tasync function runMigrations() {\n\t\treturn await Promise.all(migrations.map((m) => m.execute()));\n\t}\n\treturn { toBeCreated, toBeAdded, runMigrations };\n}\n"],"mappings":";AAAA,SAAS,WAAAA,gBAAe;AACxB,OAAO;;;ACDP,SAAS,eAAe;;;ACAxB,OAAO,UAAU;AACjB,OAAO,UAAU;;;ACDjB,SAAS,qBAAqB;AAE9B,IAAM,UAAU,cAAc;AAAA,EAC7B,eAAe;AAAA,IACd,MAAM;AAAA,EACP;AACD,CAAC;AAEM,IAAM,eAAe,CAAC,YAEvB;AACL,SAAO;AAAA,IACN,KAAK,IAAI,SAAgB;AACxB,OAAC,SAAS,YAAY,QAAQ,IAAI,IAAI,GAAG,IAAI;AAAA,IAC9C;AAAA,IACA,OAAO,IAAI,SAAgB;AAC1B,OAAC,SAAS,YAAY,QAAQ,MAAM,IAAI,GAAG,IAAI;AAAA,IAChD;AAAA,IACA,MAAM,IAAI,SAAgB;AACzB,OAAC,SAAS,YAAY,QAAQ,KAAK,IAAI,GAAG,IAAI;AAAA,IAC/C;AAAA,IACA,MAAM,IAAI,SAAgB;AACzB,OAAC,SAAS,YAAY,QAAQ,KAAK,IAAI,GAAG,IAAI;AAAA,IAC/C;AAAA,IACA,OAAO,IAAI,SAAgB;AAC1B,OAAC,SAAS,YAAY,QAAQ,MAAM,IAAI,GAAG,IAAI;AAAA,IAChD;AAAA,IACA,KAAK,IAAI,SAAgB;AACxB,OAAC,SAAS,YAAY,QAAQ,IAAI,IAAI,GAAG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AAU,IAAIC,SAAQ,EAAE,KAAK,aAAa;AAChD,UAAQ,WAAW,OAAO;AAC1B,UAAQ,MAAM;AACf;AAEA,KAAK;","names":["Command","path","path","migrate","Command"]}
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/util.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/sqlite-error.js","../../../node_modules/.pnpm/file-uri-to-path@1.0.0/node_modules/file-uri-to-path/index.js","../../../node_modules/.pnpm/bindings@1.5.0/node_modules/bindings/bindings.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/wrappers.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/transaction.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/pragma.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/backup.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/serialize.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/function.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/aggregate.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/table.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/methods/inspect.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/database.js","../../../node_modules/.pnpm/better-sqlite3@11.1.2/node_modules/better-sqlite3/lib/index.js","../src/cli/index.ts","../src/cli/commands/migrate.ts","../src/cli/get-config.ts","../src/utils/logger.ts","../src/adapters/kysely.ts","../src/adapters/get-tables.ts","../src/cli/utils/get-schema.ts","../src/cli/utils/get-migration.ts"],"sourcesContent":["'use strict';\n\nexports.getBooleanOption = (options, key) => {\n\tlet value = false;\n\tif (key in options && typeof (value = options[key]) !== 'boolean') {\n\t\tthrow new TypeError(`Expected the \"${key}\" option to be a boolean`);\n\t}\n\treturn value;\n};\n\nexports.cppdb = Symbol();\nexports.inspect = Symbol.for('nodejs.util.inspect.custom');\n","'use strict';\nconst descriptor = { value: 'SqliteError', writable: true, enumerable: false, configurable: true };\n\nfunction SqliteError(message, code) {\n\tif (new.target !== SqliteError) {\n\t\treturn new SqliteError(message, code);\n\t}\n\tif (typeof code !== 'string') {\n\t\tthrow new TypeError('Expected second argument to be a string');\n\t}\n\tError.call(this, message);\n\tdescriptor.value = '' + message;\n\tObject.defineProperty(this, 'message', descriptor);\n\tError.captureStackTrace(this, SqliteError);\n\tthis.code = code;\n}\nObject.setPrototypeOf(SqliteError, Error);\nObject.setPrototypeOf(SqliteError.prototype, Error.prototype);\nObject.defineProperty(SqliteError.prototype, 'name', descriptor);\nmodule.exports = SqliteError;\n","\n/**\n * Module dependencies.\n */\n\nvar sep = require('path').sep || '/';\n\n/**\n * Module exports.\n */\n\nmodule.exports = fileUriToPath;\n\n/**\n * File URI to Path function.\n *\n * @param {String} uri\n * @return {String} path\n * @api public\n */\n\nfunction fileUriToPath (uri) {\n if ('string' != typeof uri ||\n uri.length <= 7 ||\n 'file://' != uri.substring(0, 7)) {\n throw new TypeError('must pass in a file:// URI to convert to a file path');\n }\n\n var rest = decodeURI(uri.substring(7));\n var firstSlash = rest.indexOf('/');\n var host = rest.substring(0, firstSlash);\n var path = rest.substring(firstSlash + 1);\n\n // 2. Scheme Definition\n // As a special case, <host> can be the string \"localhost\" or the empty\n // string; this is interpreted as \"the machine from which the URL is\n // being interpreted\".\n if ('localhost' == host) host = '';\n\n if (host) {\n host = sep + sep + host;\n }\n\n // 3.2 Drives, drive letters, mount points, file system root\n // Drive letters are mapped into the top of a file URI in various ways,\n // depending on the implementation; some applications substitute\n // vertical bar (\"|\") for the colon after the drive letter, yielding\n // \"file:///c|/tmp/test.txt\". In some cases, the colon is left\n // unchanged, as in \"file:///c:/tmp/test.txt\". In other cases, the\n // colon is simply omitted, as in \"file:///c/tmp/test.txt\".\n path = path.replace(/^(.+)\\|/, '$1:');\n\n // for Windows, we need to invert the path separators from what a URI uses\n if (sep == '\\\\') {\n path = path.replace(/\\//g, '\\\\');\n }\n\n if (/^.+\\:/.test(path)) {\n // has Windows drive at beginning of path\n } else {\n // unix path…\n path = sep + path;\n }\n\n return host + path;\n}\n","/**\n * Module dependencies.\n */\n\nvar fs = require('fs'),\n path = require('path'),\n fileURLToPath = require('file-uri-to-path'),\n join = path.join,\n dirname = path.dirname,\n exists =\n (fs.accessSync &&\n function(path) {\n try {\n fs.accessSync(path);\n } catch (e) {\n return false;\n }\n return true;\n }) ||\n fs.existsSync ||\n path.existsSync,\n defaults = {\n arrow: process.env.NODE_BINDINGS_ARROW || ' β†’ ',\n compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled',\n platform: process.platform,\n arch: process.arch,\n nodePreGyp:\n 'node-v' +\n process.versions.modules +\n '-' +\n process.platform +\n '-' +\n process.arch,\n version: process.versions.node,\n bindings: 'bindings.node',\n try: [\n // node-gyp's linked version in the \"build\" dir\n ['module_root', 'build', 'bindings'],\n // node-waf and gyp_addon (a.k.a node-gyp)\n ['module_root', 'build', 'Debug', 'bindings'],\n ['module_root', 'build', 'Release', 'bindings'],\n // Debug files, for development (legacy behavior, remove for node v0.9)\n ['module_root', 'out', 'Debug', 'bindings'],\n ['module_root', 'Debug', 'bindings'],\n // Release files, but manually compiled (legacy behavior, remove for node v0.9)\n ['module_root', 'out', 'Release', 'bindings'],\n ['module_root', 'Release', 'bindings'],\n // Legacy from node-waf, node <= 0.4.x\n ['module_root', 'build', 'default', 'bindings'],\n // Production \"Release\" buildtype binary (meh...)\n ['module_root', 'compiled', 'version', 'platform', 'arch', 'bindings'],\n // node-qbs builds\n ['module_root', 'addon-build', 'release', 'install-root', 'bindings'],\n ['module_root', 'addon-build', 'debug', 'install-root', 'bindings'],\n ['module_root', 'addon-build', 'default', 'install-root', 'bindings'],\n // node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}\n ['module_root', 'lib', 'binding', 'nodePreGyp', 'bindings']\n ]\n };\n\n/**\n * The main `bindings()` function loads the compiled bindings for a given module.\n * It uses V8's Error API to determine the parent filename that this function is\n * being invoked from, which is then used to find the root directory.\n */\n\nfunction bindings(opts) {\n // Argument surgery\n if (typeof opts == 'string') {\n opts = { bindings: opts };\n } else if (!opts) {\n opts = {};\n }\n\n // maps `defaults` onto `opts` object\n Object.keys(defaults).map(function(i) {\n if (!(i in opts)) opts[i] = defaults[i];\n });\n\n // Get the module root\n if (!opts.module_root) {\n opts.module_root = exports.getRoot(exports.getFileName());\n }\n\n // Ensure the given bindings name ends with .node\n if (path.extname(opts.bindings) != '.node') {\n opts.bindings += '.node';\n }\n\n // https://github.com/webpack/webpack/issues/4175#issuecomment-342931035\n var requireFunc =\n typeof __webpack_require__ === 'function'\n ? __non_webpack_require__\n : require;\n\n var tries = [],\n i = 0,\n l = opts.try.length,\n n,\n b,\n err;\n\n for (; i < l; i++) {\n n = join.apply(\n null,\n opts.try[i].map(function(p) {\n return opts[p] || p;\n })\n );\n tries.push(n);\n try {\n b = opts.path ? requireFunc.resolve(n) : requireFunc(n);\n if (!opts.path) {\n b.path = n;\n }\n return b;\n } catch (e) {\n if (e.code !== 'MODULE_NOT_FOUND' &&\n e.code !== 'QUALIFIED_PATH_RESOLUTION_FAILED' &&\n !/not find/i.test(e.message)) {\n throw e;\n }\n }\n }\n\n err = new Error(\n 'Could not locate the bindings file. Tried:\\n' +\n tries\n .map(function(a) {\n return opts.arrow + a;\n })\n .join('\\n')\n );\n err.tries = tries;\n throw err;\n}\nmodule.exports = exports = bindings;\n\n/**\n * Gets the filename of the JavaScript file that invokes this function.\n * Used to help find the root directory of a module.\n * Optionally accepts an filename argument to skip when searching for the invoking filename\n */\n\nexports.getFileName = function getFileName(calling_file) {\n var origPST = Error.prepareStackTrace,\n origSTL = Error.stackTraceLimit,\n dummy = {},\n fileName;\n\n Error.stackTraceLimit = 10;\n\n Error.prepareStackTrace = function(e, st) {\n for (var i = 0, l = st.length; i < l; i++) {\n fileName = st[i].getFileName();\n if (fileName !== __filename) {\n if (calling_file) {\n if (fileName !== calling_file) {\n return;\n }\n } else {\n return;\n }\n }\n }\n };\n\n // run the 'prepareStackTrace' function above\n Error.captureStackTrace(dummy);\n dummy.stack;\n\n // cleanup\n Error.prepareStackTrace = origPST;\n Error.stackTraceLimit = origSTL;\n\n // handle filename that starts with \"file://\"\n var fileSchema = 'file://';\n if (fileName.indexOf(fileSchema) === 0) {\n fileName = fileURLToPath(fileName);\n }\n\n return fileName;\n};\n\n/**\n * Gets the root directory of a module, given an arbitrary filename\n * somewhere in the module tree. The \"root directory\" is the directory\n * containing the `package.json` file.\n *\n * In: /home/nate/node-native-module/lib/index.js\n * Out: /home/nate/node-native-module\n */\n\nexports.getRoot = function getRoot(file) {\n var dir = dirname(file),\n prev;\n while (true) {\n if (dir === '.') {\n // Avoids an infinite loop in rare cases, like the REPL\n dir = process.cwd();\n }\n if (\n exists(join(dir, 'package.json')) ||\n exists(join(dir, 'node_modules'))\n ) {\n // Found the 'package.json' file or 'node_modules' dir; we're done\n return dir;\n }\n if (prev === dir) {\n // Got to the top\n throw new Error(\n 'Could not find module root given file: \"' +\n file +\n '\". Do you have a `package.json` file? '\n );\n }\n // Try the parent dir next\n prev = dir;\n dir = join(dir, '..');\n }\n};\n","'use strict';\nconst { cppdb } = require('../util');\n\nexports.prepare = function prepare(sql) {\n\treturn this[cppdb].prepare(sql, this, false);\n};\n\nexports.exec = function exec(sql) {\n\tthis[cppdb].exec(sql);\n\treturn this;\n};\n\nexports.close = function close() {\n\tthis[cppdb].close();\n\treturn this;\n};\n\nexports.loadExtension = function loadExtension(...args) {\n\tthis[cppdb].loadExtension(...args);\n\treturn this;\n};\n\nexports.defaultSafeIntegers = function defaultSafeIntegers(...args) {\n\tthis[cppdb].defaultSafeIntegers(...args);\n\treturn this;\n};\n\nexports.unsafeMode = function unsafeMode(...args) {\n\tthis[cppdb].unsafeMode(...args);\n\treturn this;\n};\n\nexports.getters = {\n\tname: {\n\t\tget: function name() { return this[cppdb].name; },\n\t\tenumerable: true,\n\t},\n\topen: {\n\t\tget: function open() { return this[cppdb].open; },\n\t\tenumerable: true,\n\t},\n\tinTransaction: {\n\t\tget: function inTransaction() { return this[cppdb].inTransaction; },\n\t\tenumerable: true,\n\t},\n\treadonly: {\n\t\tget: function readonly() { return this[cppdb].readonly; },\n\t\tenumerable: true,\n\t},\n\tmemory: {\n\t\tget: function memory() { return this[cppdb].memory; },\n\t\tenumerable: true,\n\t},\n};\n","'use strict';\nconst { cppdb } = require('../util');\nconst controllers = new WeakMap();\n\nmodule.exports = function transaction(fn) {\n\tif (typeof fn !== 'function') throw new TypeError('Expected first argument to be a function');\n\n\tconst db = this[cppdb];\n\tconst controller = getController(db, this);\n\tconst { apply } = Function.prototype;\n\n\t// Each version of the transaction function has these same properties\n\tconst properties = {\n\t\tdefault: { value: wrapTransaction(apply, fn, db, controller.default) },\n\t\tdeferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },\n\t\timmediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },\n\t\texclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },\n\t\tdatabase: { value: this, enumerable: true },\n\t};\n\n\tObject.defineProperties(properties.default.value, properties);\n\tObject.defineProperties(properties.deferred.value, properties);\n\tObject.defineProperties(properties.immediate.value, properties);\n\tObject.defineProperties(properties.exclusive.value, properties);\n\n\t// Return the default version of the transaction function\n\treturn properties.default.value;\n};\n\n// Return the database's cached transaction controller, or create a new one\nconst getController = (db, self) => {\n\tlet controller = controllers.get(db);\n\tif (!controller) {\n\t\tconst shared = {\n\t\t\tcommit: db.prepare('COMMIT', self, false),\n\t\t\trollback: db.prepare('ROLLBACK', self, false),\n\t\t\tsavepoint: db.prepare('SAVEPOINT `\\t_bs3.\\t`', self, false),\n\t\t\trelease: db.prepare('RELEASE `\\t_bs3.\\t`', self, false),\n\t\t\trollbackTo: db.prepare('ROLLBACK TO `\\t_bs3.\\t`', self, false),\n\t\t};\n\t\tcontrollers.set(db, controller = {\n\t\t\tdefault: Object.assign({ begin: db.prepare('BEGIN', self, false) }, shared),\n\t\t\tdeferred: Object.assign({ begin: db.prepare('BEGIN DEFERRED', self, false) }, shared),\n\t\t\timmediate: Object.assign({ begin: db.prepare('BEGIN IMMEDIATE', self, false) }, shared),\n\t\t\texclusive: Object.assign({ begin: db.prepare('BEGIN EXCLUSIVE', self, false) }, shared),\n\t\t});\n\t}\n\treturn controller;\n};\n\n// Return a new transaction function by wrapping the given function\nconst wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {\n\tlet before, after, undo;\n\tif (db.inTransaction) {\n\t\tbefore = savepoint;\n\t\tafter = release;\n\t\tundo = rollbackTo;\n\t} else {\n\t\tbefore = begin;\n\t\tafter = commit;\n\t\tundo = rollback;\n\t}\n\tbefore.run();\n\ttry {\n\t\tconst result = apply.call(fn, this, arguments);\n\t\tafter.run();\n\t\treturn result;\n\t} catch (ex) {\n\t\tif (db.inTransaction) {\n\t\t\tundo.run();\n\t\t\tif (undo !== rollback) after.run();\n\t\t}\n\t\tthrow ex;\n\t}\n};\n","'use strict';\nconst { getBooleanOption, cppdb } = require('../util');\n\nmodule.exports = function pragma(source, options) {\n\tif (options == null) options = {};\n\tif (typeof source !== 'string') throw new TypeError('Expected first argument to be a string');\n\tif (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');\n\tconst simple = getBooleanOption(options, 'simple');\n\n\tconst stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);\n\treturn simple ? stmt.pluck().get() : stmt.all();\n};\n","'use strict';\nconst fs = require('fs');\nconst path = require('path');\nconst { promisify } = require('util');\nconst { cppdb } = require('../util');\nconst fsAccess = promisify(fs.access);\n\nmodule.exports = async function backup(filename, options) {\n\tif (options == null) options = {};\n\n\t// Validate arguments\n\tif (typeof filename !== 'string') throw new TypeError('Expected first argument to be a string');\n\tif (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');\n\n\t// Interpret options\n\tfilename = filename.trim();\n\tconst attachedName = 'attached' in options ? options.attached : 'main';\n\tconst handler = 'progress' in options ? options.progress : null;\n\n\t// Validate interpreted options\n\tif (!filename) throw new TypeError('Backup filename cannot be an empty string');\n\tif (filename === ':memory:') throw new TypeError('Invalid backup filename \":memory:\"');\n\tif (typeof attachedName !== 'string') throw new TypeError('Expected the \"attached\" option to be a string');\n\tif (!attachedName) throw new TypeError('The \"attached\" option cannot be an empty string');\n\tif (handler != null && typeof handler !== 'function') throw new TypeError('Expected the \"progress\" option to be a function');\n\n\t// Make sure the specified directory exists\n\tawait fsAccess(path.dirname(filename)).catch(() => {\n\t\tthrow new TypeError('Cannot save backup because the directory does not exist');\n\t});\n\n\tconst isNewFile = await fsAccess(filename).then(() => false, () => true);\n\treturn runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);\n};\n\nconst runBackup = (backup, handler) => {\n\tlet rate = 0;\n\tlet useDefault = true;\n\n\treturn new Promise((resolve, reject) => {\n\t\tsetImmediate(function step() {\n\t\t\ttry {\n\t\t\t\tconst progress = backup.transfer(rate);\n\t\t\t\tif (!progress.remainingPages) {\n\t\t\t\t\tbackup.close();\n\t\t\t\t\tresolve(progress);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (useDefault) {\n\t\t\t\t\tuseDefault = false;\n\t\t\t\t\trate = 100;\n\t\t\t\t}\n\t\t\t\tif (handler) {\n\t\t\t\t\tconst ret = handler(progress);\n\t\t\t\t\tif (ret !== undefined) {\n\t\t\t\t\t\tif (typeof ret === 'number' && ret === ret) rate = Math.max(0, Math.min(0x7fffffff, Math.round(ret)));\n\t\t\t\t\t\telse throw new TypeError('Expected progress callback to return a number or undefined');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsetImmediate(step);\n\t\t\t} catch (err) {\n\t\t\t\tbackup.close();\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t});\n};\n","'use strict';\nconst { cppdb } = require('../util');\n\nmodule.exports = function serialize(options) {\n\tif (options == null) options = {};\n\n\t// Validate arguments\n\tif (typeof options !== 'object') throw new TypeError('Expected first argument to be an options object');\n\n\t// Interpret and validate options\n\tconst attachedName = 'attached' in options ? options.attached : 'main';\n\tif (typeof attachedName !== 'string') throw new TypeError('Expected the \"attached\" option to be a string');\n\tif (!attachedName) throw new TypeError('The \"attached\" option cannot be an empty string');\n\n\treturn this[cppdb].serialize(attachedName);\n};\n","'use strict';\nconst { getBooleanOption, cppdb } = require('../util');\n\nmodule.exports = function defineFunction(name, options, fn) {\n\t// Apply defaults\n\tif (options == null) options = {};\n\tif (typeof options === 'function') { fn = options; options = {}; }\n\n\t// Validate arguments\n\tif (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');\n\tif (typeof fn !== 'function') throw new TypeError('Expected last argument to be a function');\n\tif (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');\n\tif (!name) throw new TypeError('User-defined function name cannot be an empty string');\n\n\t// Interpret options\n\tconst safeIntegers = 'safeIntegers' in options ? +getBooleanOption(options, 'safeIntegers') : 2;\n\tconst deterministic = getBooleanOption(options, 'deterministic');\n\tconst directOnly = getBooleanOption(options, 'directOnly');\n\tconst varargs = getBooleanOption(options, 'varargs');\n\tlet argCount = -1;\n\n\t// Determine argument count\n\tif (!varargs) {\n\t\targCount = fn.length;\n\t\tif (!Number.isInteger(argCount) || argCount < 0) throw new TypeError('Expected function.length to be a positive integer');\n\t\tif (argCount > 100) throw new RangeError('User-defined functions cannot have more than 100 arguments');\n\t}\n\n\tthis[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);\n\treturn this;\n};\n","'use strict';\nconst { getBooleanOption, cppdb } = require('../util');\n\nmodule.exports = function defineAggregate(name, options) {\n\t// Validate arguments\n\tif (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');\n\tif (typeof options !== 'object' || options === null) throw new TypeError('Expected second argument to be an options object');\n\tif (!name) throw new TypeError('User-defined function name cannot be an empty string');\n\n\t// Interpret options\n\tconst start = 'start' in options ? options.start : null;\n\tconst step = getFunctionOption(options, 'step', true);\n\tconst inverse = getFunctionOption(options, 'inverse', false);\n\tconst result = getFunctionOption(options, 'result', false);\n\tconst safeIntegers = 'safeIntegers' in options ? +getBooleanOption(options, 'safeIntegers') : 2;\n\tconst deterministic = getBooleanOption(options, 'deterministic');\n\tconst directOnly = getBooleanOption(options, 'directOnly');\n\tconst varargs = getBooleanOption(options, 'varargs');\n\tlet argCount = -1;\n\n\t// Determine argument count\n\tif (!varargs) {\n\t\targCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);\n\t\tif (argCount > 0) argCount -= 1;\n\t\tif (argCount > 100) throw new RangeError('User-defined functions cannot have more than 100 arguments');\n\t}\n\n\tthis[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);\n\treturn this;\n};\n\nconst getFunctionOption = (options, key, required) => {\n\tconst value = key in options ? options[key] : null;\n\tif (typeof value === 'function') return value;\n\tif (value != null) throw new TypeError(`Expected the \"${key}\" option to be a function`);\n\tif (required) throw new TypeError(`Missing required option \"${key}\"`);\n\treturn null;\n};\n\nconst getLength = ({ length }) => {\n\tif (Number.isInteger(length) && length >= 0) return length;\n\tthrow new TypeError('Expected function.length to be a positive integer');\n};\n","'use strict';\nconst { cppdb } = require('../util');\n\nmodule.exports = function defineTable(name, factory) {\n\t// Validate arguments\n\tif (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');\n\tif (!name) throw new TypeError('Virtual table module name cannot be an empty string');\n\n\t// Determine whether the module is eponymous-only or not\n\tlet eponymous = false;\n\tif (typeof factory === 'object' && factory !== null) {\n\t\teponymous = true;\n\t\tfactory = defer(parseTableDefinition(factory, 'used', name));\n\t} else {\n\t\tif (typeof factory !== 'function') throw new TypeError('Expected second argument to be a function or a table definition object');\n\t\tfactory = wrapFactory(factory);\n\t}\n\n\tthis[cppdb].table(factory, name, eponymous);\n\treturn this;\n};\n\nfunction wrapFactory(factory) {\n\treturn function virtualTableFactory(moduleName, databaseName, tableName, ...args) {\n\t\tconst thisObject = {\n\t\t\tmodule: moduleName,\n\t\t\tdatabase: databaseName,\n\t\t\ttable: tableName,\n\t\t};\n\n\t\t// Generate a new table definition by invoking the factory\n\t\tconst def = apply.call(factory, thisObject, args);\n\t\tif (typeof def !== 'object' || def === null) {\n\t\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" did not return a table definition object`);\n\t\t}\n\n\t\treturn parseTableDefinition(def, 'returned', moduleName);\n\t};\n}\n\nfunction parseTableDefinition(def, verb, moduleName) {\n\t// Validate required properties\n\tif (!hasOwnProperty.call(def, 'rows')) {\n\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition without a \"rows\" property`);\n\t}\n\tif (!hasOwnProperty.call(def, 'columns')) {\n\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition without a \"columns\" property`);\n\t}\n\n\t// Validate \"rows\" property\n\tconst rows = def.rows;\n\tif (typeof rows !== 'function' || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {\n\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with an invalid \"rows\" property (should be a generator function)`);\n\t}\n\n\t// Validate \"columns\" property\n\tlet columns = def.columns;\n\tif (!Array.isArray(columns) || !(columns = [...columns]).every(x => typeof x === 'string')) {\n\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with an invalid \"columns\" property (should be an array of strings)`);\n\t}\n\tif (columns.length !== new Set(columns).size) {\n\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with duplicate column names`);\n\t}\n\tif (!columns.length) {\n\t\tthrow new RangeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with zero columns`);\n\t}\n\n\t// Validate \"parameters\" property\n\tlet parameters;\n\tif (hasOwnProperty.call(def, 'parameters')) {\n\t\tparameters = def.parameters;\n\t\tif (!Array.isArray(parameters) || !(parameters = [...parameters]).every(x => typeof x === 'string')) {\n\t\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with an invalid \"parameters\" property (should be an array of strings)`);\n\t\t}\n\t} else {\n\t\tparameters = inferParameters(rows);\n\t}\n\tif (parameters.length !== new Set(parameters).size) {\n\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with duplicate parameter names`);\n\t}\n\tif (parameters.length > 32) {\n\t\tthrow new RangeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with more than the maximum number of 32 parameters`);\n\t}\n\tfor (const parameter of parameters) {\n\t\tif (columns.includes(parameter)) {\n\t\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with column \"${parameter}\" which was ambiguously defined as both a column and parameter`);\n\t\t}\n\t}\n\n\t// Validate \"safeIntegers\" option\n\tlet safeIntegers = 2;\n\tif (hasOwnProperty.call(def, 'safeIntegers')) {\n\t\tconst bool = def.safeIntegers;\n\t\tif (typeof bool !== 'boolean') {\n\t\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with an invalid \"safeIntegers\" property (should be a boolean)`);\n\t\t}\n\t\tsafeIntegers = +bool;\n\t}\n\n\t// Validate \"directOnly\" option\n\tlet directOnly = false;\n\tif (hasOwnProperty.call(def, 'directOnly')) {\n\t\tdirectOnly = def.directOnly;\n\t\tif (typeof directOnly !== 'boolean') {\n\t\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" ${verb} a table definition with an invalid \"directOnly\" property (should be a boolean)`);\n\t\t}\n\t}\n\n\t// Generate SQL for the virtual table definition\n\tconst columnDefinitions = [\n\t\t...parameters.map(identifier).map(str => `${str} HIDDEN`),\n\t\t...columns.map(identifier),\n\t];\n\treturn [\n\t\t`CREATE TABLE x(${columnDefinitions.join(', ')});`,\n\t\twrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),\n\t\tparameters,\n\t\tsafeIntegers,\n\t\tdirectOnly,\n\t];\n}\n\nfunction wrapGenerator(generator, columnMap, moduleName) {\n\treturn function* virtualTable(...args) {\n\t\t/*\n\t\t\tWe must defensively clone any buffers in the arguments, because\n\t\t\totherwise the generator could mutate one of them, which would cause\n\t\t\tus to return incorrect values for hidden columns, potentially\n\t\t\tcorrupting the database.\n\t\t */\n\t\tconst output = args.map(x => Buffer.isBuffer(x) ? Buffer.from(x) : x);\n\t\tfor (let i = 0; i < columnMap.size; ++i) {\n\t\t\toutput.push(null); // Fill with nulls to prevent gaps in array (v8 optimization)\n\t\t}\n\t\tfor (const row of generator(...args)) {\n\t\t\tif (Array.isArray(row)) {\n\t\t\t\textractRowArray(row, output, columnMap.size, moduleName);\n\t\t\t\tyield output;\n\t\t\t} else if (typeof row === 'object' && row !== null) {\n\t\t\t\textractRowObject(row, output, columnMap, moduleName);\n\t\t\t\tyield output;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" yielded something that isn't a valid row object`);\n\t\t\t}\n\t\t}\n\t};\n}\n\nfunction extractRowArray(row, output, columnCount, moduleName) {\n\tif (row.length !== columnCount) {\n\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" yielded a row with an incorrect number of columns`);\n\t}\n\tconst offset = output.length - columnCount;\n\tfor (let i = 0; i < columnCount; ++i) {\n\t\toutput[i + offset] = row[i];\n\t}\n}\n\nfunction extractRowObject(row, output, columnMap, moduleName) {\n\tlet count = 0;\n\tfor (const key of Object.keys(row)) {\n\t\tconst index = columnMap.get(key);\n\t\tif (index === undefined) {\n\t\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" yielded a row with an undeclared column \"${key}\"`);\n\t\t}\n\t\toutput[index] = row[key];\n\t\tcount += 1;\n\t}\n\tif (count !== columnMap.size) {\n\t\tthrow new TypeError(`Virtual table module \"${moduleName}\" yielded a row with missing columns`);\n\t}\n}\n\nfunction inferParameters({ length }) {\n\tif (!Number.isInteger(length) || length < 0) {\n\t\tthrow new TypeError('Expected function.length to be a positive integer');\n\t}\n\tconst params = [];\n\tfor (let i = 0; i < length; ++i) {\n\t\tparams.push(`$${i + 1}`);\n\t}\n\treturn params;\n}\n\nconst { hasOwnProperty } = Object.prototype;\nconst { apply } = Function.prototype;\nconst GeneratorFunctionPrototype = Object.getPrototypeOf(function*(){});\nconst identifier = str => `\"${str.replace(/\"/g, '\"\"')}\"`;\nconst defer = x => () => x;\n","'use strict';\nconst DatabaseInspection = function Database() {};\n\nmodule.exports = function inspect(depth, opts) {\n\treturn Object.assign(new DatabaseInspection(), this);\n};\n\n","'use strict';\nconst fs = require('fs');\nconst path = require('path');\nconst util = require('./util');\nconst SqliteError = require('./sqlite-error');\n\nlet DEFAULT_ADDON;\n\nfunction Database(filenameGiven, options) {\n\tif (new.target == null) {\n\t\treturn new Database(filenameGiven, options);\n\t}\n\n\t// Apply defaults\n\tlet buffer;\n\tif (Buffer.isBuffer(filenameGiven)) {\n\t\tbuffer = filenameGiven;\n\t\tfilenameGiven = ':memory:';\n\t}\n\tif (filenameGiven == null) filenameGiven = '';\n\tif (options == null) options = {};\n\n\t// Validate arguments\n\tif (typeof filenameGiven !== 'string') throw new TypeError('Expected first argument to be a string');\n\tif (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');\n\tif ('readOnly' in options) throw new TypeError('Misspelled option \"readOnly\" should be \"readonly\"');\n\tif ('memory' in options) throw new TypeError('Option \"memory\" was removed in v7.0.0 (use \":memory:\" filename instead)');\n\n\t// Interpret options\n\tconst filename = filenameGiven.trim();\n\tconst anonymous = filename === '' || filename === ':memory:';\n\tconst readonly = util.getBooleanOption(options, 'readonly');\n\tconst fileMustExist = util.getBooleanOption(options, 'fileMustExist');\n\tconst timeout = 'timeout' in options ? options.timeout : 5000;\n\tconst verbose = 'verbose' in options ? options.verbose : null;\n\tconst nativeBinding = 'nativeBinding' in options ? options.nativeBinding : null;\n\n\t// Validate interpreted options\n\tif (readonly && anonymous && !buffer) throw new TypeError('In-memory/temporary databases cannot be readonly');\n\tif (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the \"timeout\" option to be a positive integer');\n\tif (timeout > 0x7fffffff) throw new RangeError('Option \"timeout\" cannot be greater than 2147483647');\n\tif (verbose != null && typeof verbose !== 'function') throw new TypeError('Expected the \"verbose\" option to be a function');\n\tif (nativeBinding != null && typeof nativeBinding !== 'string' && typeof nativeBinding !== 'object') throw new TypeError('Expected the \"nativeBinding\" option to be a string or addon object');\n\n\t// Load the native addon\n\tlet addon;\n\tif (nativeBinding == null) {\n\t\taddon = DEFAULT_ADDON || (DEFAULT_ADDON = require('bindings')('better_sqlite3.node'));\n\t} else if (typeof nativeBinding === 'string') {\n\t\t// See <https://webpack.js.org/api/module-variables/#__non_webpack_require__-webpack-specific>\n\t\tconst requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;\n\t\taddon = requireFunc(path.resolve(nativeBinding).replace(/(\\.node)?$/, '.node'));\n\t} else {\n\t\t// See <https://github.com/WiseLibs/better-sqlite3/issues/972>\n\t\taddon = nativeBinding;\n\t}\n\n\tif (!addon.isInitialized) {\n\t\taddon.setErrorConstructor(SqliteError);\n\t\taddon.isInitialized = true;\n\t}\n\n\t// Make sure the specified directory exists\n\tif (!anonymous && !fs.existsSync(path.dirname(filename))) {\n\t\tthrow new TypeError('Cannot open database because the directory does not exist');\n\t}\n\n\tObject.defineProperties(this, {\n\t\t[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },\n\t\t...wrappers.getters,\n\t});\n}\n\nconst wrappers = require('./methods/wrappers');\nDatabase.prototype.prepare = wrappers.prepare;\nDatabase.prototype.transaction = require('./methods/transaction');\nDatabase.prototype.pragma = require('./methods/pragma');\nDatabase.prototype.backup = require('./methods/backup');\nDatabase.prototype.serialize = require('./methods/serialize');\nDatabase.prototype.function = require('./methods/function');\nDatabase.prototype.aggregate = require('./methods/aggregate');\nDatabase.prototype.table = require('./methods/table');\nDatabase.prototype.loadExtension = wrappers.loadExtension;\nDatabase.prototype.exec = wrappers.exec;\nDatabase.prototype.close = wrappers.close;\nDatabase.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;\nDatabase.prototype.unsafeMode = wrappers.unsafeMode;\nDatabase.prototype[util.inspect] = require('./methods/inspect');\n\nmodule.exports = Database;\n","'use strict';\nmodule.exports = require('./database');\nmodule.exports.SqliteError = require('./sqlite-error');\n","import { Command } from \"commander\";\nimport \"dotenv/config\";\nimport { migrate } from \"./commands/migrate\";\nasync function main() {\n\tconst program = new Command().name(\"better-auth\");\n\tprogram.addCommand(migrate);\n\tprogram.parse();\n}\n\nmain();\n","import { Command } from \"commander\";\nimport { getConfig } from \"../get-config\";\nimport { z } from \"zod\";\nimport { existsSync } from \"fs\";\nimport path from \"path\";\nimport { logger } from \"../../utils/logger\";\nimport { createKyselyAdapter } from \"../../adapters/kysely\";\nimport ora from \"ora\";\nimport chalk from \"chalk\";\nimport prompts from \"prompts\";\nimport { getMigrations } from \"../utils/get-migration\";\n\nexport const migrate = new Command(\"migrate\")\n\t.option(\n\t\t\"-c, --cwd <cwd>\",\n\t\t\"the working directory. defaults to the current directory.\",\n\t\tprocess.cwd(),\n\t)\n\t.option(\n\t\t\"--config <config>\",\n\t\t\"the path to the configuration file. defaults to the first configuration file found.\",\n\t)\n\t.action(async (opts) => {\n\t\tconst options = z\n\t\t\t.object({\n\t\t\t\tcwd: z.string(),\n\t\t\t\tconfig: z.string().optional(),\n\t\t\t})\n\t\t\t.parse(opts);\n\t\tconst cwd = path.resolve(options.cwd);\n\t\tif (!existsSync(cwd)) {\n\t\t\tlogger.error(`The directory \"${cwd}\" does not exist.`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst config = await getConfig({\n\t\t\tcwd,\n\t\t\tconfigPath: options.config,\n\t\t});\n\t\tif (!config) {\n\t\t\tlogger.error(\"No configuration file found.\");\n\t\t\treturn;\n\t\t}\n\t\tconst db = createKyselyAdapter(config);\n\t\tif (!db) {\n\t\t\tlogger.error(\"Invalid database configuration.\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst spinner = ora(\"preparing migration...\").start();\n\n\t\tconst { toBeAdded, toBeCreated, runMigrations } =\n\t\t\tawait getMigrations(config);\n\n\t\tif (!toBeAdded.length && !toBeCreated.length) {\n\t\t\tspinner.stop();\n\t\t\tlogger.success(\"πŸš€ No migrations needed.\");\n\t\t\tprocess.exit(0);\n\t\t}\n\n\t\tspinner.stop();\n\t\tlogger.info(`πŸ”‘ The migration will affect the following:`);\n\n\t\tfor (const table of [...toBeAdded, ...toBeCreated]) {\n\t\t\tlogger.info(\n\t\t\t\t\"->\",\n\t\t\t\tchalk.magenta(Object.keys(table.fields).join(\", \")),\n\t\t\t\tchalk.white(\"fields on\"),\n\t\t\t\tchalk.yellow(`${table.table}`),\n\t\t\t\tchalk.white(\"table.\"),\n\t\t\t);\n\t\t}\n\t\tconst { migrate } = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"migrate\",\n\t\t\tmessage: \"Are you sure you want to run these migrations?\",\n\t\t\tinitial: false,\n\t\t});\n\t\tif (!migrate) {\n\t\t\tlogger.info(\"Migration cancelled.\");\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tspinner?.start(\"migrating...\");\n\t\tawait runMigrations();\n\t\tspinner.stop();\n\t\tlogger.success(\"πŸš€ migration was completed successfully!\");\n\t\tprocess.exit(0);\n\t});\n","import path from \"node:path\";\nimport jiti from \"jiti\";\nimport type { BetterAuthOptions } from \"../types\";\nimport { logger } from \"../utils/logger\";\n\nlet possiblePaths = [\"auth.ts\", \"auth.config.ts\"];\n\npossiblePaths = [\n\t...possiblePaths,\n\t...possiblePaths.map((it) => `lib/${it}`),\n\t...possiblePaths.map((it) => `utils/${it}`),\n];\npossiblePaths = [...possiblePaths, ...possiblePaths.map((it) => `src/${it}`)];\n\nexport async function getConfig({\n\tcwd,\n\tconfigPath,\n}: {\n\tcwd: string;\n\tconfigPath?: string;\n}) {\n\ttry {\n\t\tlet configFile: BetterAuthOptions | null = null;\n\t\tif (configPath) {\n\t\t\tconst config = (await jiti(cwd).import(\n\t\t\t\tpath.join(cwd, configPath),\n\t\t\t\t{},\n\t\t\t)) as {\n\t\t\t\tauth: {\n\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t};\n\t\t\t};\n\t\t\tif (!config) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconfigFile = config.auth.options;\n\t\t}\n\n\t\tfor (const possiblePath of possiblePaths) {\n\t\t\ttry {\n\t\t\t\tconst config = (await jiti(path.join(cwd, possiblePath)).import(\n\t\t\t\t\tpath.join(cwd, possiblePath),\n\t\t\t\t\t{},\n\t\t\t\t)) as {\n\t\t\t\t\tauth?: {\n\t\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t\t};\n\t\t\t\t\tdefault?: {\n\t\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t\tif (config) {\n\t\t\t\t\tconfigFile = config.auth?.options || config.default?.options || null;\n\t\t\t\t\tif (!configFile) {\n\t\t\t\t\t\tlogger.error(\"[#better-auth]: Couldn't read your auth config.\");\n\t\t\t\t\t\tlogger.break();\n\t\t\t\t\t\tlogger.info(\n\t\t\t\t\t\t\t\"[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tprocess.exit(1);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (!(e instanceof Error && e.message.includes(\"Cannot find module\"))) {\n\t\t\t\t\tlogger.error(e);\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn configFile;\n\t} catch (e) {\n\t\treturn null;\n\t}\n}\n\nexport { possiblePaths };\n","import { createConsola } from \"consola\";\n\nconst consola = createConsola({\n\tformatOptions: {\n\t\tdate: false,\n\t},\n});\n\nexport const createLogger = (options?: {\n\tdisabled?: boolean;\n}) => {\n\treturn {\n\t\tlog: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.log(\"\", ...args);\n\t\t},\n\t\terror: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.error(\"\", ...args);\n\t\t},\n\t\twarn: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.warn(\"\", ...args);\n\t\t},\n\t\tinfo: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.info(\"\", ...args);\n\t\t},\n\t\tdebug: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.debug(\"\", ...args);\n\t\t},\n\t\tbox: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.box(\"\", ...args);\n\t\t},\n\t\tsuccess: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.success(\"\", ...args);\n\t\t},\n\t\tbreak: (...args: any[]) => {\n\t\t\t!options?.disabled && console.log(\"\\n\");\n\t\t},\n\t};\n};\n\nexport const logger = createLogger();\n","import Database from \"better-sqlite3\";\nimport { Kysely } from \"kysely\";\nimport {\n\ttype Dialect,\n\tMysqlDialect,\n\tPostgresDialect,\n\tSqliteDialect,\n} from \"kysely\";\nimport { createPool } from \"mysql2\";\nimport pg from \"pg\";\nimport type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\nimport type { Adapter, Where } from \"../types/adapter\";\n\nconst { Pool } = pg;\n\nfunction convertWhere(w?: Where[]) {\n\tif (!w)\n\t\treturn {\n\t\t\tand: null,\n\t\t\tor: null,\n\t\t};\n\tconst and = w\n\t\t?.filter((w) => w.connector === \"AND\" || !w.connector)\n\t\t.reduce(\n\t\t\t(acc, w) =>\n\t\t\t\t({\n\t\t\t\t\t...acc,\n\t\t\t\t\t[w.field]: w.value,\n\t\t\t\t}) as any,\n\t\t\t{},\n\t\t);\n\tconst or = w\n\t\t?.filter((w) => w.connector === \"OR\")\n\t\t.reduce(\n\t\t\t(acc, w) =>\n\t\t\t\t({\n\t\t\t\t\t...acc,\n\t\t\t\t\t[w.field]: w.value,\n\t\t\t\t}) as any,\n\t\t\t{},\n\t\t);\n\treturn {\n\t\tand: Object.keys(and).length ? and : null,\n\t\tor: Object.keys(or).length ? or : null,\n\t};\n}\n\nfunction transformTo(\n\tval: any,\n\tfields: Record<string, FieldAttribute>,\n\ttransform: KyselyAdapterConfig[\"transform\"],\n) {\n\tfor (const key in val) {\n\t\tif (\n\t\t\tval[key] === 0 &&\n\t\t\tfields[key]?.type === \"boolean\" &&\n\t\t\ttransform?.boolean\n\t\t) {\n\t\t\tval[key] = false;\n\t\t}\n\t\tif (\n\t\t\tval[key] === 1 &&\n\t\t\tfields[key]?.type === \"boolean\" &&\n\t\t\ttransform?.boolean\n\t\t) {\n\t\t\tval[key] = true;\n\t\t}\n\t\tif (fields[key]?.type === \"date\") {\n\t\t\tif (!(val[key] instanceof Date)) {\n\t\t\t\tval[key] = new Date(val[key]);\n\t\t\t}\n\t\t}\n\t}\n\treturn val;\n}\n\nfunction transformFrom(val: any, transform: KyselyAdapterConfig[\"transform\"]) {\n\tfor (const key in val) {\n\t\tif (typeof val[key] === \"boolean\" && transform?.boolean) {\n\t\t\tval[key] = val[key] ? 1 : 0;\n\t\t}\n\t\tif (val[key] instanceof Date) {\n\t\t\tval[key] = val[key].toISOString();\n\t\t}\n\t}\n\treturn val;\n}\n\nexport interface KyselyAdapterConfig {\n\t/**\n\t * Transform dates and booleans for sqlite.\n\t */\n\ttransform?: {\n\t\tschema: {\n\t\t\t[table: string]: Record<string, FieldAttribute>;\n\t\t};\n\t\tboolean: boolean;\n\t\tdate: boolean;\n\t};\n}\n\nexport const kyselyAdapter = (\n\tdb: Kysely<any>,\n\tconfig?: KyselyAdapterConfig,\n): Adapter => {\n\treturn {\n\t\tasync create(data) {\n\t\t\tlet { model, data: val, select } = data;\n\t\t\tif (config?.transform) {\n\t\t\t\tval = transformFrom(val, config.transform);\n\t\t\t}\n\t\t\tlet res = await db\n\t\t\t\t.insertInto(model)\n\t\t\t\t.values(val as any)\n\t\t\t\t.returningAll()\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\tres = schema ? transformTo(val, schema, config.transform) : res;\n\t\t\t}\n\n\t\t\tif (select?.length) {\n\t\t\t\tconst data = res\n\t\t\t\t\t? select.reduce((acc, cur) => {\n\t\t\t\t\t\t\tif (res?.[cur]) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t[cur]: res[cur],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t}, {} as any)\n\t\t\t\t\t: null;\n\t\t\t\tres = data;\n\t\t\t}\n\n\t\t\treturn res as any;\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tlet query = db.selectFrom(model).selectAll();\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tlet res = await query.executeTakeFirst();\n\t\t\tif (select?.length) {\n\t\t\t\tconst data = res\n\t\t\t\t\t? select.reduce((acc, cur) => {\n\t\t\t\t\t\t\tif (res?.[cur]) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t[cur]: res[cur],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t}, {} as any)\n\t\t\t\t\t: null;\n\t\t\t\tres = data;\n\t\t\t}\n\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\tres = res && schema ? transformTo(res, schema, config.transform) : res;\n\n\t\t\t\treturn res || null;\n\t\t\t}\n\t\t\treturn (res || null) as any;\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tlet query = db.selectFrom(model);\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tconst res = await query.selectAll().execute();\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\treturn schema\n\t\t\t\t\t? res.map((v) => transformTo(v, schema, config.transform))\n\t\t\t\t\t: res;\n\t\t\t}\n\t\t\treturn res as any;\n\t\t},\n\t\tasync update(data) {\n\t\t\tlet { model, where, update: val } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\n\t\t\tif (config?.transform) {\n\t\t\t\tval = transformFrom(val, config.transform);\n\t\t\t}\n\n\t\t\tlet query = db.updateTable(model).set(val);\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tconst res = await query.returningAll().executeTakeFirst();\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\treturn schema ? transformTo(res, schema, config.transform) : res;\n\t\t\t}\n\t\t\treturn res as any;\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tlet query = db.deleteFrom(model);\n\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\n\t\t\tawait query.execute();\n\t\t},\n\t};\n};\n\nexport const getDialect = (config: BetterAuthOptions) => {\n\tif (!config.database) {\n\t\treturn null;\n\t}\n\tlet dialect: Dialect | null = null;\n\tif (\"provider\" in config.database) {\n\t\tconst provider = config.database.provider;\n\t\tconst connectionString = config.database.url.trim();\n\t\tif (provider === \"postgres\") {\n\t\t\tconst pool = new Pool({\n\t\t\t\tconnectionString,\n\t\t\t});\n\t\t\tdialect = new PostgresDialect({\n\t\t\t\tpool,\n\t\t\t});\n\t\t}\n\t\tif (provider === \"mysql\") {\n\t\t\tconst params = new URL(connectionString);\n\t\t\tconst pool = createPool({\n\t\t\t\thost: params.hostname,\n\t\t\t\tuser: params.username,\n\t\t\t\tpassword: params.password,\n\t\t\t\tdatabase: params.pathname.split(\"/\")[1],\n\t\t\t\tport: Number(params.port),\n\t\t\t});\n\t\t\tdialect = new MysqlDialect({ pool });\n\t\t}\n\n\t\tif (provider === \"sqlite\") {\n\t\t\tconst db = new Database(connectionString);\n\t\t\tdialect = new SqliteDialect({\n\t\t\t\tdatabase: db,\n\t\t\t});\n\t\t}\n\t}\n\treturn dialect;\n};\n\nexport const createKyselyAdapter = (config: BetterAuthOptions) => {\n\tconst dialect = getDialect(config);\n\tif (!dialect) {\n\t\treturn null;\n\t}\n\tconst db = new Kysely<any>({\n\t\tdialect,\n\t});\n\treturn db;\n};\n\nexport const getDatabaseType = (config: BetterAuthOptions) => {\n\tif (\"provider\" in config.database) {\n\t\treturn config.database.provider;\n\t}\n\tif (\"dialect\" in config.database) {\n\t\tif (config.database.dialect instanceof PostgresDialect) {\n\t\t\treturn \"postgres\";\n\t\t}\n\t\tif (config.database.dialect instanceof MysqlDialect) {\n\t\t\treturn \"mysql\";\n\t\t}\n\t\tif (config.database.dialect instanceof SqliteDialect) {\n\t\t\treturn \"sqlite\";\n\t\t}\n\t}\n\treturn \"sqlite\";\n};\n","import type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\n\nexport type BetterAuthDbSchema = Record<\n\tstring,\n\t{\n\t\ttableName: string;\n\t\tfields: Record<string, FieldAttribute>;\n\t\tdisableMigrations?: boolean;\n\t}\n>;\n\nexport const getAuthTables = (options: BetterAuthOptions) => {\n\tconst pluginSchema = options.plugins?.reduce((acc, plugin) => {\n\t\tconst schema = plugin.schema;\n\t\treturn {\n\t\t\t...acc,\n\t\t\t...schema,\n\t\t};\n\t}, {});\n\n\treturn {\n\t\t...pluginSchema,\n\t\tuser: {\n\t\t\ttableName: options.user?.modelName || \"user\",\n\t\t\tfields: {\n\t\t\t\tname: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\temailVerified: {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdefaultValue: () => false,\n\t\t\t\t},\n\t\t\t\timage: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tsession: {\n\t\t\ttableName: options.session?.modelName || \"session\",\n\t\t\tfields: {\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t},\n\t\t\t\tipAddress: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tuserAgent: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\taccount: {\n\t\t\ttableName: options.account?.modelName || \"account\",\n\t\t\tfields: {\n\t\t\t\taccountId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\tproviderId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\taccessToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tidToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\taccessTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\trefreshTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t} satisfies BetterAuthDbSchema;\n};\n","import {\n\tgetAuthTables,\n\ttype BetterAuthDbSchema,\n} from \"../../adapters/get-tables\";\nimport type { FieldAttribute } from \"../../db\";\nimport type { BetterAuthOptions } from \"../../types\";\n\nexport function getPluginTable(config: BetterAuthOptions) {\n\tconst pluginsMigrations =\n\t\tconfig.plugins?.flatMap((plugin) =>\n\t\t\tObject.keys(plugin.schema || {})\n\t\t\t\t.map((key) => {\n\t\t\t\t\tconst schema = plugin.schema || {};\n\t\t\t\t\tconst table = schema[key]!;\n\t\t\t\t\tif (table?.disableMigration) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttableName: key,\n\t\t\t\t\t\tfields: table?.fields as Record<string, FieldAttribute>,\n\t\t\t\t\t};\n\t\t\t\t})\n\t\t\t\t.filter((value) => value !== undefined),\n\t\t) || [];\n\treturn pluginsMigrations;\n}\nexport function getSchema(config: BetterAuthOptions) {\n\tconst baseSchema = getAuthTables(config);\n\tconst pluginSchema = getPluginTable(config);\n\tconst schema = [\n\t\t...pluginSchema,\n\t\tbaseSchema.user,\n\t\tbaseSchema.session,\n\t\tbaseSchema.account,\n\t].reduce((acc, curr) => {\n\t\t//@ts-expect-error\n\t\tacc[curr.tableName] = {\n\t\t\tfields: {\n\t\t\t\t...acc[curr.tableName]?.fields,\n\t\t\t\t...curr.fields,\n\t\t\t},\n\t\t};\n\t\treturn acc;\n\t}, {} as BetterAuthDbSchema);\n\treturn schema;\n}\n","import type {\n\tAlterTableColumnAlteringBuilder,\n\tCreateTableBuilder,\n} from \"kysely\";\nimport type { FieldAttribute, FieldType } from \"../../db\";\nimport { logger } from \"../../utils/logger\";\nimport type { BetterAuthOptions } from \"../../types\";\nimport { getSchema } from \"./get-schema\";\nimport { createKyselyAdapter, getDatabaseType } from \"../../adapters/kysely\";\n\nconst postgresMap = {\n\tstring: [\"character varying\", \"text\"],\n\tnumber: [\n\t\t\"integer\",\n\t\t\"bigint\",\n\t\t\"smallint\",\n\t\t\"numeric\",\n\t\t\"real\",\n\t\t\"double precision\",\n\t],\n\tboolean: [\"boolean\"],\n\tdate: [\"timestamp\", \"date\"],\n};\nconst mysqlMap = {\n\tstring: [\"varchar\", \"text\"],\n\tnumber: [\n\t\t\"integer\",\n\t\t\"int\",\n\t\t\"bigint\",\n\t\t\"smallint\",\n\t\t\"decimal\",\n\t\t\"float\",\n\t\t\"double\",\n\t],\n\tboolean: [\"boolean\"],\n\tdate: [\"date\", \"datetime\"],\n};\n\nconst sqliteMap = {\n\tstring: [\"TEXT\"],\n\tnumber: [\"INTEGER\", \"REAL\"],\n\tboolean: [\"INTEGER\", \"BOOLEAN\"], // 0 or 1\n\tdate: [\"DATE\", \"INTEGER\"],\n};\n\nconst map = {\n\tpostgres: postgresMap,\n\tmysql: mysqlMap,\n\tsqlite: sqliteMap,\n};\n\nexport function matchType(\n\tcolumnDataType: string,\n\tfieldType: FieldType,\n\tdbType: \"postgres\" | \"sqlite\" | \"mysql\",\n) {\n\tconst types = map[dbType];\n\tconst type = types[fieldType].map((t) => t.toLowerCase());\n\tconst matches = type.includes(columnDataType.toLowerCase());\n\treturn matches;\n}\n\nexport async function getMigrations(config: BetterAuthOptions) {\n\tconst betterAuthSchema = getSchema(config);\n\tconst dbType = getDatabaseType(config);\n\tconst db = createKyselyAdapter(config);\n\tif (!db) {\n\t\tlogger.error(\"Invalid database configuration.\");\n\t\tprocess.exit(1);\n\t}\n\tconst tableMetadata = await db.introspection.getTables();\n\tconst toBeCreated: {\n\t\ttable: string;\n\t\tfields: Record<string, FieldAttribute>;\n\t}[] = [];\n\tconst toBeAdded: {\n\t\ttable: string;\n\t\tfields: Record<string, FieldAttribute>;\n\t}[] = [];\n\tfor (const [key, value] of Object.entries(betterAuthSchema)) {\n\t\tconst table = tableMetadata.find((t) => t.name === key);\n\t\tif (!table) {\n\t\t\tconst tIndex = toBeCreated.findIndex((t) => t.table === key);\n\t\t\tif (tIndex === -1) {\n\t\t\t\ttoBeCreated.push({\n\t\t\t\t\ttable: key,\n\t\t\t\t\tfields: value.fields,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\ttoBeCreated[tIndex].fields = {\n\t\t\t\t\t...toBeCreated[tIndex].fields,\n\t\t\t\t\t...value.fields,\n\t\t\t\t};\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tlet toBeAddedFields: Record<string, FieldAttribute> = {};\n\t\tfor (const [fieldName, field] of Object.entries(value.fields)) {\n\t\t\tconst column = table.columns.find((c) => c.name === fieldName);\n\t\t\tif (!column) {\n\t\t\t\ttoBeAddedFields[fieldName] = field;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (matchType(column.dataType, field.type, dbType)) {\n\t\t\t\tcontinue;\n\t\t\t} else {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Field ${fieldName} in table ${key} has a different type in the database. Expected ${field.type} but got ${column.dataType}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (Object.keys(toBeAddedFields).length > 0) {\n\t\t\ttoBeAdded.push({\n\t\t\t\ttable: key,\n\t\t\t\tfields: toBeAddedFields,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst typeMap = {\n\t\tstring: \"text\",\n\t\tboolean: \"boolean\",\n\t\tnumber: \"integer\",\n\t\tdate: \"date\",\n\t} as const;\n\tconst migrations: (\n\t\t| AlterTableColumnAlteringBuilder\n\t\t| CreateTableBuilder<string, string>\n\t)[] = [];\n\n\tif (toBeAdded.length) {\n\t\tfor (const table of toBeAdded) {\n\t\t\tlogger.info(`Adding fields to table ${table.table}`);\n\t\t\tfor (const [fieldName, field] of Object.entries(table.fields)) {\n\t\t\t\tlogger.info(`Adding field ${fieldName} with type ${field.type}`);\n\n\t\t\t\tconst type = typeMap[field.type];\n\t\t\t\tconst exec = db.schema\n\t\t\t\t\t.alterTable(table.table)\n\t\t\t\t\t.addColumn(fieldName, type, (col) => {\n\t\t\t\t\t\tcol = field.required !== false ? col.notNull() : col;\n\t\t\t\t\t\tif (field.references) {\n\t\t\t\t\t\t\tcol = col.references(\n\t\t\t\t\t\t\t\t`${field.references.model}.${field.references.field}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn col;\n\t\t\t\t\t});\n\t\t\t\tmigrations.push(exec);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (toBeCreated.length) {\n\t\tfor (const table of toBeCreated) {\n\t\t\tlet dbT = db.schema\n\t\t\t\t.createTable(table.table)\n\t\t\t\t.addColumn(\"id\", \"text\", (col) => col.primaryKey());\n\t\t\tfor (const [fieldName, field] of Object.entries(table.fields)) {\n\t\t\t\tconst type = typeMap[field.type];\n\t\t\t\tdbT = dbT.addColumn(fieldName, type, (col) => {\n\t\t\t\t\tcol = field.required !== false ? col.notNull() : col;\n\t\t\t\t\tif (field.references) {\n\t\t\t\t\t\tcol = col.references(\n\t\t\t\t\t\t\t`${field.references.model}.${field.references.field}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn col;\n\t\t\t\t});\n\t\t\t}\n\t\t\tmigrations.push(dbT);\n\t\t}\n\t}\n\tasync function runMigrations() {\n\t\treturn await Promise.all(migrations.map((m) => m.execute()));\n\t}\n\treturn { toBeCreated, toBeAdded, runMigrations };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAEA,YAAQ,mBAAmB,CAAC,SAAS,QAAQ;AAC5C,UAAI,QAAQ;AACZ,UAAI,OAAO,WAAW,QAAQ,QAAQ,QAAQ,GAAG,OAAO,WAAW;AAClE,cAAM,IAAI,UAAU,iBAAiB,GAAG,0BAA0B;AAAA,MACnE;AACA,aAAO;AAAA,IACR;AAEA,YAAQ,QAAQ,OAAO;AACvB,YAAQ,UAAU,OAAO,IAAI,4BAA4B;AAAA;AAAA;;;ACXzD;AAAA;AAAA;AACA,QAAM,aAAa,EAAE,OAAO,eAAe,UAAU,MAAM,YAAY,OAAO,cAAc,KAAK;AAEjG,aAAS,YAAY,SAAS,MAAM;AACnC,UAAI,eAAe,aAAa;AAC/B,eAAO,IAAI,YAAY,SAAS,IAAI;AAAA,MACrC;AACA,UAAI,OAAO,SAAS,UAAU;AAC7B,cAAM,IAAI,UAAU,yCAAyC;AAAA,MAC9D;AACA,YAAM,KAAK,MAAM,OAAO;AACxB,iBAAW,QAAQ,KAAK;AACxB,aAAO,eAAe,MAAM,WAAW,UAAU;AACjD,YAAM,kBAAkB,MAAM,WAAW;AACzC,WAAK,OAAO;AAAA,IACb;AACA,WAAO,eAAe,aAAa,KAAK;A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,QAAQ,iCAA0B;AACzC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEA,UAAQ,KAAK;AACb,SAAO,KAAK,oDAA6C;AAEzD,aAAW,SAAS,CAAC,GAAG,WAAW,GAAG,WAAW,GAAG;AACnD,WAAO;AAAA,MACN;AAAA,MACA,MAAM,QAAQ,OAAO,KAAK,MAAM,MAAM,EAAE,KAAK,IAAI,CAAC;AAAA,MAClD,MAAM,MAAM,WAAW;AAAA,MACvB,MAAM,OAAO,GAAG,MAAM,KAAK,EAAE;AAAA,MAC7B,MAAM,MAAM,QAAQ;AAAA,IACrB;AAAA,EACD;AACA,QAAM,EAAE,SAAAC,SAAQ,IAAI,MAAM,QAAQ;AAAA,IACjC,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS;AAAA,EACV,CAAC;AACD,MAAI,CAACA,UAAS;AACb,WAAO,KAAK,sBAAsB;AAClC,YAAQ,KAAK,CAAC;AAAA,EACf;AACA,WAAS,MAAM,cAAc;AAC7B,QAAM,cAAc;AACpB,UAAQ,KAAK;AACb,SAAO,QAAQ,iDAA0C;AACzD,UAAQ,KAAK,CAAC;AACf,CAAC;;;ADlFF,eAAe,OAAO;AACrB,QAAM,UAAU,IAAIC,SAAQ,EAAE,KAAK,aAAa;AAChD,UAAQ,WAAW,OAAO;AAC1B,UAAQ,MAAM;AACf;AAEA,KAAK;","names":["path","path","i","path","Database","path","Database","Command","path","Database","path","migrate","Command"]}
package/dist/client.js CHANGED
@@ -36,10 +36,7 @@ function getBaseURL(url, path) {
36
36
  if (url) {
37
37
  return withPath(url, path);
38
38
  }
39
- const env = typeof process !== "undefined" ? process.env : typeof import.meta !== "undefined" ? (
40
- //@ts-ignore
41
- import.meta.env
42
- ) : {};
39
+ const env = typeof process !== "undefined" ? process.env : {};
43
40
  const fromEnv = env.BETTER_AUTH_URL || env.AUTH_URL || env.NEXT_PUBLIC_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
44
41
  if (fromEnv) {
45
42
  return withPath(fromEnv, path);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts","../src/client/create-client-plugin.ts","../src/plugins/two-factor/client.ts","../src/plugins/organization/client.ts","../src/plugins/organization/access/src/access.ts","../src/plugins/organization/access/statement.ts","../src/plugins/passkey/client.ts","../src/plugins/username/client.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\t//@ts-ignore\n\tconst env: any =\n\t\ttypeof process !== \"undefined\"\n\t\t\t? process.env\n\t\t\t: typeof import.meta !== \"undefined\"\n\t\t\t\t? //@ts-ignore\n\t\t\t\t\timport.meta.env\n\t\t\t\t: {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n","import type { BetterFetch, BetterFetchPlugin } from \"@better-fetch/fetch\";\nimport type { Endpoint } from \"better-call\";\nimport type { AuthProxySignal } from \"./proxy\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\nimport type { AuthPlugin } from \"./type\";\nimport type { useAuthStore as reactStore } from \"./react\";\nimport type { useAuthStore as vueStore } from \"./vue\";\nimport type { useAuthStore as preactStore } from \"./preact\";\n\nexport const createClientPlugin = <E extends BetterAuthPlugin = never>() => {\n\treturn <\n\t\tActions extends Record<string, any>,\n\t\tIntegrations extends {\n\t\t\treact?: (useStore: typeof reactStore) => Record<string, any>;\n\t\t\tvue?: (useStore: typeof vueStore) => Record<string, any>;\n\t\t\tpreact?: (useStore: typeof preactStore) => Record<string, any>;\n\t\t\tsvelte?: () => Record<string, any>;\n\t\t},\n\t>(\n\t\t$fn: ($fetch: BetterFetch) => {\n\t\t\tid: string;\n\t\t\tactions?: Actions;\n\t\t\tauthProxySignal?: AuthProxySignal[];\n\t\t\tsignals?: Record<string, PreinitializedWritableAtom<boolean>>;\n\t\t\tatoms?: Record<string, Atom<any>>;\n\t\t\tintegrations?: Integrations;\n\t\t\tpathMethods?: Record<string, \"POST\" | \"GET\">;\n\t\t\tfetchPlugins?: BetterFetchPlugin[];\n\t\t},\n\t) => {\n\t\treturn ($fetch: BetterFetch) => {\n\t\t\tconst data = $fn($fetch);\n\t\t\treturn {\n\t\t\t\t...data,\n\t\t\t\tintegrations: data.integrations as Integrations,\n\t\t\t\tplugin: {} as E,\n\t\t\t};\n\t\t};\n\t};\n};\n\nexport interface AuthClientPlugin {\n\tid: string;\n\tendpoint: Record<string, Endpoint>;\n}\n","import { createClientPlugin } from \"../../client/create-client-plugin\";\nimport type { twoFactor as twoFa } from \"../../plugins/two-factor\";\n\nexport const twoFactorClient = (\n\toptions: {\n\t\ttwoFactorPage: string;\n\t\t/**\n\t\t * Redirect to the two factor page. If twoFactorPage\n\t\t * is not set this will redirect to the root path.\n\t\t * @default true\n\t\t */\n\t\tredirect?: boolean;\n\t} = {\n\t\tredirect: true,\n\t\ttwoFactorPage: \"/\",\n\t},\n) => {\n\treturn createClientPlugin<ReturnType<typeof twoFa>>()(($fetch) => {\n\t\treturn {\n\t\t\tid: \"two-factor\",\n\t\t\tauthProxySignal: [\n\t\t\t\t{\n\t\t\t\t\tmatcher: (path) =>\n\t\t\t\t\t\tpath === \"/two-factor/enable\" || path === \"/two-factor/send-otp\",\n\t\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t\t},\n\t\t\t],\n\t\t\tpathMethods: {\n\t\t\t\t\"enable/totp\": \"POST\",\n\t\t\t\t\"/two-factor/disable\": \"POST\",\n\t\t\t\t\"/two-factor/enable\": \"POST\",\n\t\t\t\t\"/two-factor/send-otp\": \"POST\",\n\t\t\t},\n\t\t\tfetchPlugins: [\n\t\t\t\t{\n\t\t\t\t\tid: \"two-factor\",\n\t\t\t\t\tname: \"two-factor\",\n\t\t\t\t\thooks: {\n\t\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\t\tif (context.data?.twoFactorRedirect) {\n\t\t\t\t\t\t\t\tif (options.redirect) {\n\t\t\t\t\t\t\t\t\twindow.location.href = options.twoFactorPage;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t});\n};\n","import { atom, computed, task } from \"nanostores\";\nimport type {\n\tInvitation,\n\tMember,\n\tOrganization,\n} from \"../../plugins/organization/schema\";\nimport type { Prettify } from \"../../types/helper\";\nimport type { organization as org } from \"../../plugins\";\nimport { createClientPlugin } from \"../../client/create-client-plugin\";\nimport {\n\tcreateAccessControl,\n\tdefaultStatements,\n\ttype AccessControl,\n\ttype Role,\n} from \"./access\";\n\ninterface OrganizationClientOptions {\n\tac: AccessControl;\n\troles?: {\n\t\t[key in \"admin\" | \"member\" | \"owner\"]?: Role<any>;\n\t};\n}\n\nexport const organizationClient = <O extends OrganizationClientOptions>(\n\toptions?: O,\n) =>\n\tcreateClientPlugin<ReturnType<typeof org>>()(($fetch) => {\n\t\tconst activeOrgId = atom<string | null>(null);\n\t\tconst $listOrg = atom<boolean>(false);\n\t\tconst $activeOrgSignal = atom<boolean>(false);\n\t\tconst $activeOrganization = computed([activeOrgId, $activeOrgSignal], () =>\n\t\t\ttask(async () => {\n\t\t\t\tif (!activeOrgId.get()) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tconst organization = await $fetch<\n\t\t\t\t\tPrettify<\n\t\t\t\t\t\tOrganization & {\n\t\t\t\t\t\t\tmembers: Member[];\n\t\t\t\t\t\t\tinvitations: Invitation[];\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t>(\"/organization/set-active\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tcredentials: \"include\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\torgId: activeOrgId.get(),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn organization.data;\n\t\t\t}),\n\t\t);\n\n\t\tconst $listOrganizations = computed($listOrg, () =>\n\t\t\ttask(async () => {\n\t\t\t\tconst organizations = await $fetch<Organization[]>(\n\t\t\t\t\t\"/organization/list\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn organizations.data;\n\t\t\t}),\n\t\t);\n\n\t\tconst $activeInvitationId = atom<string | null>(null);\n\t\tconst $invitation = computed($activeInvitationId, () =>\n\t\t\ttask(async () => {\n\t\t\t\tif (!$activeInvitationId.get()) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"No invitation found\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst res = await $fetch<\n\t\t\t\t\tPrettify<\n\t\t\t\t\t\tInvitation & {\n\t\t\t\t\t\t\torganizationName: string;\n\t\t\t\t\t\t\torganizationSlug: string;\n\t\t\t\t\t\t\tinviterEmail: string;\n\t\t\t\t\t\t\tinviterName: string;\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t>(\"/organization/get-active-invitation\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: {\n\t\t\t\t\t\tid: $activeInvitationId.get(),\n\t\t\t\t\t},\n\t\t\t\t\tcredentials: \"include\",\n\t\t\t\t});\n\t\t\t\treturn res;\n\t\t\t}),\n\t\t);\n\t\ttype DefaultStatements = typeof defaultStatements;\n\t\ttype Statements = O[\"ac\"] extends AccessControl<infer S>\n\t\t\t? S extends Record<string, Array<any>>\n\t\t\t\t? S & DefaultStatements\n\t\t\t\t: DefaultStatements\n\t\t\t: DefaultStatements;\n\t\treturn {\n\t\t\tid: \"organization\",\n\t\t\tactions: {\n\t\t\t\torganization: {\n\t\t\t\t\tsetActive(orgId: string | null) {\n\t\t\t\t\t\tactiveOrgId.set(orgId);\n\t\t\t\t\t},\n\t\t\t\t\tsetInvitationId: (id: string | null) => {\n\t\t\t\t\t\t$activeInvitationId.set(id);\n\t\t\t\t\t},\n\t\t\t\t\thasPermission: async (\n\t\t\t\t\t\tpermission: Partial<{\n\t\t\t\t\t\t\t//@ts-expect-error fix this later\n\t\t\t\t\t\t\t[key in keyof Statements]: Statements[key][number][];\n\t\t\t\t\t\t}>,\n\t\t\t\t\t) => {\n\t\t\t\t\t\tawait $fetch<boolean>(\"/organization/has-permission\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tpermission,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tintegrations: {\n\t\t\t\treact(useStore) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\torganization: {\n\t\t\t\t\t\t\tuseActiveOrganization() {\n\t\t\t\t\t\t\t\treturn useStore($activeOrganization);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tuseListOrganization() {\n\t\t\t\t\t\t\t\treturn useStore($listOrganizations);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tuseInvitation() {\n\t\t\t\t\t\t\t\treturn useStore($invitation);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tvue(useStore) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tuseActiveOrganization() {\n\t\t\t\t\t\t\treturn useStore($activeOrganization);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tuseListOrganization() {\n\t\t\t\t\t\t\treturn useStore($listOrganizations);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tuseInvitation() {\n\t\t\t\t\t\t\treturn useStore($invitation);\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tpreact(useStore) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tuseActiveOrganization() {\n\t\t\t\t\t\t\treturn useStore($activeOrganization);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tuseListOrganization() {\n\t\t\t\t\t\t\treturn useStore($listOrganizations);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tuseInvitation() {\n\t\t\t\t\t\t\treturn useStore($invitation);\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tsvelte() {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t$activeOrganization,\n\t\t\t\t\t\t$listOrganizations,\n\t\t\t\t\t\t$invitation,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t\tsignals: {\n\t\t\t\t$listOrg,\n\t\t\t\t$activeOrgSignal,\n\t\t\t},\n\t\t\tauthProxySignal: [\n\t\t\t\t{\n\t\t\t\t\tmatcher(path) {\n\t\t\t\t\t\treturn path.startsWith(\"/organization\");\n\t\t\t\t\t},\n\t\t\t\t\tatom: \"$listOrg\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tmatcher(path) {\n\t\t\t\t\t\treturn path.startsWith(\"/organization\");\n\t\t\t\t\t},\n\t\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t});\n","import type { StatementsPrimitive as Statements, Subset } from \"./types\";\n\nexport class ParsingError extends Error {\n\tpublic readonly path: string;\n\tconstructor(message: string, path: string) {\n\t\tsuper(message);\n\t\tthis.path = path;\n\t}\n}\n\ntype Connector = \"OR\" | \"AND\";\n\nexport class AccessControl<TStatements extends Statements = Statements> {\n\tprivate readonly statements: TStatements;\n\tconstructor(private readonly s: TStatements) {\n\t\tthis.statements = s;\n\t}\n\tpublic newRole<K extends keyof TStatements>(\n\t\tstatements: Subset<K, TStatements>,\n\t) {\n\t\treturn new Role<Subset<K, TStatements>>(statements);\n\t}\n}\n\nexport type AuthortizeResponse =\n\t| { success: false; error: string }\n\t| { success: true; error?: never };\n\nexport class Role<TStatements extends Statements> {\n\tpublic readonly statements: TStatements;\n\n\tconstructor(statements: TStatements) {\n\t\tthis.statements = statements;\n\t}\n\n\tpublic authorize<K extends keyof TStatements>(\n\t\trequest: Subset<K, TStatements>,\n\t\tconnector?: Connector,\n\t): AuthortizeResponse {\n\t\tfor (const [requestedResource, requestedActions] of Object.entries(\n\t\t\trequest,\n\t\t)) {\n\t\t\tconst allowedActions = this.statements[requestedResource];\n\t\t\tif (!allowedActions) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: `You are not allowed to access resource: ${requestedResource}`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst success =\n\t\t\t\tconnector === \"OR\"\n\t\t\t\t\t? (requestedActions as string[]).some((requestedAction) =>\n\t\t\t\t\t\t\tallowedActions.includes(requestedAction),\n\t\t\t\t\t\t)\n\t\t\t\t\t: (requestedActions as string[]).every((requestedAction) =>\n\t\t\t\t\t\t\tallowedActions.includes(requestedAction),\n\t\t\t\t\t\t);\n\t\t\tif (success) {\n\t\t\t\treturn { success };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: `unauthorized to access resource \"${requestedResource}\"`,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: \"Not authorized\",\n\t\t};\n\t}\n\n\tstatic fromString<TStatements extends Statements>(s: string) {\n\t\tconst statements = JSON.parse(s) as TStatements;\n\n\t\tif (typeof statements !== \"object\") {\n\t\t\tthrow new ParsingError(\"statements is not an object\", \".\");\n\t\t}\n\t\tfor (const [resource, actions] of Object.entries(statements)) {\n\t\t\tif (typeof resource !== \"string\") {\n\t\t\t\tthrow new ParsingError(\"invalid resource identifier\", resource);\n\t\t\t}\n\t\t\tif (!Array.isArray(actions)) {\n\t\t\t\tthrow new ParsingError(\"actions is not an array\", resource);\n\t\t\t}\n\t\t\tfor (let i = 0; i < actions.length; i++) {\n\t\t\t\tif (typeof actions[i] !== \"string\") {\n\t\t\t\t\tthrow new ParsingError(\"action is not a string\", `${resource}[${i}]`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn new Role<TStatements>(statements);\n\t}\n\n\tpublic toString(): string {\n\t\treturn JSON.stringify(this.statements);\n\t}\n}\n","import { AccessControl } from \"./src/access\";\nimport type { StatementsPrimitive } from \"./src/types\";\n\nexport const createAccessControl = <S extends StatementsPrimitive>(\n\tstatements: S,\n) => {\n\treturn new AccessControl<S>(statements);\n};\n\nexport const defaultStatements = {\n\torganization: [\"update\", \"delete\"],\n\tmember: [\"create\", \"update\", \"delete\"],\n\tinvitation: [\"create\", \"cancel\"],\n} as const;\n\nexport const defaultAc = createAccessControl(defaultStatements);\n\nexport const adminAc = defaultAc.newRole({\n\torganization: [\"update\"],\n\tinvitation: [\"create\", \"cancel\"],\n\tmember: [\"create\", \"update\", \"delete\"],\n});\n\nexport const ownerAc = defaultAc.newRole({\n\torganization: [\"update\", \"delete\"],\n\tmember: [\"create\", \"update\", \"delete\"],\n\tinvitation: [\"create\", \"cancel\"],\n});\n\nexport const memberAc = defaultAc.newRole({\n\torganization: [],\n\tmember: [],\n\tinvitation: [],\n});\n\nexport const defaultRoles = {\n\tadmin: adminAc,\n\towner: ownerAc,\n\tmember: memberAc,\n};\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport {\n\tWebAuthnError,\n\tstartAuthentication,\n\tstartRegistration,\n} from \"@simplewebauthn/browser\";\nimport type {\n\tPublicKeyCredentialCreationOptionsJSON,\n\tPublicKeyCredentialRequestOptionsJSON,\n} from \"@simplewebauthn/types\";\nimport type { Session } from \"inspector\";\nimport type { User } from \"../../adapters/schema\";\nimport type { passkey as passkeyPl, Passkey } from \"../../plugins\";\nimport { createClientPlugin } from \"../../client/create-client-plugin\";\n\nexport const getPasskeyActions = ($fetch: BetterFetch) => {\n\tconst signInPasskey = async (opts?: {\n\t\tautoFill?: boolean;\n\t\temail?: string;\n\t\tcallbackURL?: string;\n\t}) => {\n\t\tconst response = await $fetch<PublicKeyCredentialRequestOptionsJSON>(\n\t\t\t\"/passkey/generate-authenticate-options\",\n\t\t\t{\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\temail: opts?.email,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\tif (!response.data) {\n\t\t\treturn response;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startAuthentication(\n\t\t\t\tresponse.data,\n\t\t\t\topts?.autoFill || false,\n\t\t\t);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tsession: Session;\n\t\t\t\tuser: User;\n\t\t\t}>(\"/passkey/verify-authentication\", {\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t\ttype: \"authenticate\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconsole.log(e);\n\t\t}\n\t};\n\n\tconst registerPasskey = async () => {\n\t\tconst options = await $fetch<PublicKeyCredentialCreationOptionsJSON>(\n\t\t\t\"/passkey/generate-register-options\",\n\t\t\t{\n\t\t\t\tmethod: \"GET\",\n\t\t\t},\n\t\t);\n\t\tif (!options.data) {\n\t\t\treturn options;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startRegistration(options.data);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tpasskey: Passkey;\n\t\t\t}>(\"/passkey/verify-registration\", {\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t\ttype: \"register\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof WebAuthnError) {\n\t\t\t\tif (e.code === \"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"previously registered\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\treturn {\n\t\tsignInPasskey,\n\t\tregisterPasskey,\n\t};\n};\n\nexport const passkeyClient = createClientPlugin<ReturnType<typeof passkeyPl>>()(\n\t($fetch) => {\n\t\treturn {\n\t\t\tid: \"passkey\",\n\t\t\tactions: getPasskeyActions($fetch),\n\t\t};\n\t},\n);\n","import type { username } from \".\";\nimport { createClientPlugin } from \"../../client/create-client-plugin\";\n\nexport const usernameClient = createClientPlugin<ReturnType<typeof username>>()(\n\t($fetch) => {\n\t\treturn {\n\t\t\tid: \"username\",\n\t\t};\n\t},\n);\n"],"mappings":";AAAA,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,UAAU,aAAa;AAAA,EAC/B,SAAS,OAAO;AAC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D,UAAI,CAAC,SAAS,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,IACD,SAAS,GAAG;AACX,cAAQ,IAAI,CAAC;AAAA,IACd;AAAA,EACD;AAEA,QAAM,kBAAkB,YAAY;AACnC,UAAM,UAAU,MAAM;AAAA,MACrB;AAAA,MACA;AAAA,QACC,QAAQ;AAAA,MACT;AAAA,IACD;AACA,QAAI,CAAC,QAAQ,MAAM;AAClB,aAAO;AAAA,IACR;AACA,QAAI;AACH,YAAM,MAAM,MAAM,kBAAkB,QAAQ,IAAI;AAChD,YAAM,WAAW,MAAM,OAEpB,gCAAgC;AAAA,QAClC,MAAM;AAAA,UACL,UAAU;AAAA,UACV,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AACD,UAAI,CAAC,SAAS,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,IACD,SAAS,GAAG;AACX,UAAI,aAAa,eAAe;AAC/B,YAAI,EAAE,SAAS,6CAA6C;AAC3D,iBAAO;AAAA,YACN,MAAM;AAAA,YACN,OAAO;AAAA,cACN,SAAS;AAAA,cACT,QAAQ;AAAA,cACR,YAAY;AAAA,YACb;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;AAEO,IAAM,gBAAgB,mBAAiD;AAAA,EAC7E,CAAC,WAAW;AACX,WAAO;AAAA,MACN,IAAI;AAAA,MACJ,SAAS,kBAAkB,MAAM;AAAA,IAClC;AAAA,EACD;AACD;;;ACvGO,IAAM,iBAAiB,mBAAgD;AAAA,EAC7E,CAAC,WAAW;AACX,WAAO;AAAA,MACN,IAAI;AAAA,IACL;AAAA,EACD;AACD;","names":["atom","computed","task","atom","computed","task"]}
1
+ {"version":3,"sources":["../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts","../src/client/create-client-plugin.ts","../src/plugins/two-factor/client.ts","../src/plugins/organization/client.ts","../src/plugins/organization/access/src/access.ts","../src/plugins/organization/access/statement.ts","../src/plugins/passkey/client.ts","../src/plugins/username/client.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\tconst env: any = typeof process !== \"undefined\" ? process.env : {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n","import type { BetterFetch, BetterFetchPlugin } from \"@better-fetch/fetch\";\nimport type { Endpoint } from \"better-call\";\nimport type { AuthProxySignal } from \"./proxy\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\nimport type { AuthPlugin } from \"./type\";\nimport type { useAuthStore as reactStore } from \"./react\";\nimport type { useAuthStore as vueStore } from \"./vue\";\nimport type { useAuthStore as preactStore } from \"./preact\";\n\nexport const createClientPlugin = <E extends BetterAuthPlugin = never>() => {\n\treturn <\n\t\tActions extends Record<string, any>,\n\t\tIntegrations extends {\n\t\t\treact?: (useStore: typeof reactStore) => Record<string, any>;\n\t\t\tvue?: (useStore: typeof vueStore) => Record<string, any>;\n\t\t\tpreact?: (useStore: typeof preactStore) => Record<string, any>;\n\t\t\tsvelte?: () => Record<string, any>;\n\t\t},\n\t>(\n\t\t$fn: ($fetch: BetterFetch) => {\n\t\t\tid: string;\n\t\t\tactions?: Actions;\n\t\t\tauthProxySignal?: AuthProxySignal[];\n\t\t\tsignals?: Record<string, PreinitializedWritableAtom<boolean>>;\n\t\t\tatoms?: Record<string, Atom<any>>;\n\t\t\tintegrations?: Integrations;\n\t\t\tpathMethods?: Record<string, \"POST\" | \"GET\">;\n\t\t\tfetchPlugins?: BetterFetchPlugin[];\n\t\t},\n\t) => {\n\t\treturn ($fetch: BetterFetch) => {\n\t\t\tconst data = $fn($fetch);\n\t\t\treturn {\n\t\t\t\t...data,\n\t\t\t\tintegrations: data.integrations as Integrations,\n\t\t\t\tplugin: {} as E,\n\t\t\t};\n\t\t};\n\t};\n};\n\nexport interface AuthClientPlugin {\n\tid: string;\n\tendpoint: Record<string, Endpoint>;\n}\n","import { createClientPlugin } from \"../../client/create-client-plugin\";\nimport type { twoFactor as twoFa } from \"../../plugins/two-factor\";\n\nexport const twoFactorClient = (\n\toptions: {\n\t\ttwoFactorPage: string;\n\t\t/**\n\t\t * Redirect to the two factor page. If twoFactorPage\n\t\t * is not set this will redirect to the root path.\n\t\t * @default true\n\t\t */\n\t\tredirect?: boolean;\n\t} = {\n\t\tredirect: true,\n\t\ttwoFactorPage: \"/\",\n\t},\n) => {\n\treturn createClientPlugin<ReturnType<typeof twoFa>>()(($fetch) => {\n\t\treturn {\n\t\t\tid: \"two-factor\",\n\t\t\tauthProxySignal: [\n\t\t\t\t{\n\t\t\t\t\tmatcher: (path) =>\n\t\t\t\t\t\tpath === \"/two-factor/enable\" || path === \"/two-factor/send-otp\",\n\t\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t\t},\n\t\t\t],\n\t\t\tpathMethods: {\n\t\t\t\t\"enable/totp\": \"POST\",\n\t\t\t\t\"/two-factor/disable\": \"POST\",\n\t\t\t\t\"/two-factor/enable\": \"POST\",\n\t\t\t\t\"/two-factor/send-otp\": \"POST\",\n\t\t\t},\n\t\t\tfetchPlugins: [\n\t\t\t\t{\n\t\t\t\t\tid: \"two-factor\",\n\t\t\t\t\tname: \"two-factor\",\n\t\t\t\t\thooks: {\n\t\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\t\tif (context.data?.twoFactorRedirect) {\n\t\t\t\t\t\t\t\tif (options.redirect) {\n\t\t\t\t\t\t\t\t\twindow.location.href = options.twoFactorPage;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t});\n};\n","import { atom, computed, task } from \"nanostores\";\nimport type {\n\tInvitation,\n\tMember,\n\tOrganization,\n} from \"../../plugins/organization/schema\";\nimport type { Prettify } from \"../../types/helper\";\nimport type { organization as org } from \"../../plugins\";\nimport { createClientPlugin } from \"../../client/create-client-plugin\";\nimport {\n\tcreateAccessControl,\n\tdefaultStatements,\n\ttype AccessControl,\n\ttype Role,\n} from \"./access\";\n\ninterface OrganizationClientOptions {\n\tac: AccessControl;\n\troles?: {\n\t\t[key in \"admin\" | \"member\" | \"owner\"]?: Role<any>;\n\t};\n}\n\nexport const organizationClient = <O extends OrganizationClientOptions>(\n\toptions?: O,\n) =>\n\tcreateClientPlugin<ReturnType<typeof org>>()(($fetch) => {\n\t\tconst activeOrgId = atom<string | null>(null);\n\t\tconst $listOrg = atom<boolean>(false);\n\t\tconst $activeOrgSignal = atom<boolean>(false);\n\t\tconst $activeOrganization = computed([activeOrgId, $activeOrgSignal], () =>\n\t\t\ttask(async () => {\n\t\t\t\tif (!activeOrgId.get()) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tconst organization = await $fetch<\n\t\t\t\t\tPrettify<\n\t\t\t\t\t\tOrganization & {\n\t\t\t\t\t\t\tmembers: Member[];\n\t\t\t\t\t\t\tinvitations: Invitation[];\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t>(\"/organization/set-active\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tcredentials: \"include\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\torgId: activeOrgId.get(),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn organization.data;\n\t\t\t}),\n\t\t);\n\n\t\tconst $listOrganizations = computed($listOrg, () =>\n\t\t\ttask(async () => {\n\t\t\t\tconst organizations = await $fetch<Organization[]>(\n\t\t\t\t\t\"/organization/list\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn organizations.data;\n\t\t\t}),\n\t\t);\n\n\t\tconst $activeInvitationId = atom<string | null>(null);\n\t\tconst $invitation = computed($activeInvitationId, () =>\n\t\t\ttask(async () => {\n\t\t\t\tif (!$activeInvitationId.get()) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"No invitation found\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst res = await $fetch<\n\t\t\t\t\tPrettify<\n\t\t\t\t\t\tInvitation & {\n\t\t\t\t\t\t\torganizationName: string;\n\t\t\t\t\t\t\torganizationSlug: string;\n\t\t\t\t\t\t\tinviterEmail: string;\n\t\t\t\t\t\t\tinviterName: string;\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t>(\"/organization/get-active-invitation\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: {\n\t\t\t\t\t\tid: $activeInvitationId.get(),\n\t\t\t\t\t},\n\t\t\t\t\tcredentials: \"include\",\n\t\t\t\t});\n\t\t\t\treturn res;\n\t\t\t}),\n\t\t);\n\t\ttype DefaultStatements = typeof defaultStatements;\n\t\ttype Statements = O[\"ac\"] extends AccessControl<infer S>\n\t\t\t? S extends Record<string, Array<any>>\n\t\t\t\t? S & DefaultStatements\n\t\t\t\t: DefaultStatements\n\t\t\t: DefaultStatements;\n\t\treturn {\n\t\t\tid: \"organization\",\n\t\t\tactions: {\n\t\t\t\torganization: {\n\t\t\t\t\tsetActive(orgId: string | null) {\n\t\t\t\t\t\tactiveOrgId.set(orgId);\n\t\t\t\t\t},\n\t\t\t\t\tsetInvitationId: (id: string | null) => {\n\t\t\t\t\t\t$activeInvitationId.set(id);\n\t\t\t\t\t},\n\t\t\t\t\thasPermission: async (\n\t\t\t\t\t\tpermission: Partial<{\n\t\t\t\t\t\t\t//@ts-expect-error fix this later\n\t\t\t\t\t\t\t[key in keyof Statements]: Statements[key][number][];\n\t\t\t\t\t\t}>,\n\t\t\t\t\t) => {\n\t\t\t\t\t\tawait $fetch<boolean>(\"/organization/has-permission\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tpermission,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tintegrations: {\n\t\t\t\treact(useStore) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\torganization: {\n\t\t\t\t\t\t\tuseActiveOrganization() {\n\t\t\t\t\t\t\t\treturn useStore($activeOrganization);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tuseListOrganization() {\n\t\t\t\t\t\t\t\treturn useStore($listOrganizations);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tuseInvitation() {\n\t\t\t\t\t\t\t\treturn useStore($invitation);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tvue(useStore) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tuseActiveOrganization() {\n\t\t\t\t\t\t\treturn useStore($activeOrganization);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tuseListOrganization() {\n\t\t\t\t\t\t\treturn useStore($listOrganizations);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tuseInvitation() {\n\t\t\t\t\t\t\treturn useStore($invitation);\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tpreact(useStore) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tuseActiveOrganization() {\n\t\t\t\t\t\t\treturn useStore($activeOrganization);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tuseListOrganization() {\n\t\t\t\t\t\t\treturn useStore($listOrganizations);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tuseInvitation() {\n\t\t\t\t\t\t\treturn useStore($invitation);\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tsvelte() {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t$activeOrganization,\n\t\t\t\t\t\t$listOrganizations,\n\t\t\t\t\t\t$invitation,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t\tsignals: {\n\t\t\t\t$listOrg,\n\t\t\t\t$activeOrgSignal,\n\t\t\t},\n\t\t\tauthProxySignal: [\n\t\t\t\t{\n\t\t\t\t\tmatcher(path) {\n\t\t\t\t\t\treturn path.startsWith(\"/organization\");\n\t\t\t\t\t},\n\t\t\t\t\tatom: \"$listOrg\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tmatcher(path) {\n\t\t\t\t\t\treturn path.startsWith(\"/organization\");\n\t\t\t\t\t},\n\t\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t});\n","import type { StatementsPrimitive as Statements, Subset } from \"./types\";\n\nexport class ParsingError extends Error {\n\tpublic readonly path: string;\n\tconstructor(message: string, path: string) {\n\t\tsuper(message);\n\t\tthis.path = path;\n\t}\n}\n\ntype Connector = \"OR\" | \"AND\";\n\nexport class AccessControl<TStatements extends Statements = Statements> {\n\tprivate readonly statements: TStatements;\n\tconstructor(private readonly s: TStatements) {\n\t\tthis.statements = s;\n\t}\n\tpublic newRole<K extends keyof TStatements>(\n\t\tstatements: Subset<K, TStatements>,\n\t) {\n\t\treturn new Role<Subset<K, TStatements>>(statements);\n\t}\n}\n\nexport type AuthortizeResponse =\n\t| { success: false; error: string }\n\t| { success: true; error?: never };\n\nexport class Role<TStatements extends Statements> {\n\tpublic readonly statements: TStatements;\n\n\tconstructor(statements: TStatements) {\n\t\tthis.statements = statements;\n\t}\n\n\tpublic authorize<K extends keyof TStatements>(\n\t\trequest: Subset<K, TStatements>,\n\t\tconnector?: Connector,\n\t): AuthortizeResponse {\n\t\tfor (const [requestedResource, requestedActions] of Object.entries(\n\t\t\trequest,\n\t\t)) {\n\t\t\tconst allowedActions = this.statements[requestedResource];\n\t\t\tif (!allowedActions) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: `You are not allowed to access resource: ${requestedResource}`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst success =\n\t\t\t\tconnector === \"OR\"\n\t\t\t\t\t? (requestedActions as string[]).some((requestedAction) =>\n\t\t\t\t\t\t\tallowedActions.includes(requestedAction),\n\t\t\t\t\t\t)\n\t\t\t\t\t: (requestedActions as string[]).every((requestedAction) =>\n\t\t\t\t\t\t\tallowedActions.includes(requestedAction),\n\t\t\t\t\t\t);\n\t\t\tif (success) {\n\t\t\t\treturn { success };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: `unauthorized to access resource \"${requestedResource}\"`,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: \"Not authorized\",\n\t\t};\n\t}\n\n\tstatic fromString<TStatements extends Statements>(s: string) {\n\t\tconst statements = JSON.parse(s) as TStatements;\n\n\t\tif (typeof statements !== \"object\") {\n\t\t\tthrow new ParsingError(\"statements is not an object\", \".\");\n\t\t}\n\t\tfor (const [resource, actions] of Object.entries(statements)) {\n\t\t\tif (typeof resource !== \"string\") {\n\t\t\t\tthrow new ParsingError(\"invalid resource identifier\", resource);\n\t\t\t}\n\t\t\tif (!Array.isArray(actions)) {\n\t\t\t\tthrow new ParsingError(\"actions is not an array\", resource);\n\t\t\t}\n\t\t\tfor (let i = 0; i < actions.length; i++) {\n\t\t\t\tif (typeof actions[i] !== \"string\") {\n\t\t\t\t\tthrow new ParsingError(\"action is not a string\", `${resource}[${i}]`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn new Role<TStatements>(statements);\n\t}\n\n\tpublic toString(): string {\n\t\treturn JSON.stringify(this.statements);\n\t}\n}\n","import { AccessControl } from \"./src/access\";\nimport type { StatementsPrimitive } from \"./src/types\";\n\nexport const createAccessControl = <S extends StatementsPrimitive>(\n\tstatements: S,\n) => {\n\treturn new AccessControl<S>(statements);\n};\n\nexport const defaultStatements = {\n\torganization: [\"update\", \"delete\"],\n\tmember: [\"create\", \"update\", \"delete\"],\n\tinvitation: [\"create\", \"cancel\"],\n} as const;\n\nexport const defaultAc = createAccessControl(defaultStatements);\n\nexport const adminAc = defaultAc.newRole({\n\torganization: [\"update\"],\n\tinvitation: [\"create\", \"cancel\"],\n\tmember: [\"create\", \"update\", \"delete\"],\n});\n\nexport const ownerAc = defaultAc.newRole({\n\torganization: [\"update\", \"delete\"],\n\tmember: [\"create\", \"update\", \"delete\"],\n\tinvitation: [\"create\", \"cancel\"],\n});\n\nexport const memberAc = defaultAc.newRole({\n\torganization: [],\n\tmember: [],\n\tinvitation: [],\n});\n\nexport const defaultRoles = {\n\tadmin: adminAc,\n\towner: ownerAc,\n\tmember: memberAc,\n};\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport {\n\tWebAuthnError,\n\tstartAuthentication,\n\tstartRegistration,\n} from \"@simplewebauthn/browser\";\nimport type {\n\tPublicKeyCredentialCreationOptionsJSON,\n\tPublicKeyCredentialRequestOptionsJSON,\n} from \"@simplewebauthn/types\";\nimport type { Session } from \"inspector\";\nimport type { User } from \"../../adapters/schema\";\nimport type { passkey as passkeyPl, Passkey } from \"../../plugins\";\nimport { createClientPlugin } from \"../../client/create-client-plugin\";\n\nexport const getPasskeyActions = ($fetch: BetterFetch) => {\n\tconst signInPasskey = async (opts?: {\n\t\tautoFill?: boolean;\n\t\temail?: string;\n\t\tcallbackURL?: string;\n\t}) => {\n\t\tconst response = await $fetch<PublicKeyCredentialRequestOptionsJSON>(\n\t\t\t\"/passkey/generate-authenticate-options\",\n\t\t\t{\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\temail: opts?.email,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\tif (!response.data) {\n\t\t\treturn response;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startAuthentication(\n\t\t\t\tresponse.data,\n\t\t\t\topts?.autoFill || false,\n\t\t\t);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tsession: Session;\n\t\t\t\tuser: User;\n\t\t\t}>(\"/passkey/verify-authentication\", {\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t\ttype: \"authenticate\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconsole.log(e);\n\t\t}\n\t};\n\n\tconst registerPasskey = async () => {\n\t\tconst options = await $fetch<PublicKeyCredentialCreationOptionsJSON>(\n\t\t\t\"/passkey/generate-register-options\",\n\t\t\t{\n\t\t\t\tmethod: \"GET\",\n\t\t\t},\n\t\t);\n\t\tif (!options.data) {\n\t\t\treturn options;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startRegistration(options.data);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tpasskey: Passkey;\n\t\t\t}>(\"/passkey/verify-registration\", {\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t\ttype: \"register\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof WebAuthnError) {\n\t\t\t\tif (e.code === \"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"previously registered\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\treturn {\n\t\tsignInPasskey,\n\t\tregisterPasskey,\n\t};\n};\n\nexport const passkeyClient = createClientPlugin<ReturnType<typeof passkeyPl>>()(\n\t($fetch) => {\n\t\treturn {\n\t\t\tid: \"passkey\",\n\t\t\tactions: getPasskeyActions($fetch),\n\t\t};\n\t},\n);\n","import type { username } from \".\";\nimport { createClientPlugin } from \"../../client/create-client-plugin\";\n\nexport const usernameClient = createClientPlugin<ReturnType<typeof username>>()(\n\t($fetch) => {\n\t\treturn {\n\t\t\tid: \"username\",\n\t\t};\n\t},\n);\n"],"mappings":";AAAA,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,UAAU,aAAa;AAAA,EAC/B,SAAS,OAAO;AACf,YAAQ,MAAM,gBAAgB,KAAK;AACnC,WAAO;AAAA,EACR;AACD;AAEA,SAAS,SAAS,KAAa,OAAO,aAAa;AAClD,QAAM,UAAU,aAAa,GAAG;AAChC,MAAI,SAAS;AACZ,WAAO;AAAA,MACN,SAAS,IAAI,IAAI,GAAG,EAAE;AAAA,MACtB,UAAU;AAAA,IACX;AAAA,EACD;AACA,SAAO,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AAC7C,SAAO;AAAA,IACN,SAAS;AAAA,IACT,UAAU,GAAG,GAAG,GAAG,IAAI;AAAA,EACxB;AACD;AAEO,SAAS,WAAW,KAAc,MAAe;AACvD,MAAI,K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