@deessejs/cli 0.6.24 → 0.6.25
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/package.json +1 -1
- package/dist/commands/admin/create.d.ts +0 -14
- package/dist/commands/admin.d.ts +0 -29
- package/dist/commands/admin.d.ts.map +0 -1
- package/dist/commands/admin.js +0 -22
- package/dist/commands/admin.js.map +0 -1
- package/dist/commands/db/generate.d.ts +0 -11
- package/dist/commands/db/generate.d.ts.map +0 -1
- package/dist/commands/db/generate.js +0 -45
- package/dist/commands/db/generate.js.map +0 -1
- package/dist/commands/db/index.d.ts +0 -15
- package/dist/commands/db/index.d.ts.map +0 -1
- package/dist/commands/db/index.js +0 -100
- package/dist/commands/db/index.js.map +0 -1
- package/dist/commands/db/migrate.d.ts +0 -16
- package/dist/commands/db/migrate.d.ts.map +0 -1
- package/dist/commands/db/migrate.js +0 -75
- package/dist/commands/db/migrate.js.map +0 -1
- package/dist/commands/db/push.d.ts +0 -12
- package/dist/commands/db/push.d.ts.map +0 -1
- package/dist/commands/db/push.js +0 -39
- package/dist/commands/db/push.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -167
- package/dist/index.js.map +0 -1
- package/dist/lib/admin/create.d.ts +0 -33
- package/dist/lib/admin/create.d.ts.map +0 -1
- package/dist/lib/admin/create.js +0 -46
- package/dist/lib/admin/create.js.map +0 -1
- package/dist/lib/config/loader.d.ts +0 -99
- package/dist/lib/config/loader.d.ts.map +0 -1
- package/dist/lib/config/loader.js +0 -242
- package/dist/lib/config/loader.js.map +0 -1
- package/dist/lib/db/auth-schema.d.ts +0 -39
- package/dist/lib/db/auth-schema.d.ts.map +0 -1
- package/dist/lib/db/auth-schema.js +0 -115
- package/dist/lib/db/auth-schema.js.map +0 -1
- package/dist/lib/db/schema.d.ts +0 -43
- package/dist/lib/db/schema.d.ts.map +0 -1
- package/dist/lib/db/schema.js +0 -144
- package/dist/lib/db/schema.js.map +0 -1
- package/dist/lib/index.d.ts +0 -5
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/index.js +0 -6
- package/dist/lib/index.js.map +0 -1
- package/dist/utils/schema-loader.d.ts +0 -16
- package/dist/utils/schema-loader.d.ts.map +0 -1
- package/dist/utils/schema-loader.js +0 -46
- package/dist/utils/schema-loader.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/lib/admin/create.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAOlE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE7C,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,qBAAa,kBAAmB,SAAQ,KAAK;aAGzB,IAAI,CAAC,EAAE,MAAM;aACb,UAAU,CAAC,EAAE,MAAM;gBAFnC,OAAO,EAAE,MAAM,EACC,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,UAAU,CAAC,EAAE,MAAM,YAAA;CAKtC;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA+B7F"}
|
package/dist/lib/admin/create.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Backend logic for creating admin users
|
|
3
|
-
*
|
|
4
|
-
* This module contains the pure business logic for creating an admin user
|
|
5
|
-
* via better-auth. It has no CLI dependencies (@clack/prompts, etc.).
|
|
6
|
-
*/
|
|
7
|
-
import { betterAuth } from "better-auth";
|
|
8
|
-
import { admin } from "better-auth/plugins";
|
|
9
|
-
import { drizzleAdapter } from "@better-auth/drizzle-adapter";
|
|
10
|
-
export class AdminCreationError extends Error {
|
|
11
|
-
code;
|
|
12
|
-
suggestion;
|
|
13
|
-
constructor(message, code, suggestion) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.code = code;
|
|
16
|
-
this.suggestion = suggestion;
|
|
17
|
-
this.name = 'AdminCreationError';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export async function createAdminUser(options) {
|
|
21
|
-
const { email, password, name, database, secret, baseURL, plugins, schema } = options;
|
|
22
|
-
try {
|
|
23
|
-
const auth = betterAuth({
|
|
24
|
-
database: drizzleAdapter(database, { provider: "pg", schema }),
|
|
25
|
-
baseURL,
|
|
26
|
-
secret,
|
|
27
|
-
emailAndPassword: { enabled: true },
|
|
28
|
-
plugins: [admin(), ...(plugins || [])],
|
|
29
|
-
});
|
|
30
|
-
// Create admin user via better-auth API (admin plugin provides createUser)
|
|
31
|
-
const api = auth.api;
|
|
32
|
-
const result = await api.createUser({
|
|
33
|
-
body: {
|
|
34
|
-
email,
|
|
35
|
-
password,
|
|
36
|
-
name,
|
|
37
|
-
role: 'admin',
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
throw new AdminCreationError(error instanceof Error ? error.message : 'Failed to create admin user', 'ADMIN_CREATION_FAILED', 'Check your database connection and credentials');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46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AI;gBACJ,IAAI,EAAE,OAAO;aACd;SACF,CAAC,CAAC;QAEH,OAAO,MAA2B,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,kBAAkB,CAC1B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,EACtE,uBAAuB,EACvB,gDAAgD,CACjD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration loader for Deesse projects
|
|
3
|
-
*
|
|
4
|
-
* Handles loading and processing of deesse.config.ts files.
|
|
5
|
-
* Uses tsx to support TypeScript imports natively.
|
|
6
|
-
*/
|
|
7
|
-
interface Config {
|
|
8
|
-
name?: string;
|
|
9
|
-
database?: unknown;
|
|
10
|
-
plugins?: unknown[];
|
|
11
|
-
pages?: unknown[];
|
|
12
|
-
secret?: string;
|
|
13
|
-
auth?: {
|
|
14
|
-
baseURL?: string;
|
|
15
|
-
plugins?: unknown[];
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
interface InternalConfig extends Config {
|
|
19
|
-
auth?: {
|
|
20
|
-
baseURL: string;
|
|
21
|
-
plugins: unknown[];
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export declare class ConfigLoaderError extends Error {
|
|
25
|
-
readonly code?: string | undefined;
|
|
26
|
-
constructor(message: string, code?: string | undefined);
|
|
27
|
-
}
|
|
28
|
-
export interface MinimalConfig {
|
|
29
|
-
secret: string;
|
|
30
|
-
auth?: {
|
|
31
|
-
baseURL?: string;
|
|
32
|
-
plugins?: unknown[];
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export interface LoadConfigResult {
|
|
36
|
-
rawConfig: Config;
|
|
37
|
-
processedConfig: InternalConfig;
|
|
38
|
-
configPath: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Load the raw config from a deesse.config.ts file using tsx
|
|
42
|
-
*
|
|
43
|
-
* Uses tsx to execute the config file directly and export the config object.
|
|
44
|
-
* This properly handles TypeScript imports and module context.
|
|
45
|
-
*/
|
|
46
|
-
export declare function loadRawConfig(cwd: string): Promise<{
|
|
47
|
-
config: Config;
|
|
48
|
-
configPath: string;
|
|
49
|
-
}>;
|
|
50
|
-
/**
|
|
51
|
-
* Process raw config via defineConfig to get InternalConfig
|
|
52
|
-
*/
|
|
53
|
-
export declare function processConfig(rawConfig: Config): InternalConfig;
|
|
54
|
-
/**
|
|
55
|
-
* Load and process a deesse config
|
|
56
|
-
*/
|
|
57
|
-
export declare function loadConfig(cwd: string): Promise<LoadConfigResult>;
|
|
58
|
-
/**
|
|
59
|
-
* Load minimal config without executing the config file
|
|
60
|
-
*
|
|
61
|
-
* Extracts only secret and auth.baseURL via regex to avoid loading
|
|
62
|
-
* pages and other runtime-only config that would fail during CLI use.
|
|
63
|
-
*/
|
|
64
|
-
export declare function loadMinimalConfig(cwd: string): Promise<{
|
|
65
|
-
config: MinimalConfig;
|
|
66
|
-
configPath: string;
|
|
67
|
-
}>;
|
|
68
|
-
/**
|
|
69
|
-
* BetterAuthPlugin type for schema generation
|
|
70
|
-
*/
|
|
71
|
-
interface BetterAuthPlugin {
|
|
72
|
-
name: string;
|
|
73
|
-
schema?: Record<string, {
|
|
74
|
-
fields: Record<string, unknown>;
|
|
75
|
-
}>;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Load minimal config with plugins using tsx to execute the config file
|
|
79
|
-
*
|
|
80
|
-
* This properly extracts the plugins array from the config by executing
|
|
81
|
-
* it with tsx (like better-auth CLI does with jiti). This is needed for
|
|
82
|
-
* schema generation to include plugin-injected fields (e.g., admin plugin
|
|
83
|
-
* adds role, banned, banReason, banExpires to user table).
|
|
84
|
-
*/
|
|
85
|
-
export declare function loadMinimalConfigWithPlugins(cwd: string): Promise<{
|
|
86
|
-
config: MinimalConfig;
|
|
87
|
-
plugins: BetterAuthPlugin[];
|
|
88
|
-
configPath: string;
|
|
89
|
-
}>;
|
|
90
|
-
/**
|
|
91
|
-
* Check if the admin plugin is configured in the config
|
|
92
|
-
*/
|
|
93
|
-
export declare function hasAdminPlugin(config: InternalConfig): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Verify admin plugin is configured, throw if not
|
|
96
|
-
*/
|
|
97
|
-
export declare function verifyAdminPlugin(config: InternalConfig): void;
|
|
98
|
-
export {};
|
|
99
|
-
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/lib/config/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,UAAU,MAAM;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;KACrB,CAAC;CACH;AAED,UAAU,cAAe,SAAQ,MAAM;IACrC,IAAI,CAAC,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,CAAC;KACpB,CAAC;CACH;AAED,qBAAa,iBAAkB,SAAQ,KAAK;aACG,IAAI,CAAC,EAAE,MAAM;gBAA9C,OAAO,EAAE,MAAM,EAAkB,IAAI,CAAC,EAAE,MAAM,YAAA;CAI3D;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,gBA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4
|
-
* Handles loading and processing of deesse.config.ts files.
|
|
5
|
-
* Uses tsx to support TypeScript imports natively.
|
|
6
|
-
*/
|
|
7
|
-
import * as path from 'node:path';
|
|
8
|
-
import { createRequire } from 'node:module';
|
|
9
|
-
import { execSync } from 'node:child_process';
|
|
10
|
-
const CONFIG_PATHS = ['src/deesse.config.ts', 'deesse.config.ts', 'config/deesse.ts'];
|
|
11
|
-
export class ConfigLoaderError extends Error {
|
|
12
|
-
code;
|
|
13
|
-
constructor(message, code) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.code = code;
|
|
16
|
-
this.name = 'ConfigLoaderError';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Load the raw config from a deesse.config.ts file using tsx
|
|
21
|
-
*
|
|
22
|
-
* Uses tsx to execute the config file directly and export the config object.
|
|
23
|
-
* This properly handles TypeScript imports and module context.
|
|
24
|
-
*/
|
|
25
|
-
export async function loadRawConfig(cwd) {
|
|
26
|
-
let configPath = '';
|
|
27
|
-
for (const configFile of CONFIG_PATHS) {
|
|
28
|
-
configPath = path.resolve(cwd, configFile);
|
|
29
|
-
try {
|
|
30
|
-
// Try to access the file
|
|
31
|
-
const { access } = await import('node:fs/promises');
|
|
32
|
-
await access(configPath);
|
|
33
|
-
// File exists, break out of loop
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
// Try next path
|
|
38
|
-
configPath = '';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!configPath) {
|
|
42
|
-
throw new ConfigLoaderError(`Config file not found. Searched paths:\n${CONFIG_PATHS.map((p) => ` - ${p}`).join('\n')}\nRun 'deesse init' to create a new project.`);
|
|
43
|
-
}
|
|
44
|
-
// Use tsx to load and execute the TypeScript config file directly
|
|
45
|
-
// The config file is run as a module, and we export the config to stdout
|
|
46
|
-
const loaderScript = `
|
|
47
|
-
import { pathToFileURL } from 'node:url';
|
|
48
|
-
const configPath = pathToFileURL(${JSON.stringify(configPath)}).href;
|
|
49
|
-
const mod = await import(configPath);
|
|
50
|
-
const config = mod.config || mod.default;
|
|
51
|
-
if (!config) {
|
|
52
|
-
console.error('No config export found');
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
// Serialize to JSON (handles plain data, not functions)
|
|
56
|
-
console.log(JSON.stringify(config));
|
|
57
|
-
`;
|
|
58
|
-
try {
|
|
59
|
-
// Execute with tsx, preserving the current environment
|
|
60
|
-
const result = execSync(`node --import tsx -e ${JSON.stringify(loaderScript)}`, {
|
|
61
|
-
cwd,
|
|
62
|
-
encoding: 'utf-8',
|
|
63
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
64
|
-
env: { ...process.env },
|
|
65
|
-
});
|
|
66
|
-
const rawConfig = JSON.parse(result.trim());
|
|
67
|
-
if (!rawConfig) {
|
|
68
|
-
throw new ConfigLoaderError(`No config found in ${configPath}`);
|
|
69
|
-
}
|
|
70
|
-
return { config: rawConfig, configPath };
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
const err = error;
|
|
74
|
-
throw new ConfigLoaderError(`Failed to load config from ${configPath}: ${err.stderr || err.message || String(error)}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Process raw config via defineConfig to get InternalConfig
|
|
79
|
-
*/
|
|
80
|
-
export function processConfig(rawConfig) {
|
|
81
|
-
const require = createRequire(import.meta.url);
|
|
82
|
-
try {
|
|
83
|
-
const deesse = require('deesse');
|
|
84
|
-
if (typeof deesse.defineConfig !== 'function') {
|
|
85
|
-
throw new ConfigLoaderError('deesse package does not export defineConfig');
|
|
86
|
-
}
|
|
87
|
-
return deesse.defineConfig(rawConfig);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
if (error instanceof ConfigLoaderError) {
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
throw new ConfigLoaderError(`Failed to process config: ${error instanceof Error ? error.message : String(error)}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Load and process a deesse config
|
|
98
|
-
*/
|
|
99
|
-
export async function loadConfig(cwd) {
|
|
100
|
-
const { config: rawConfig, configPath } = await loadRawConfig(cwd);
|
|
101
|
-
const processedConfig = processConfig(rawConfig);
|
|
102
|
-
return { rawConfig, processedConfig, configPath };
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Load minimal config without executing the config file
|
|
106
|
-
*
|
|
107
|
-
* Extracts only secret and auth.baseURL via regex to avoid loading
|
|
108
|
-
* pages and other runtime-only config that would fail during CLI use.
|
|
109
|
-
*/
|
|
110
|
-
export async function loadMinimalConfig(cwd) {
|
|
111
|
-
const { configPath } = await findConfigPath(cwd);
|
|
112
|
-
// Read file content directly
|
|
113
|
-
const { readFile } = await import('node:fs/promises');
|
|
114
|
-
const content = await readFile(configPath, 'utf-8');
|
|
115
|
-
const config = { secret: '' };
|
|
116
|
-
// Extract secret: matches `secret: process.env.DEESSE_SECRET!` or similar patterns
|
|
117
|
-
const secretMatch = content.match(/secret\s*:\s*process\.env\.(\w+)!/);
|
|
118
|
-
if (secretMatch) {
|
|
119
|
-
const envVar = secretMatch[1];
|
|
120
|
-
const value = process.env[envVar];
|
|
121
|
-
if (!value) {
|
|
122
|
-
throw new ConfigLoaderError(`Environment variable ${envVar} is not set. Make sure your .env file contains ${envVar}`);
|
|
123
|
-
}
|
|
124
|
-
config.secret = value;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
// Try matching `secret: 'value'` or `secret: "value"`
|
|
128
|
-
const secretLiteralMatch = content.match(/secret\s*:\s*['"]([^'"]+)['"]/);
|
|
129
|
-
if (secretLiteralMatch) {
|
|
130
|
-
config.secret = secretLiteralMatch[1];
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (!config.secret) {
|
|
134
|
-
throw new ConfigLoaderError(`Could not extract 'secret' from ${configPath}. ` +
|
|
135
|
-
'Make sure your config has: secret: process.env.DEESSE_SECRET!');
|
|
136
|
-
}
|
|
137
|
-
// Extract auth.baseURL: matches `baseURL: process.env.VAR || 'default'` or `baseURL: 'https://...'`
|
|
138
|
-
const baseURLMatch = content.match(/baseURL\s*:\s*(?:process\.env\.(\w+)\s*\|\|\s*)?['"]([^'"]+)['"]/);
|
|
139
|
-
if (baseURLMatch) {
|
|
140
|
-
const envVar = baseURLMatch[1];
|
|
141
|
-
const defaultValue = baseURLMatch[2];
|
|
142
|
-
config.auth = {
|
|
143
|
-
baseURL: envVar && process.env[envVar] ? process.env[envVar] : defaultValue,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
return { config, configPath };
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Load minimal config with plugins using tsx to execute the config file
|
|
150
|
-
*
|
|
151
|
-
* This properly extracts the plugins array from the config by executing
|
|
152
|
-
* it with tsx (like better-auth CLI does with jiti). This is needed for
|
|
153
|
-
* schema generation to include plugin-injected fields (e.g., admin plugin
|
|
154
|
-
* adds role, banned, banReason, banExpires to user table).
|
|
155
|
-
*/
|
|
156
|
-
export async function loadMinimalConfigWithPlugins(cwd) {
|
|
157
|
-
const { config: minimalConfig, configPath } = await loadMinimalConfig(cwd);
|
|
158
|
-
// Use tsx to execute the config file and extract plugins
|
|
159
|
-
const loaderScript = `
|
|
160
|
-
import { pathToFileURL } from 'node:url';
|
|
161
|
-
const configPath = pathToFileURL(${JSON.stringify(configPath)}).href;
|
|
162
|
-
const mod = await import(configPath);
|
|
163
|
-
const config = mod.config || mod.default;
|
|
164
|
-
if (!config || !config.auth || !config.auth.plugins) {
|
|
165
|
-
console.log(JSON.stringify({ plugins: [] }));
|
|
166
|
-
} else {
|
|
167
|
-
// Extract just the plugin names and schemas for schema generation
|
|
168
|
-
const plugins = config.auth.plugins.map((p) => ({
|
|
169
|
-
name: typeof p === 'object' && p !== null ? (p.name || String(p)) : String(p),
|
|
170
|
-
schema: typeof p === 'object' && p !== null && 'schema' in p ? p.schema : undefined,
|
|
171
|
-
}));
|
|
172
|
-
console.log(JSON.stringify({ plugins }));
|
|
173
|
-
}
|
|
174
|
-
`;
|
|
175
|
-
try {
|
|
176
|
-
const result = execSync(`node --import tsx -e ${JSON.stringify(loaderScript)}`, {
|
|
177
|
-
cwd,
|
|
178
|
-
encoding: 'utf-8',
|
|
179
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
180
|
-
env: { ...process.env },
|
|
181
|
-
});
|
|
182
|
-
const parsed = JSON.parse(result.trim());
|
|
183
|
-
const plugins = parsed.plugins || [];
|
|
184
|
-
return { config: minimalConfig, plugins, configPath };
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
const err = error;
|
|
188
|
-
throw new ConfigLoaderError(`Failed to load plugins from config: ${err.stderr || err.message || String(error)}`);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Find the config file path without loading content
|
|
193
|
-
*/
|
|
194
|
-
async function findConfigPath(cwd) {
|
|
195
|
-
for (const configFile of CONFIG_PATHS) {
|
|
196
|
-
const configPath = path.resolve(cwd, configFile);
|
|
197
|
-
try {
|
|
198
|
-
const { access } = await import('node:fs/promises');
|
|
199
|
-
await access(configPath);
|
|
200
|
-
return { configPath };
|
|
201
|
-
}
|
|
202
|
-
catch {
|
|
203
|
-
// Try next path
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
throw new ConfigLoaderError(`Config file not found. Searched paths:\n${CONFIG_PATHS.map((p) => ` - ${p}`).join('\n')}\nRun 'deesse init' to create a new project.`);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Check if the admin plugin is configured in the config
|
|
210
|
-
*/
|
|
211
|
-
export function hasAdminPlugin(config) {
|
|
212
|
-
if (!config.auth?.plugins) {
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
return config.auth.plugins.some((plugin) => {
|
|
216
|
-
// Check if plugin has a name property indicating it's the admin plugin
|
|
217
|
-
if (plugin && typeof plugin === 'object' && 'name' in plugin) {
|
|
218
|
-
const name = plugin.name;
|
|
219
|
-
return name === 'admin' || String(name).includes('admin');
|
|
220
|
-
}
|
|
221
|
-
// Fallback to string representation check
|
|
222
|
-
const pluginStr = String(plugin);
|
|
223
|
-
return pluginStr.includes('admin') || pluginStr.includes('Admin');
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Verify admin plugin is configured, throw if not
|
|
228
|
-
*/
|
|
229
|
-
export function verifyAdminPlugin(config) {
|
|
230
|
-
if (!hasAdminPlugin(config)) {
|
|
231
|
-
throw new ConfigLoaderError('Admin plugin not configured. The admin plugin is automatically included by defineConfig,\n' +
|
|
232
|
-
'but your config must have an auth section configured.\n\n' +
|
|
233
|
-
'Example deesse.config.ts:\n' +
|
|
234
|
-
' export const config = defineConfig({\n' +
|
|
235
|
-
' auth: {\n' +
|
|
236
|
-
' baseURL: process.env.NEXT_PUBLIC_BASE_URL,\n' +
|
|
237
|
-
' },\n' +
|
|
238
|
-
' // ... other config\n' +
|
|
239
|
-
' });');
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
//# sourceMappingURL=loader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/lib/config/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,YAAY,GAAG,CAAC,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;AAsBtF,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACG;IAA7C,YAAY,OAAe,EAAkB,IAAa;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI,G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AO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YAC7D,MAAM,IAAI,GAAI,MAA4B,CAAC,IAAI,CAAC;YAChD,OAAO,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC5D,CAAC;QACD,0CAA0C;QAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB;IACtD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,iBAAiB,CACzB,4FAA4F;YAC1F,2DAA2D;YAC3D,6BAA6B;YAC7B,0CAA0C;YAC1C,eAAe;YACf,oDAAoD;YACpD,UAAU;YACV,2BAA2B;YAC3B,OAAO,CACV,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Better-Auth schema generation for db commands
|
|
3
|
-
*
|
|
4
|
-
* Since auth is mandatory in DeesseJS, db:generate and db:push
|
|
5
|
-
* must also generate the auth schema tables.
|
|
6
|
-
*
|
|
7
|
-
* Uses the programmatic API (generateDrizzleSchema from auth/api)
|
|
8
|
-
* instead of spawning npx auth@latest generate.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* BetterAuthPlugin type for schema generation
|
|
12
|
-
*/
|
|
13
|
-
interface BetterAuthPlugin {
|
|
14
|
-
name: string;
|
|
15
|
-
schema?: Record<string, {
|
|
16
|
-
fields: Record<string, unknown>;
|
|
17
|
-
}>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Generate the better-auth schema using the programmatic API
|
|
21
|
-
*
|
|
22
|
-
* This calls generateDrizzleSchema() directly to generate the auth tables
|
|
23
|
-
* (user, session, account, verification) without needing a config file.
|
|
24
|
-
*
|
|
25
|
-
* @param cwd - Working directory
|
|
26
|
-
* @param plugins - Array of BetterAuthPlugin objects to include in schema generation.
|
|
27
|
-
* Pass undefined to use an empty array (no plugin fields).
|
|
28
|
-
*/
|
|
29
|
-
export declare function generateAuthSchema(cwd?: string, plugins?: BetterAuthPlugin[]): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Check if auth schema file exists
|
|
32
|
-
*/
|
|
33
|
-
export declare function authSchemaExists(cwd?: string): Promise<boolean>;
|
|
34
|
-
/**
|
|
35
|
-
* Get the path to the auth schema file
|
|
36
|
-
*/
|
|
37
|
-
export declare function getAuthSchemaPath(cwd?: string): string;
|
|
38
|
-
export {};
|
|
39
|
-
//# sourceMappingURL=auth-schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-schema.d.ts","sourceRoot":"","sources":["../../../src/lib/db/auth-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAqDH;;GAEG;AACH,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CAC9D;AAWD;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,GAAE,MAAsB,EAC3B,OAAO,CAAC,EAAE,gBAAgB,EAAE,GAC3B,OAAO,CAAC,IAAI,CAAC,CAiDf;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQpF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,CAErE"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Better-Auth schema generation for db commands
|
|
3
|
-
*
|
|
4
|
-
* Since auth is mandatory in DeesseJS, db:generate and db:push
|
|
5
|
-
* must also generate the auth schema tables.
|
|
6
|
-
*
|
|
7
|
-
* Uses the programmatic API (generateDrizzleSchema from auth/api)
|
|
8
|
-
* instead of spawning npx auth@latest generate.
|
|
9
|
-
*/
|
|
10
|
-
import { writeFile, access, mkdir } from 'node:fs/promises';
|
|
11
|
-
import { existsSync } from 'node:fs';
|
|
12
|
-
import * as path from 'node:path';
|
|
13
|
-
const AUTH_SCHEMA_OUTPUT = './src/db/auth-schema.ts';
|
|
14
|
-
async function generateDrizzleSchemaInternal(
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
opts) {
|
|
17
|
-
// Dynamic import to get the generator
|
|
18
|
-
const { generateDrizzleSchema } = await import('auth/api');
|
|
19
|
-
return generateDrizzleSchema(opts);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Create a mock adapter for schema generation
|
|
23
|
-
*/
|
|
24
|
-
function createMockAdapter(dialect) {
|
|
25
|
-
// Map postgresql to pg for drizzle
|
|
26
|
-
const provider = dialect === 'postgresql' ? 'pg' : dialect;
|
|
27
|
-
return {
|
|
28
|
-
id: 'drizzle',
|
|
29
|
-
options: {
|
|
30
|
-
adapterConfig: {
|
|
31
|
-
adapterId: 'drizzle',
|
|
32
|
-
},
|
|
33
|
-
provider,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Ensure a directory exists
|
|
39
|
-
*/
|
|
40
|
-
async function ensureDir(dirPath) {
|
|
41
|
-
if (!existsSync(dirPath)) {
|
|
42
|
-
await mkdir(dirPath, { recursive: true });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Generate the better-auth schema using the programmatic API
|
|
47
|
-
*
|
|
48
|
-
* This calls generateDrizzleSchema() directly to generate the auth tables
|
|
49
|
-
* (user, session, account, verification) without needing a config file.
|
|
50
|
-
*
|
|
51
|
-
* @param cwd - Working directory
|
|
52
|
-
* @param plugins - Array of BetterAuthPlugin objects to include in schema generation.
|
|
53
|
-
* Pass undefined to use an empty array (no plugin fields).
|
|
54
|
-
*/
|
|
55
|
-
export async function generateAuthSchema(cwd = process.cwd(), plugins) {
|
|
56
|
-
const outputPath = path.resolve(cwd, AUTH_SCHEMA_OUTPUT);
|
|
57
|
-
console.warn('Generating better-auth schema...');
|
|
58
|
-
try {
|
|
59
|
-
// Create mock adapter for drizzle with postgresql dialect
|
|
60
|
-
const adapter = createMockAdapter('postgresql');
|
|
61
|
-
// Generate the schema using the programmatic API
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
-
const schema = await generateDrizzleSchemaInternal({
|
|
64
|
-
file: outputPath,
|
|
65
|
-
adapter,
|
|
66
|
-
options: {
|
|
67
|
-
database: {},
|
|
68
|
-
plugins: plugins ?? [],
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
if (!schema.code) {
|
|
72
|
-
console.warn('Auth schema is already up to date.');
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// Ensure parent directory exists
|
|
76
|
-
const parentDir = path.dirname(outputPath);
|
|
77
|
-
await ensureDir(parentDir);
|
|
78
|
-
// Write the generated schema to file
|
|
79
|
-
await writeFile(outputPath, schema.code, 'utf-8');
|
|
80
|
-
// Append schema export (combined object of all auth tables)
|
|
81
|
-
// This is needed because generateDrizzleSchema exports named tables,
|
|
82
|
-
// but drizzle expects a schema object with all tables
|
|
83
|
-
// Named 'schema' to match drizzle-kit's expectation
|
|
84
|
-
const schemaExport = `\nexport const schema = { user, session, account, verification };\n`;
|
|
85
|
-
await writeFile(outputPath, schemaExport, { flag: 'a' });
|
|
86
|
-
console.warn(`Auth schema generated: ${outputPath}`);
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
if (error.code === 'ENOENT') {
|
|
90
|
-
throw new Error('better-auth schema generation failed. Please ensure better-auth is installed:\n' +
|
|
91
|
-
' npm install better-auth');
|
|
92
|
-
}
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Check if auth schema file exists
|
|
98
|
-
*/
|
|
99
|
-
export async function authSchemaExists(cwd = process.cwd()) {
|
|
100
|
-
const outputPath = path.resolve(cwd, AUTH_SCHEMA_OUTPUT);
|
|
101
|
-
try {
|
|
102
|
-
await access(outputPath);
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Get the path to the auth schema file
|
|
111
|
-
*/
|
|
112
|
-
export function getAuthSchemaPath(cwd = process.cwd()) {
|
|
113
|
-
return path.resolve(cwd, AUTH_SCHEMA_OUTPUT);
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=auth-schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-schema.js","sourceRoot":"","sources":["../../../src/lib/db/auth-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AAmBrD,KAAK,UAAU,6BAA6B;AAC1C,8DAA8D;AAC9D,IAAS;IAET,sCAAsC;IACtC,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IAE3D,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAS,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.ts
|
|
5
|
-
* This is required because drizzle-kit's programmatic API takes schema objects,
|
|
6
|
-
* not file paths.
|
|
7
|
-
*/
|
|
8
|
-
declare const DEFAULT_SCHEMA_PATH = "./src/db/schema.ts";
|
|
9
|
-
declare const DEFAULT_DRIZZLE_CONFIG_PATH = "./drizzle.config.ts";
|
|
10
|
-
export { DEFAULT_SCHEMA_PATH, DEFAULT_DRIZZLE_CONFIG_PATH };
|
|
11
|
-
export interface SchemaLoaderResult {
|
|
12
|
-
schema: Record<string, unknown>;
|
|
13
|
-
schemaPath: string;
|
|
14
|
-
}
|
|
15
|
-
export declare class SchemaLoaderError extends Error {
|
|
16
|
-
readonly code?: string | undefined;
|
|
17
|
-
constructor(message: string, code?: string | undefined);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Load Drizzle schema objects from the user's schema file
|
|
21
|
-
*/
|
|
22
|
-
export declare function loadSchema(cwd?: string): Promise<SchemaLoaderResult>;
|
|
23
|
-
/**
|
|
24
|
-
* Verify the schema file exists
|
|
25
|
-
*/
|
|
26
|
-
export declare function verifySchemaPath(cwd?: string): Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
* Check if schema file exists
|
|
29
|
-
*/
|
|
30
|
-
export declare function schemaExists(cwd?: string): Promise<boolean>;
|
|
31
|
-
/**
|
|
32
|
-
* Check if drizzle config exists
|
|
33
|
-
*/
|
|
34
|
-
export declare function drizzleConfigExists(cwd?: string): Promise<boolean>;
|
|
35
|
-
/**
|
|
36
|
-
* Create the default schema file with auth schema import
|
|
37
|
-
*/
|
|
38
|
-
export declare function createDefaultSchema(cwd?: string): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Create the default drizzle config file
|
|
41
|
-
*/
|
|
42
|
-
export declare function createDrizzleConfig(cwd?: string): Promise<void>;
|
|
43
|
-
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/lib/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,QAAA,MAAM,mBAAmB,uBAAuB,CAAC;AACjD,QAAA,MAAM,2BAA2B,wBAAwB,CAAC;AAG1D,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,iBAAkB,SAAQ,KAAK;aACG,IAAI,CAAC,EAAE,MAAM;gBAA9C,OAAO,EAAE,MAAM,EAAkB,IAAI,CAAC,EAAE,MAAM,YAAA;CAI3D;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAwCzF;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CAanF;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQhF;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQvF;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBpF;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBpF"}
|