stackkit 0.1.3 → 0.1.5
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/README.md +5 -3
- package/dist/cli/add.d.ts +2 -1
- package/dist/cli/add.js +325 -102
- package/dist/cli/create.d.ts +2 -2
- package/dist/cli/create.js +96 -30
- package/dist/cli/doctor.js +25 -17
- package/dist/cli/list.js +14 -2
- package/dist/index.js +22 -3
- package/dist/lib/conversion/js-conversion.js +2 -2
- package/dist/lib/discovery/module-discovery.d.ts +0 -1
- package/dist/lib/discovery/module-discovery.js +35 -35
- package/dist/lib/env/env-editor.js +1 -1
- package/dist/lib/framework/framework-utils.d.ts +1 -1
- package/dist/lib/framework/framework-utils.js +3 -3
- package/dist/lib/generation/code-generator.d.ts +18 -4
- package/dist/lib/generation/code-generator.js +212 -147
- package/dist/lib/generation/generator-utils.d.ts +11 -0
- package/dist/lib/generation/generator-utils.js +124 -0
- package/dist/lib/git-utils.js +20 -0
- package/dist/lib/project/detect.js +2 -4
- package/dist/lib/utils/package-root.js +2 -2
- package/dist/types/index.d.ts +0 -10
- package/modules/auth/authjs/generator.json +10 -0
- package/modules/auth/authjs/module.json +0 -9
- package/modules/auth/better-auth/files/lib/auth.ts +38 -31
- package/modules/auth/better-auth/files/prisma/schema.prisma +3 -3
- package/modules/auth/better-auth/generator.json +58 -28
- package/modules/auth/better-auth/module.json +0 -24
- package/modules/database/mongoose/files/models/health.ts +34 -0
- package/modules/database/mongoose/generator.json +27 -8
- package/modules/database/mongoose/module.json +1 -2
- package/modules/database/prisma/files/lib/prisma.ts +27 -21
- package/modules/database/prisma/files/prisma.config.ts +17 -0
- package/modules/database/prisma/generator.json +79 -15
- package/modules/database/prisma/module.json +1 -4
- package/package.json +1 -1
- package/templates/express/src/server.ts +9 -3
- package/templates/express/tsconfig.json +2 -23
- package/templates/nextjs/lib/env.ts +1 -1
- package/dist/lib/database/database-config.d.ts +0 -6
- package/dist/lib/database/database-config.js +0 -9
- package/modules/database/mongoose/files/models/User.ts +0 -34
- /package/modules/database/mongoose/files/lib/{db.ts → mongoose.ts} +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GeneratorConfig } from "./code-generator";
|
|
2
|
+
import type { ModuleMetadata } from "../../types";
|
|
3
|
+
export declare function mergeModuleIntoGeneratorConfig(config: GeneratorConfig, modulePath: string): Promise<GeneratorConfig>;
|
|
4
|
+
export declare function mergeGeneratorIntoModuleMetadata(metadata: ModuleMetadata, modulePath: string): Promise<ModuleMetadata>;
|
|
5
|
+
export declare function locateOperationSource(generatorType: string, generatorName: string, sourceRel: string): string | null;
|
|
6
|
+
declare const _default: {
|
|
7
|
+
mergeModuleIntoGeneratorConfig: typeof mergeModuleIntoGeneratorConfig;
|
|
8
|
+
mergeGeneratorIntoModuleMetadata: typeof mergeGeneratorIntoModuleMetadata;
|
|
9
|
+
locateOperationSource: typeof locateOperationSource;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.mergeModuleIntoGeneratorConfig = mergeModuleIntoGeneratorConfig;
|
|
37
|
+
exports.mergeGeneratorIntoModuleMetadata = mergeGeneratorIntoModuleMetadata;
|
|
38
|
+
exports.locateOperationSource = locateOperationSource;
|
|
39
|
+
const fs = __importStar(require("fs-extra"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const package_root_1 = require("../utils/package-root");
|
|
42
|
+
async function mergeModuleIntoGeneratorConfig(config, modulePath) {
|
|
43
|
+
const modulePathJson = path.join(modulePath, "module.json");
|
|
44
|
+
if (await fs.pathExists(modulePathJson)) {
|
|
45
|
+
try {
|
|
46
|
+
const moduleConfig = await fs.readJson(modulePathJson);
|
|
47
|
+
if (moduleConfig.postInstall && Array.isArray(moduleConfig.postInstall)) {
|
|
48
|
+
config.postInstall = moduleConfig.postInstall;
|
|
49
|
+
}
|
|
50
|
+
if (moduleConfig.dependencies && typeof moduleConfig.dependencies === "object") {
|
|
51
|
+
config.dependencies = { ...(config.dependencies || {}), ...moduleConfig.dependencies };
|
|
52
|
+
}
|
|
53
|
+
if (moduleConfig.devDependencies && typeof moduleConfig.devDependencies === "object") {
|
|
54
|
+
config.devDependencies = {
|
|
55
|
+
...(config.devDependencies || {}),
|
|
56
|
+
...moduleConfig.devDependencies,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (moduleConfig.scripts && typeof moduleConfig.scripts === "object") {
|
|
60
|
+
config.scripts = { ...(config.scripts || {}), ...moduleConfig.scripts };
|
|
61
|
+
}
|
|
62
|
+
if (moduleConfig.envVars && typeof moduleConfig.envVars === "object") {
|
|
63
|
+
config.envVars = { ...(config.envVars || {}), ...moduleConfig.envVars };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// ignore invalid module.json
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
72
|
+
async function mergeGeneratorIntoModuleMetadata(metadata, modulePath) {
|
|
73
|
+
const generatorPath = path.join(modulePath, "generator.json");
|
|
74
|
+
if (await fs.pathExists(generatorPath)) {
|
|
75
|
+
try {
|
|
76
|
+
const generator = await fs.readJson(generatorPath);
|
|
77
|
+
if (generator.envVars) {
|
|
78
|
+
metadata.envVars = metadata.envVars || [];
|
|
79
|
+
for (const [key, value] of Object.entries(generator.envVars)) {
|
|
80
|
+
metadata.envVars.push({
|
|
81
|
+
key,
|
|
82
|
+
value: value,
|
|
83
|
+
description: `Environment variable for ${key}`,
|
|
84
|
+
required: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (generator.dependencies) {
|
|
89
|
+
metadata.dependencies = { ...metadata.dependencies, ...generator.dependencies };
|
|
90
|
+
}
|
|
91
|
+
if (generator.devDependencies) {
|
|
92
|
+
metadata.devDependencies = { ...metadata.devDependencies, ...generator.devDependencies };
|
|
93
|
+
}
|
|
94
|
+
if (generator.postInstall && Array.isArray(generator.postInstall)) {
|
|
95
|
+
metadata.postInstall = metadata.postInstall || [];
|
|
96
|
+
metadata.postInstall.push(...generator.postInstall);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// ignore invalid generator.json
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return metadata;
|
|
104
|
+
}
|
|
105
|
+
function locateOperationSource(generatorType, generatorName, sourceRel) {
|
|
106
|
+
const packageRoot = (0, package_root_1.getPackageRoot)();
|
|
107
|
+
const modulesPath = path.join(packageRoot, "modules");
|
|
108
|
+
const templatesPath = path.join(packageRoot, "templates");
|
|
109
|
+
const moduleBasePath = generatorType === "framework"
|
|
110
|
+
? path.join(templatesPath, generatorName)
|
|
111
|
+
: path.join(modulesPath, generatorType, generatorName);
|
|
112
|
+
const sourcePath = path.join(moduleBasePath, "files", sourceRel);
|
|
113
|
+
try {
|
|
114
|
+
return sourcePath;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.default = {
|
|
121
|
+
mergeModuleIntoGeneratorConfig,
|
|
122
|
+
mergeGeneratorIntoModuleMetadata,
|
|
123
|
+
locateOperationSource,
|
|
124
|
+
};
|
package/dist/lib/git-utils.js
CHANGED
|
@@ -3,7 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.initGit = initGit;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
async function initGit(cwd) {
|
|
6
|
+
try {
|
|
7
|
+
(0, child_process_1.execSync)("git --version", { stdio: "pipe" });
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
throw new Error("Git is not installed or not available in PATH");
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
(0, child_process_1.execSync)("git status", { cwd, stdio: "pipe" });
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// Not a git repo, proceed with initialization
|
|
18
|
+
}
|
|
6
19
|
(0, child_process_1.execSync)("git init", { cwd, stdio: "pipe" });
|
|
7
20
|
(0, child_process_1.execSync)("git add .", { cwd, stdio: "pipe" });
|
|
21
|
+
try {
|
|
22
|
+
(0, child_process_1.execSync)("git diff --cached --quiet", { cwd, stdio: "pipe" });
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Files are staged, proceed with commit
|
|
27
|
+
}
|
|
8
28
|
(0, child_process_1.execSync)('git commit -m "Initial commit"', { cwd, stdio: "pipe" });
|
|
9
29
|
}
|
|
@@ -63,14 +63,13 @@ async function detectProjectInfo(targetDir) {
|
|
|
63
63
|
language = "js";
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
-
// Default to TypeScript if neither exists
|
|
67
66
|
language = "ts";
|
|
68
67
|
}
|
|
69
68
|
// Detect package manager
|
|
70
69
|
const yarnLockExists = await fs_extra_1.default.pathExists(path_1.default.join(targetDir, "yarn.lock"));
|
|
71
70
|
const pnpmLockExists = await fs_extra_1.default.pathExists(path_1.default.join(targetDir, "pnpm-lock.yaml"));
|
|
72
71
|
const bunLockExists = await fs_extra_1.default.pathExists(path_1.default.join(targetDir, "bun.lockb"));
|
|
73
|
-
let packageManager = "
|
|
72
|
+
let packageManager = "pnpm";
|
|
74
73
|
if (pnpmLockExists) {
|
|
75
74
|
packageManager = "pnpm";
|
|
76
75
|
}
|
|
@@ -84,8 +83,7 @@ async function detectProjectInfo(targetDir) {
|
|
|
84
83
|
const hasAuth = !!(packageJson.dependencies?.["next-auth"] ||
|
|
85
84
|
packageJson.dependencies?.["better-auth"] ||
|
|
86
85
|
packageJson.dependencies?.["@auth/core"] ||
|
|
87
|
-
packageJson.dependencies?.["@kinde-oss/kinde-auth-nextjs"]
|
|
88
|
-
packageJson.dependencies?.["passport"]);
|
|
86
|
+
packageJson.dependencies?.["@kinde-oss/kinde-auth-nextjs"]);
|
|
89
87
|
const hasPrisma = !!(packageJson.dependencies?.["@prisma/client"] || packageJson.devDependencies?.["prisma"]);
|
|
90
88
|
const hasDatabase = hasPrisma ||
|
|
91
89
|
!!(packageJson.dependencies?.["mongoose"] ||
|
|
@@ -37,9 +37,9 @@ exports.getPackageRoot = getPackageRoot;
|
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
38
|
function getPackageRoot() {
|
|
39
39
|
try {
|
|
40
|
-
return path.dirname(require.resolve(
|
|
40
|
+
return path.dirname(require.resolve("stackkit/package.json"));
|
|
41
41
|
}
|
|
42
42
|
catch {
|
|
43
|
-
return path.resolve(__dirname,
|
|
43
|
+
return path.resolve(__dirname, "..", "..", "..");
|
|
44
44
|
}
|
|
45
45
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -28,16 +28,6 @@ export interface ModuleMetadata {
|
|
|
28
28
|
};
|
|
29
29
|
}>;
|
|
30
30
|
postInstall?: string[];
|
|
31
|
-
databaseAdapters?: {
|
|
32
|
-
common?: {
|
|
33
|
-
dependencies?: Record<string, string>;
|
|
34
|
-
devDependencies?: Record<string, string>;
|
|
35
|
-
};
|
|
36
|
-
providers?: Record<string, Record<string, {
|
|
37
|
-
dependencies?: Record<string, string>;
|
|
38
|
-
devDependencies?: Record<string, string>;
|
|
39
|
-
}>>;
|
|
40
|
-
};
|
|
41
31
|
frameworkConfigs?: Record<string, {
|
|
42
32
|
dependencies?: Record<string, string>;
|
|
43
33
|
devDependencies?: Record<string, string>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "authjs",
|
|
3
3
|
"displayName": "Auth.js",
|
|
4
|
-
"description": "Authentication with Auth.js (NextAuth.js v5)",
|
|
5
4
|
"category": "auth",
|
|
6
5
|
"provider": "authjs",
|
|
7
6
|
"supportedFrameworks": ["nextjs"],
|
|
@@ -10,13 +9,5 @@
|
|
|
10
9
|
"databases": ["prisma"],
|
|
11
10
|
"languages": ["typescript", "javascript"],
|
|
12
11
|
"packageManagers": ["npm", "yarn", "pnpm", "bun"]
|
|
13
|
-
},
|
|
14
|
-
"databaseAdapters": {
|
|
15
|
-
"common": {
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@auth/prisma-adapter": "^2.7.1"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {}
|
|
20
|
-
}
|
|
21
12
|
}
|
|
22
13
|
}
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import { betterAuth } from "better-auth";
|
|
2
2
|
import { sendEmail } from "./email/email-service";
|
|
3
3
|
import { getVerificationEmailTemplate, getPasswordResetEmailTemplate } from "./email/email-templates";
|
|
4
|
-
{{#
|
|
5
|
-
|
|
4
|
+
{{#switch database}}
|
|
5
|
+
{{#case prisma}}
|
|
6
|
+
import { prisma } from "{{framework == 'nextjs' ? '@/lib' : '.'}}/prisma";
|
|
6
7
|
import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
7
|
-
{{/
|
|
8
|
-
{{#
|
|
9
|
-
import {
|
|
8
|
+
{{/case}}
|
|
9
|
+
{{#case mongoose}}
|
|
10
|
+
import { mongoose } from "{{framework == 'nextjs' ? '@/lib' : '.'}}/mongoose";
|
|
10
11
|
import { mongodbAdapter } from "better-auth/adapters/mongodb";
|
|
11
|
-
{{/
|
|
12
|
+
{{/case}}
|
|
13
|
+
{{/switch}}
|
|
12
14
|
|
|
13
|
-
export
|
|
14
|
-
{
|
|
15
|
+
export async function initAuth() {
|
|
16
|
+
return betterAuth({
|
|
17
|
+
{{#switch database}}
|
|
18
|
+
{{#case prisma}}
|
|
15
19
|
database: prismaAdapter(prisma, {
|
|
16
|
-
|
|
20
|
+
provider: "{{prismaProvider}}",
|
|
17
21
|
}),
|
|
18
|
-
{{/
|
|
19
|
-
{{#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
{{/case}}
|
|
23
|
+
{{#case mongoose}}
|
|
24
|
+
const mongooseInstance = await mongoose();
|
|
25
|
+
const client = mongooseInstance.connection.getClient();
|
|
26
|
+
const db = client.db();
|
|
27
|
+
database: mongodbAdapter(db, { client }),
|
|
28
|
+
{{/case}}
|
|
29
|
+
{{/switch}}
|
|
22
30
|
user: {
|
|
23
31
|
additionalFields: {
|
|
24
32
|
role: {
|
|
@@ -31,6 +39,15 @@ export const auth = betterAuth({
|
|
|
31
39
|
emailAndPassword: {
|
|
32
40
|
enabled: true,
|
|
33
41
|
requireEmailVerification: true,
|
|
42
|
+
sendResetPassword: async ({ user, url }) => {
|
|
43
|
+
const { html, text } = getPasswordResetEmailTemplate(user, url);
|
|
44
|
+
await sendEmail({
|
|
45
|
+
to: user.email,
|
|
46
|
+
subject: "Reset Your Password",
|
|
47
|
+
text,
|
|
48
|
+
html,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
34
51
|
},
|
|
35
52
|
socialProviders: {
|
|
36
53
|
google: {
|
|
@@ -50,22 +67,9 @@ export const auth = betterAuth({
|
|
|
50
67
|
},
|
|
51
68
|
sendOnSignIn: true,
|
|
52
69
|
},
|
|
53
|
-
password: {
|
|
54
|
-
reset: {
|
|
55
|
-
sendResetEmail: async ({ user, url }) => {
|
|
56
|
-
const { html, text } = getPasswordResetEmailTemplate(user, url);
|
|
57
|
-
await sendEmail({
|
|
58
|
-
to: user.email,
|
|
59
|
-
subject: "Reset Your Password",
|
|
60
|
-
text,
|
|
61
|
-
html,
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
70
|
rateLimit: {
|
|
67
|
-
window: 10,
|
|
68
|
-
max: 100,
|
|
71
|
+
window: 10,
|
|
72
|
+
max: 100,
|
|
69
73
|
},
|
|
70
74
|
account: {
|
|
71
75
|
accountLinking: {
|
|
@@ -77,7 +81,10 @@ export const auth = betterAuth({
|
|
|
77
81
|
cookieCache: {
|
|
78
82
|
enabled: true,
|
|
79
83
|
},
|
|
80
|
-
expiresIn: 60 * 60 * 24 * 7,
|
|
81
|
-
updateAge: 60 * 60 * 24,
|
|
84
|
+
expiresIn: 60 * 60 * 24 * 7,
|
|
85
|
+
updateAge: 60 * 60 * 24,
|
|
82
86
|
}
|
|
83
|
-
})
|
|
87
|
+
})
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const auth = await initAuth();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{{#var defaultId = {{#if prismaProvider ==
|
|
1
|
+
{{#var defaultId = {{#if prismaProvider == mongodb}}@default(auto()) @map("_id") @db.ObjectId{{else}}@default(cuid()){{/if}}}}
|
|
2
2
|
model User {
|
|
3
3
|
id String @id {{defaultId}}
|
|
4
4
|
name String
|
|
@@ -23,7 +23,7 @@ model Session {
|
|
|
23
23
|
updatedAt DateTime @updatedAt
|
|
24
24
|
ipAddress String?
|
|
25
25
|
userAgent String?
|
|
26
|
-
userId String
|
|
26
|
+
userId String {{#if prismaProvider == mongodb}} @db.ObjectId{{/if}}
|
|
27
27
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
28
28
|
|
|
29
29
|
@@index([userId])
|
|
@@ -34,7 +34,7 @@ model Account {
|
|
|
34
34
|
id String @id {{defaultId}}
|
|
35
35
|
accountId String
|
|
36
36
|
providerId String
|
|
37
|
-
userId String
|
|
37
|
+
userId String {{#if prismaProvider == mongodb}} @db.ObjectId{{/if}}
|
|
38
38
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
39
39
|
accessToken String?
|
|
40
40
|
refreshToken String?
|
|
@@ -5,49 +5,36 @@
|
|
|
5
5
|
"operations": [
|
|
6
6
|
{
|
|
7
7
|
"type": "create-file",
|
|
8
|
-
"description": "Create Better Auth configuration file",
|
|
9
8
|
"source": "lib/auth.ts",
|
|
10
9
|
"destination": "lib/auth.ts",
|
|
11
10
|
"condition": { "framework": ["nextjs", "express"] }
|
|
12
11
|
},
|
|
13
12
|
{
|
|
14
13
|
"type": "create-file",
|
|
15
|
-
"description": "Create email service for sending emails",
|
|
16
14
|
"source": "lib/email-service.ts",
|
|
17
15
|
"destination": "lib/email/email-service.ts",
|
|
18
16
|
"condition": { "framework": ["nextjs", "express"] }
|
|
19
17
|
},
|
|
20
18
|
{
|
|
21
19
|
"type": "create-file",
|
|
22
|
-
"description": "Create email templates",
|
|
23
20
|
"source": "lib/email-templates.ts",
|
|
24
21
|
"destination": "lib/email/email-templates.ts",
|
|
25
22
|
"condition": { "framework": ["nextjs", "express"] }
|
|
26
23
|
},
|
|
27
24
|
{
|
|
28
25
|
"type": "create-file",
|
|
29
|
-
"description": "Create Better Auth API routes for Next.js",
|
|
30
26
|
"source": "api/auth/[...all]/route.ts",
|
|
31
27
|
"destination": "app/api/auth/[...all]/route.ts",
|
|
32
28
|
"condition": { "framework": "nextjs" }
|
|
33
29
|
},
|
|
34
30
|
{
|
|
35
31
|
"type": "create-file",
|
|
36
|
-
"description": "Create Better Auth client for React",
|
|
37
32
|
"source": "lib/auth-client.ts",
|
|
38
33
|
"destination": "lib/auth-client.ts",
|
|
39
34
|
"condition": { "framework": ["nextjs", "react"] }
|
|
40
35
|
},
|
|
41
|
-
{
|
|
42
|
-
"type": "create-file",
|
|
43
|
-
"description": "Create Better Auth middleware for Next.js",
|
|
44
|
-
"destination": "proxy.ts",
|
|
45
|
-
"condition": { "framework": "nextjs" },
|
|
46
|
-
"content": "import { auth } from \"@/lib/auth\";\n\nexport default auth((req) => {\n console.log('middleware', req.auth)\n})\n\nexport const config = {\n matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],\n}"
|
|
47
|
-
},
|
|
48
36
|
{
|
|
49
37
|
"type": "patch-file",
|
|
50
|
-
"description": "Add Better Auth schema to Prisma schema",
|
|
51
38
|
"destination": "prisma/schema.prisma",
|
|
52
39
|
"condition": { "database": "prisma" },
|
|
53
40
|
"operations": [
|
|
@@ -56,23 +43,66 @@
|
|
|
56
43
|
"source": "prisma/schema.prisma"
|
|
57
44
|
}
|
|
58
45
|
]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"type": "patch-file",
|
|
49
|
+
"destination": "src/server.ts",
|
|
50
|
+
"condition": { "framework": "express" },
|
|
51
|
+
"operations": [
|
|
52
|
+
{
|
|
53
|
+
"type": "add-import",
|
|
54
|
+
"imports": ["import { initAuth } from \"@/lib/auth\";"]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"type": "add-code",
|
|
58
|
+
"before": "const port = env.port;",
|
|
59
|
+
"code": "await initAuth();"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"type": "patch-file",
|
|
65
|
+
"destination": "src/app.ts",
|
|
66
|
+
"condition": { "framework": "express" },
|
|
67
|
+
"operations": [
|
|
68
|
+
{
|
|
69
|
+
"type": "add-import",
|
|
70
|
+
"imports": ["import { auth } from \"@/lib/auth\";",
|
|
71
|
+
"import { toNodeHandler } from \"better-auth/node\";"]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"type": "add-code",
|
|
75
|
+
"after": "// routes",
|
|
76
|
+
"code": "app.all(\"/api/auth/*splat\", toNodeHandler(auth));"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"type": "add-dependency",
|
|
82
|
+
"condition": { "framework": ["nextjs", "express"] },
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"nodemailer": "^7.0.12"
|
|
85
|
+
},
|
|
86
|
+
"devDependencies": {
|
|
87
|
+
"@types/nodemailer": "^7.0.5"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"type": "add-env",
|
|
92
|
+
"envVars": {
|
|
93
|
+
"BETTER_AUTH_SECRET": "",
|
|
94
|
+
"BETTER_AUTH_URL": "http://localhost:3000",
|
|
95
|
+
"EMAIL_HOST": "smtp.gmail.com",
|
|
96
|
+
"EMAIL_PORT": "587",
|
|
97
|
+
"EMAIL_USER": "",
|
|
98
|
+
"EMAIL_PASS": "",
|
|
99
|
+
"EMAIL_FROM": "noreply@yourapp.com"
|
|
100
|
+
}
|
|
59
101
|
}
|
|
60
102
|
],
|
|
61
103
|
"dependencies": {
|
|
62
|
-
"better-auth": "^1.4.12"
|
|
63
|
-
"nodemailer": "^7.0.12"
|
|
64
|
-
},
|
|
65
|
-
"devDependencies": {
|
|
66
|
-
"@types/nodemailer": "^7.0.5"
|
|
104
|
+
"better-auth": "^1.4.12"
|
|
67
105
|
},
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"BETTER_AUTH_SECRET": "",
|
|
71
|
-
"BETTER_AUTH_URL": "http://localhost:3000",
|
|
72
|
-
"EMAIL_HOST": "smtp.gmail.com",
|
|
73
|
-
"EMAIL_PORT": "587",
|
|
74
|
-
"EMAIL_USER": "",
|
|
75
|
-
"EMAIL_PASS": "",
|
|
76
|
-
"EMAIL_FROM": "noreply@yourapp.com"
|
|
77
|
-
}
|
|
106
|
+
"devDependencies": {},
|
|
107
|
+
"scripts": {}
|
|
78
108
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-auth",
|
|
3
3
|
"displayName": "Better Auth",
|
|
4
|
-
"description": "Modern authentication with Better Auth",
|
|
5
4
|
"category": "auth",
|
|
6
5
|
"provider": "better-auth",
|
|
7
6
|
"supportedFrameworks": ["nextjs", "express", "react"],
|
|
@@ -10,28 +9,5 @@
|
|
|
10
9
|
"databases": ["prisma", "mongoose"],
|
|
11
10
|
"languages": ["typescript", "javascript"],
|
|
12
11
|
"packageManagers": ["npm", "yarn", "pnpm", "bun"]
|
|
13
|
-
},
|
|
14
|
-
"databaseAdapters": {
|
|
15
|
-
"prisma-postgresql": {
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@prisma/adapter-pg": "^5.0.0",
|
|
18
|
-
"pg": "^8.0.0"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"prisma-mongodb": {
|
|
22
|
-
"dependencies": {}
|
|
23
|
-
},
|
|
24
|
-
"prisma-mysql": {
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@prisma/adapter-mariadb": "^5.0.0",
|
|
27
|
-
"mysql2": "^3.0.0"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"prisma-sqlite": {
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@prisma/adapter-better-sqlite3": "^5.0.0",
|
|
33
|
-
"better-sqlite3": "^9.0.0"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
12
|
}
|
|
37
13
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import mongoose, { Document, Schema } from "mongoose";
|
|
2
|
+
|
|
3
|
+
export interface IHealth extends Document {
|
|
4
|
+
success: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
version: string;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
updatedAt: Date;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const healthSchema: Schema = new Schema(
|
|
12
|
+
{
|
|
13
|
+
success: {
|
|
14
|
+
type: Boolean,
|
|
15
|
+
default: true,
|
|
16
|
+
},
|
|
17
|
+
message: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
version: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
timestamps: true,
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Add indexes for better performance
|
|
32
|
+
healthSchema.index({ createdAt: -1 });
|
|
33
|
+
|
|
34
|
+
export default mongoose.models.Health || mongoose.model<IHealth>("Health", healthSchema);
|
|
@@ -5,20 +5,39 @@
|
|
|
5
5
|
"operations": [
|
|
6
6
|
{
|
|
7
7
|
"type": "create-file",
|
|
8
|
-
"source": "lib/
|
|
9
|
-
"destination": "src/lib/
|
|
8
|
+
"source": "lib/mongoose.ts",
|
|
9
|
+
"destination": "src/lib/mongoose.ts"
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"type": "create-file",
|
|
13
|
-
"source": "models/
|
|
14
|
-
"destination": "
|
|
13
|
+
"source": "models/health.ts",
|
|
14
|
+
"destination": "models/health.ts"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"type": "patch-file",
|
|
18
|
+
"destination": "src/server.ts",
|
|
19
|
+
"condition": { "framework": "express" },
|
|
20
|
+
"operations": [
|
|
21
|
+
{
|
|
22
|
+
"type": "add-import",
|
|
23
|
+
"imports": ["import { mongoose } from \"@/lib/mongoose\";"]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"type": "add-code",
|
|
27
|
+
"after": "async function startServer() {",
|
|
28
|
+
"code": "await mongoose();"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"type": "add-env",
|
|
34
|
+
"envVars": {
|
|
35
|
+
"MONGODB_URI": "mongodb://localhost:27017/database_name"
|
|
36
|
+
}
|
|
15
37
|
}
|
|
16
38
|
],
|
|
17
39
|
"dependencies": {
|
|
18
40
|
"mongoose": "^8.8.0"
|
|
19
41
|
},
|
|
20
|
-
"devDependencies": {}
|
|
21
|
-
"envVars": {
|
|
22
|
-
"MONGODB_URI": "mongodb://localhost:27017/database_name"
|
|
23
|
-
}
|
|
42
|
+
"devDependencies": {}
|
|
24
43
|
}
|