@proofkit/better-auth 0.1.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/LICENSE.md +21 -0
- package/README.md +11 -0
- package/dist/esm/adapter.d.ts +13 -0
- package/dist/esm/adapter.js +178 -0
- package/dist/esm/adapter.js.map +1 -0
- package/dist/esm/better-auth-cli/utils/add-svelte-kit-env-modules.d.ts +3 -0
- package/dist/esm/better-auth-cli/utils/add-svelte-kit-env-modules.js +101 -0
- package/dist/esm/better-auth-cli/utils/add-svelte-kit-env-modules.js.map +1 -0
- package/dist/esm/better-auth-cli/utils/get-config.d.ts +8 -0
- package/dist/esm/better-auth-cli/utils/get-config.js +177 -0
- package/dist/esm/better-auth-cli/utils/get-config.js.map +1 -0
- package/dist/esm/better-auth-cli/utils/get-tsconfig-info.d.ts +2 -0
- package/dist/esm/better-auth-cli/utils/get-tsconfig-info.js +25 -0
- package/dist/esm/better-auth-cli/utils/get-tsconfig-info.js.map +1 -0
- package/dist/esm/cli/index.d.ts +2 -0
- package/dist/esm/cli/index.js +86 -0
- package/dist/esm/cli/index.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/migrate.d.ts +82 -0
- package/dist/esm/migrate.js +181 -0
- package/dist/esm/migrate.js.map +1 -0
- package/dist/esm/odata/index.d.ts +21 -0
- package/dist/esm/odata/index.js +27 -0
- package/dist/esm/odata/index.js.map +1 -0
- package/package.json +70 -0
- package/src/adapter.ts +221 -0
- package/src/better-auth-cli/README.md +1 -0
- package/src/better-auth-cli/utils/add-svelte-kit-env-modules.ts +108 -0
- package/src/better-auth-cli/utils/get-config.ts +220 -0
- package/src/better-auth-cli/utils/get-tsconfig-info.ts +26 -0
- package/src/cli/index.ts +116 -0
- package/src/index.ts +1 -0
- package/src/migrate.ts +236 -0
- package/src/odata/index.ts +45 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Proof+Geist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @proofkit/better-auth
|
|
2
|
+
|
|
3
|
+
`@proofkit/better-auth` is a tool for generating TypeScript types from FileMaker database schemas, making it easier to work with FileMaker data in modern TypeScript projects.
|
|
4
|
+
|
|
5
|
+
Run the tool directly from the command line:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @proofkit/better-auth@latest
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Check out the full documentation at [proofkit.dev](https://proofkit.dev/docs/better-auth).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CleanedWhere, AdapterDebugLogs } from 'better-auth/adapters';
|
|
2
|
+
import { FmOdataConfig } from './odata.js';
|
|
3
|
+
interface FileMakerAdapterConfig {
|
|
4
|
+
debugLogs?: AdapterDebugLogs;
|
|
5
|
+
usePlural?: boolean;
|
|
6
|
+
odata: FmOdataConfig;
|
|
7
|
+
}
|
|
8
|
+
export type AdapterOptions = {
|
|
9
|
+
config: FileMakerAdapterConfig;
|
|
10
|
+
};
|
|
11
|
+
export declare function parseWhere(where?: CleanedWhere[]): string;
|
|
12
|
+
export declare const FileMakerAdapter: (_config?: FileMakerAdapterConfig) => (options: import('better-auth').BetterAuthOptions) => import('better-auth').Adapter;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createAdapter } from "better-auth/adapters";
|
|
2
|
+
import { FmOdata } from "./odata/index.js";
|
|
3
|
+
import { z, prettifyError } from "zod/v4";
|
|
4
|
+
const configSchema = z.object({
|
|
5
|
+
debugLogs: z.unknown().optional(),
|
|
6
|
+
usePlural: z.boolean().optional(),
|
|
7
|
+
odata: z.object({
|
|
8
|
+
hostname: z.string(),
|
|
9
|
+
auth: z.object({ username: z.string(), password: z.string() }),
|
|
10
|
+
database: z.string().endsWith(".fmp12")
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
const defaultConfig = {
|
|
14
|
+
debugLogs: false,
|
|
15
|
+
usePlural: false,
|
|
16
|
+
odata: {
|
|
17
|
+
hostname: "",
|
|
18
|
+
auth: { username: "", password: "" },
|
|
19
|
+
database: ""
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function parseWhere(where) {
|
|
23
|
+
if (!where || where.length === 0) return "";
|
|
24
|
+
function quoteField(field, value) {
|
|
25
|
+
if (value === null || value instanceof Date) return field;
|
|
26
|
+
if (field === "id" || /[\s_]/.test(field)) return `"${field}"`;
|
|
27
|
+
return field;
|
|
28
|
+
}
|
|
29
|
+
function formatValue(value) {
|
|
30
|
+
if (value === null) return "null";
|
|
31
|
+
if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
|
|
32
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
33
|
+
if (value instanceof Date) return `'${value.toISOString()}'`;
|
|
34
|
+
if (Array.isArray(value)) return `(${value.map(formatValue).join(",")})`;
|
|
35
|
+
return value.toString();
|
|
36
|
+
}
|
|
37
|
+
const opMap = {
|
|
38
|
+
eq: "eq",
|
|
39
|
+
ne: "ne",
|
|
40
|
+
lt: "lt",
|
|
41
|
+
lte: "le",
|
|
42
|
+
gt: "gt",
|
|
43
|
+
gte: "ge"
|
|
44
|
+
};
|
|
45
|
+
const clauses = [];
|
|
46
|
+
for (let i = 0; i < where.length; i++) {
|
|
47
|
+
const cond = where[i];
|
|
48
|
+
if (!cond) continue;
|
|
49
|
+
const field = quoteField(cond.field, cond.value);
|
|
50
|
+
let clause = "";
|
|
51
|
+
switch (cond.operator) {
|
|
52
|
+
case "eq":
|
|
53
|
+
case "ne":
|
|
54
|
+
case "lt":
|
|
55
|
+
case "lte":
|
|
56
|
+
case "gt":
|
|
57
|
+
case "gte":
|
|
58
|
+
clause = `${field} ${opMap[cond.operator]} ${formatValue(cond.value)}`;
|
|
59
|
+
break;
|
|
60
|
+
case "in":
|
|
61
|
+
if (Array.isArray(cond.value)) {
|
|
62
|
+
clause = cond.value.map((v) => `${field} eq ${formatValue(v)}`).join(" or ");
|
|
63
|
+
clause = `(${clause})`;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case "contains":
|
|
67
|
+
clause = `contains(${field}, ${formatValue(cond.value)})`;
|
|
68
|
+
break;
|
|
69
|
+
case "starts_with":
|
|
70
|
+
clause = `startswith(${field}, ${formatValue(cond.value)})`;
|
|
71
|
+
break;
|
|
72
|
+
case "ends_with":
|
|
73
|
+
clause = `endswith(${field}, ${formatValue(cond.value)})`;
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
clause = `${field} eq ${formatValue(cond.value)}`;
|
|
77
|
+
}
|
|
78
|
+
clauses.push(clause);
|
|
79
|
+
if (i < where.length - 1) {
|
|
80
|
+
clauses.push((cond.connector || "and").toLowerCase());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return clauses.join(" ");
|
|
84
|
+
}
|
|
85
|
+
const FileMakerAdapter = (_config = defaultConfig) => {
|
|
86
|
+
const parsed = configSchema.loose().safeParse(_config);
|
|
87
|
+
if (!parsed.success) {
|
|
88
|
+
throw new Error(`Invalid configuration: ${prettifyError(parsed.error)}`);
|
|
89
|
+
}
|
|
90
|
+
const config = parsed.data;
|
|
91
|
+
const odata = config.odata instanceof FmOdata ? config.odata : new FmOdata(config.odata);
|
|
92
|
+
const db = odata.database;
|
|
93
|
+
return createAdapter({
|
|
94
|
+
config: {
|
|
95
|
+
adapterId: "filemaker",
|
|
96
|
+
adapterName: "FileMaker",
|
|
97
|
+
usePlural: config.usePlural ?? false,
|
|
98
|
+
// Whether the table names in the schema are plural.
|
|
99
|
+
debugLogs: config.debugLogs ?? false,
|
|
100
|
+
// Whether to enable debug logs.
|
|
101
|
+
supportsJSON: false,
|
|
102
|
+
// Whether the database supports JSON. (Default: false)
|
|
103
|
+
supportsDates: false,
|
|
104
|
+
// Whether the database supports dates. (Default: true)
|
|
105
|
+
supportsBooleans: false,
|
|
106
|
+
// Whether the database supports booleans. (Default: true)
|
|
107
|
+
supportsNumericIds: false
|
|
108
|
+
// Whether the database supports auto-incrementing numeric IDs. (Default: true)
|
|
109
|
+
},
|
|
110
|
+
adapter: ({ options }) => {
|
|
111
|
+
return {
|
|
112
|
+
options: { config },
|
|
113
|
+
create: async ({ data, model, select }) => {
|
|
114
|
+
const row = await db.table(model).create(data);
|
|
115
|
+
return row;
|
|
116
|
+
},
|
|
117
|
+
count: async ({ model, where }) => {
|
|
118
|
+
const count = await db.table(model).count(parseWhere(where));
|
|
119
|
+
return count;
|
|
120
|
+
},
|
|
121
|
+
findOne: async ({ model, where }) => {
|
|
122
|
+
const row = await db.table(model).query({
|
|
123
|
+
filter: parseWhere(where),
|
|
124
|
+
top: 1
|
|
125
|
+
});
|
|
126
|
+
return row[0] ?? null;
|
|
127
|
+
},
|
|
128
|
+
findMany: async ({ model, where, limit, offset, sortBy }) => {
|
|
129
|
+
const filter = parseWhere(where);
|
|
130
|
+
const rows = await db.table(model).query({
|
|
131
|
+
filter,
|
|
132
|
+
top: limit,
|
|
133
|
+
skip: offset,
|
|
134
|
+
orderBy: sortBy
|
|
135
|
+
});
|
|
136
|
+
return rows.map((row) => row);
|
|
137
|
+
},
|
|
138
|
+
delete: async ({ model, where }) => {
|
|
139
|
+
const rows = await db.table(model).query({
|
|
140
|
+
filter: parseWhere(where),
|
|
141
|
+
top: 1,
|
|
142
|
+
select: [`"id"`]
|
|
143
|
+
});
|
|
144
|
+
const row = rows[0];
|
|
145
|
+
if (!row) return;
|
|
146
|
+
await db.table(model).delete(row.id);
|
|
147
|
+
},
|
|
148
|
+
deleteMany: async ({ model, where }) => {
|
|
149
|
+
const filter = parseWhere(where);
|
|
150
|
+
const count = await db.table(model).count(filter);
|
|
151
|
+
await db.table(model).deleteMany(filter);
|
|
152
|
+
return count;
|
|
153
|
+
},
|
|
154
|
+
update: async ({ model, where, update }) => {
|
|
155
|
+
const rows = await db.table(model).query({
|
|
156
|
+
filter: parseWhere(where),
|
|
157
|
+
top: 1,
|
|
158
|
+
select: [`"id"`]
|
|
159
|
+
});
|
|
160
|
+
const row = rows[0];
|
|
161
|
+
if (!row) return null;
|
|
162
|
+
const result = await db.table(model).update(row["id"], update);
|
|
163
|
+
return result;
|
|
164
|
+
},
|
|
165
|
+
updateMany: async ({ model, where, update }) => {
|
|
166
|
+
const filter = parseWhere(where);
|
|
167
|
+
const rows = await db.table(model).updateMany(filter, update);
|
|
168
|
+
return rows.length;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
export {
|
|
175
|
+
FileMakerAdapter,
|
|
176
|
+
parseWhere
|
|
177
|
+
};
|
|
178
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sources":["../../src/adapter.ts"],"sourcesContent":["import {\n CleanedWhere,\n createAdapter,\n type AdapterDebugLogs,\n} from \"better-auth/adapters\";\nimport { FmOdata, type FmOdataConfig } from \"./odata\";\nimport { prettifyError, z } from \"zod/v4\";\n\ninterface FileMakerAdapterConfig {\n /**\n * Helps you debug issues with the adapter.\n */\n debugLogs?: AdapterDebugLogs;\n /**\n * If the table names in the schema are plural.\n */\n usePlural?: boolean;\n\n /**\n * Connection details for the FileMaker server.\n */\n odata: FmOdataConfig;\n}\n\nexport type AdapterOptions = {\n config: FileMakerAdapterConfig;\n};\n\nconst configSchema = z.object({\n debugLogs: z.unknown().optional(),\n usePlural: z.boolean().optional(),\n odata: z.object({\n hostname: z.string(),\n auth: z.object({ username: z.string(), password: z.string() }),\n database: z.string().endsWith(\".fmp12\"),\n }),\n});\n\nconst defaultConfig: Required<FileMakerAdapterConfig> = {\n debugLogs: false,\n usePlural: false,\n odata: {\n hostname: \"\",\n auth: { username: \"\", password: \"\" },\n database: \"\",\n },\n};\n\n/**\n * Parse the where clause to an OData filter string.\n * @param where - The where clause to parse.\n * @returns The OData filter string.\n * @internal\n */\nexport function parseWhere(where?: CleanedWhere[]): string {\n if (!where || where.length === 0) return \"\";\n\n // Helper to quote field names with special chars or if field is 'id'\n function quoteField(field: string, value?: any) {\n // Never quote for null or date values (per test expectations)\n if (value === null || value instanceof Date) return field;\n // Always quote if field is 'id' or has space or underscore\n if (field === \"id\" || /[\\s_]/.test(field)) return `\"${field}\"`;\n return field;\n }\n\n // Helper to format values for OData\n function formatValue(value: any): string {\n if (value === null) return \"null\";\n if (typeof value === \"string\") return `'${value.replace(/'/g, \"''\")}'`;\n if (typeof value === \"boolean\") return value ? \"true\" : \"false\";\n if (value instanceof Date) return `'${value.toISOString()}'`;\n if (Array.isArray(value)) return `(${value.map(formatValue).join(\",\")})`;\n return value.toString();\n }\n\n // Map our operators to OData\n const opMap: Record<string, string> = {\n eq: \"eq\",\n ne: \"ne\",\n lt: \"lt\",\n lte: \"le\",\n gt: \"gt\",\n gte: \"ge\",\n };\n\n // Build each clause\n const clauses: string[] = [];\n for (let i = 0; i < where.length; i++) {\n const cond = where[i];\n if (!cond) continue;\n const field = quoteField(cond.field, cond.value);\n let clause = \"\";\n switch (cond.operator) {\n case \"eq\":\n case \"ne\":\n case \"lt\":\n case \"lte\":\n case \"gt\":\n case \"gte\":\n clause = `${field} ${opMap[cond.operator!]} ${formatValue(cond.value)}`;\n break;\n case \"in\":\n if (Array.isArray(cond.value)) {\n clause = cond.value\n .map((v) => `${field} eq ${formatValue(v)}`)\n .join(\" or \");\n clause = `(${clause})`;\n }\n break;\n case \"contains\":\n clause = `contains(${field}, ${formatValue(cond.value)})`;\n break;\n case \"starts_with\":\n clause = `startswith(${field}, ${formatValue(cond.value)})`;\n break;\n case \"ends_with\":\n clause = `endswith(${field}, ${formatValue(cond.value)})`;\n break;\n default:\n clause = `${field} eq ${formatValue(cond.value)}`;\n }\n clauses.push(clause);\n // Add connector if not last\n if (i < where.length - 1) {\n clauses.push((cond.connector || \"and\").toLowerCase());\n }\n }\n return clauses.join(\" \");\n}\n\nexport const FileMakerAdapter = (\n _config: FileMakerAdapterConfig = defaultConfig,\n) => {\n const parsed = configSchema.loose().safeParse(_config);\n\n if (!parsed.success) {\n throw new Error(`Invalid configuration: ${prettifyError(parsed.error)}`);\n }\n const config = parsed.data;\n\n const odata =\n config.odata instanceof FmOdata ? config.odata : new FmOdata(config.odata);\n const db = odata.database;\n\n return createAdapter({\n config: {\n adapterId: \"filemaker\",\n adapterName: \"FileMaker\",\n usePlural: config.usePlural ?? false, // Whether the table names in the schema are plural.\n debugLogs: config.debugLogs ?? false, // Whether to enable debug logs.\n supportsJSON: false, // Whether the database supports JSON. (Default: false)\n supportsDates: false, // Whether the database supports dates. (Default: true)\n supportsBooleans: false, // Whether the database supports booleans. (Default: true)\n supportsNumericIds: false, // Whether the database supports auto-incrementing numeric IDs. (Default: true)\n },\n adapter: ({ options }) => {\n return {\n options: { config },\n create: async ({ data, model, select }) => {\n const row = await db.table(model).create(data);\n return row as unknown as typeof data;\n },\n count: async ({ model, where }) => {\n const count = await db.table(model).count(parseWhere(where));\n return count;\n },\n findOne: async ({ model, where }) => {\n const row = await db.table(model).query({\n filter: parseWhere(where),\n top: 1,\n });\n return (row[0] as any) ?? null;\n },\n findMany: async ({ model, where, limit, offset, sortBy }) => {\n const filter = parseWhere(where);\n\n const rows = await db.table(model).query({\n filter,\n top: limit,\n skip: offset,\n orderBy: sortBy,\n });\n return rows.map((row) => row as any);\n },\n delete: async ({ model, where }) => {\n const rows = await db.table(model).query({\n filter: parseWhere(where),\n top: 1,\n select: [`\"id\"`],\n });\n const row = rows[0] as { id: string } | undefined;\n if (!row) return;\n await db.table(model).delete(row.id);\n },\n deleteMany: async ({ model, where }) => {\n const filter = parseWhere(where);\n const count = await db.table(model).count(filter);\n await db.table(model).deleteMany(filter);\n return count;\n },\n update: async ({ model, where, update }) => {\n const rows = await db.table(model).query({\n filter: parseWhere(where),\n top: 1,\n select: [`\"id\"`],\n });\n const row = rows[0] as { id: string } | undefined;\n if (!row) return null;\n const result = await db.table(model).update(row[\"id\"], update as any);\n return result as any;\n },\n updateMany: async ({ model, where, update }) => {\n const filter = parseWhere(where);\n const rows = await db.table(model).updateMany(filter, update as any);\n return rows.length;\n },\n };\n },\n });\n};\n"],"names":[],"mappings":";;;AA4BA,MAAM,eAAe,EAAE,OAAO;AAAA,EAC5B,WAAW,EAAE,QAAQ,EAAE,SAAS;AAAA,EAChC,WAAW,EAAE,QAAQ,EAAE,SAAS;AAAA,EAChC,OAAO,EAAE,OAAO;AAAA,IACd,UAAU,EAAE,OAAO;AAAA,IACnB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,GAAG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,YACL,QAAQ,CAAC,MAAM;AAAA,UAAA,CAChB;AACK,gBAAA,MAAM,KAAK,CAAC;AAClB,cAAI,CAAC,IAAK;AACV,gBAAM,GAAG,MAAM,KAAK,EAAE,OAAO,IAAI,EAAE;AAAA,QACrC;AAAA,QACA,YAAY,OAAO,EAAE,OAAO,YAAY;AAChC,gBAAA,SAAS,WAAW,KAAK;AAC/B,gBAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,EAAE,MAAM,MAAM;AAChD,gBAAM,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AAChC,iBAAA;AAAA,QACT;AAAA,QACA,QAAQ,OAAO,EAAE,OAAO,OAAO,aAAa;AAC1C,gBAAM,OAAO,MAAM,GAAG,MAAM,KAAK,EAAE,MAAM;AAAA,YACvC,QAAQ,WAAW,KAAK;AAAA,YACxB,KAAK;AAAA,YACL,QAAQ,CAAC,MAAM;AAAA,UAAA,CAChB;AACK,gBAAA,MAAM,KAAK,CAAC;AACd,cAAA,CAAC,IAAY,QAAA;AACX,gBAAA,SAAS,MAAM,GAAG,MAAM,KAAK,EAAE,OAAO,IAAI,IAAI,GAAG,MAAa;AAC7D,iBAAA;AAAA,QACT;AAAA,QACA,YAAY,OAAO,EAAE,OAAO,OAAO,aAAa;AACxC,gBAAA,SAAS,WAAW,KAAK;AACzB,gBAAA,OAAO,MAAM,GAAG,MAAM,KAAK,EAAE,WAAW,QAAQ,MAAa;AACnE,iBAAO,KAAK;AAAA,QAAA;AAAA,MAEhB;AAAA,IAAA;AAAA,EACF,CACD;AACH;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function addSvelteKitEnvModules(aliases: Record<string, string>): void;
|
|
2
|
+
export declare function filterPrivateEnv(publicPrefix: string, privatePrefix: string): Record<string, string>;
|
|
3
|
+
export declare function filterPublicEnv(publicPrefix: string, privatePrefix: string): Record<string, string>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
function addSvelteKitEnvModules(aliases) {
|
|
2
|
+
aliases["$env/dynamic/private"] = createDataUriModule(
|
|
3
|
+
createDynamicEnvModule()
|
|
4
|
+
);
|
|
5
|
+
aliases["$env/dynamic/public"] = createDataUriModule(
|
|
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
|
+
);
|
|
14
|
+
}
|
|
15
|
+
function createDataUriModule(module) {
|
|
16
|
+
return `data:text/javascript;charset=utf-8,${encodeURIComponent(module)}`;
|
|
17
|
+
}
|
|
18
|
+
function createStaticEnvModule(env) {
|
|
19
|
+
const declarations = Object.keys(env).filter((k) => validIdentifier.test(k) && !reserved.has(k)).map((k) => `export const ${k} = ${JSON.stringify(env[k])};`);
|
|
20
|
+
return `
|
|
21
|
+
${declarations.join("\n")}
|
|
22
|
+
// jiti dirty hack: .unknown
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
function createDynamicEnvModule() {
|
|
26
|
+
return `
|
|
27
|
+
export const env = process.env;
|
|
28
|
+
// jiti dirty hack: .unknown
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
function filterPrivateEnv(publicPrefix, privatePrefix) {
|
|
32
|
+
return Object.fromEntries(
|
|
33
|
+
Object.entries(process.env).filter(
|
|
34
|
+
([k]) => k.startsWith(privatePrefix) && !k.startsWith(publicPrefix)
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
function filterPublicEnv(publicPrefix, privatePrefix) {
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
Object.entries(process.env).filter(
|
|
41
|
+
([k]) => k.startsWith(publicPrefix) && privatePrefix === ""
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
46
|
+
const reserved = /* @__PURE__ */ new Set([
|
|
47
|
+
"do",
|
|
48
|
+
"if",
|
|
49
|
+
"in",
|
|
50
|
+
"for",
|
|
51
|
+
"let",
|
|
52
|
+
"new",
|
|
53
|
+
"try",
|
|
54
|
+
"var",
|
|
55
|
+
"case",
|
|
56
|
+
"else",
|
|
57
|
+
"enum",
|
|
58
|
+
"eval",
|
|
59
|
+
"null",
|
|
60
|
+
"this",
|
|
61
|
+
"true",
|
|
62
|
+
"void",
|
|
63
|
+
"with",
|
|
64
|
+
"await",
|
|
65
|
+
"break",
|
|
66
|
+
"catch",
|
|
67
|
+
"class",
|
|
68
|
+
"const",
|
|
69
|
+
"false",
|
|
70
|
+
"super",
|
|
71
|
+
"throw",
|
|
72
|
+
"while",
|
|
73
|
+
"yield",
|
|
74
|
+
"delete",
|
|
75
|
+
"export",
|
|
76
|
+
"import",
|
|
77
|
+
"public",
|
|
78
|
+
"return",
|
|
79
|
+
"static",
|
|
80
|
+
"switch",
|
|
81
|
+
"typeof",
|
|
82
|
+
"default",
|
|
83
|
+
"extends",
|
|
84
|
+
"finally",
|
|
85
|
+
"package",
|
|
86
|
+
"private",
|
|
87
|
+
"continue",
|
|
88
|
+
"debugger",
|
|
89
|
+
"function",
|
|
90
|
+
"arguments",
|
|
91
|
+
"interface",
|
|
92
|
+
"protected",
|
|
93
|
+
"implements",
|
|
94
|
+
"instanceof"
|
|
95
|
+
]);
|
|
96
|
+
export {
|
|
97
|
+
addSvelteKitEnvModules,
|
|
98
|
+
filterPrivateEnv,
|
|
99
|
+
filterPublicEnv
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=add-svelte-kit-env-modules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-svelte-kit-env-modules.js","sources":["../../../../src/better-auth-cli/utils/add-svelte-kit-env-modules.ts"],"sourcesContent":["export function addSvelteKitEnvModules(aliases: Record<string, string>) {\n\taliases[\"$env/dynamic/private\"] = createDataUriModule(\n\t\tcreateDynamicEnvModule(),\n\t);\n\taliases[\"$env/dynamic/public\"] = createDataUriModule(\n\t\tcreateDynamicEnvModule(),\n\t);\n\taliases[\"$env/static/private\"] = createDataUriModule(\n\t\tcreateStaticEnvModule(filterPrivateEnv(\"PUBLIC_\", \"\")),\n\t);\n\taliases[\"$env/static/public\"] = createDataUriModule(\n\t\tcreateStaticEnvModule(filterPublicEnv(\"PUBLIC_\", \"\")),\n\t);\n}\n\nfunction createDataUriModule(module: string) {\n\treturn `data:text/javascript;charset=utf-8,${encodeURIComponent(module)}`;\n}\n\nfunction createStaticEnvModule(env: Record<string, string>) {\n\tconst declarations = Object.keys(env)\n\t\t.filter((k) => validIdentifier.test(k) && !reserved.has(k))\n\t\t.map((k) => `export const ${k} = ${JSON.stringify(env[k])};`);\n\n\treturn `\n ${declarations.join(\"\\n\")}\n // jiti dirty hack: .unknown\n `;\n}\n\nfunction createDynamicEnvModule() {\n\treturn `\n export const env = process.env;\n // jiti dirty hack: .unknown\n `;\n}\n\nexport function filterPrivateEnv(publicPrefix: string, privatePrefix: string) {\n\treturn Object.fromEntries(\n\t\tObject.entries(process.env).filter(\n\t\t\t([k]) =>\n\t\t\t\tk.startsWith(privatePrefix) &&\n\t\t\t\t(publicPrefix === \"\" || !k.startsWith(publicPrefix)),\n\t\t),\n\t) as Record<string, string>;\n}\n\nexport function filterPublicEnv(publicPrefix: string, privatePrefix: string) {\n\treturn Object.fromEntries(\n\t\tObject.entries(process.env).filter(\n\t\t\t([k]) =>\n\t\t\t\tk.startsWith(publicPrefix) &&\n\t\t\t\t(privatePrefix === \"\" || !k.startsWith(privatePrefix)),\n\t\t),\n\t) as Record<string, string>;\n}\n\nconst validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\nconst reserved = new Set([\n\t\"do\",\n\t\"if\",\n\t\"in\",\n\t\"for\",\n\t\"let\",\n\t\"new\",\n\t\"try\",\n\t\"var\",\n\t\"case\",\n\t\"else\",\n\t\"enum\",\n\t\"eval\",\n\t\"null\",\n\t\"this\",\n\t\"true\",\n\t\"void\",\n\t\"with\",\n\t\"await\",\n\t\"break\",\n\t\"catch\",\n\t\"class\",\n\t\"const\",\n\t\"false\",\n\t\"super\",\n\t\"throw\",\n\t\"while\",\n\t\"yield\",\n\t\"delete\",\n\t\"export\",\n\t\"import\",\n\t\"public\",\n\t\"return\",\n\t\"static\",\n\t\"switch\",\n\t\"typeof\",\n\t\"default\",\n\t\"extends\",\n\t\"finally\",\n\t\"package\",\n\t\"private\",\n\t\"continue\",\n\t\"debugger\",\n\t\"function\",\n\t\"arguments\",\n\t\"interface\",\n\t\"protected\",\n\t\"implements\",\n\t\"instanceof\",\n]);\n"],"names":[],"mappings":"AAAO,SAAS,uBAAuB,SAAiC;AACvE,UAAQ,sBAAsB,IAAI;AAAA,IACjC,uBAAuB;AAAA,EACxB;AACA,UAAQ,qBAAqB,IAAI;AAAA,IAChC,uBAAuB;AAAA,EACxB;AACA,UAAQ,qBAAqB,IAAI;AAAA,IAChC,sBAAsB,iBAAiB,WAAW,EAAE,CAAC;AAAA,EACtD;AACA,UAAQ,oBAAoB,IAAI;AAAA,IAC/B,sBAAsB,gBAAgB,WAAW,EAAE,CAAC;AAAA,EACrD;AACD;AAEA,SAAS,oBAAoB,QAAgB;AACrC,SAAA,sCAAsC,mBAAmB,MAAM,CAAC;AACxE;AAEA,SAAS,sBAAsB,KAA6B;AAC3D,QAAM,eAAe,OAAO,KAAK,GAAG,EAClC,OAAO,CAAC,MAAM,gBAAgB,KAAK,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,CAAC,EACzD,IAAI,CAAC,MAAM,gBAAgB,CAAC,MAAM,KAAK,UAAU,IAAI,CAAC,CAAC,CAAC,GAAG;AAEtD,SAAA;AAAA,IACJ,aAAa,KAAK,IAAI,CAAC;AAAA;AAAA;AAG3B;AAEA,SAAS,yBAAyB;AAC1B,SAAA;AAAA;AAAA;AAAA;AAIR;AAEgB,SAAA,iBAAiB,cAAsB,eAAuB;AAC7E,SAAO,OAAO;AAAA,IACb,OAAO,QAAQ,QAAQ,GAAG,EAAE;AAAA,MAC3B,CAAC,CAAC,CAAC,MACF,EAAE,WAAW,aAAa,KACF,CAAC,EAAE,WAAW,YAAY;AAAA,IAAA;AAAA,EAErD;AACD;AAEgB,SAAA,gBAAgB,cAAsB,eAAuB;AAC5E,SAAO,OAAO;AAAA,IACb,OAAO,QAAQ,QAAQ,GAAG,EAAE;AAAA,MAC3B,CAAC,CAAC,CAAC,MACF,EAAE,WAAW,YAAY,KACxB,kBAAkB;AAAA,IAAiC;AAAA,EAEvD;AACD;AAEA,MAAM,kBAAkB;AACxB,MAAM,+BAAe,IAAI;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAC;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BetterAuthOptions } from 'better-auth';
|
|
2
|
+
declare let possiblePaths: string[];
|
|
3
|
+
export declare function getConfig({ cwd, configPath, shouldThrowOnError, }: {
|
|
4
|
+
cwd: string;
|
|
5
|
+
configPath?: string;
|
|
6
|
+
shouldThrowOnError?: boolean;
|
|
7
|
+
}): Promise<BetterAuthOptions | null>;
|
|
8
|
+
export { possiblePaths };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { loadConfig } from "c12";
|
|
2
|
+
import { logger, BetterAuthError } from "better-auth";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import babelPresetTypeScript from "@babel/preset-typescript";
|
|
5
|
+
import babelPresetReact from "@babel/preset-react";
|
|
6
|
+
import fs, { existsSync } from "fs";
|
|
7
|
+
import { addSvelteKitEnvModules } from "./add-svelte-kit-env-modules.js";
|
|
8
|
+
import { getTsconfigInfo } from "./get-tsconfig-info.js";
|
|
9
|
+
let possiblePaths = [
|
|
10
|
+
"auth.ts",
|
|
11
|
+
"auth.tsx",
|
|
12
|
+
"auth.js",
|
|
13
|
+
"auth.jsx",
|
|
14
|
+
"auth.server.js",
|
|
15
|
+
"auth.server.ts"
|
|
16
|
+
];
|
|
17
|
+
possiblePaths = [
|
|
18
|
+
...possiblePaths,
|
|
19
|
+
...possiblePaths.map((it) => `lib/server/${it}`),
|
|
20
|
+
...possiblePaths.map((it) => `server/${it}`),
|
|
21
|
+
...possiblePaths.map((it) => `lib/${it}`),
|
|
22
|
+
...possiblePaths.map((it) => `utils/${it}`)
|
|
23
|
+
];
|
|
24
|
+
possiblePaths = [
|
|
25
|
+
...possiblePaths,
|
|
26
|
+
...possiblePaths.map((it) => `src/${it}`),
|
|
27
|
+
...possiblePaths.map((it) => `app/${it}`)
|
|
28
|
+
];
|
|
29
|
+
function getPathAliases(cwd) {
|
|
30
|
+
const tsConfigPath = path.join(cwd, "tsconfig.json");
|
|
31
|
+
if (!fs.existsSync(tsConfigPath)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const tsConfig = getTsconfigInfo(cwd);
|
|
36
|
+
const { paths = {}, baseUrl = "." } = tsConfig.compilerOptions || {};
|
|
37
|
+
const result = {};
|
|
38
|
+
const obj = Object.entries(paths);
|
|
39
|
+
for (const [alias, aliasPaths] of obj) {
|
|
40
|
+
for (const aliasedPath of aliasPaths) {
|
|
41
|
+
const resolvedBaseUrl = path.join(cwd, baseUrl);
|
|
42
|
+
const finalAlias = alias.slice(-1) === "*" ? alias.slice(0, -1) : alias;
|
|
43
|
+
const finalAliasedPath = aliasedPath.slice(-1) === "*" ? aliasedPath.slice(0, -1) : aliasedPath;
|
|
44
|
+
result[finalAlias || ""] = path.join(resolvedBaseUrl, finalAliasedPath);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
addSvelteKitEnvModules(result);
|
|
48
|
+
return result;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(error);
|
|
51
|
+
throw new BetterAuthError("Error parsing tsconfig.json");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const jitiOptions = (cwd) => {
|
|
55
|
+
const alias = getPathAliases(cwd) || {};
|
|
56
|
+
return {
|
|
57
|
+
transformOptions: {
|
|
58
|
+
babel: {
|
|
59
|
+
presets: [
|
|
60
|
+
[
|
|
61
|
+
babelPresetTypeScript,
|
|
62
|
+
{
|
|
63
|
+
isTSX: true,
|
|
64
|
+
allExtensions: true
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
[babelPresetReact, { runtime: "automatic" }]
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
72
|
+
alias
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
async function getConfig({
|
|
76
|
+
cwd,
|
|
77
|
+
configPath,
|
|
78
|
+
shouldThrowOnError = false
|
|
79
|
+
}) {
|
|
80
|
+
var _a, _b, _c, _d;
|
|
81
|
+
try {
|
|
82
|
+
let configFile = null;
|
|
83
|
+
if (configPath) {
|
|
84
|
+
let resolvedPath = path.join(cwd, configPath);
|
|
85
|
+
if (existsSync(configPath)) resolvedPath = configPath;
|
|
86
|
+
const { config } = await loadConfig({
|
|
87
|
+
configFile: resolvedPath,
|
|
88
|
+
dotenv: true,
|
|
89
|
+
jitiOptions: jitiOptions(cwd)
|
|
90
|
+
});
|
|
91
|
+
if (!config.auth && !config.default) {
|
|
92
|
+
if (shouldThrowOnError) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Couldn't read your auth config in ${resolvedPath}. Make sure to default export your auth instance or to export as a variable named auth.`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
logger.error(
|
|
98
|
+
`[#better-auth]: Couldn't read your auth config in ${resolvedPath}. Make sure to default export your auth instance or to export as a variable named auth.`
|
|
99
|
+
);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
configFile = ((_a = config.auth) == null ? void 0 : _a.options) || ((_b = config.default) == null ? void 0 : _b.options) || null;
|
|
103
|
+
}
|
|
104
|
+
if (!configFile) {
|
|
105
|
+
for (const possiblePath of possiblePaths) {
|
|
106
|
+
try {
|
|
107
|
+
const { config } = await loadConfig({
|
|
108
|
+
configFile: possiblePath,
|
|
109
|
+
jitiOptions: jitiOptions(cwd)
|
|
110
|
+
});
|
|
111
|
+
const hasConfig = Object.keys(config).length > 0;
|
|
112
|
+
if (hasConfig) {
|
|
113
|
+
configFile = ((_c = config.auth) == null ? void 0 : _c.options) || ((_d = config.default) == null ? void 0 : _d.options) || null;
|
|
114
|
+
if (!configFile) {
|
|
115
|
+
if (shouldThrowOnError) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
"Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth."
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
logger.error("[#better-auth]: Couldn't read your auth config.");
|
|
121
|
+
console.log("");
|
|
122
|
+
logger.info(
|
|
123
|
+
"[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth."
|
|
124
|
+
);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
if (typeof e === "object" && e && "message" in e && typeof e.message === "string" && e.message.includes(
|
|
131
|
+
"This module cannot be imported from a Client Component module"
|
|
132
|
+
)) {
|
|
133
|
+
if (shouldThrowOnError) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
logger.error(
|
|
139
|
+
`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`
|
|
140
|
+
);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
if (shouldThrowOnError) {
|
|
144
|
+
throw e;
|
|
145
|
+
}
|
|
146
|
+
logger.error("[#better-auth]: Couldn't read your auth config.", e);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return configFile;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
if (typeof e === "object" && e && "message" in e && typeof e.message === "string" && e.message.includes(
|
|
154
|
+
"This module cannot be imported from a Client Component module"
|
|
155
|
+
)) {
|
|
156
|
+
if (shouldThrowOnError) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
logger.error(
|
|
162
|
+
`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`
|
|
163
|
+
);
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
if (shouldThrowOnError) {
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
logger.error("Couldn't read your auth config.", e);
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export {
|
|
174
|
+
getConfig,
|
|
175
|
+
possiblePaths
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=get-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-config.js","sources":["../../../../src/better-auth-cli/utils/get-config.ts"],"sourcesContent":["import { loadConfig } from \"c12\";\nimport type { BetterAuthOptions } from \"better-auth\";\nimport { logger } from \"better-auth\";\nimport path from \"path\";\n// @ts-expect-error not typed\nimport babelPresetTypeScript from \"@babel/preset-typescript\";\n// @ts-expect-error not typed\nimport babelPresetReact from \"@babel/preset-react\";\nimport fs, { existsSync } from \"fs\";\nimport { BetterAuthError } from \"better-auth\";\nimport { addSvelteKitEnvModules } from \"./add-svelte-kit-env-modules\";\nimport { getTsconfigInfo } from \"./get-tsconfig-info\";\n\nlet possiblePaths = [\n \"auth.ts\",\n \"auth.tsx\",\n \"auth.js\",\n \"auth.jsx\",\n \"auth.server.js\",\n \"auth.server.ts\",\n];\n\npossiblePaths = [\n ...possiblePaths,\n ...possiblePaths.map((it) => `lib/server/${it}`),\n ...possiblePaths.map((it) => `server/${it}`),\n ...possiblePaths.map((it) => `lib/${it}`),\n ...possiblePaths.map((it) => `utils/${it}`),\n];\npossiblePaths = [\n ...possiblePaths,\n ...possiblePaths.map((it) => `src/${it}`),\n ...possiblePaths.map((it) => `app/${it}`),\n];\n\nfunction getPathAliases(cwd: string): Record<string, string> | null {\n const tsConfigPath = path.join(cwd, \"tsconfig.json\");\n if (!fs.existsSync(tsConfigPath)) {\n return null;\n }\n try {\n const tsConfig = getTsconfigInfo(cwd);\n const { paths = {}, baseUrl = \".\" } = tsConfig.compilerOptions || {};\n const result: Record<string, string> = {};\n const obj = Object.entries(paths) as [string, string[]][];\n for (const [alias, aliasPaths] of obj) {\n for (const aliasedPath of aliasPaths) {\n const resolvedBaseUrl = path.join(cwd, baseUrl);\n const finalAlias = alias.slice(-1) === \"*\" ? alias.slice(0, -1) : alias;\n const finalAliasedPath =\n aliasedPath.slice(-1) === \"*\"\n ? aliasedPath.slice(0, -1)\n : aliasedPath;\n\n result[finalAlias || \"\"] = path.join(resolvedBaseUrl, finalAliasedPath);\n }\n }\n addSvelteKitEnvModules(result);\n return result;\n } catch (error) {\n console.error(error);\n throw new BetterAuthError(\"Error parsing tsconfig.json\");\n }\n}\n/**\n * .tsx files are not supported by Jiti.\n */\nconst jitiOptions = (cwd: string) => {\n const alias = getPathAliases(cwd) || {};\n return {\n transformOptions: {\n babel: {\n presets: [\n [\n babelPresetTypeScript,\n {\n isTSX: true,\n allExtensions: true,\n },\n ],\n [babelPresetReact, { runtime: \"automatic\" }],\n ],\n },\n },\n extensions: [\".ts\", \".tsx\", \".js\", \".jsx\"],\n alias,\n };\n};\nexport async function getConfig({\n cwd,\n configPath,\n shouldThrowOnError = false,\n}: {\n cwd: string;\n configPath?: string;\n shouldThrowOnError?: boolean;\n}) {\n try {\n let configFile: BetterAuthOptions | null = null;\n if (configPath) {\n let resolvedPath: string = path.join(cwd, configPath);\n if (existsSync(configPath)) resolvedPath = configPath; // If the configPath is a file, use it as is, as it means the path wasn't relative.\n const { config } = await loadConfig<{\n auth: {\n options: BetterAuthOptions;\n };\n default?: {\n options: BetterAuthOptions;\n };\n }>({\n configFile: resolvedPath,\n dotenv: true,\n jitiOptions: jitiOptions(cwd),\n });\n if (!config.auth && !config.default) {\n if (shouldThrowOnError) {\n throw new Error(\n `Couldn't read your auth config in ${resolvedPath}. Make sure to default export your auth instance or to export as a variable named auth.`,\n );\n }\n logger.error(\n `[#better-auth]: Couldn't read your auth config in ${resolvedPath}. Make sure to default export your auth instance or to export as a variable named auth.`,\n );\n process.exit(1);\n }\n configFile = config.auth?.options || config.default?.options || null;\n }\n\n if (!configFile) {\n for (const possiblePath of possiblePaths) {\n try {\n const { config } = await loadConfig<{\n auth: {\n options: BetterAuthOptions;\n };\n default?: {\n options: BetterAuthOptions;\n };\n }>({\n configFile: possiblePath,\n jitiOptions: jitiOptions(cwd),\n });\n const hasConfig = Object.keys(config).length > 0;\n if (hasConfig) {\n configFile =\n config.auth?.options || config.default?.options || null;\n if (!configFile) {\n if (shouldThrowOnError) {\n throw new Error(\n \"Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth.\",\n );\n }\n logger.error(\"[#better-auth]: Couldn't read your auth config.\");\n console.log(\"\");\n logger.info(\n \"[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth.\",\n );\n process.exit(1);\n }\n break;\n }\n } catch (e) {\n if (\n typeof e === \"object\" &&\n e &&\n \"message\" in e &&\n typeof e.message === \"string\" &&\n e.message.includes(\n \"This module cannot be imported from a Client Component module\",\n )\n ) {\n if (shouldThrowOnError) {\n throw new Error(\n `Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`,\n );\n }\n logger.error(\n `Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`,\n );\n process.exit(1);\n }\n if (shouldThrowOnError) {\n throw e;\n }\n logger.error(\"[#better-auth]: Couldn't read your auth config.\", e);\n process.exit(1);\n }\n }\n }\n return configFile;\n } catch (e) {\n if (\n typeof e === \"object\" &&\n e &&\n \"message\" in e &&\n typeof e.message === \"string\" &&\n e.message.includes(\n \"This module cannot be imported from a Client Component module\",\n )\n ) {\n if (shouldThrowOnError) {\n throw new Error(\n `Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`,\n );\n }\n logger.error(\n `Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`,\n );\n process.exit(1);\n }\n if (shouldThrowOnError) {\n throw e;\n }\n\n logger.error(\"Couldn't read your auth config.\", e);\n process.exit(1);\n }\n}\n\nexport { possiblePaths };\n"],"names":[],"mappings":";;;;;;;;AAaA,IAAI,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,gBAAgB;AAAA,EACd,GAAG;AAAA,EACH,GAAG,cAAc,IAAI,CAA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P,mBAAgB,YAAW;AACrD,gBAAI,CAAC,YAAY;AACf,kBAAI,oBAAoB;AACtB,sBAAM,IAAI;AAAA,kBACR;AAAA,gBACF;AAAA,cAAA;AAEF,qBAAO,MAAM,iDAAiD;AAC9D,sBAAQ,IAAI,EAAE;AACP,qBAAA;AAAA,gBACL;AAAA,cACF;AACA,sBAAQ,KAAK,CAAC;AAAA,YAAA;AAEhB;AAAA,UAAA;AAAA,iBAEK,GAAG;AAER,cAAA,OAAO,MAAM,YACb,KACA,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ;AAAA,YACR;AAAA,UAAA,GAEF;AACA,gBAAI,oBAAoB;AACtB,oBAAM,IAAI;AAAA,gBACR;AAAA,cACF;AAAA,YAAA;AAEK,mBAAA;AAAA,cACL;AAAA,YACF;AACA,oBAAQ,KAAK,CAAC;AAAA,UAAA;AAEhB,cAAI,oBAAoB;AAChB,kBAAA;AAAA,UAAA;AAED,iBAAA,MAAM,mDAAmD,CAAC;AACjE,kBAAQ,KAAK,CAAC;AAAA,QAAA;AAAA,MAChB;AAAA,IACF;AAEK,WAAA;AAAA,WACA,GAAG;AAER,QAAA,OAAO,MAAM,YACb,KACA,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ;AAAA,MACR;AAAA,IAAA,GAEF;AACA,UAAI,oBAAoB;AACtB,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MAAA;AAEK,aAAA;AAAA,QACL;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAAA;AAEhB,QAAI,oBAAoB;AAChB,YAAA;AAAA,IAAA;AAGD,WAAA,MAAM,mCAAmC,CAAC;AACjD,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
function stripJsonComments(jsonString) {
|
|
4
|
+
return jsonString.replace(
|
|
5
|
+
/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
|
|
6
|
+
(m, g) => g ? "" : m
|
|
7
|
+
).replace(/,(?=\s*[}\]])/g, "");
|
|
8
|
+
}
|
|
9
|
+
function getTsconfigInfo(cwd, flatPath) {
|
|
10
|
+
let tsConfigPath;
|
|
11
|
+
{
|
|
12
|
+
tsConfigPath = cwd ? path.join(cwd, "tsconfig.json") : path.join("tsconfig.json");
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const text = fs.readFileSync(tsConfigPath, "utf-8");
|
|
16
|
+
return JSON.parse(stripJsonComments(text));
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
getTsconfigInfo,
|
|
23
|
+
stripJsonComments
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=get-tsconfig-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-tsconfig-info.js","sources":["../../../../src/better-auth-cli/utils/get-tsconfig-info.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs-extra\";\n\nexport function stripJsonComments(jsonString: string): string {\n\treturn jsonString\n\t\t.replace(/\\\\\"|\"(?:\\\\\"|[^\"])*\"|(\\/\\/.*|\\/\\*[\\s\\S]*?\\*\\/)/g, (m, g) =>\n\t\t\tg ? \"\" : m,\n\t\t)\n\t\t.replace(/,(?=\\s*[}\\]])/g, \"\");\n}\nexport function getTsconfigInfo(cwd?: string, flatPath?: string) {\n\tlet tsConfigPath: string;\n\tif (flatPath) {\n\t\ttsConfigPath = flatPath;\n\t} else {\n\t\ttsConfigPath = cwd\n\t\t\t? path.join(cwd, \"tsconfig.json\")\n\t\t\t: path.join(\"tsconfig.json\");\n\t}\n\ttry {\n\t\tconst text = fs.readFileSync(tsConfigPath, \"utf-8\");\n\t\treturn JSON.parse(stripJsonComments(text));\n\t} catch (error) {\n\t\tthrow error;\n\t}\n}\n"],"names":[],"mappings":";;AAGO,SAAS,kBAAkB,YAA4B;AAC7D,SAAO,WACL;AAAA,IAAQ;AAAA,IAAkD,CAAC,GAAG,MAC9D,IAAI,KAAK;AAAA,EAAA,EAET,QAAQ,kBAAkB,EAAE;AAC/B;AACgB,SAAA,gBAAgB,KAAc,UAAmB;AAC5D,MAAA;AAGG;AACS,mBAAA,MACZ,KAAK,KAAK,KAAK,eAAe,IAC9B,KAAK,KAAK,eAAe;AAAA,EAAA;AAEzB,MAAA;AACH,UAAM,OAAO,GAAG,aAAa,cAAc,OAAO;AAClD,WAAO,KAAK,MAAM,kBAAkB,IAAI,CAAC;AAAA,WACjC,OAAO;AACT,UAAA;AAAA,EAAA;AAER;"}
|