auth 1.5.0-beta.20 → 1.5.0
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/index.mjs +169 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -27,6 +27,7 @@ import z from "zod";
|
|
|
27
27
|
import { env } from "@better-auth/core/env";
|
|
28
28
|
import { log } from "@clack/prompts";
|
|
29
29
|
import { base64 } from "@better-auth/utils/base64";
|
|
30
|
+
import * as semver from "semver";
|
|
30
31
|
import "dotenv/config";
|
|
31
32
|
|
|
32
33
|
//#region src/utils/add-cloudflare-modules.ts
|
|
@@ -436,11 +437,56 @@ async function getConfig({ cwd, configPath, shouldThrowOnError = false }) {
|
|
|
436
437
|
|
|
437
438
|
//#endregion
|
|
438
439
|
//#region src/commands/generate.ts
|
|
440
|
+
function createMockAdapter$1(adapterId, dialect) {
|
|
441
|
+
let provider;
|
|
442
|
+
if (dialect) {
|
|
443
|
+
if (adapterId === "drizzle") if (dialect === "postgresql") provider = "pg";
|
|
444
|
+
else if (dialect === "mysql" || dialect === "sqlite") provider = dialect;
|
|
445
|
+
else provider = dialect;
|
|
446
|
+
else if (adapterId === "prisma") provider = dialect;
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
id: adapterId,
|
|
450
|
+
create: async () => {
|
|
451
|
+
throw new Error("Mock adapter methods should not be called");
|
|
452
|
+
},
|
|
453
|
+
findOne: async () => {
|
|
454
|
+
throw new Error("Mock adapter methods should not be called");
|
|
455
|
+
},
|
|
456
|
+
findMany: async () => {
|
|
457
|
+
throw new Error("Mock adapter methods should not be called");
|
|
458
|
+
},
|
|
459
|
+
count: async () => {
|
|
460
|
+
throw new Error("Mock adapter methods should not be called");
|
|
461
|
+
},
|
|
462
|
+
update: async () => {
|
|
463
|
+
throw new Error("Mock adapter methods should not be called");
|
|
464
|
+
},
|
|
465
|
+
updateMany: async () => {
|
|
466
|
+
throw new Error("Mock adapter methods should not be called");
|
|
467
|
+
},
|
|
468
|
+
delete: async () => {
|
|
469
|
+
throw new Error("Mock adapter methods should not be called");
|
|
470
|
+
},
|
|
471
|
+
deleteMany: async () => {
|
|
472
|
+
throw new Error("Mock adapter methods should not be called");
|
|
473
|
+
},
|
|
474
|
+
transaction: async (callback) => {
|
|
475
|
+
throw new Error("Mock adapter methods should not be called");
|
|
476
|
+
},
|
|
477
|
+
options: {
|
|
478
|
+
adapterConfig: { adapterId },
|
|
479
|
+
...provider && { provider }
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
439
483
|
async function generateAction(opts) {
|
|
440
484
|
const options = z$1.object({
|
|
441
485
|
cwd: z$1.string(),
|
|
442
486
|
config: z$1.string().optional(),
|
|
443
487
|
output: z$1.string().optional(),
|
|
488
|
+
adapter: z$1.string().optional(),
|
|
489
|
+
dialect: z$1.string().optional(),
|
|
444
490
|
y: z$1.boolean().optional(),
|
|
445
491
|
yes: z$1.boolean().optional()
|
|
446
492
|
}).parse(opts);
|
|
@@ -457,7 +503,9 @@ async function generateAction(opts) {
|
|
|
457
503
|
console.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");
|
|
458
504
|
return;
|
|
459
505
|
}
|
|
460
|
-
|
|
506
|
+
let adapter;
|
|
507
|
+
if (options.adapter) adapter = createMockAdapter$1(options.adapter, options.dialect);
|
|
508
|
+
else adapter = await getAdapter(config).catch((e) => {
|
|
461
509
|
console.error(e.message);
|
|
462
510
|
process.exit(1);
|
|
463
511
|
});
|
|
@@ -559,7 +607,7 @@ async function generateAction(opts) {
|
|
|
559
607
|
} catch {}
|
|
560
608
|
process.exit(0);
|
|
561
609
|
}
|
|
562
|
-
const generate = new Command("generate").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("--config <config>", "the path to the configuration file. defaults to the first configuration file found.").option("--output <output>", "the file to output to the generated schema").option("-y, --yes", "automatically answer yes to all prompts", false).option("--y", "(deprecated) same as --yes", false).action(generateAction);
|
|
610
|
+
const generate = new Command("generate").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("--config <config>", "the path to the configuration file. defaults to the first configuration file found.").option("--output <output>", "the file to output to the generated schema").option("--adapter <adapter>", "specify the adapter type (e.g., prisma, drizzle, kysely) without requiring a configured adapter").option("--dialect <dialect>", "specify the database dialect/provider (e.g., postgresql, mysql, sqlite). For drizzle, postgresql maps to 'pg'").option("-y, --yes", "automatically answer yes to all prompts", false).option("--y", "(deprecated) same as --yes", false).action(generateAction);
|
|
563
611
|
|
|
564
612
|
//#endregion
|
|
565
613
|
//#region src/commands/info.ts
|
|
@@ -5672,6 +5720,124 @@ const generateSecretHash = () => {
|
|
|
5672
5720
|
return Crypto.randomBytes(32).toString("hex");
|
|
5673
5721
|
};
|
|
5674
5722
|
|
|
5723
|
+
//#endregion
|
|
5724
|
+
//#region src/utils/fetch-latest-version.ts
|
|
5725
|
+
async function fetchLatestVersion(packageName) {
|
|
5726
|
+
const encoded = packageName.startsWith("@") ? `@${encodeURIComponent(packageName.slice(1))}` : encodeURIComponent(packageName);
|
|
5727
|
+
try {
|
|
5728
|
+
const response = await fetch(`https://registry.npmjs.org/${encoded}/latest`);
|
|
5729
|
+
if (!response.ok) return null;
|
|
5730
|
+
return (await response.json()).version ?? null;
|
|
5731
|
+
} catch {
|
|
5732
|
+
return null;
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
|
|
5736
|
+
//#endregion
|
|
5737
|
+
//#region src/commands/upgrade.ts
|
|
5738
|
+
function isBetterAuthPackage(name) {
|
|
5739
|
+
return name === "better-auth" || name.startsWith("@better-auth/");
|
|
5740
|
+
}
|
|
5741
|
+
async function upgradeAction(opts) {
|
|
5742
|
+
const options = z$1.object({
|
|
5743
|
+
cwd: z$1.string(),
|
|
5744
|
+
yes: z$1.boolean().optional()
|
|
5745
|
+
}).parse(opts);
|
|
5746
|
+
const cwd = path.resolve(options.cwd);
|
|
5747
|
+
if (!existsSync(cwd)) {
|
|
5748
|
+
console.error(`The directory "${cwd}" does not exist.`);
|
|
5749
|
+
process.exit(1);
|
|
5750
|
+
}
|
|
5751
|
+
let packageJson;
|
|
5752
|
+
try {
|
|
5753
|
+
packageJson = getPackageInfo(cwd);
|
|
5754
|
+
} catch {
|
|
5755
|
+
console.error(`Could not read package.json in "${cwd}". Make sure you are in a project directory.`);
|
|
5756
|
+
process.exit(1);
|
|
5757
|
+
}
|
|
5758
|
+
const deps = packageJson.dependencies ?? {};
|
|
5759
|
+
const devDeps = packageJson.devDependencies ?? {};
|
|
5760
|
+
const candidates = [];
|
|
5761
|
+
for (const [name, version] of Object.entries(deps)) if (isBetterAuthPackage(name) && !version.startsWith("workspace:")) candidates.push({
|
|
5762
|
+
name,
|
|
5763
|
+
current: version,
|
|
5764
|
+
depType: "prod"
|
|
5765
|
+
});
|
|
5766
|
+
for (const [name, version] of Object.entries(devDeps)) if (isBetterAuthPackage(name) && !version.startsWith("workspace:")) candidates.push({
|
|
5767
|
+
name,
|
|
5768
|
+
current: version,
|
|
5769
|
+
depType: "dev"
|
|
5770
|
+
});
|
|
5771
|
+
if (candidates.length === 0) {
|
|
5772
|
+
console.log("No better-auth packages found in this project.");
|
|
5773
|
+
return;
|
|
5774
|
+
}
|
|
5775
|
+
const spinner = yoctoSpinner({ text: "checking for updates..." }).start();
|
|
5776
|
+
const results = await Promise.allSettled(candidates.map(async (c) => {
|
|
5777
|
+
const latest = await fetchLatestVersion(c.name);
|
|
5778
|
+
return {
|
|
5779
|
+
...c,
|
|
5780
|
+
latest
|
|
5781
|
+
};
|
|
5782
|
+
}));
|
|
5783
|
+
const upgrades = [];
|
|
5784
|
+
for (const result of results) {
|
|
5785
|
+
if (result.status !== "fulfilled" || !result.value.latest) continue;
|
|
5786
|
+
const { name, current, latest, depType } = result.value;
|
|
5787
|
+
const coerced = semver.coerce(current);
|
|
5788
|
+
if (coerced && semver.lt(coerced, latest)) upgrades.push({
|
|
5789
|
+
name,
|
|
5790
|
+
current,
|
|
5791
|
+
latest,
|
|
5792
|
+
depType
|
|
5793
|
+
});
|
|
5794
|
+
}
|
|
5795
|
+
spinner.stop();
|
|
5796
|
+
if (upgrades.length === 0) {
|
|
5797
|
+
console.log("All better-auth packages are up to date.");
|
|
5798
|
+
return;
|
|
5799
|
+
}
|
|
5800
|
+
console.log(`\nThe following packages can be upgraded:\n`);
|
|
5801
|
+
for (const u of upgrades) console.log(` ${chalk.cyan(u.name)} ${chalk.gray(u.current)} ${chalk.white("→")} ${chalk.green(u.latest)}`);
|
|
5802
|
+
console.log();
|
|
5803
|
+
let confirmed = options.yes;
|
|
5804
|
+
if (!confirmed) confirmed = (await prompts({
|
|
5805
|
+
type: "confirm",
|
|
5806
|
+
name: "confirmed",
|
|
5807
|
+
message: "Do you want to upgrade these packages?",
|
|
5808
|
+
initial: true
|
|
5809
|
+
})).confirmed;
|
|
5810
|
+
if (!confirmed) {
|
|
5811
|
+
console.log("Upgrade cancelled.");
|
|
5812
|
+
return;
|
|
5813
|
+
}
|
|
5814
|
+
const { packageManager } = await detectPackageManager(cwd, packageJson);
|
|
5815
|
+
const prodUpgrades = upgrades.filter((u) => u.depType === "prod").map((u) => `${u.name}@${u.latest}`);
|
|
5816
|
+
const devUpgrades = upgrades.filter((u) => u.depType === "dev").map((u) => `${u.name}@${u.latest}`);
|
|
5817
|
+
const installSpinner = yoctoSpinner({ text: "installing updates..." }).start();
|
|
5818
|
+
try {
|
|
5819
|
+
if (prodUpgrades.length > 0) await installDependencies({
|
|
5820
|
+
dependencies: prodUpgrades,
|
|
5821
|
+
packageManager,
|
|
5822
|
+
cwd,
|
|
5823
|
+
type: "prod"
|
|
5824
|
+
});
|
|
5825
|
+
if (devUpgrades.length > 0) await installDependencies({
|
|
5826
|
+
dependencies: devUpgrades,
|
|
5827
|
+
packageManager,
|
|
5828
|
+
cwd,
|
|
5829
|
+
type: "dev"
|
|
5830
|
+
});
|
|
5831
|
+
installSpinner.stop();
|
|
5832
|
+
console.log(chalk.green("Successfully upgraded better-auth packages."));
|
|
5833
|
+
} catch (error) {
|
|
5834
|
+
installSpinner.stop();
|
|
5835
|
+
console.error("Failed to install updates:", error);
|
|
5836
|
+
process.exit(1);
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5839
|
+
const upgrade = new Command("upgrade").description("Upgrade better-auth packages to their latest versions").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("-y, --yes", "automatically accept and upgrade without prompting", false).action(upgradeAction);
|
|
5840
|
+
|
|
5675
5841
|
//#endregion
|
|
5676
5842
|
//#region src/index.ts
|
|
5677
5843
|
process.on("SIGINT", () => process.exit(0));
|
|
@@ -5684,7 +5850,7 @@ async function main() {
|
|
|
5684
5850
|
packageInfo = await getPackageInfo();
|
|
5685
5851
|
cliVersion = packageInfo.version || "1.1.2";
|
|
5686
5852
|
} catch {}
|
|
5687
|
-
program.addCommand(init).addCommand(migrate).addCommand(generate).addCommand(generateSecret).addCommand(info).addCommand(login).addCommand(logout).addCommand(mcp).version(cliVersion).description("Better Auth CLI").action(() => program.help());
|
|
5853
|
+
program.addCommand(init).addCommand(migrate).addCommand(generate).addCommand(generateSecret).addCommand(info).addCommand(login).addCommand(logout).addCommand(mcp).addCommand(upgrade).version(cliVersion).description("Better Auth CLI").action(() => program.help());
|
|
5688
5854
|
program.parse();
|
|
5689
5855
|
}
|
|
5690
5856
|
main().catch((error) => {
|