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.
Files changed (64) 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 +42 -88
  11. package/dist/cli/index.cjs.map +1 -1
  12. package/dist/cli/index.js +80 -126
  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/cli/start.md +1 -1
  17. package/dist/docs/guides/authentication.md +30 -4
  18. package/dist/docs/guides/deployment.md +1 -1
  19. package/dist/docs/guides/environment-variables.md +1 -1
  20. package/dist/docs/index.md +1 -1
  21. package/dist/docs/skills/SKILL.md +2 -2
  22. package/dist/docs/skills/api-surface.md +8 -0
  23. package/dist/index.cjs +8 -8
  24. package/dist/index.js +1 -1
  25. package/dist/registry/index.json +1 -1
  26. package/dist/registry/js-mongo/admin-users.json +1 -1
  27. package/dist/registry/js-mongo/auth.json +1 -1
  28. package/dist/registry/js-mongo/auth@apple.json +1 -1
  29. package/dist/registry/js-mongo/auth@google.json +1 -1
  30. package/dist/registry/js-mongo/email-client.json +1 -1
  31. package/dist/registry/js-mongo/forgot-password.json +1 -1
  32. package/dist/registry/js-pg-model/admin-users.json +1 -1
  33. package/dist/registry/js-pg-model/auth.json +1 -1
  34. package/dist/registry/js-pg-model/auth@apple.json +1 -1
  35. package/dist/registry/js-pg-model/auth@google.json +1 -1
  36. package/dist/registry/js-pg-model/email-client.json +1 -1
  37. package/dist/registry/js-pg-model/forgot-password.json +1 -1
  38. package/dist/registry/js-pg-table/admin-users.json +1 -1
  39. package/dist/registry/js-pg-table/auth.json +1 -1
  40. package/dist/registry/js-pg-table/auth@apple.json +1 -1
  41. package/dist/registry/js-pg-table/auth@google.json +1 -1
  42. package/dist/registry/js-pg-table/email-client.json +1 -1
  43. package/dist/registry/js-pg-table/forgot-password.json +1 -1
  44. package/dist/registry/ts-mongo/admin-users.json +1 -1
  45. package/dist/registry/ts-mongo/auth.json +1 -1
  46. package/dist/registry/ts-mongo/auth@apple.json +1 -1
  47. package/dist/registry/ts-mongo/auth@google.json +1 -1
  48. package/dist/registry/ts-mongo/email-client.json +1 -1
  49. package/dist/registry/ts-mongo/forgot-password.json +1 -1
  50. package/dist/registry/ts-pg-model/admin-users.json +1 -1
  51. package/dist/registry/ts-pg-model/auth.json +1 -1
  52. package/dist/registry/ts-pg-model/auth@apple.json +1 -1
  53. package/dist/registry/ts-pg-model/auth@google.json +1 -1
  54. package/dist/registry/ts-pg-model/email-client.json +1 -1
  55. package/dist/registry/ts-pg-model/forgot-password.json +1 -1
  56. package/dist/registry/ts-pg-table/admin-users.json +1 -1
  57. package/dist/registry/ts-pg-table/auth.json +1 -1
  58. package/dist/registry/ts-pg-table/auth@apple.json +1 -1
  59. package/dist/registry/ts-pg-table/auth@google.json +1 -1
  60. package/dist/registry/ts-pg-table/email-client.json +1 -1
  61. package/dist/registry/ts-pg-table/forgot-password.json +1 -1
  62. package/package.json +3 -3
  63. package/dist/chunk-2J3HHQKP.cjs.map +0 -1
  64. package/dist/chunk-RSZB7VAO.js.map +0 -1
@@ -29,6 +29,30 @@ var _commander = require('commander');
29
29
 
30
30
 
