auth 1.7.0 → 1.7.2
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/api.d.mts +6 -5
- package/dist/api.mjs +15 -2
- package/dist/index.mjs +48 -9
- package/package.json +5 -5
package/dist/api.d.mts
CHANGED
|
@@ -7,6 +7,11 @@ interface SchemaGeneratorResult {
|
|
|
7
7
|
fileName: string;
|
|
8
8
|
overwrite?: boolean;
|
|
9
9
|
append?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Schema changes the generated code contains but no database can apply
|
|
12
|
+
* without corrupting the rows it already holds.
|
|
13
|
+
*/
|
|
14
|
+
unsafeChanges?: string[];
|
|
10
15
|
}
|
|
11
16
|
interface SchemaGenerator {
|
|
12
17
|
<Options extends BetterAuthOptions>(opts: {
|
|
@@ -26,11 +31,7 @@ declare const generateSchema: (opts: {
|
|
|
26
31
|
adapter: DBAdapter$1;
|
|
27
32
|
file?: string;
|
|
28
33
|
options: BetterAuthOptions;
|
|
29
|
-
}) => Promise<SchemaGeneratorResult
|
|
30
|
-
code: string;
|
|
31
|
-
fileName: string;
|
|
32
|
-
overwrite: boolean | undefined;
|
|
33
|
-
}>;
|
|
34
|
+
}) => Promise<SchemaGeneratorResult>;
|
|
34
35
|
//#endregion
|
|
35
36
|
//#region src/generators/drizzle.d.ts
|
|
36
37
|
declare const generateDrizzleSchema: SchemaGenerator;
|
package/dist/api.mjs
CHANGED
|
@@ -321,11 +321,24 @@ function generateImport({ databaseType, tables, options, schemaName }) {
|
|
|
321
321
|
}
|
|
322
322
|
//#endregion
|
|
323
323
|
//#region src/generators/kysely.ts
|
|
324
|
+
function commentBanner(unsafeChanges) {
|
|
325
|
+
const rule = `-- ${"-".repeat(77)}`;
|
|
326
|
+
const lines = [
|
|
327
|
+
rule,
|
|
328
|
+
"-- DO NOT RUN THIS SCRIPT AS IT IS.",
|
|
329
|
+
"-- Applying it to a populated database corrupts the rows it touches:"
|
|
330
|
+
];
|
|
331
|
+
for (const change of unsafeChanges) lines.push("--", `-- ${change}`);
|
|
332
|
+
lines.push(rule, "");
|
|
333
|
+
return lines.join("\n");
|
|
334
|
+
}
|
|
324
335
|
const generateKyselySchema = async ({ options, file }) => {
|
|
325
|
-
const { compileMigrations } = await getMigrations(options);
|
|
336
|
+
const { compileMigrations, unsafeChanges } = await getMigrations(options, { throwOnUnsafe: false });
|
|
326
337
|
const migrations = await compileMigrations();
|
|
338
|
+
const code = migrations.trim() === ";" ? "" : migrations;
|
|
327
339
|
return {
|
|
328
|
-
code:
|
|
340
|
+
code: unsafeChanges.length ? `${commentBanner(unsafeChanges)}${code}` : code,
|
|
341
|
+
unsafeChanges,
|
|
329
342
|
fileName: file || `./better-auth_migrations/${(/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-")}.sql`
|
|
330
343
|
};
|
|
331
344
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { APIError, BetterAuthError } from "@better-auth/core/error";
|
|
2
3
|
import { Command } from "commander";
|
|
3
4
|
import { exec, execSync, spawn } from "node:child_process";
|
|
4
5
|
import * as fs$2 from "node:fs";
|
|
@@ -10,7 +11,6 @@ import path, { join } from "node:path";
|
|
|
10
11
|
import chalk from "chalk";
|
|
11
12
|
import prompts from "prompts";
|
|
12
13
|
import yoctoSpinner from "yocto-spinner";
|
|
13
|
-
import { APIError, BetterAuthError } from "@better-auth/core/error";
|
|
14
14
|
import { betterAuth } from "better-auth";
|
|
15
15
|
import * as z from "zod";
|
|
16
16
|
import babelPresetReact from "@babel/preset-react";
|
|
@@ -25,7 +25,7 @@ import { capitalizeFirstLetter, toSnakeCase } from "@better-auth/core/utils/stri
|
|
|
25
25
|
import { initGetFieldName, initGetModelName } from "better-auth/adapters";
|
|
26
26
|
import { getAuthTables } from "better-auth/db";
|
|
27
27
|
import prettier, { format } from "prettier";
|
|
28
|
-
import { getMigrations } from "better-auth/db/migration";
|
|
28
|
+
import { UnsafeMigrationError, getMigrations } from "better-auth/db/migration";
|
|
29
29
|
import { produceSchema } from "@mrleebo/prisma-ast";
|
|
30
30
|
import Crypto from "node:crypto";
|
|
31
31
|
import open from "open";
|
|
@@ -1667,11 +1667,24 @@ function generateImport({ databaseType, tables, options, schemaName }) {
|
|
|
1667
1667
|
}
|
|
1668
1668
|
//#endregion
|
|
1669
1669
|
//#region src/generators/kysely.ts
|
|
1670
|
+
function commentBanner(unsafeChanges) {
|
|
1671
|
+
const rule = `-- ${"-".repeat(77)}`;
|
|
1672
|
+
const lines = [
|
|
1673
|
+
rule,
|
|
1674
|
+
"-- DO NOT RUN THIS SCRIPT AS IT IS.",
|
|
1675
|
+
"-- Applying it to a populated database corrupts the rows it touches:"
|
|
1676
|
+
];
|
|
1677
|
+
for (const change of unsafeChanges) lines.push("--", `-- ${change}`);
|
|
1678
|
+
lines.push(rule, "");
|
|
1679
|
+
return lines.join("\n");
|
|
1680
|
+
}
|
|
1670
1681
|
const generateKyselySchema = async ({ options, file }) => {
|
|
1671
|
-
const { compileMigrations } = await getMigrations(options);
|
|
1682
|
+
const { compileMigrations, unsafeChanges } = await getMigrations(options, { throwOnUnsafe: false });
|
|
1672
1683
|
const migrations = await compileMigrations();
|
|
1684
|
+
const code = migrations.trim() === ";" ? "" : migrations;
|
|
1673
1685
|
return {
|
|
1674
|
-
code:
|
|
1686
|
+
code: unsafeChanges.length ? `${commentBanner(unsafeChanges)}${code}` : code,
|
|
1687
|
+
unsafeChanges,
|
|
1675
1688
|
fileName: file || `./better-auth_migrations/${(/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-")}.sql`
|
|
1676
1689
|
};
|
|
1677
1690
|
};
|
|
@@ -2278,6 +2291,11 @@ async function generateAction(opts) {
|
|
|
2278
2291
|
options: config
|
|
2279
2292
|
});
|
|
2280
2293
|
spinner.stop();
|
|
2294
|
+
if (schema.unsafeChanges?.length) {
|
|
2295
|
+
console.warn(chalk.red.bold(`⚠ ${schema.unsafeChanges.length} ${schema.unsafeChanges.length === 1 ? "change in this schema corrupts" : "changes in this schema corrupt"} a populated database.`));
|
|
2296
|
+
for (const change of schema.unsafeChanges) console.warn(chalk.red(`-> ${change}`));
|
|
2297
|
+
console.warn(chalk.red.bold("The generated script carries the same warning. Fix the reported columns before you run it."));
|
|
2298
|
+
}
|
|
2281
2299
|
if (!schema.code) {
|
|
2282
2300
|
await removeGeneratedStub();
|
|
2283
2301
|
console.log("Your schema is already up to date.");
|
|
@@ -2955,7 +2973,7 @@ function installDependencies({ dependencies, packageManager, cwd, type = "prod",
|
|
|
2955
2973
|
}
|
|
2956
2974
|
//#endregion
|
|
2957
2975
|
//#region src/version.ts
|
|
2958
|
-
const cliVersion = "1.7.
|
|
2976
|
+
const cliVersion = "1.7.2";
|
|
2959
2977
|
//#endregion
|
|
2960
2978
|
//#region src/commands/init/configs/frameworks.config.ts
|
|
2961
2979
|
const FRAMEWORKS = [
|
|
@@ -4923,7 +4941,7 @@ const tempPluginsConfig = {
|
|
|
4923
4941
|
{
|
|
4924
4942
|
flag: "siwe-email-domain-name",
|
|
4925
4943
|
question: "What is the email domain name?",
|
|
4926
|
-
description: "
|
|
4944
|
+
description: "A custom email domain for wallet-derived addresses.",
|
|
4927
4945
|
skip: "prompt",
|
|
4928
4946
|
argument: {
|
|
4929
4947
|
index: 0,
|
|
@@ -7334,7 +7352,27 @@ async function migrateAction(opts) {
|
|
|
7334
7352
|
process.exit(1);
|
|
7335
7353
|
}
|
|
7336
7354
|
const spinner = yoctoSpinner({ text: "preparing migration..." }).start();
|
|
7337
|
-
|
|
7355
|
+
let plan;
|
|
7356
|
+
try {
|
|
7357
|
+
plan = await getMigrations(config);
|
|
7358
|
+
} catch (error) {
|
|
7359
|
+
spinner.stop();
|
|
7360
|
+
if (!(error instanceof UnsafeMigrationError)) throw error;
|
|
7361
|
+
console.error(chalk.red("The migration was refused, and nothing ran."));
|
|
7362
|
+
console.error(error.message);
|
|
7363
|
+
console.error(`Run ${chalk.yellow("npx auth@latest generate")} to read the statements without executing them.`);
|
|
7364
|
+
try {
|
|
7365
|
+
await (await createTelemetry(config)).publish({
|
|
7366
|
+
type: "cli_migrate",
|
|
7367
|
+
payload: {
|
|
7368
|
+
outcome: "unsafe_change",
|
|
7369
|
+
config: await getTelemetryAuthConfig(config)
|
|
7370
|
+
}
|
|
7371
|
+
});
|
|
7372
|
+
} catch {}
|
|
7373
|
+
process.exit(1);
|
|
7374
|
+
}
|
|
7375
|
+
const { toBeAdded, toBeAddedIndexes, toBeCreated, runMigrations } = plan;
|
|
7338
7376
|
if (!toBeAdded.length && !toBeAddedIndexes.length && !toBeCreated.length) {
|
|
7339
7377
|
spinner.stop();
|
|
7340
7378
|
console.log("🚀 No migrations needed.");
|
|
@@ -7529,10 +7567,11 @@ process.on("SIGTERM", () => process.exit(0));
|
|
|
7529
7567
|
async function main() {
|
|
7530
7568
|
const program = new Command("better-auth");
|
|
7531
7569
|
program.addCommand(ai).addCommand(createAdmin).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());
|
|
7532
|
-
program.
|
|
7570
|
+
await program.parseAsync();
|
|
7533
7571
|
}
|
|
7534
7572
|
main().catch((error) => {
|
|
7535
|
-
|
|
7573
|
+
if (error instanceof BetterAuthError) console.error(error.message);
|
|
7574
|
+
else console.error("Error running Better Auth CLI:", error);
|
|
7536
7575
|
process.exit(1);
|
|
7537
7576
|
});
|
|
7538
7577
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auth",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "The CLI for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"semver": "^7.8.4",
|
|
65
65
|
"yocto-spinner": "^1.2.0",
|
|
66
66
|
"zod": "^4.3.6",
|
|
67
|
-
"@better-auth/core": "1.7.
|
|
68
|
-
"@better-auth/telemetry": "1.7.
|
|
69
|
-
"better-auth": "1.7.
|
|
67
|
+
"@better-auth/core": "1.7.2",
|
|
68
|
+
"@better-auth/telemetry": "1.7.2",
|
|
69
|
+
"better-auth": "1.7.2"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/better-sqlite3": "^7.6.13",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"tsx": "^4.21.0",
|
|
79
79
|
"type-fest": "^5.7.0",
|
|
80
80
|
"typescript": "^6.0.3",
|
|
81
|
-
"@better-auth/passkey": "1.7.
|
|
81
|
+
"@better-auth/passkey": "1.7.2"
|
|
82
82
|
},
|
|
83
83
|
"scripts": {
|
|
84
84
|
"build": "tsdown",
|