express-file-cluster 0.9.1 → 0.9.2
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 +17 -65
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +4 -52
- 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/guides/authentication.md +30 -4
- 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
|
@@ -1326,7 +1326,7 @@ function entityRegisterContent(pascal, camel, cfg) {
|
|
|
1326
1326
|
const db = entityOrm(cfg);
|
|
1327
1327
|
const typedArgs = ts ? "(req: Request, res: Response)" : "(req, res)";
|
|
1328
1328
|
const typeImport = ts ? "import type { Request, Response } from 'express';\n" : "";
|
|
1329
|
-
return `${typeImport}import
|
|
1329
|
+
return `${typeImport}import { hashPassword } from 'express-file-cluster/auth';
|
|
1330
1330
|
import { ${pascal} } from '../../../model/${pascal}.js';
|
|
1331
1331
|
|
|
1332
1332
|
export const POST = async ${typedArgs} => {
|
|
@@ -1336,7 +1336,7 @@ export const POST = async ${typedArgs} => {
|
|
|
1336
1336
|
}
|
|
1337
1337
|
const existing = await ${db.findOne(pascal, "{ email }")};
|
|
1338
1338
|
if (existing) return res.status(409).json({ error: 'Email already in use' });
|
|
1339
|
-
const hashed = await
|
|
1339
|
+
const hashed = await hashPassword(password);
|
|
1340
1340
|
const record = await ${db.create(pascal, "{ name, email, password: hashed }")};
|
|
1341
1341
|
const { password: _, ...safe } = record;
|
|
1342
1342
|
res.status(201).json({ message: '${pascal} account created', ${camel}: safe });
|
|
@@ -1348,8 +1348,7 @@ function entityLoginContent(pascal, slug, cfg) {
|
|
|
1348
1348
|
const db = entityOrm(cfg);
|
|
1349
1349
|
const typedArgs = ts ? "(req: Request, res: Response)" : "(req, res)";
|
|
1350
1350
|
const typeImport = ts ? "import type { Request, Response } from 'express';\n" : "";
|
|
1351
|
-
return `${typeImport}import
|
|
1352
|
-
import { issueToken } from 'express-file-cluster/auth';
|
|
1351
|
+
return `${typeImport}import { issueToken, verifyPassword } from 'express-file-cluster/auth';
|
|
1353
1352
|
import { ${pascal} } from '../../../model/${pascal}.js';
|
|
1354
1353
|
|
|
1355
1354
|
export const POST = async ${typedArgs} => {
|
|
@@ -1358,7 +1357,7 @@ export const POST = async ${typedArgs} => {
|
|
|
1358
1357
|
|
|
1359
1358
|
const record = await ${db.findOne(pascal, "{ email }")};
|
|
1360
1359
|
if (!record) return res.status(401).json({ error: 'Invalid credentials' });
|
|
1361
|
-
const match = await
|
|
1360
|
+
const match = await verifyPassword(password, record.password);
|
|
1362
1361
|
if (!match) return res.status(401).json({ error: 'Invalid credentials' });
|
|
1363
1362
|
if (!record.isActive) return res.status(403).json({ error: 'Account suspended' });
|
|
1364
1363
|
await issueToken(res, { id: record.id, role: record.role, email: record.email });
|
|
@@ -1440,36 +1439,6 @@ function generateEntityAuth(cwd, entityName, cfg, options) {
|
|
|
1440
1439
|
if (entityUsesTables(cfg) && !options?.dryRun) {
|
|
1441
1440
|
result.manual.push(...registerModels(cwd, cfg.language, [pascal]));
|
|
1442
1441
|
}
|
|
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
1442
|
const envFile = path7.join(cwd, ".env");
|
|
1474
1443
|
if (fs7.existsSync(envFile)) {
|
|
1475
1444
|
const envKeys = readEnvKeys(envFile);
|
|
@@ -1704,7 +1673,6 @@ function addCommand() {
|
|
|
1704
1673
|
"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
1674
|
);
|
|
1706
1675
|
}
|
|
1707
|
-
let anyInstallNeeded = false;
|
|
1708
1676
|
if (entityNames.length > 0) {
|
|
1709
1677
|
const { cwd: cwd2, cfg: cfg2, detected: detected2 } = load();
|
|
1710
1678
|
if (detected2) {
|
|
@@ -1740,24 +1708,8 @@ function addCommand() {
|
|
|
1740
1708
|
console.log(
|
|
1741
1709
|
pc8.dim(` Protect routes with: requireAuth('${slug}')`)
|
|
1742
1710
|
);
|
|
1743
|
-
if (result2.installNeeded) anyInstallNeeded = true;
|
|
1744
1711
|
}
|
|
1745
1712
|
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
1713
|
if (registryNames.length === 0) return;
|
|
1762
1714
|
}
|
|
1763
1715
|
const { cwd, registry, cfg, detected } = load();
|