express-file-cluster 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.cjs +8 -2
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +12 -1
- package/dist/auth/index.d.ts +12 -1
- package/dist/auth/index.js +9 -3
- package/dist/{chunk-2J3HHQKP.cjs → chunk-ANUSWEAP.cjs} +55 -2
- package/dist/chunk-ANUSWEAP.cjs.map +1 -0
- package/dist/{chunk-RSZB7VAO.js → chunk-ATL4GYFU.js} +54 -1
- package/dist/chunk-ATL4GYFU.js.map +1 -0
- package/dist/cli/index.cjs +42 -88
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +80 -126
- package/dist/cli/index.js.map +1 -1
- package/dist/docs/api-reference/auth.md +35 -0
- package/dist/docs/cli/add.md +2 -2
- package/dist/docs/cli/start.md +1 -1
- package/dist/docs/guides/authentication.md +30 -4
- package/dist/docs/guides/deployment.md +1 -1
- package/dist/docs/guides/environment-variables.md +1 -1
- package/dist/docs/index.md +1 -1
- package/dist/docs/skills/SKILL.md +2 -2
- package/dist/docs/skills/api-surface.md +8 -0
- package/dist/index.cjs +8 -8
- package/dist/index.js +1 -1
- package/dist/registry/index.json +1 -1
- package/dist/registry/js-mongo/admin-users.json +1 -1
- package/dist/registry/js-mongo/auth.json +1 -1
- package/dist/registry/js-mongo/auth@apple.json +1 -1
- package/dist/registry/js-mongo/auth@google.json +1 -1
- package/dist/registry/js-mongo/email-client.json +1 -1
- package/dist/registry/js-mongo/forgot-password.json +1 -1
- package/dist/registry/js-pg-model/admin-users.json +1 -1
- package/dist/registry/js-pg-model/auth.json +1 -1
- package/dist/registry/js-pg-model/auth@apple.json +1 -1
- package/dist/registry/js-pg-model/auth@google.json +1 -1
- package/dist/registry/js-pg-model/email-client.json +1 -1
- package/dist/registry/js-pg-model/forgot-password.json +1 -1
- package/dist/registry/js-pg-table/admin-users.json +1 -1
- package/dist/registry/js-pg-table/auth.json +1 -1
- package/dist/registry/js-pg-table/auth@apple.json +1 -1
- package/dist/registry/js-pg-table/auth@google.json +1 -1
- package/dist/registry/js-pg-table/email-client.json +1 -1
- package/dist/registry/js-pg-table/forgot-password.json +1 -1
- package/dist/registry/ts-mongo/admin-users.json +1 -1
- package/dist/registry/ts-mongo/auth.json +1 -1
- package/dist/registry/ts-mongo/auth@apple.json +1 -1
- package/dist/registry/ts-mongo/auth@google.json +1 -1
- package/dist/registry/ts-mongo/email-client.json +1 -1
- package/dist/registry/ts-mongo/forgot-password.json +1 -1
- package/dist/registry/ts-pg-model/admin-users.json +1 -1
- package/dist/registry/ts-pg-model/auth.json +1 -1
- package/dist/registry/ts-pg-model/auth@apple.json +1 -1
- package/dist/registry/ts-pg-model/auth@google.json +1 -1
- package/dist/registry/ts-pg-model/email-client.json +1 -1
- package/dist/registry/ts-pg-model/forgot-password.json +1 -1
- package/dist/registry/ts-pg-table/admin-users.json +1 -1
- package/dist/registry/ts-pg-table/auth.json +1 -1
- package/dist/registry/ts-pg-table/auth@apple.json +1 -1
- package/dist/registry/ts-pg-table/auth@google.json +1 -1
- package/dist/registry/ts-pg-table/email-client.json +1 -1
- package/dist/registry/ts-pg-table/forgot-password.json +1 -1
- package/package.json +3 -3
- package/dist/chunk-2J3HHQKP.cjs.map +0 -1
- package/dist/chunk-RSZB7VAO.js.map +0 -1
package/dist/cli/index.js
CHANGED
|
@@ -26,9 +26,33 @@ import { Command as Command10 } from "commander";
|
|
|
26
26
|
// src/cli/commands/start.ts
|
|
27
27
|
import { Command } from "commander";
|
|
28
28
|
import { spawn } from "child_process";
|
|
29
|
-
import
|
|
30
|
-
import
|
|
29
|
+
import path2 from "path";
|
|
30
|
+
import fs2 from "fs";
|
|
31
31
|
import pc from "picocolors";
|
|
32
|
+
|
|
33
|
+
// src/cli/env.ts
|
|
34
|
+
import fs from "fs";
|
|
35
|
+
import path from "path";
|
|
36
|
+
function readEnvFile(cwd = process.cwd()) {
|
|
37
|
+
const envPath = path.join(cwd, ".env");
|
|
38
|
+
if (!fs.existsSync(envPath)) return {};
|
|
39
|
+
const vars = {};
|
|
40
|
+
for (const line of fs.readFileSync(envPath, "utf8").split("\n")) {
|
|
41
|
+
const trimmed = line.trim();
|
|
42
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
43
|
+
const eq = trimmed.indexOf("=");
|
|
44
|
+
if (eq === -1) continue;
|
|
45
|
+
const key = trimmed.slice(0, eq).trim();
|
|
46
|
+
const raw = trimmed.slice(eq + 1).trim();
|
|
47
|
+
vars[key] = raw.replace(/^(['"])(.*)\1$/, "$2");
|
|
48
|
+
}
|
|
49
|
+
return vars;
|
|
50
|
+
}
|
|
51
|
+
function envVar(key, cwd = process.cwd()) {
|
|
52
|
+
return process.env[key] || readEnvFile(cwd)[key] || void 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/cli/commands/start.ts
|
|
32
56
|
function startCommand() {
|
|
33
57
|
const cmd = new Command("start");
|
|
34
58
|
cmd.argument("<mode>", "dev | prod").description("Start the EFC server").action((mode) => {
|
|
@@ -44,9 +68,9 @@ function startCommand() {
|
|
|
44
68
|
return cmd;
|
|
45
69
|
}
|
|
46
70
|
function writeDevEnvPreload(cwd) {
|
|
47
|
-
const cacheDir =
|
|
48
|
-
|
|
49
|
-
const preloadPath =
|
|
71
|
+
const cacheDir = path2.join(cwd, "node_modules", ".cache", "efc");
|
|
72
|
+
fs2.mkdirSync(cacheDir, { recursive: true });
|
|
73
|
+
const preloadPath = path2.join(cacheDir, "dev-env-preload.mjs");
|
|
50
74
|
const source = `// Auto-generated by \`efc start dev\` \u2014 re-reads .env fresh on every restart
|
|
51
75
|
// so tsx watch restarts always pick up the latest .env, instead of reusing a stale snapshot.
|
|
52
76
|
import fs from 'node:fs';
|
|
@@ -75,7 +99,7 @@ if (fs.existsSync(envFile)) {
|
|
|
75
99
|
}
|
|
76
100
|
process.env[MARKER] = injectedNow.join(',');
|
|
77
101
|
`;
|
|
78
|
-
|
|
102
|
+
fs2.writeFileSync(preloadPath, source);
|
|
79
103
|
return preloadPath;
|
|
80
104
|
}
|
|
81
105
|
function startDev() {
|
|
@@ -95,9 +119,9 @@ function startDev() {
|
|
|
95
119
|
function findTsx() {
|
|
96
120
|
let dir = cwd;
|
|
97
121
|
while (true) {
|
|
98
|
-
const candidate =
|
|
99
|
-
if (
|
|
100
|
-
const parent =
|
|
122
|
+
const candidate = path2.join(dir, "node_modules", ".bin", "tsx");
|
|
123
|
+
if (fs2.existsSync(candidate)) return candidate;
|
|
124
|
+
const parent = path2.dirname(dir);
|
|
101
125
|
if (parent === dir) return void 0;
|
|
102
126
|
dir = parent;
|
|
103
127
|
}
|
|
@@ -120,7 +144,7 @@ function startDev() {
|
|
|
120
144
|
NODE_ENV: "development",
|
|
121
145
|
NODE_OPTIONS: [process.env["NODE_OPTIONS"], `--import ${preloadPath}`].filter(Boolean).join(" ")
|
|
122
146
|
};
|
|
123
|
-
const child = tsx ? spawn(tsx, ["watch", "--include", "src", entry], { stdio: "inherit", env }) : spawn(process.execPath, ["--watch", "--watch-path",
|
|
147
|
+
const child = tsx ? spawn(tsx, ["watch", "--include", "src", entry], { stdio: "inherit", env }) : spawn(process.execPath, ["--watch", "--watch-path", path2.join(cwd, "src"), entry], {
|
|
124
148
|
stdio: "inherit",
|
|
125
149
|
env
|
|
126
150
|
});
|
|
@@ -135,9 +159,9 @@ function forwardSignals(child) {
|
|
|
135
159
|
function startProd() {
|
|
136
160
|
const cwd = process.cwd();
|
|
137
161
|
const distEntry = [
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
].find((f) =>
|
|
162
|
+
path2.join(cwd, "dist", "src", "index.js"),
|
|
163
|
+
path2.join(cwd, "dist", "index.js")
|
|
164
|
+
].find((f) => fs2.existsSync(f));
|
|
141
165
|
if (!distEntry) {
|
|
142
166
|
console.error(pc.red("[EFC] dist/src/index.js not found. Run `efc build prod` first."));
|
|
143
167
|
process.exit(1);
|
|
@@ -145,26 +169,26 @@ function startProd() {
|
|
|
145
169
|
console.log(pc.cyan("[EFC] Starting production server\u2026"));
|
|
146
170
|
const child = spawn("node", [distEntry], {
|
|
147
171
|
stdio: "inherit",
|
|
148
|
-
env: { ...process.env, NODE_ENV: "production" }
|
|
172
|
+
env: { ...readEnvFile(cwd), ...process.env, NODE_ENV: "production" }
|
|
149
173
|
});
|
|
150
174
|
forwardSignals(child);
|
|
151
175
|
}
|
|
152
176
|
function resolveEntry() {
|
|
153
177
|
const cwd = process.cwd();
|
|
154
178
|
const candidates = [
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
179
|
+
path2.join(cwd, "src", "index.ts"),
|
|
180
|
+
path2.join(cwd, "index.ts"),
|
|
181
|
+
path2.join(cwd, "src", "index.js"),
|
|
182
|
+
path2.join(cwd, "index.js")
|
|
159
183
|
];
|
|
160
|
-
return candidates.find((f) =>
|
|
184
|
+
return candidates.find((f) => fs2.existsSync(f)) ?? null;
|
|
161
185
|
}
|
|
162
186
|
|
|
163
187
|
// src/cli/commands/build.ts
|
|
164
188
|
import { Command as Command2 } from "commander";
|
|
165
189
|
import { spawn as spawn2 } from "child_process";
|
|
166
|
-
import
|
|
167
|
-
import
|
|
190
|
+
import path3 from "path";
|
|
191
|
+
import fs3 from "fs";
|
|
168
192
|
import pc2 from "picocolors";
|
|
169
193
|
function buildCommand() {
|
|
170
194
|
const cmd = new Command2("build");
|
|
@@ -180,19 +204,19 @@ function buildCommand() {
|
|
|
180
204
|
function findBin(name) {
|
|
181
205
|
let dir = process.cwd();
|
|
182
206
|
while (true) {
|
|
183
|
-
const candidate =
|
|
184
|
-
if (
|
|
185
|
-
const parent =
|
|
207
|
+
const candidate = path3.join(dir, "node_modules", ".bin", name);
|
|
208
|
+
if (fs3.existsSync(candidate)) return candidate;
|
|
209
|
+
const parent = path3.dirname(dir);
|
|
186
210
|
if (parent === dir) return name;
|
|
187
211
|
dir = parent;
|
|
188
212
|
}
|
|
189
213
|
}
|
|
190
214
|
function writeAppTsupConfig(cwd) {
|
|
191
|
-
const pkgPath =
|
|
192
|
-
const isEsm =
|
|
215
|
+
const pkgPath = path3.join(cwd, "package.json");
|
|
216
|
+
const isEsm = fs3.existsSync(pkgPath) && JSON.parse(fs3.readFileSync(pkgPath, "utf8")).type === "module";
|
|
193
217
|
const entry = [
|
|
194
218
|
"src/**/*.{ts,mts,js,mjs}",
|
|
195
|
-
...["efc.config.ts", "efc.config.js"].filter((f) =>
|
|
219
|
+
...["efc.config.ts", "efc.config.js"].filter((f) => fs3.existsSync(path3.join(cwd, f))),
|
|
196
220
|
"!src/**/*.d.ts",
|
|
197
221
|
"!src/**/*.test.*",
|
|
198
222
|
"!src/**/__tests__/**"
|
|
@@ -212,21 +236,21 @@ function writeAppTsupConfig(cwd) {
|
|
|
212
236
|
},
|
|
213
237
|
};
|
|
214
238
|
`;
|
|
215
|
-
const configPath =
|
|
216
|
-
|
|
217
|
-
|
|
239
|
+
const configPath = path3.join(cwd, "node_modules", ".cache", "efc", "tsup.config.mjs");
|
|
240
|
+
fs3.mkdirSync(path3.dirname(configPath), { recursive: true });
|
|
241
|
+
fs3.writeFileSync(configPath, config);
|
|
218
242
|
return configPath;
|
|
219
243
|
}
|
|
220
244
|
function hasTsupConfig() {
|
|
221
245
|
const cwd = process.cwd();
|
|
222
246
|
return ["tsup.config.ts", "tsup.config.js", "tsup.config.mjs", "tsup.config.cjs"].some(
|
|
223
|
-
(f) =>
|
|
247
|
+
(f) => fs3.existsSync(path3.join(cwd, f))
|
|
224
248
|
);
|
|
225
249
|
}
|
|
226
250
|
function findTsConfig() {
|
|
227
251
|
const cwd = process.cwd();
|
|
228
|
-
const tsconfig =
|
|
229
|
-
return
|
|
252
|
+
const tsconfig = path3.join(cwd, "tsconfig.json");
|
|
253
|
+
return fs3.existsSync(tsconfig) ? tsconfig : null;
|
|
230
254
|
}
|
|
231
255
|
function buildProd() {
|
|
232
256
|
console.log(pc2.cyan("[EFC] Building for production\u2026"));
|
|
@@ -245,14 +269,14 @@ function buildProd() {
|
|
|
245
269
|
});
|
|
246
270
|
}
|
|
247
271
|
function copyJsProject(cwd) {
|
|
248
|
-
const dist =
|
|
249
|
-
|
|
250
|
-
|
|
272
|
+
const dist = path3.join(cwd, "dist");
|
|
273
|
+
fs3.rmSync(dist, { recursive: true, force: true });
|
|
274
|
+
fs3.cpSync(path3.join(cwd, "src"), path3.join(dist, "src"), {
|
|
251
275
|
recursive: true,
|
|
252
276
|
filter: (src) => !/(\.test\.[cm]?js$|[\\/]__tests__([\\/]|$))/.test(src)
|
|
253
277
|
});
|
|
254
278
|
for (const f of ["efc.config.js", "efc.config.mjs"]) {
|
|
255
|
-
if (
|
|
279
|
+
if (fs3.existsSync(path3.join(cwd, f))) fs3.copyFileSync(path3.join(cwd, f), path3.join(dist, f));
|
|
256
280
|
}
|
|
257
281
|
console.log(pc2.green("[EFC] Build complete \u2192 dist/ (JavaScript copied as-is)"));
|
|
258
282
|
}
|
|
@@ -262,8 +286,8 @@ function transpile() {
|
|
|
262
286
|
if (hasTsupConfig()) {
|
|
263
287
|
tsupArgs = [];
|
|
264
288
|
} else {
|
|
265
|
-
const hasTs =
|
|
266
|
-
if (!hasTs && !
|
|
289
|
+
const hasTs = fs3.existsSync(path3.join(cwd, "src", "index.ts"));
|
|
290
|
+
if (!hasTs && !fs3.existsSync(path3.join(cwd, "src", "index.js"))) {
|
|
267
291
|
console.error(pc2.red("[EFC] Could not find entry point. Expected src/index.ts"));
|
|
268
292
|
process.exit(1);
|
|
269
293
|
return;
|
|
@@ -308,8 +332,8 @@ function runTests(extraArgs) {
|
|
|
308
332
|
|
|
309
333
|
// src/cli/commands/generate.ts
|
|
310
334
|
import { Command as Command4 } from "commander";
|
|
311
|
-
import
|
|
312
|
-
import
|
|
335
|
+
import fs4 from "fs";
|
|
336
|
+
import path4 from "path";
|
|
313
337
|
import pc4 from "picocolors";
|
|
314
338
|
function generateCommand() {
|
|
315
339
|
const cmd = new Command4("generate").alias("g").description("Scaffold EFC modules");
|
|
@@ -321,18 +345,18 @@ function generateCommand() {
|
|
|
321
345
|
return cmd;
|
|
322
346
|
}
|
|
323
347
|
function writeFile(filePath, content) {
|
|
324
|
-
const dir =
|
|
325
|
-
|
|
326
|
-
if (
|
|
348
|
+
const dir = path4.dirname(filePath);
|
|
349
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
350
|
+
if (fs4.existsSync(filePath)) {
|
|
327
351
|
console.error(pc4.red(`File already exists: ${filePath}`));
|
|
328
352
|
process.exit(1);
|
|
329
353
|
}
|
|
330
|
-
|
|
331
|
-
console.log(pc4.green(` created ${
|
|
354
|
+
fs4.writeFileSync(filePath, content, "utf8");
|
|
355
|
+
console.log(pc4.green(` created ${path4.relative(process.cwd(), filePath)}`));
|
|
332
356
|
}
|
|
333
357
|
function generateRoute(routePath) {
|
|
334
358
|
const cwd = process.cwd();
|
|
335
|
-
const filePath =
|
|
359
|
+
const filePath = path4.join(cwd, "src", "api", `${routePath}.ts`);
|
|
336
360
|
const content = `import type { Request, Response } from 'express';
|
|
337
361
|
import type { RouteMeta } from 'express-file-cluster';
|
|
338
362
|
|
|
@@ -383,7 +407,7 @@ export const POST = async (req: Request, res: Response) => {
|
|
|
383
407
|
}
|
|
384
408
|
function generateTask(name) {
|
|
385
409
|
const cwd = process.cwd();
|
|
386
|
-
const filePath =
|
|
410
|
+
const filePath = path4.join(cwd, "src", "tasks", `${name}.ts`);
|
|
387
411
|
const content = `import { defineTask } from 'express-file-cluster/tasks';
|
|
388
412
|
|
|
389
413
|
interface ${name}Payload {
|
|
@@ -400,7 +424,7 @@ export default defineTask<${name}Payload>(async (payload) => {
|
|
|
400
424
|
}
|
|
401
425
|
function generateMiddleware(name) {
|
|
402
426
|
const cwd = process.cwd();
|
|
403
|
-
const filePath =
|
|
427
|
+
const filePath = path4.join(cwd, "src", "middlewares", `${name}.ts`);
|
|
404
428
|
const content = `import type { Request, Response, NextFunction } from 'express';
|
|
405
429
|
|
|
406
430
|
export function ${name}(req: Request, res: Response, next: NextFunction): void {
|
|
@@ -411,12 +435,12 @@ export function ${name}(req: Request, res: Response, next: NextFunction): void {
|
|
|
411
435
|
writeFile(filePath, content);
|
|
412
436
|
console.log(pc4.cyan(`[EFC] Middleware scaffolded`));
|
|
413
437
|
}
|
|
414
|
-
var isTypeScript = () =>
|
|
438
|
+
var isTypeScript = () => fs4.existsSync(path4.join(process.cwd(), "tsconfig.json"));
|
|
415
439
|
var snake = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^A-Za-z0-9]+/g, "_").replace(/^_|_$/g, "").toLowerCase();
|
|
416
440
|
function generateMigration(name) {
|
|
417
441
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:T]/g, "").slice(0, 14);
|
|
418
442
|
const ts = isTypeScript();
|
|
419
|
-
const filePath =
|
|
443
|
+
const filePath = path4.join(
|
|
420
444
|
process.cwd(),
|
|
421
445
|
"src",
|
|
422
446
|
"migrations",
|
|
@@ -444,7 +468,7 @@ export async function down(${ctx})${ret} {
|
|
|
444
468
|
}
|
|
445
469
|
function generateSeed(name) {
|
|
446
470
|
const ts = isTypeScript();
|
|
447
|
-
const filePath =
|
|
471
|
+
const filePath = path4.join(process.cwd(), "src", "seeds", `${snake(name)}.${ts ? "ts" : "js"}`);
|
|
448
472
|
const typeImport = ts ? "import type { MigrationContext } from 'express-file-cluster';\n" : "";
|
|
449
473
|
const ctx = ts ? "{ engine }: MigrationContext" : "{ engine }";
|
|
450
474
|
writeFile(
|
|
@@ -466,28 +490,6 @@ import path5 from "path";
|
|
|
466
490
|
import fs5 from "fs";
|
|
467
491
|
import pc6 from "picocolors";
|
|
468
492
|
|
|
469
|
-
// src/cli/env.ts
|
|
470
|
-
import fs4 from "fs";
|
|
471
|
-
import path4 from "path";
|
|
472
|
-
function readEnvFile(cwd = process.cwd()) {
|
|
473
|
-
const envPath = path4.join(cwd, ".env");
|
|
474
|
-
if (!fs4.existsSync(envPath)) return {};
|
|
475
|
-
const vars = {};
|
|
476
|
-
for (const line of fs4.readFileSync(envPath, "utf8").split("\n")) {
|
|
477
|
-
const trimmed = line.trim();
|
|
478
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
479
|
-
const eq = trimmed.indexOf("=");
|
|
480
|
-
if (eq === -1) continue;
|
|
481
|
-
const key = trimmed.slice(0, eq).trim();
|
|
482
|
-
const raw = trimmed.slice(eq + 1).trim();
|
|
483
|
-
vars[key] = raw.replace(/^(['"])(.*)\1$/, "$2");
|
|
484
|
-
}
|
|
485
|
-
return vars;
|
|
486
|
-
}
|
|
487
|
-
function envVar(key, cwd = process.cwd()) {
|
|
488
|
-
return process.env[key] || readEnvFile(cwd)[key] || void 0;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
493
|
// src/cli/commands/task-admin.ts
|
|
492
494
|
import { Command as Command5 } from "commander";
|
|
493
495
|
import pc5 from "picocolors";
|
|
@@ -1326,7 +1328,7 @@ function entityRegisterContent(pascal, camel, cfg) {
|
|
|
1326
1328
|
const db = entityOrm(cfg);
|
|
1327
1329
|
const typedArgs = ts ? "(req: Request, res: Response)" : "(req, res)";
|
|
1328
1330
|
const typeImport = ts ? "import type { Request, Response } from 'express';\n" : "";
|
|
1329
|
-
return `${typeImport}import
|
|
1331
|
+
return `${typeImport}import { hashPassword } from 'express-file-cluster/auth';
|
|
1330
1332
|
import { ${pascal} } from '../../../model/${pascal}.js';
|
|
1331
1333
|
|
|
1332
1334
|
export const POST = async ${typedArgs} => {
|
|
@@ -1336,7 +1338,7 @@ export const POST = async ${typedArgs} => {
|
|
|
1336
1338
|
}
|
|
1337
1339
|
const existing = await ${db.findOne(pascal, "{ email }")};
|
|
1338
1340
|
if (existing) return res.status(409).json({ error: 'Email already in use' });
|
|
1339
|
-
const hashed = await
|
|
1341
|
+
const hashed = await hashPassword(password);
|
|
1340
1342
|
const record = await ${db.create(pascal, "{ name, email, password: hashed }")};
|
|
1341
1343
|
const { password: _, ...safe } = record;
|
|
1342
1344
|
res.status(201).json({ message: '${pascal} account created', ${camel}: safe });
|
|
@@ -1348,8 +1350,7 @@ function entityLoginContent(pascal, slug, cfg) {
|
|
|
1348
1350
|
const db = entityOrm(cfg);
|
|
1349
1351
|
const typedArgs = ts ? "(req: Request, res: Response)" : "(req, res)";
|
|
1350
1352
|
const typeImport = ts ? "import type { Request, Response } from 'express';\n" : "";
|
|
1351
|
-
return `${typeImport}import
|
|
1352
|
-
import { issueToken } from 'express-file-cluster/auth';
|
|
1353
|
+
return `${typeImport}import { issueToken, verifyPassword } from 'express-file-cluster/auth';
|
|
1353
1354
|
import { ${pascal} } from '../../../model/${pascal}.js';
|
|
1354
1355
|
|
|
1355
1356
|
export const POST = async ${typedArgs} => {
|
|
@@ -1358,7 +1359,7 @@ export const POST = async ${typedArgs} => {
|
|
|
1358
1359
|
|
|
1359
1360
|
const record = await ${db.findOne(pascal, "{ email }")};
|
|
1360
1361
|
if (!record) return res.status(401).json({ error: 'Invalid credentials' });
|
|
1361
|
-
const match = await
|
|
1362
|
+
const match = await verifyPassword(password, record.password);
|
|
1362
1363
|
if (!match) return res.status(401).json({ error: 'Invalid credentials' });
|
|
1363
1364
|
if (!record.isActive) return res.status(403).json({ error: 'Account suspended' });
|
|
1364
1365
|
await issueToken(res, { id: record.id, role: record.role, email: record.email });
|
|
@@ -1440,36 +1441,6 @@ function generateEntityAuth(cwd, entityName, cfg, options) {
|
|
|
1440
1441
|
if (entityUsesTables(cfg) && !options?.dryRun) {
|
|
1441
1442
|
result.manual.push(...registerModels(cwd, cfg.language, [pascal]));
|
|
1442
1443
|
}
|
|
1443
|
-
const pkgFile = path7.join(cwd, "package.json");
|
|
1444
|
-
if (fs7.existsSync(pkgFile)) {
|
|
1445
|
-
try {
|
|
1446
|
-
const pkg = JSON.parse(fs7.readFileSync(pkgFile, "utf8"));
|
|
1447
|
-
let pkgChanged = false;
|
|
1448
|
-
const deps = pkg["dependencies"] ?? {};
|
|
1449
|
-
const devDeps = pkg["devDependencies"] ?? {};
|
|
1450
|
-
if (!deps["bcrypt"]) {
|
|
1451
|
-
deps["bcrypt"] = "^5.1.0";
|
|
1452
|
-
pkg["dependencies"] = Object.fromEntries(
|
|
1453
|
-
Object.entries(deps).sort(([a], [b]) => a.localeCompare(b))
|
|
1454
|
-
);
|
|
1455
|
-
pkgChanged = true;
|
|
1456
|
-
}
|
|
1457
|
-
if (cfg.language === "typescript" && !devDeps["@types/bcrypt"]) {
|
|
1458
|
-
devDeps["@types/bcrypt"] = "^5.0.0";
|
|
1459
|
-
pkg["devDependencies"] = Object.fromEntries(
|
|
1460
|
-
Object.entries(devDeps).sort(([a], [b]) => a.localeCompare(b))
|
|
1461
|
-
);
|
|
1462
|
-
pkgChanged = true;
|
|
1463
|
-
}
|
|
1464
|
-
if (pkgChanged) {
|
|
1465
|
-
result.installNeeded = true;
|
|
1466
|
-
if (!options?.dryRun) {
|
|
1467
|
-
fs7.writeFileSync(pkgFile, JSON.stringify(pkg, null, 2) + "\n");
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
} catch {
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
1444
|
const envFile = path7.join(cwd, ".env");
|
|
1474
1445
|
if (fs7.existsSync(envFile)) {
|
|
1475
1446
|
const envKeys = readEnvKeys(envFile);
|
|
@@ -1704,7 +1675,6 @@ function addCommand() {
|
|
|
1704
1675
|
"Specify at least one item or entity to add \u2014 e.g. `efc add auth` or `efc add auth:merchant`. Run `efc list` to see available features."
|
|
1705
1676
|
);
|
|
1706
1677
|
}
|
|
1707
|
-
let anyInstallNeeded = false;
|
|
1708
1678
|
if (entityNames.length > 0) {
|
|
1709
1679
|
const { cwd: cwd2, cfg: cfg2, detected: detected2 } = load();
|
|
1710
1680
|
if (detected2) {
|
|
@@ -1740,24 +1710,8 @@ function addCommand() {
|
|
|
1740
1710
|
console.log(
|
|
1741
1711
|
pc8.dim(` Protect routes with: requireAuth('${slug}')`)
|
|
1742
1712
|
);
|
|
1743
|
-
if (result2.installNeeded) anyInstallNeeded = true;
|
|
1744
1713
|
}
|
|
1745
1714
|
console.log();
|
|
1746
|
-
if (anyInstallNeeded && !opts.dryRun) {
|
|
1747
|
-
const pm = packageManager(cwd2);
|
|
1748
|
-
if (opts.install) {
|
|
1749
|
-
console.log(pc8.dim(` $ ${pm} install`));
|
|
1750
|
-
const r = spawnSync(pm, ["install"], {
|
|
1751
|
-
cwd: cwd2,
|
|
1752
|
-
stdio: "inherit",
|
|
1753
|
-
shell: process.platform === "win32"
|
|
1754
|
-
});
|
|
1755
|
-
if (r.status !== 0)
|
|
1756
|
-
console.log(pc8.yellow(` ${pm} install failed \u2014 run it yourself.`));
|
|
1757
|
-
} else {
|
|
1758
|
-
console.log(pc8.yellow(` Run \`${pm} install\` for the new packages.`));
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
1715
|
if (registryNames.length === 0) return;
|
|
1762
1716
|
}
|
|
1763
1717
|
const { cwd, registry, cfg, detected } = load();
|