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.
Files changed (61) hide show
  1. package/dist/auth/index.cjs +8 -2
  2. package/dist/auth/index.cjs.map +1 -1
  3. package/dist/auth/index.d.cts +12 -1
  4. package/dist/auth/index.d.ts +12 -1
  5. package/dist/auth/index.js +9 -3
  6. package/dist/{chunk-2J3HHQKP.cjs → chunk-ANUSWEAP.cjs} +55 -2
  7. package/dist/chunk-ANUSWEAP.cjs.map +1 -0
  8. package/dist/{chunk-RSZB7VAO.js → chunk-ATL4GYFU.js} +54 -1
  9. package/dist/chunk-ATL4GYFU.js.map +1 -0
  10. package/dist/cli/index.cjs +17 -65
  11. package/dist/cli/index.cjs.map +1 -1
  12. package/dist/cli/index.js +4 -52
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/docs/api-reference/auth.md +35 -0
  15. package/dist/docs/cli/add.md +2 -2
  16. package/dist/docs/guides/authentication.md +30 -4
  17. package/dist/docs/index.md +1 -1
  18. package/dist/docs/skills/SKILL.md +2 -2
  19. package/dist/docs/skills/api-surface.md +8 -0
  20. package/dist/index.cjs +8 -8
  21. package/dist/index.js +1 -1
  22. package/dist/registry/index.json +1 -1
  23. package/dist/registry/js-mongo/admin-users.json +1 -1
  24. package/dist/registry/js-mongo/auth.json +1 -1
  25. package/dist/registry/js-mongo/auth@apple.json +1 -1
  26. package/dist/registry/js-mongo/auth@google.json +1 -1
  27. package/dist/registry/js-mongo/email-client.json +1 -1
  28. package/dist/registry/js-mongo/forgot-password.json +1 -1
  29. package/dist/registry/js-pg-model/admin-users.json +1 -1
  30. package/dist/registry/js-pg-model/auth.json +1 -1
  31. package/dist/registry/js-pg-model/auth@apple.json +1 -1
  32. package/dist/registry/js-pg-model/auth@google.json +1 -1
  33. package/dist/registry/js-pg-model/email-client.json +1 -1
  34. package/dist/registry/js-pg-model/forgot-password.json +1 -1
  35. package/dist/registry/js-pg-table/admin-users.json +1 -1
  36. package/dist/registry/js-pg-table/auth.json +1 -1
  37. package/dist/registry/js-pg-table/auth@apple.json +1 -1
  38. package/dist/registry/js-pg-table/auth@google.json +1 -1
  39. package/dist/registry/js-pg-table/email-client.json +1 -1
  40. package/dist/registry/js-pg-table/forgot-password.json +1 -1
  41. package/dist/registry/ts-mongo/admin-users.json +1 -1
  42. package/dist/registry/ts-mongo/auth.json +1 -1
  43. package/dist/registry/ts-mongo/auth@apple.json +1 -1
  44. package/dist/registry/ts-mongo/auth@google.json +1 -1
  45. package/dist/registry/ts-mongo/email-client.json +1 -1
  46. package/dist/registry/ts-mongo/forgot-password.json +1 -1
  47. package/dist/registry/ts-pg-model/admin-users.json +1 -1
  48. package/dist/registry/ts-pg-model/auth.json +1 -1
  49. package/dist/registry/ts-pg-model/auth@apple.json +1 -1
  50. package/dist/registry/ts-pg-model/auth@google.json +1 -1
  51. package/dist/registry/ts-pg-model/email-client.json +1 -1
  52. package/dist/registry/ts-pg-model/forgot-password.json +1 -1
  53. package/dist/registry/ts-pg-table/admin-users.json +1 -1
  54. package/dist/registry/ts-pg-table/auth.json +1 -1
  55. package/dist/registry/ts-pg-table/auth@apple.json +1 -1
  56. package/dist/registry/ts-pg-table/auth@google.json +1 -1
  57. package/dist/registry/ts-pg-table/email-client.json +1 -1
  58. package/dist/registry/ts-pg-table/forgot-password.json +1 -1
  59. package/package.json +3 -3
  60. package/dist/chunk-2J3HHQKP.cjs.map +0 -1
  61. package/dist/chunk-RSZB7VAO.js.map +0 -1
