@proofkit/better-auth 0.3.0 → 0.3.1-beta.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/esm/adapter.d.ts +3 -3
- package/dist/esm/adapter.js +45 -24
- package/dist/esm/adapter.js.map +1 -1
- package/dist/esm/better-auth-cli/utils/add-svelte-kit-env-modules.js +4 -12
- package/dist/esm/better-auth-cli/utils/add-svelte-kit-env-modules.js.map +1 -1
- package/dist/esm/better-auth-cli/utils/get-config.js +12 -21
- package/dist/esm/better-auth-cli/utils/get-config.js.map +1 -1
- package/dist/esm/better-auth-cli/utils/get-tsconfig-info.js +4 -11
- package/dist/esm/better-auth-cli/utils/get-tsconfig-info.js.map +1 -1
- package/dist/esm/cli/index.js +9 -23
- package/dist/esm/cli/index.js.map +1 -1
- package/dist/esm/migrate.d.ts +2 -2
- package/dist/esm/migrate.js +58 -49
- package/dist/esm/migrate.js.map +1 -1
- package/dist/esm/odata/index.d.ts +6 -6
- package/dist/esm/odata/index.js +18 -60
- package/dist/esm/odata/index.js.map +1 -1
- package/package.json +7 -5
- package/src/adapter.ts +55 -41
- package/src/better-auth-cli/utils/add-svelte-kit-env-modules.ts +68 -80
- package/src/better-auth-cli/utils/get-config.ts +16 -30
- package/src/better-auth-cli/utils/get-tsconfig-info.ts +12 -20
- package/src/cli/index.ts +10 -29
- package/src/index.ts +1 -0
- package/src/migrate.ts +68 -77
- package/src/odata/index.ts +29 -73
package/src/adapter.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
CleanedWhere,
|
|
3
|
-
createAdapter,
|
|
4
|
-
type AdapterDebugLogs,
|
|
5
|
-
} from "better-auth/adapters";
|
|
6
|
-
import { createRawFetch, type FmOdataConfig } from "./odata";
|
|
7
|
-
import { prettifyError, z } from "zod/v4";
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: library code */
|
|
8
2
|
import { logger } from "better-auth";
|
|
3
|
+
import { type AdapterDebugLogs, type CleanedWhere, createAdapter } from "better-auth/adapters";
|
|
9
4
|
import buildQuery from "odata-query";
|
|
5
|
+
import { prettifyError, z } from "zod/v4";
|
|
6
|
+
import { createRawFetch, type FmOdataConfig } from "./odata";
|
|
10
7
|
|
|
11
8
|
const configSchema = z.object({
|
|
12
9
|
debugLogs: z.unknown().optional(),
|
|
13
10
|
usePlural: z.boolean().optional(),
|
|
14
11
|
odata: z.object({
|
|
15
12
|
serverUrl: z.url(),
|
|
16
|
-
auth: z.union([
|
|
17
|
-
z.object({ username: z.string(), password: z.string() }),
|
|
18
|
-
z.object({ apiKey: z.string() }),
|
|
19
|
-
]),
|
|
13
|
+
auth: z.union([z.object({ username: z.string(), password: z.string() }), z.object({ apiKey: z.string() })]),
|
|
20
14
|
database: z.string().endsWith(".fmp12"),
|
|
21
15
|
}),
|
|
22
16
|
});
|
|
@@ -37,9 +31,9 @@ interface FileMakerAdapterConfig {
|
|
|
37
31
|
odata: FmOdataConfig;
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
export
|
|
34
|
+
export interface AdapterOptions {
|
|
41
35
|
config: FileMakerAdapterConfig;
|
|
42
|
-
}
|
|
36
|
+
}
|
|
43
37
|
|
|
44
38
|
const defaultConfig: Required<FileMakerAdapterConfig> = {
|
|
45
39
|
debugLogs: false,
|
|
@@ -51,6 +45,10 @@ const defaultConfig: Required<FileMakerAdapterConfig> = {
|
|
|
51
45
|
},
|
|
52
46
|
};
|
|
53
47
|
|
|
48
|
+
// Regex patterns for field validation and ISO date detection
|
|
49
|
+
const FIELD_SPECIAL_CHARS_REGEX = /[\s_]/;
|
|
50
|
+
const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
|
|
51
|
+
|
|
54
52
|
/**
|
|
55
53
|
* Parse the where clause to an OData filter string.
|
|
56
54
|
* @param where - The where clause to parse.
|
|
@@ -58,29 +56,42 @@ const defaultConfig: Required<FileMakerAdapterConfig> = {
|
|
|
58
56
|
* @internal
|
|
59
57
|
*/
|
|
60
58
|
export function parseWhere(where?: CleanedWhere[]): string {
|
|
61
|
-
if (!where || where.length === 0)
|
|
59
|
+
if (!where || where.length === 0) {
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
62
|
|
|
63
63
|
// Helper to quote field names with special chars or if field is 'id'
|
|
64
64
|
function quoteField(field: string, value?: any) {
|
|
65
65
|
// Never quote for null or date values (per test expectations)
|
|
66
|
-
if (value === null || value instanceof Date)
|
|
66
|
+
if (value === null || value instanceof Date) {
|
|
67
|
+
return field;
|
|
68
|
+
}
|
|
67
69
|
// Always quote if field is 'id' or has space or underscore
|
|
68
|
-
if (field === "id" ||
|
|
70
|
+
if (field === "id" || FIELD_SPECIAL_CHARS_REGEX.test(field)) {
|
|
71
|
+
return `"${field}"`;
|
|
72
|
+
}
|
|
69
73
|
return field;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
// Helper to format values for OData
|
|
73
77
|
function formatValue(value: any): string {
|
|
74
|
-
if (value === null)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
+
if (value === null) {
|
|
79
|
+
return "null";
|
|
80
|
+
}
|
|
81
|
+
if (typeof value === "boolean") {
|
|
82
|
+
return value ? "true" : "false";
|
|
83
|
+
}
|
|
84
|
+
if (value instanceof Date) {
|
|
85
|
+
return value.toISOString();
|
|
86
|
+
}
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
return `(${value.map(formatValue).join(",")})`;
|
|
89
|
+
}
|
|
78
90
|
|
|
79
91
|
// Handle strings - check if it's an ISO date string first
|
|
80
92
|
if (typeof value === "string") {
|
|
81
93
|
// Check if it's an ISO date string (YYYY-MM-DDTHH:mm:ss.sssZ format)
|
|
82
|
-
|
|
83
|
-
if (isoDateRegex.test(value)) {
|
|
94
|
+
if (ISO_DATE_REGEX.test(value)) {
|
|
84
95
|
return value; // Return ISO date strings without quotes
|
|
85
96
|
}
|
|
86
97
|
return `'${value.replace(/'/g, "''")}'`; // Regular strings get quotes
|
|
@@ -103,7 +114,9 @@ export function parseWhere(where?: CleanedWhere[]): string {
|
|
|
103
114
|
const clauses: string[] = [];
|
|
104
115
|
for (let i = 0; i < where.length; i++) {
|
|
105
116
|
const cond = where[i];
|
|
106
|
-
if (!cond)
|
|
117
|
+
if (!cond) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
107
120
|
const field = quoteField(cond.field, cond.value);
|
|
108
121
|
let clause = "";
|
|
109
122
|
switch (cond.operator) {
|
|
@@ -113,13 +126,11 @@ export function parseWhere(where?: CleanedWhere[]): string {
|
|
|
113
126
|
case "lte":
|
|
114
127
|
case "gt":
|
|
115
128
|
case "gte":
|
|
116
|
-
clause = `${field} ${opMap[cond.operator
|
|
129
|
+
clause = `${field} ${opMap[cond.operator]} ${formatValue(cond.value)}`;
|
|
117
130
|
break;
|
|
118
131
|
case "in":
|
|
119
132
|
if (Array.isArray(cond.value)) {
|
|
120
|
-
clause = cond.value
|
|
121
|
-
.map((v) => `${field} eq ${formatValue(v)}`)
|
|
122
|
-
.join(" or ");
|
|
133
|
+
clause = cond.value.map((v) => `${field} eq ${formatValue(v)}`).join(" or ");
|
|
123
134
|
clause = `(${clause})`;
|
|
124
135
|
}
|
|
125
136
|
break;
|
|
@@ -144,9 +155,7 @@ export function parseWhere(where?: CleanedWhere[]): string {
|
|
|
144
155
|
return clauses.join(" ");
|
|
145
156
|
}
|
|
146
157
|
|
|
147
|
-
export const FileMakerAdapter = (
|
|
148
|
-
_config: FileMakerAdapterConfig = defaultConfig,
|
|
149
|
-
) => {
|
|
158
|
+
export const FileMakerAdapter = (_config: FileMakerAdapterConfig = defaultConfig) => {
|
|
150
159
|
const parsed = configSchema.loose().safeParse(_config);
|
|
151
160
|
|
|
152
161
|
if (!parsed.success) {
|
|
@@ -154,7 +163,7 @@ export const FileMakerAdapter = (
|
|
|
154
163
|
}
|
|
155
164
|
const config = parsed.data;
|
|
156
165
|
|
|
157
|
-
const { fetch
|
|
166
|
+
const { fetch } = createRawFetch({
|
|
158
167
|
...config.odata,
|
|
159
168
|
logging: config.debugLogs ? "verbose" : "none",
|
|
160
169
|
});
|
|
@@ -170,10 +179,9 @@ export const FileMakerAdapter = (
|
|
|
170
179
|
supportsBooleans: false, // Whether the database supports booleans. (Default: true)
|
|
171
180
|
supportsNumericIds: false, // Whether the database supports auto-incrementing numeric IDs. (Default: true)
|
|
172
181
|
},
|
|
173
|
-
adapter: (
|
|
182
|
+
adapter: () => {
|
|
174
183
|
return {
|
|
175
|
-
|
|
176
|
-
create: async ({ data, model, select }) => {
|
|
184
|
+
create: async ({ data, model }) => {
|
|
177
185
|
if (model === "session") {
|
|
178
186
|
console.log("session", data);
|
|
179
187
|
}
|
|
@@ -232,9 +240,7 @@ export const FileMakerAdapter = (
|
|
|
232
240
|
const query = buildQuery({
|
|
233
241
|
top: limit,
|
|
234
242
|
skip: offset,
|
|
235
|
-
orderBy: sortBy
|
|
236
|
-
? `${sortBy.field} ${sortBy.direction ?? "asc"}`
|
|
237
|
-
: undefined,
|
|
243
|
+
orderBy: sortBy ? `${sortBy.field} ${sortBy.direction ?? "asc"}` : undefined,
|
|
238
244
|
filter: filter.length > 0 ? filter : undefined,
|
|
239
245
|
});
|
|
240
246
|
logger.debug("QUERY", query);
|
|
@@ -303,7 +309,9 @@ export const FileMakerAdapter = (
|
|
|
303
309
|
const res = await fetch(`/${model}('${id}')`, {
|
|
304
310
|
method: "DELETE",
|
|
305
311
|
});
|
|
306
|
-
if (!res.error)
|
|
312
|
+
if (!res.error) {
|
|
313
|
+
deleted++;
|
|
314
|
+
}
|
|
307
315
|
}
|
|
308
316
|
return deleted;
|
|
309
317
|
},
|
|
@@ -324,14 +332,18 @@ export const FileMakerAdapter = (
|
|
|
324
332
|
logger.debug("EXISTING", existing.data);
|
|
325
333
|
|
|
326
334
|
const id = existing.data?.value?.[0]?.id;
|
|
327
|
-
if (!id)
|
|
335
|
+
if (!id) {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
328
338
|
|
|
329
339
|
const patchRes = await fetch(`/${model}('${id}')`, {
|
|
330
340
|
method: "PATCH",
|
|
331
341
|
body: update,
|
|
332
342
|
});
|
|
333
343
|
logger.debug("PATCH RES", patchRes.data);
|
|
334
|
-
if (patchRes.error)
|
|
344
|
+
if (patchRes.error) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
335
347
|
|
|
336
348
|
// Read back the updated record
|
|
337
349
|
const readBack = await fetch(`/${model}('${id}')`, {
|
|
@@ -361,7 +373,9 @@ export const FileMakerAdapter = (
|
|
|
361
373
|
method: "PATCH",
|
|
362
374
|
body: update,
|
|
363
375
|
});
|
|
364
|
-
if (!res.error)
|
|
376
|
+
if (!res.error) {
|
|
377
|
+
updated++;
|
|
378
|
+
}
|
|
365
379
|
}
|
|
366
380
|
return updated as any;
|
|
367
381
|
},
|
|
@@ -1,108 +1,96 @@
|
|
|
1
1
|
export function addSvelteKitEnvModules(aliases: Record<string, string>) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
createDynamicEnvModule(),
|
|
7
|
-
);
|
|
8
|
-
aliases["$env/static/private"] = createDataUriModule(
|
|
9
|
-
createStaticEnvModule(filterPrivateEnv("PUBLIC_", "")),
|
|
10
|
-
);
|
|
11
|
-
aliases["$env/static/public"] = createDataUriModule(
|
|
12
|
-
createStaticEnvModule(filterPublicEnv("PUBLIC_", "")),
|
|
13
|
-
);
|
|
2
|
+
aliases["$env/dynamic/private"] = createDataUriModule(createDynamicEnvModule());
|
|
3
|
+
aliases["$env/dynamic/public"] = createDataUriModule(createDynamicEnvModule());
|
|
4
|
+
aliases["$env/static/private"] = createDataUriModule(createStaticEnvModule(filterPrivateEnv("PUBLIC_", "")));
|
|
5
|
+
aliases["$env/static/public"] = createDataUriModule(createStaticEnvModule(filterPublicEnv("PUBLIC_", "")));
|
|
14
6
|
}
|
|
15
7
|
|
|
16
8
|
function createDataUriModule(module: string) {
|
|
17
|
-
|
|
9
|
+
return `data:text/javascript;charset=utf-8,${encodeURIComponent(module)}`;
|
|
18
10
|
}
|
|
19
11
|
|
|
20
12
|
function createStaticEnvModule(env: Record<string, string>) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const declarations = Object.keys(env)
|
|
14
|
+
.filter((k) => validIdentifier.test(k) && !reserved.has(k))
|
|
15
|
+
.map((k) => `export const ${k} = ${JSON.stringify(env[k])};`);
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
return `
|
|
26
18
|
${declarations.join("\n")}
|
|
27
19
|
// jiti dirty hack: .unknown
|
|
28
20
|
`;
|
|
29
21
|
}
|
|
30
22
|
|
|
31
23
|
function createDynamicEnvModule() {
|
|
32
|
-
|
|
24
|
+
return `
|
|
33
25
|
export const env = process.env;
|
|
34
26
|
// jiti dirty hack: .unknown
|
|
35
27
|
`;
|
|
36
28
|
}
|
|
37
29
|
|
|
38
30
|
export function filterPrivateEnv(publicPrefix: string, privatePrefix: string) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
),
|
|
45
|
-
) as Record<string, string>;
|
|
31
|
+
return Object.fromEntries(
|
|
32
|
+
Object.entries(process.env).filter(
|
|
33
|
+
([k]) => k.startsWith(privatePrefix) && (publicPrefix === "" || !k.startsWith(publicPrefix)),
|
|
34
|
+
),
|
|
35
|
+
) as Record<string, string>;
|
|
46
36
|
}
|
|
47
37
|
|
|
48
38
|
export function filterPublicEnv(publicPrefix: string, privatePrefix: string) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
),
|
|
55
|
-
) as Record<string, string>;
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
Object.entries(process.env).filter(
|
|
41
|
+
([k]) => k.startsWith(publicPrefix) && (privatePrefix === "" || !k.startsWith(privatePrefix)),
|
|
42
|
+
),
|
|
43
|
+
) as Record<string, string>;
|
|
56
44
|
}
|
|
57
45
|
|
|
58
46
|
const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
59
47
|
const reserved = new Set([
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
48
|
+
"do",
|
|
49
|
+
"if",
|
|
50
|
+
"in",
|
|
51
|
+
"for",
|
|
52
|
+
"let",
|
|
53
|
+
"new",
|
|
54
|
+
"try",
|
|
55
|
+
"var",
|
|
56
|
+
"case",
|
|
57
|
+
"else",
|
|
58
|
+
"enum",
|
|
59
|
+
"eval",
|
|
60
|
+
"null",
|
|
61
|
+
"this",
|
|
62
|
+
"true",
|
|
63
|
+
"void",
|
|
64
|
+
"with",
|
|
65
|
+
"await",
|
|
66
|
+
"break",
|
|
67
|
+
"catch",
|
|
68
|
+
"class",
|
|
69
|
+
"const",
|
|
70
|
+
"false",
|
|
71
|
+
"super",
|
|
72
|
+
"throw",
|
|
73
|
+
"while",
|
|
74
|
+
"yield",
|
|
75
|
+
"delete",
|
|
76
|
+
"export",
|
|
77
|
+
"import",
|
|
78
|
+
"public",
|
|
79
|
+
"return",
|
|
80
|
+
"static",
|
|
81
|
+
"switch",
|
|
82
|
+
"typeof",
|
|
83
|
+
"default",
|
|
84
|
+
"extends",
|
|
85
|
+
"finally",
|
|
86
|
+
"package",
|
|
87
|
+
"private",
|
|
88
|
+
"continue",
|
|
89
|
+
"debugger",
|
|
90
|
+
"function",
|
|
91
|
+
"arguments",
|
|
92
|
+
"interface",
|
|
93
|
+
"protected",
|
|
94
|
+
"implements",
|
|
95
|
+
"instanceof",
|
|
108
96
|
]);
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { logger } from "better-auth";
|
|
4
|
-
import path from "path";
|
|
5
|
-
// @ts-expect-error not typed
|
|
6
|
-
import babelPresetTypeScript from "@babel/preset-typescript";
|
|
1
|
+
import fs, { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
7
3
|
// @ts-expect-error not typed
|
|
8
4
|
import babelPresetReact from "@babel/preset-react";
|
|
9
|
-
|
|
10
|
-
import
|
|
5
|
+
// @ts-expect-error not typed
|
|
6
|
+
import babelPresetTypeScript from "@babel/preset-typescript";
|
|
7
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
8
|
+
import { BetterAuthError, logger } from "better-auth";
|
|
9
|
+
import { loadConfig } from "c12";
|
|
11
10
|
import { addSvelteKitEnvModules } from "./add-svelte-kit-env-modules";
|
|
12
11
|
import { getTsconfigInfo } from "./get-tsconfig-info";
|
|
13
12
|
|
|
14
|
-
let possiblePaths = [
|
|
15
|
-
"auth.ts",
|
|
16
|
-
"auth.tsx",
|
|
17
|
-
"auth.js",
|
|
18
|
-
"auth.jsx",
|
|
19
|
-
"auth.server.js",
|
|
20
|
-
"auth.server.ts",
|
|
21
|
-
];
|
|
13
|
+
let possiblePaths = ["auth.ts", "auth.tsx", "auth.js", "auth.jsx", "auth.server.js", "auth.server.ts"];
|
|
22
14
|
|
|
23
15
|
possiblePaths = [
|
|
24
16
|
...possiblePaths,
|
|
@@ -47,10 +39,7 @@ function getPathAliases(cwd: string): Record<string, string> | null {
|
|
|
47
39
|
for (const aliasedPath of aliasPaths) {
|
|
48
40
|
const resolvedBaseUrl = path.join(cwd, baseUrl);
|
|
49
41
|
const finalAlias = alias.slice(-1) === "*" ? alias.slice(0, -1) : alias;
|
|
50
|
-
const finalAliasedPath =
|
|
51
|
-
aliasedPath.slice(-1) === "*"
|
|
52
|
-
? aliasedPath.slice(0, -1)
|
|
53
|
-
: aliasedPath;
|
|
42
|
+
const finalAliasedPath = aliasedPath.slice(-1) === "*" ? aliasedPath.slice(0, -1) : aliasedPath;
|
|
54
43
|
|
|
55
44
|
result[finalAlias || ""] = path.join(resolvedBaseUrl, finalAliasedPath);
|
|
56
45
|
}
|
|
@@ -99,7 +88,9 @@ export async function getConfig({
|
|
|
99
88
|
let configFile: BetterAuthOptions | null = null;
|
|
100
89
|
if (configPath) {
|
|
101
90
|
let resolvedPath: string = path.join(cwd, configPath);
|
|
102
|
-
if (existsSync(configPath))
|
|
91
|
+
if (existsSync(configPath)) {
|
|
92
|
+
resolvedPath = configPath; // If the configPath is a file, use it as is, as it means the path wasn't relative.
|
|
93
|
+
}
|
|
103
94
|
const { config } = await loadConfig<{
|
|
104
95
|
auth: {
|
|
105
96
|
options: BetterAuthOptions;
|
|
@@ -112,7 +103,7 @@ export async function getConfig({
|
|
|
112
103
|
dotenv: true,
|
|
113
104
|
jitiOptions: jitiOptions(cwd),
|
|
114
105
|
});
|
|
115
|
-
if (!config.auth
|
|
106
|
+
if (!(config.auth || config.default)) {
|
|
116
107
|
if (shouldThrowOnError) {
|
|
117
108
|
throw new Error(
|
|
118
109
|
`Couldn't read your auth config in ${resolvedPath}. Make sure to default export your auth instance or to export as a variable named auth.`,
|
|
@@ -142,8 +133,7 @@ export async function getConfig({
|
|
|
142
133
|
});
|
|
143
134
|
const hasConfig = Object.keys(config).length > 0;
|
|
144
135
|
if (hasConfig) {
|
|
145
|
-
configFile =
|
|
146
|
-
config.auth?.options || config.default?.options || null;
|
|
136
|
+
configFile = config.auth?.options || config.default?.options || null;
|
|
147
137
|
if (!configFile) {
|
|
148
138
|
if (shouldThrowOnError) {
|
|
149
139
|
throw new Error(
|
|
@@ -165,9 +155,7 @@ export async function getConfig({
|
|
|
165
155
|
e &&
|
|
166
156
|
"message" in e &&
|
|
167
157
|
typeof e.message === "string" &&
|
|
168
|
-
e.message.includes(
|
|
169
|
-
"This module cannot be imported from a Client Component module",
|
|
170
|
-
)
|
|
158
|
+
e.message.includes("This module cannot be imported from a Client Component module")
|
|
171
159
|
) {
|
|
172
160
|
if (shouldThrowOnError) {
|
|
173
161
|
throw new Error(
|
|
@@ -194,9 +182,7 @@ export async function getConfig({
|
|
|
194
182
|
e &&
|
|
195
183
|
"message" in e &&
|
|
196
184
|
typeof e.message === "string" &&
|
|
197
|
-
e.message.includes(
|
|
198
|
-
"This module cannot be imported from a Client Component module",
|
|
199
|
-
)
|
|
185
|
+
e.message.includes("This module cannot be imported from a Client Component module")
|
|
200
186
|
) {
|
|
201
187
|
if (shouldThrowOnError) {
|
|
202
188
|
throw new Error(
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import path from "path";
|
|
1
|
+
import path from "node:path";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
3
|
|
|
4
4
|
export function stripJsonComments(jsonString: string): string {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
)
|
|
9
|
-
.replace(/,(?=\s*[}\]])/g, "");
|
|
5
|
+
return jsonString
|
|
6
|
+
.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => (g ? "" : m))
|
|
7
|
+
.replace(/,(?=\s*[}\]])/g, "");
|
|
10
8
|
}
|
|
11
9
|
export function getTsconfigInfo(cwd?: string, flatPath?: string) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const text = fs.readFileSync(tsConfigPath, "utf-8");
|
|
22
|
-
return JSON.parse(stripJsonComments(text));
|
|
23
|
-
} catch (error) {
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
10
|
+
let tsConfigPath: string;
|
|
11
|
+
if (flatPath) {
|
|
12
|
+
tsConfigPath = flatPath;
|
|
13
|
+
} else {
|
|
14
|
+
tsConfigPath = cwd ? path.join(cwd, "tsconfig.json") : path.join("tsconfig.json");
|
|
15
|
+
}
|
|
16
|
+
const text = fs.readFileSync(tsConfigPath, "utf-8");
|
|
17
|
+
return JSON.parse(stripJsonComments(text));
|
|
26
18
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node --no-warnings
|
|
2
2
|
import { Command } from "@commander-js/extra-typings";
|
|
3
|
-
import fs from "fs-extra";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
executeMigration,
|
|
7
|
-
planMigration,
|
|
8
|
-
prettyPrintMigrationPlan,
|
|
9
|
-
} from "../migrate";
|
|
10
|
-
import { getAdapter, getAuthTables } from "better-auth/db";
|
|
11
|
-
import { getConfig } from "../better-auth-cli/utils/get-config";
|
|
12
3
|
import { logger } from "better-auth";
|
|
13
|
-
import
|
|
4
|
+
import { getAdapter, getAuthTables } from "better-auth/db";
|
|
14
5
|
import chalk from "chalk";
|
|
15
|
-
import
|
|
6
|
+
import fs from "fs-extra";
|
|
7
|
+
import prompts from "prompts";
|
|
8
|
+
import type { AdapterOptions } from "../adapter";
|
|
9
|
+
import { getConfig } from "../better-auth-cli/utils/get-config";
|
|
10
|
+
import { executeMigration, planMigration, prettyPrintMigrationPlan } from "../migrate";
|
|
16
11
|
import { createRawFetch } from "../odata";
|
|
17
12
|
import "dotenv/config";
|
|
18
13
|
|
|
@@ -21,11 +16,7 @@ async function main() {
|
|
|
21
16
|
|
|
22
17
|
program
|
|
23
18
|
.command("migrate", { isDefault: true })
|
|
24
|
-
.option(
|
|
25
|
-
"--cwd <path>",
|
|
26
|
-
"Path to the current working directory",
|
|
27
|
-
process.cwd(),
|
|
28
|
-
)
|
|
19
|
+
.option("--cwd <path>", "Path to the current working directory", process.cwd())
|
|
29
20
|
.option("--config <path>", "Path to the config file")
|
|
30
21
|
.option("-u, --username <username>", "Full Access Username")
|
|
31
22
|
.option("-p, --password <password>", "Full Access Password")
|
|
@@ -55,9 +46,7 @@ async function main() {
|
|
|
55
46
|
});
|
|
56
47
|
|
|
57
48
|
if (adapter.id !== "filemaker") {
|
|
58
|
-
logger.error(
|
|
59
|
-
"This generator is only compatible with the FileMaker adapter.",
|
|
60
|
-
);
|
|
49
|
+
logger.error("This generator is only compatible with the FileMaker adapter.");
|
|
61
50
|
return;
|
|
62
51
|
}
|
|
63
52
|
|
|
@@ -77,11 +66,7 @@ async function main() {
|
|
|
77
66
|
logging: "verbose", // Enable logging for CLI operations
|
|
78
67
|
});
|
|
79
68
|
|
|
80
|
-
const migrationPlan = await planMigration(
|
|
81
|
-
fetch,
|
|
82
|
-
betterAuthSchema,
|
|
83
|
-
adapterConfig.odata.database,
|
|
84
|
-
);
|
|
69
|
+
const migrationPlan = await planMigration(fetch, betterAuthSchema, adapterConfig.odata.database);
|
|
85
70
|
|
|
86
71
|
if (migrationPlan.length === 0) {
|
|
87
72
|
logger.info("No changes to apply. Database is up to date.");
|
|
@@ -92,11 +77,7 @@ async function main() {
|
|
|
92
77
|
prettyPrintMigrationPlan(migrationPlan);
|
|
93
78
|
|
|
94
79
|
if (migrationPlan.length > 0) {
|
|
95
|
-
console.log(
|
|
96
|
-
chalk.gray(
|
|
97
|
-
"💡 Tip: You can use the --yes flag to skip this confirmation.",
|
|
98
|
-
),
|
|
99
|
-
);
|
|
80
|
+
console.log(chalk.gray("💡 Tip: You can use the --yes flag to skip this confirmation."));
|
|
100
81
|
}
|
|
101
82
|
|
|
102
83
|
const { confirm } = await prompts({
|
package/src/index.ts
CHANGED