create-lupine 1.0.30 → 1.0.31

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/index.js CHANGED
@@ -29,6 +29,20 @@ function generateRandomString(length) {
29
29
  return [...crypto.randomBytes(length)].map((x) => chars[x % chars.length]).join('');
30
30
  }
31
31
 
32
+ function generateLayeredPasswordHash(password) {
33
+ const saltHex = crypto.randomBytes(16).toString('hex');
34
+ const keyHex = crypto
35
+ .scryptSync(password, Buffer.from(saltHex, 'hex'), 32, {
36
+ N: 16384,
37
+ r: 8,
38
+ p: 1,
39
+ maxmem: 64 * 1024 * 1024,
40
+ })
41
+ .toString('hex');
42
+ const verifierHex = crypto.createHash('sha256').update(keyHex).digest('hex');
43
+ return `scrypt2$${saltHex}$${verifierHex}`;
44
+ }
45
+
32
46
  const red = (str) => `\x1b[31m${str}\x1b[0m`;
33
47
  const green = (str) => `\x1b[32m${str}\x1b[0m`;
34
48
  const bold = (str) => `\x1b[1m${str}\x1b[0m`;
@@ -328,12 +342,18 @@ async function init() {
328
342
  if (fs.existsSync(path.join(root, '.env'))) {
329
343
  let envContent = fs.readFileSync(path.join(root, '.env'), 'utf-8');
330
344
 
331
- // Auto-generate passwords
332
- const keysToUpdate = ['ADMIN_PASS=', 'CRYPTO_KEY=', 'DEV_ADMIN_PASS=', 'DEV_CRYPTO_KEY=', 'DEV_TOKEN='];
333
- keysToUpdate.forEach((key) => {
334
- // Replace line starting with key=
345
+ // Auto-generate keys & random layered scrypt password placeholders
346
+ const secretKeys = ['CRYPTO_KEY=', 'DEV_CRYPTO_KEY=', 'DEV_TOKEN='];
347
+ secretKeys.forEach((key) => {
335
348
  envContent = envContent.replace(new RegExp(`^${key}.*`, 'gm'), `${key}${generateRandomString(32)}`);
336
349
  });
350
+ const passwordKeys = ['ADMIN_PASS=', 'DEV_ADMIN_PASS='];
351
+ passwordKeys.forEach((key) => {
352
+ envContent = envContent.replace(
353
+ new RegExp(`^${key}.*`, 'gm'),
354
+ `${key}${generateLayeredPasswordHash(generateRandomString(32))}`
355
+ );
356
+ });
337
357
 
338
358
  envContent = envContent.replace(/{APP-NAME}/g, appName);
339
359
  fs.writeFileSync(path.join(root, '.env'), envContent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-lupine",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "Scaffolding tool for Lupine.js projects",
5
5
  "bin": {
6
6
  "create-lupine": "index.js"
@@ -3,8 +3,8 @@ WEB.API_PORT=11080
3
3
  WEB.API_BASE_URL=
4
4
 
5
5
  # start with “app_name.” will be assigned to the individual app's env object
6
- # demo.app.WEB.test2=11aa
7
- # demo.app.test2=11aa
6
+ # demo.WEB.test2=11aa
7
+ # demo.test2=11aa
8
8
 
9
9
  # used by Server Side Renderring for fetch (can't be localhost)
10
10
  API_BASE_URL=http://127.0.0.1:11080
@@ -31,14 +31,22 @@ LOG_OUT_TO_CONSOLE=true
31
31
  # server path for web (appName_web), server (server) and data (appName_data)
32
32
  SERVER_ROOT_PATH=dist/server_root
33
33
  ADMIN_USER=admin
34
+ # ADMIN_PASS and DEV_ADMIN_PASS use layered salted scrypt ("scrypt2$<saltHex>$<sha256(scryptKeyHex)>"):
35
+ # node -e 'const pwd="YOUR PASSWORD",c=require("crypto"),s=c.randomBytes(16).toString("hex"),k=c.scryptSync(pwd,Buffer.from(s,"hex"),32,{N:16384,r:8,p:1,maxmem:64*1024*1024}).toString("hex");console.log(`scrypt2$${s}$${c.createHash("sha256").update(k).digest("hex")}`)'
34
36
  ADMIN_PASS=
35
37
  CRYPTO_KEY=
38
+ # Admin session expiration in days (default: 90)
39
+ # ADMIN_SESSION_EXPIRE_DAYS=90
36
40
 
37
41
  # for development
38
42
  DEV_ADMIN_USER=admin
39
43
  DEV_ADMIN_PASS=
40
44
  DEV_CRYPTO_KEY=
41
45
  DEV_TOKEN=
46
+ # Dev-admin session expiration in days (default: 90)
47
+ # DEV_ADMIN_SESSION_EXPIRE_DAYS=90
48
+ # Set DEV_ENABLE_SHELL=true only when remote shell debugging is explicitly needed
49
+ # DEV_ENABLE_SHELL=false
42
50
 
43
51
  # define apps on the same port with different domains (locally or on a real server)
44
52
  # in local, the domains should be added to the /etc/hosts (or C:\Windows\System32\drivers\etc\hosts) file
@@ -56,10 +56,11 @@ const initAndStartServer = async () => {
56
56
  const sslKeyPath = process.env[ServerEnvKeys.SSL_KEY_PATH] || '';
57
57
  const sslCrtPath = process.env[ServerEnvKeys.SSL_CRT_PATH] || '';
58
58
 
59
+ const rawDevToken = process.env['DEV_TOKEN'] || '';
59
60
  // Can't use log until initApp is called (after AppStart.start)
60
61
  await appStart.start({
61
62
  debug: process.env[ServerEnvKeys.NODE_ENV] === 'development',
62
- devToken: CryptoUtils.sha256(process.env['DEV_TOKEN'] || ''),
63
+ devToken: rawDevToken ? CryptoUtils.sha256(rawDevToken) : '',
63
64
  appEnvFile: envFile,
64
65
  apiConfig: {
65
66
  serverRoot: `${serverRootPath}`,