31
31
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
32
+
33
+ // src/cli/env.ts
34
+
35
+
36
+ function readEnvFile(cwd = process.cwd()) {
37
+ const envPath = _path2.default.join(cwd, ".env");
38
+ if (!_fs2.default.existsSync(envPath)) return {};
39
+ const vars = {};
40
+ for (const line of _fs2.default.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 (0, _commander.Command)("start");
34
58
  cmd.argument("<mode>", "dev | prod").description("Start the EFC server").action((mode) => {
@@ -145,7 +169,7 @@ function startProd() {
145
169
  console.log(_picocolors2.default.cyan("[EFC] Starting production server\u2026"));
146
170
  const child = _child_process.spawn.call(void 0, "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
  }
@@ -466,28 +490,6 @@ export default async function seed(${ctx}) {
466
490
 
467
491
 
468
492
 
469
- // src/cli/env.ts
470
-
471
-
472
- function readEnvFile(cwd = process.cwd()) {
473
- const envPath = _path2.default.join(cwd, ".env");
474
- if (!_fs2.default.existsSync(envPath)) return {};
475
- const vars = {};
476
- for (const line of _fs2.default.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
 
493
495
 
@@ -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 bcrypt from 'bcrypt';
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 bcrypt.hash(password, 10);
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 bcrypt from 'bcrypt';
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 bcrypt.compare(password, record.password);
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,42 +1441,12 @@ function generateEntityAuth(cwd, entityName, cfg, options) {
1440
1441
  if (entityUsesTables(cfg) && !_optionalChain([options, 'optionalAccess', _37 => _37.dryRun])) {
1441
1442
  result.manual.push(...registerModels(cwd, cfg.language, [pascal]));
1442
1443
  }
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
1444
  const envFile = _path2.default.join(cwd, ".env");
1474
1445
  if (_fs2.default.existsSync(envFile)) {
1475
1446
  const envKeys = readEnvKeys(envFile);
1476
1447
  if (!envKeys.includes("JWT_SECRET")) {
1477
1448
  const secret = _crypto2.default.randomBytes(64).toString("hex");
1478
- if (!_optionalChain([options, 'optionalAccess', _39 => _39.dryRun])) {
1449
+ if (!_optionalChain([options, 'optionalAccess', _38 => _38.dryRun])) {
1479
1450
  appendEnv(envFile, [`JWT_SECRET=${secret}`]);
1480
1451
  const exampleFile = _path2.default.join(cwd, ".env.example");
1481
1452
  if (_fs2.default.existsSync(exampleFile) && !readEnvKeys(exampleFile).includes("JWT_SECRET")) {
@@ -1487,7 +1458,7 @@ function generateEntityAuth(cwd, entityName, cfg, options) {
1487
1458
  }
1488
1459
  const itemName = `auth:${slug}`;
1489
1460
  if (!cfg.items.includes(itemName)) cfg.items.push(itemName);
1490
- if (!_optionalChain([options, 'optionalAccess', _40 => _40.dryRun])) {
1461
+ if (!_optionalChain([options, 'optionalAccess', _39 => _39.dryRun])) {
1491
1462
  writeEfcJson(cwd, cfg);
1492
1463
  }
1493
1464
  return result;
@@ -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
  _picocolors2.default.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(_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
1715
  if (registryNames.length === 0) return;
1762
1716
  }
1763
1717
  const { cwd, registry, cfg, detected } = load();
@@ -1844,7 +1798,7 @@ function listCommand() {
1844
1798
  try {
1845
1799
  const cwd = process.cwd();
1846
1800
  const registry = new Registry();
1847
- const installed = new Set(_nullishCoalesce(_optionalChain([readEfcJson, 'call', _41 => _41(cwd), 'optionalAccess', _42 => _42.items]), () => ( [])));
1801
+ const installed = new Set(_nullishCoalesce(_optionalChain([readEfcJson, 'call', _40 => _40(cwd), 'optionalAccess', _41 => _41.items]), () => ( [])));
1848
1802
  const groups = [...new Set(registry.index.items.map((i) => i.group))];
1849
1803
  for (const group of groups) {
1850
1804
  console.log(_picocolors2.default.bold(`
@@ -1855,7 +1809,7 @@ function listCommand() {
1855
1809
  console.log(` ${mark} ${_picocolors2.default.cyan(item.name.padEnd(20))} ${item.description}${deps}`);
1856
1810
  }
1857
1811
  }
1858
- const entities = (_nullishCoalesce(_optionalChain([readEfcJson, 'call', _43 => _43(cwd), 'optionalAccess', _44 => _44.items]), () => ( []))).filter((i) => i.startsWith("auth:")).map((i) => i.slice(5));
1812
+ const entities = (_nullishCoalesce(_optionalChain([readEfcJson, 'call', _42 => _42(cwd), 'optionalAccess', _43 => _43.items]), () => ( []))).filter((i) => i.startsWith("auth:")).map((i) => i.slice(5));
1859
1813
  if (entities.length > 0) {
1860
1814
  console.log(_picocolors2.default.bold("\n custom auth entities"));
1861
1815
  for (const e of entities) {
@@ -2013,15 +1967,15 @@ function parseAttrs(s) {
2013
1967
  return out;
2014
1968
  }
2015
1969
  function arg(a, name) {
2016
- if (!_optionalChain([a, 'optionalAccess', _45 => _45.args])) return void 0;
1970
+ if (!_optionalChain([a, 'optionalAccess', _44 => _44.args])) return void 0;
2017
1971
  const parts = splitTop(a.args, ",");
2018
1972
  if (name) {
2019
1973
  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()]);
1974
+ return _optionalChain([p, 'optionalAccess', _45 => _45.slice, 'call', _46 => _46(name.length + 1), 'access', _47 => _47.trim, 'call', _48 => _48()]);
2021
1975
  }
2022
1976
  return parts.find((x) => !/^\w+\s*:/.test(x));
2023
1977
  }
2024
- var unquote = (s) => _optionalChain([s, 'optionalAccess', _50 => _50.replace, 'call', _51 => _51(/^"(.*)"$/, "$1")]);
1978
+ var unquote = (s) => _optionalChain([s, 'optionalAccess', _49 => _49.replace, 'call', _50 => _50(/^"(.*)"$/, "$1")]);
2025
1979
  var list = (s) => s ? splitTop(s.replace(/^\[|\]$/g, ""), ",").map((x) => x.trim()).filter(Boolean) : [];
2026
1980
  function parsePrisma(source) {
2027
1981
  const text = source.replace(/\/\/.*$/gm, "");
@@ -2034,7 +1988,7 @@ function parsePrisma(source) {
2034
1988
  const [, kind, name, body] = block;
2035
1989
  const lines = body.split("\n").map((l) => l.trim()).filter(Boolean);
2036
1990
  if (kind === "datasource") {
2037
- provider = unquote(_optionalChain([/provider\s*=\s*("[^"]*")/, 'access', _52 => _52.exec, 'call', _53 => _53(body), 'optionalAccess', _54 => _54[1]]));
1991
+ provider = unquote(_optionalChain([/provider\s*=\s*("[^"]*")/, 'access', _51 => _51.exec, 'call', _52 => _52(body), 'optionalAccess', _53 => _53[1]]));
2038
1992
  } else if (kind === "enum") {
2039
1993
  const values = [];
2040
1994
  const names = [];
@@ -2096,7 +2050,7 @@ function importPrisma(source) {
2096
2050
  const def = _nullishCoalesce(arg(attr(_nullishCoalesce(id, () => ( { attrs: [] })), "@default")), () => ( ""));
2097
2051
  idKind.set(
2098
2052
  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"
2053
+ _optionalChain([id, 'optionalAccess', _54 => _54.type]) === "Int" && /autoincrement/.test(def) ? "serial" : _optionalChain([id, 'optionalAccess', _55 => _55.type]) === "BigInt" && /autoincrement/.test(def) ? "bigserial" : "uuid"
2100
2054
  );
2101
2055
  }
2102
2056
  const rels = [];
@@ -2182,7 +2136,7 @@ function importPrisma(source) {
2182
2136
  continue;
2183
2137
  }
2184
2138
  const other = partner(r);
2185
- if (r.list && _optionalChain([other, 'optionalAccess', _57 => _57.list])) {
2139
+ if (r.list && _optionalChain([other, 'optionalAccess', _56 => _56.list])) {
2186
2140
  if (m.name < r.target || m.name === r.target && f.name < other.field) {
2187
2141
  fields.push([
2188
2142
  f.name,
@@ -2252,7 +2206,7 @@ function importPrisma(source) {
2252
2206
  }
2253
2207
  function scalarDef(f, enums, notes) {
2254
2208
  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)]);
2209
+ const dbType = _optionalChain([db, 'optionalAccess', _57 => _57.name, 'access', _58 => _58.slice, 'call', _59 => _59(4)]);
2256
2210
  let def;
2257
2211
  const e = enums.get(f.type);
2258
2212
  if (e) def = { type: "string", enum: e.values, nativeEnum: true };
@@ -2260,7 +2214,7 @@ function scalarDef(f, enums, notes) {
2260
2214
  switch (f.type) {
2261
2215
  case "String":
2262
2216
  if (dbType === "Uuid") def = { type: "uuid" };
2263
- else if (dbType === "VarChar" && _optionalChain([db, 'optionalAccess', _61 => _61.args]))
2217
+ else if (dbType === "VarChar" && _optionalChain([db, 'optionalAccess', _60 => _60.args]))
2264
2218
  def = { type: "string", maxLength: Number(db.args) };
2265
2219
  else def = { type: "string" };
2266
2220
  break;
@@ -2274,7 +2228,7 @@ function scalarDef(f, enums, notes) {
2274
2228
  def = { type: "number" };
2275
2229
  break;
2276
2230
  case "Decimal": {
2277
- const [p, s] = (_nullishCoalesce(_optionalChain([db, 'optionalAccess', _62 => _62.args]), () => ( ""))).split(",").map((x) => Number(x.trim()));
2231
+ const [p, s] = (_nullishCoalesce(_optionalChain([db, 'optionalAccess', _61 => _61.args]), () => ( ""))).split(",").map((x) => Number(x.trim()));
2278
2232
  def = p ? { type: "decimal", precision: p, scale: _nullishCoalesce(s, () => ( 0)) } : { type: "decimal" };
2279
2233
  break;
2280
2234
  }