@@ -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 bcrypt from 'bcrypt';
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 bcrypt.hash(password, 10);
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 bcrypt from 'bcrypt';
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 bcrypt.compare(password, record.password);
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,42 +1439,12 @@ function generateEntityAuth(cwd, entityName, cfg, options) {
1440
1439
  if (entityUsesTables(cfg) && !_optionalChain([options, 'optionalAccess', _37 => _37.dryRun])) {
1441
1440
  result.manual.push(...registerModels(cwd, cfg.language, [pascal]));
1442
1441
  }
1443
- const pkgFile = _path2.default.join(cwd, "package.json");
1444
- if (_fs2.default.existsSync(pkgFile)) {
1445
- try {
1446
- const pkg = JSON.parse(_fs2.default.readFileSync(pkgFile, "utf8"));
1447
- let pkgChanged = false;
1448
- const deps = _nullishCoalesce(pkg["dependencies"], () => ( {}));
1449
- const devDeps = _nullishCoalesce(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 (!_optionalChain([options, 'optionalAccess', _38 => _38.dryRun])) {
1467
- _fs2.default.writeFileSync(pkgFile, JSON.stringify(pkg, null, 2) + "\n");
1468
- }
1469
- }
1470
- } catch (e3) {
1471
- }
1472
- }
1473
1442
  const envFile = _path2.default.join(cwd, ".env");
1474
1443
  if (_fs2.default.existsSync(envFile)) {
1475
1444
  const envKeys = readEnvKeys(envFile);
1476
1445
  if (!envKeys.includes("JWT_SECRET")) {
1477
1446
  const secret = _crypto2.default.randomBytes(64).toString("hex");
1478
- if (!_optionalChain([options, 'optionalAccess', _39 => _39.dryRun])) {
1447
+ if (!_optionalChain([options, 'optionalAccess', _38 => _38.dryRun])) {
1479
1448
  appendEnv(envFile, [`JWT_SECRET=${secret}`]);
1480
1449
  const exampleFile = _path2.default.join(cwd, ".env.example");
1481
1450
  if (_fs2.default.existsSync(exampleFile) && !readEnvKeys(exampleFile).includes("JWT_SECRET")) {
@@ -1487,7 +1456,7 @@ function generateEntityAuth(cwd, entityName, cfg, options) {
1487
1456
  }
1488
1457
  const itemName = `auth:${slug}`;
1489
1458
  if (!cfg.items.includes(itemName)) cfg.items.push(itemName);
1490
- if (!_optionalChain([options, 'optionalAccess', _40 => _40.dryRun])) {
1459
+ if (!_optionalChain([options, 'optionalAccess', _39 => _39.dryRun])) {
1491
1460
  writeEfcJson(cwd, cfg);
1492
1461
  }
1493
1462
  return result;
@@ -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
  _picocolors2.default.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(_picocolors2.default.dim(` $ ${pm} install`));
1750
- const r = _child_process.spawnSync.call(void 0, pm, ["install"], {
1751
- cwd: cwd2,
1752
- stdio: "inherit",
1753
- shell: process.platform === "win32"
1754
- });
1755
- if (r.status !== 0)
1756
- console.log(_picocolors2.default.yellow(` ${pm} install failed \u2014 run it yourself.`));
1757
- } else {
1758
- console.log(_picocolors2.default.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();
@@ -1844,7 +1796,7 @@ function listCommand() {
1844
1796
  try {
1845
1797
  const cwd = process.cwd();
1846
1798
  const registry = new Registry();
1847
- const installed = new Set(_nullishCoalesce(_optionalChain([readEfcJson, 'call', _41 => _41(cwd), 'optionalAccess', _42 => _42.items]), () => ( [])));
1799
+ const installed = new Set(_nullishCoalesce(_optionalChain([readEfcJson, 'call', _40 => _40(cwd), 'optionalAccess', _41 => _41.items]), () => ( [])));
1848
1800
  const groups = [...new Set(registry.index.items.map((i) => i.group))];
1849
1801
  for (const group of groups) {
1850
1802
  console.log(_picocolors2.default.bold(`
@@ -1855,7 +1807,7 @@ function listCommand() {
1855
1807
  console.log(` ${mark} ${_picocolors2.default.cyan(item.name.padEnd(20))} ${item.description}${deps}`);
1856
1808
  }
1857
1809
  }
1858
- const entities = (_nullishCoalesce(_optionalChain([readEfcJson, 'call', _43 => _43(cwd), 'optionalAccess', _44 => _44.items]), () => ( []))).filter((i) => i.startsWith("auth:")).map((i) => i.slice(5));
1810
+ const entities = (_nullishCoalesce(_optionalChain([readEfcJson, 'call', _42 => _42(cwd), 'optionalAccess', _43 => _43.items]), () => ( []))).filter((i) => i.startsWith("auth:")).map((i) => i.slice(5));
1859
1811
  if (entities.length > 0) {
1860
1812
  console.log(_picocolors2.default.bold("\n custom auth entities"));
1861
1813
  for (const e of entities) {
@@ -2013,15 +1965,15 @@ function parseAttrs(s) {
2013
1965
  return out;
2014
1966
  }
2015
1967
  function arg(a, name) {
2016
- if (!_optionalChain([a, 'optionalAccess', _45 => _45.args])) return void 0;
1968
+ if (!_optionalChain([a, 'optionalAccess', _44 => _44.args])) return void 0;
2017
1969
  const parts = splitTop(a.args, ",");
2018
1970
  if (name) {
2019
1971
  const p = parts.find((x) => x.startsWith(`${name}:`));
2020
- return _optionalChain([p, 'optionalAccess', _46 => _46.slice, 'call', _47 => _47(name.length + 1), 'access', _48 => _48.trim, 'call', _49 => _49()]);
1972
+ return _optionalChain([p, 'optionalAccess', _45 => _45.slice, 'call', _46 => _46(name.length + 1), 'access', _47 => _47.trim, 'call', _48 => _48()]);
2021
1973
  }
2022
1974
  return parts.find((x) => !/^\w+\s*:/.test(x));
2023
1975
  }
2024
- var unquote = (s) => _optionalChain([s, 'optionalAccess', _50 => _50.replace, 'call', _51 => _51(/^"(.*)"$/, "$1")]);
1976
+ var unquote = (s) => _optionalChain([s, 'optionalAccess', _49 => _49.replace, 'call', _50 => _50(/^"(.*)"$/, "$1")]);
2025
1977
  var list = (s) => s ? splitTop(s.replace(/^\[|\]$/g, ""), ",").map((x) => x.trim()).filter(Boolean) : [];
2026
1978
  function parsePrisma(source) {
2027
1979
  const text = source.replace(/\/\/.*$/gm, "");
@@ -2034,7 +1986,7 @@ function parsePrisma(source) {
2034
1986
  const [, kind, name, body] = block;
2035
1987
  const lines = body.split("\n").map((l) => l.trim()).filter(Boolean);
2036
1988
  if (kind === "datasource") {
2037
- provider = unquote(_optionalChain([/provider\s*=\s*("[^"]*")/, 'access', _52 => _52.exec, 'call', _53 => _53(body), 'optionalAccess', _54 => _54[1]]));
1989
+ provider = unquote(_optionalChain([/provider\s*=\s*("[^"]*")/, 'access', _51 => _51.exec, 'call', _52 => _52(body), 'optionalAccess', _53 => _53[1]]));
2038
1990
  } else if (kind === "enum") {
2039
1991
  const values = [];
2040
1992
  const names = [];
@@ -2096,7 +2048,7 @@ function importPrisma(source) {
2096
2048
  const def = _nullishCoalesce(arg(attr(_nullishCoalesce(id, () => ( { attrs: [] })), "@default")), () => ( ""));
2097
2049
  idKind.set(
2098
2050
  m.name,
2099
- _optionalChain([id, 'optionalAccess', _55 => _55.type]) === "Int" && /autoincrement/.test(def) ? "serial" : _optionalChain([id, 'optionalAccess', _56 => _56.type]) === "BigInt" && /autoincrement/.test(def) ? "bigserial" : "uuid"
2051
+ _optionalChain([id, 'optionalAccess', _54 => _54.type]) === "Int" && /autoincrement/.test(def) ? "serial" : _optionalChain([id, 'optionalAccess', _55 => _55.type]) === "BigInt" && /autoincrement/.test(def) ? "bigserial" : "uuid"
2100
2052
  );
2101
2053
  }
2102
2054
  const rels = [];
@@ -2182,7 +2134,7 @@ function importPrisma(source) {
2182
2134
  continue;
2183
2135
  }
2184
2136
  const other = partner(r);
2185
- if (r.list && _optionalChain([other, 'optionalAccess', _57 => _57.list])) {
2137
+ if (r.list && _optionalChain([other, 'optionalAccess', _56 => _56.list])) {
2186
2138
  if (m.name < r.target || m.name === r.target && f.name < other.field) {
2187
2139
  fields.push([
2188
2140
  f.name,
@@ -2252,7 +2204,7 @@ function importPrisma(source) {
2252
2204
  }
2253
2205
  function scalarDef(f, enums, notes) {
2254
2206
  const db = f.attrs.find((a) => a.name.startsWith("@db."));
2255
- const dbType = _optionalChain([db, 'optionalAccess', _58 => _58.name, 'access', _59 => _59.slice, 'call', _60 => _60(4)]);
2207
+ const dbType = _optionalChain([db, 'optionalAccess', _57 => _57.name, 'access', _58 => _58.slice, 'call', _59 => _59(4)]);
2256
2208
  let def;
2257
2209
  const e = enums.get(f.type);
2258
2210
  if (e) def = { type: "string", enum: e.values, nativeEnum: true };
@@ -2260,7 +2212,7 @@ function scalarDef(f, enums, notes) {
2260
2212
  switch (f.type) {
2261
2213
  case "String":
2262
2214
  if (dbType === "Uuid") def = { type: "uuid" };
2263
- else if (dbType === "VarChar" && _optionalChain([db, 'optionalAccess', _61 => _61.args]))
2215
+ else if (dbType === "VarChar" && _optionalChain([db, 'optionalAccess', _60 => _60.args]))
2264
2216
  def = { type: "string", maxLength: Number(db.args) };
2265
2217
  else def = { type: "string" };
2266
2218
  break;
@@ -2274,7 +2226,7 @@ function scalarDef(f, enums, notes) {
2274
2226
  def = { type: "number" };
2275
2227
  break;
2276
2228
  case "Decimal": {
2277
- const [p, s] = (_nullishCoalesce(_optionalChain([db, 'optionalAccess', _62 => _62.args]), () => ( ""))).split(",").map((x) => Number(x.trim()));
2229
+ const [p, s] = (_nullishCoalesce(_optionalChain([db, 'optionalAccess', _61 => _61.args]), () => ( ""))).split(",").map((x) => Number(x.trim()));
2278
2230
  def = p ? { type: "decimal", precision: p, scale: _nullishCoalesce(s, () => ( 0)) } : { type: "decimal" };
2279
2231
  break;
2280
2232
  }