@seip/bluebird-js 0.0.1 → 0.1.1

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 (81) hide show
  1. package/.env_example +53 -53
  2. package/AGENTS.md +426 -403
  3. package/LICENSE +1 -1
  4. package/README.md +292 -285
  5. package/app/routes/api.js +50 -50
  6. package/app/routes/web.js +55 -53
  7. package/app/views/about.js +63 -0
  8. package/app/views/dashboard.js +147 -0
  9. package/app/views/index.js +80 -0
  10. package/app/views/layouts/main/view.js +81 -0
  11. package/app/views/legal/terms.html +19 -0
  12. package/app/views/login.js +80 -0
  13. package/core/app.d.ts +18 -18
  14. package/core/app.js +684 -644
  15. package/core/auth.d.ts +13 -13
  16. package/core/auth.js +326 -326
  17. package/core/cache.d.ts +17 -17
  18. package/core/cache.js +475 -475
  19. package/core/cli/doctor.js +287 -287
  20. package/core/cli/ecosystem.js +162 -162
  21. package/core/cli/init.js +779 -779
  22. package/core/cli/migrate.js +541 -541
  23. package/core/cli/model.js +66 -66
  24. package/core/cli/nginx.js +199 -199
  25. package/core/cli/route.js +120 -120
  26. package/core/cli/view.js +55 -36
  27. package/core/config.d.ts +3 -3
  28. package/core/config.js +111 -111
  29. package/core/csrf.d.ts +3 -3
  30. package/core/csrf.js +114 -114
  31. package/core/database.d.ts +15 -15
  32. package/core/database.js +636 -636
  33. package/core/debug.d.ts +3 -3
  34. package/core/debug.js +249 -249
  35. package/core/hash.d.ts +3 -3
  36. package/core/hash.js +194 -194
  37. package/core/html.d.ts +42 -0
  38. package/core/html.js +217 -0
  39. package/core/index.d.ts +1176 -1071
  40. package/core/logger.d.ts +3 -3
  41. package/core/logger.js +127 -124
  42. package/core/middleware.d.ts +3 -3
  43. package/core/middleware.js +28 -28
  44. package/core/model.d.ts +19 -19
  45. package/core/model.js +600 -600
  46. package/core/queue.d.ts +13 -13
  47. package/core/queue.js +172 -172
  48. package/core/ratelimit.d.ts +3 -3
  49. package/core/ratelimit.js +145 -145
  50. package/core/redis.d.ts +21 -21
  51. package/core/redis.js +230 -230
  52. package/core/render-cache.js +212 -0
  53. package/core/render.d.ts +3 -3
  54. package/core/render.js +199 -555
  55. package/core/router.d.ts +3 -3
  56. package/core/router.js +171 -171
  57. package/core/seo.d.ts +3 -3
  58. package/core/seo.js +106 -106
  59. package/core/swagger.d.ts +3 -3
  60. package/core/swagger.js +60 -60
  61. package/core/upload.d.ts +13 -13
  62. package/core/upload.js +102 -102
  63. package/core/util/colors.js +82 -82
  64. package/core/validate.d.ts +15 -15
  65. package/core/validate.js +364 -364
  66. package/core/view-loader.js +162 -0
  67. package/core/vite.d.ts +3 -3
  68. package/core/vite.js +145 -145
  69. package/core/ws.d.ts +13 -13
  70. package/core/ws.js +245 -245
  71. package/index.js +18 -18
  72. package/jsconfig.json +15 -15
  73. package/package.json +85 -86
  74. package/production.md +273 -273
  75. package/public/css/bluebird.min.css +1 -1
  76. package/public/js/bluebird-client.js +1780 -1662
  77. package/public/js/bluebird.min.js +1072 -1072
  78. package/app/views/about.html +0 -161
  79. package/app/views/dashboard.html +0 -140
  80. package/app/views/index.html +0 -150
  81. package/app/views/login.html +0 -144
package/core/cli/route.js CHANGED
@@ -1,121 +1,121 @@
1
- #!/usr/bin/env node
2
-
3
- import path from "node:path";
4
- import fs from "node:fs";
5
- import colors from "../util/colors.js";
6
-
7
- /**
8
- * CLI tool for scaffolding RESTful routes.
9
- */
10
- class RouteCLI {
11
- /**
12
- * Creates a new RESTful route file with Validation, Cache, and optional Auth.
13
- */
14
- create() {
15
- const rawArgs = process.argv.slice(2);
16
- const args = rawArgs.filter(
17
- (a) => a !== "route" && a !== "make:route" && !a.endsWith("route.js")
18
- );
19
-
20
- let routeName = args.find((a) => !a.startsWith("-"));
21
- const withAuth = args.some((a) => a === "--auth" || a === "-a");
22
-
23
- if (!routeName) {
24
- console.log(colors.red("[ERROR] Missing route name."));
25
- console.log("");
26
- console.log("Usage:");
27
- console.log(" npx bluebird-js make:route <name> [--auth]");
28
- console.log("");
29
- console.log("Examples:");
30
- console.log(" npx bluebird-js make:route products");
31
- console.log(" npx bluebird-js make:route articles --auth");
32
- process.exit(1);
33
- }
34
-
35
- routeName = routeName.toLowerCase().replace(/[^a-z0-9_-]/g, "");
36
- const singularName = routeName.endsWith("s") ? routeName.slice(0, -1) : routeName;
37
- const pascalName = routeName.charAt(0).toUpperCase() + routeName.slice(1);
38
- const routerVarName = `router${pascalName}`;
39
- const basePath = `/${routeName}`;
40
-
41
- const routesFolder = path.resolve(process.cwd(), "app/routes");
42
- if (!fs.existsSync(routesFolder)) {
43
- fs.mkdirSync(routesFolder, { recursive: true });
44
- }
45
-
46
- const filename = `${routeName}.js`;
47
- const filePath = path.join(routesFolder, filename);
48
- if (fs.existsSync(filePath)) {
49
- console.log(colors.yellow(`[WARN] Route file '${filename}' already exists at app/routes/${filename}.`));
50
- return;
51
- }
52
-
53
- const authImport = withAuth
54
- ? 'import Auth from "@seip/bluebird-js/core/auth.js";\n'
55
- : "";
56
-
57
- const authProtect = withAuth ? "Auth.protect(), " : "";
58
-
59
- const content = `import Router from "@seip/bluebird-js/core/router.js";
60
- import Validator from "@seip/bluebird-js/core/validate.js";
61
- import Cache from "@seip/bluebird-js/core/cache.js";
62
- ${authImport}const ${routerVarName} = new Router("${basePath}");
63
-
64
- const ${singularName}Schema = {
65
- name: { required: true, min: 2, max: 255 },
66
- description: { required: false },
67
- price: { required: false }
68
- };
69
-
70
- const validate${pascalName} = new Validator(${singularName}Schema, "en");
71
-
72
- ${routerVarName}.get("/", Cache.middleware(60), (req, res) => {
73
- res.ok({ ${routeName}: [] }, "${pascalName} list retrieved successfully");
74
- });
75
-
76
- ${routerVarName}.get("/:id", Cache.middleware(60), (req, res) => {
77
- const { id } = req.params;
78
- res.ok({ ${singularName}: { id } }, "${pascalName} retrieved successfully");
79
- });
80
-
81
- ${routerVarName}.post("/", ${authProtect}validate${pascalName}.middleware(), async (req, res) => {
82
- const data = req.body;
83
-
84
- await Cache.delete("${basePath}");
85
-
86
- res.created({ ${singularName}: data }, "${pascalName} created successfully");
87
- });
88
-
89
- ${routerVarName}.put("/:id", ${authProtect}validate${pascalName}.middleware(), async (req, res) => {
90
- const { id } = req.params;
91
- const data = req.body;
92
-
93
- await Cache.delete("${basePath}");
94
- await Cache.delete(\`${basePath}/\${id}\`);
95
-
96
- res.ok({ ${singularName}: { id, ...data } }, "${pascalName} updated successfully");
97
- });
98
-
99
- ${routerVarName}.delete("/:id", ${authProtect}async (req, res) => {
100
- const { id } = req.params;
101
-
102
- await Cache.delete("${basePath}");
103
- await Cache.delete(\`${basePath}/\${id}\`);
104
-
105
- res.ok({ id }, "${pascalName} deleted successfully");
106
- });
107
-
108
- export default ${routerVarName};
109
- `;
110
-
111
- fs.writeFileSync(filePath, content, "utf-8");
112
- console.log(colors.green(`[OK] Route '${routeName}' created at app/routes/${filename}`));
113
- console.log("");
114
- console.log(colors.cyan("To register this route, import it in index.js:"));
115
- console.log(colors.gray(` import ${routerVarName} from "./app/routes/${filename}";`));
116
- console.log(colors.gray(` Add ${routerVarName} to the routes array in new App({ routes: [...] })`));
117
- }
118
- }
119
-
120
- const routeCLI = new RouteCLI();
1
+ #!/usr/bin/env node
2
+
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ import colors from "../util/colors.js";
6
+
7
+ /**
8
+ * CLI tool for scaffolding RESTful routes.
9
+ */
10
+ class RouteCLI {
11
+ /**
12
+ * Creates a new RESTful route file with Validation, Cache, and optional Auth.
13
+ */
14
+ create() {
15
+ const rawArgs = process.argv.slice(2);
16
+ const args = rawArgs.filter(
17
+ (a) => a !== "route" && a !== "make:route" && !a.endsWith("route.js")
18
+ );
19
+
20
+ let routeName = args.find((a) => !a.startsWith("-"));
21
+ const withAuth = args.some((a) => a === "--auth" || a === "-a");
22
+
23
+ if (!routeName) {
24
+ console.log(colors.red("[ERROR] Missing route name."));
25
+ console.log("");
26
+ console.log("Usage:");
27
+ console.log(" npx bluebird-js make:route <name> [--auth]");
28
+ console.log("");
29
+ console.log("Examples:");
30
+ console.log(" npx bluebird-js make:route products");
31
+ console.log(" npx bluebird-js make:route articles --auth");
32
+ process.exit(1);
33
+ }
34
+
35
+ routeName = routeName.toLowerCase().replace(/[^a-z0-9_-]/g, "");
36
+ const singularName = routeName.endsWith("s") ? routeName.slice(0, -1) : routeName;
37
+ const pascalName = routeName.charAt(0).toUpperCase() + routeName.slice(1);
38
+ const routerVarName = `router${pascalName}`;
39
+ const basePath = `/${routeName}`;
40
+
41
+ const routesFolder = path.resolve(process.cwd(), "app/routes");
42
+ if (!fs.existsSync(routesFolder)) {
43
+ fs.mkdirSync(routesFolder, { recursive: true });
44
+ }
45
+
46
+ const filename = `${routeName}.js`;
47
+ const filePath = path.join(routesFolder, filename);
48
+ if (fs.existsSync(filePath)) {
49
+ console.log(colors.yellow(`[WARN] Route file '${filename}' already exists at app/routes/${filename}.`));
50
+ return;
51
+ }
52
+
53
+ const authImport = withAuth
54
+ ? 'import Auth from "@seip/bluebird-js/core/auth.js";\n'
55
+ : "";
56
+
57
+ const authProtect = withAuth ? "Auth.protect(), " : "";
58
+
59
+ const content = `import Router from "@seip/bluebird-js/core/router.js";
60
+ import Validator from "@seip/bluebird-js/core/validate.js";
61
+ import Cache from "@seip/bluebird-js/core/cache.js";
62
+ ${authImport}const ${routerVarName} = new Router("${basePath}");
63
+
64
+ const ${singularName}Schema = {
65
+ name: { required: true, min: 2, max: 255 },
66
+ description: { required: false },
67
+ price: { required: false }
68
+ };
69
+
70
+ const validate${pascalName} = new Validator(${singularName}Schema, "en");
71
+
72
+ ${routerVarName}.get("/", Cache.middleware(60), (req, res) => {
73
+ res.ok({ ${routeName}: [] }, "${pascalName} list retrieved successfully");
74
+ });
75
+
76
+ ${routerVarName}.get("/:id", Cache.middleware(60), (req, res) => {
77
+ const { id } = req.params;
78
+ res.ok({ ${singularName}: { id } }, "${pascalName} retrieved successfully");
79
+ });
80
+
81
+ ${routerVarName}.post("/", ${authProtect}validate${pascalName}.middleware(), async (req, res) => {
82
+ const data = req.body;
83
+
84
+ await Cache.delete("${basePath}");
85
+
86
+ res.created({ ${singularName}: data }, "${pascalName} created successfully");
87
+ });
88
+
89
+ ${routerVarName}.put("/:id", ${authProtect}validate${pascalName}.middleware(), async (req, res) => {
90
+ const { id } = req.params;
91
+ const data = req.body;
92
+
93
+ await Cache.delete("${basePath}");
94
+ await Cache.delete(\`${basePath}/\${id}\`);
95
+
96
+ res.ok({ ${singularName}: { id, ...data } }, "${pascalName} updated successfully");
97
+ });
98
+
99
+ ${routerVarName}.delete("/:id", ${authProtect}async (req, res) => {
100
+ const { id } = req.params;
101
+
102
+ await Cache.delete("${basePath}");
103
+ await Cache.delete(\`${basePath}/\${id}\`);
104
+
105
+ res.ok({ id }, "${pascalName} deleted successfully");
106
+ });
107
+
108
+ export default ${routerVarName};
109
+ `;
110
+
111
+ fs.writeFileSync(filePath, content, "utf-8");
112
+ console.log(colors.green(`[OK] Route '${routeName}' created at app/routes/${filename}`));
113
+ console.log("");
114
+ console.log(colors.cyan("To register this route, import it in index.js:"));
115
+ console.log(colors.gray(` import ${routerVarName} from "./app/routes/${filename}";`));
116
+ console.log(colors.gray(` Add ${routerVarName} to the routes array in new App({ routes: [...] })`));
117
+ }
118
+ }
119
+
120
+ const routeCLI = new RouteCLI();
121
121
  routeCLI.create();
package/core/cli/view.js CHANGED
@@ -11,66 +11,85 @@ const args = rawArgs.filter(
11
11
  (a) => a !== "view" && a !== "make:view" && !a.endsWith("view.js")
12
12
  );
13
13
  const viewName = args.find((a) => !a.startsWith("-"));
14
- const useEjs = rawArgs.some((a) => a === "--ejs");
14
+ const isHtml = rawArgs.some((a) => a === "--html");
15
15
 
16
16
  if (!viewName) {
17
17
  console.log(colors.red("[ERROR] Missing view name."));
18
- console.log("Usage: npx bluebird-js make:view <name> [--ejs]");
18
+ console.log("Usage: npx bluebird-js make:view <name> [--html]");
19
19
  process.exit(1);
20
20
  }
21
21
 
22
22
  const cleanName = viewName.toLowerCase().replace(/[^a-z0-9_-]/g, "_");
23
- const ext = useEjs ? ".ejs" : ".html";
24
- const fileName = `${cleanName}${ext}`;
25
- const filePath = path.join(VIEWS_DIR, fileName);
23
+ const titleCase = cleanName.charAt(0).toUpperCase() + cleanName.slice(1);
26
24
 
27
25
  if (!fs.existsSync(VIEWS_DIR)) {
28
26
  fs.mkdirSync(VIEWS_DIR, { recursive: true });
29
27
  }
30
28
 
31
- if (fs.existsSync(filePath)) {
32
- console.log(colors.yellow(`[WARN] View '${fileName}' already exists at app/views/${fileName}.`));
33
- process.exit(0);
34
- }
29
+ if (isHtml) {
30
+ const filePath = path.join(VIEWS_DIR, `${cleanName}.html`);
31
+ if (fs.existsSync(filePath)) {
32
+ console.log(colors.yellow(`[WARN] View '${cleanName}.html' already exists at app/views/${cleanName}.html`));
33
+ process.exit(0);
34
+ }
35
35
 
36
- const titleCase = cleanName.charAt(0).toUpperCase() + cleanName.slice(1);
37
-
38
- const htmlTemplate = `<!DOCTYPE html>
39
- <html lang="en">
36
+ const rawHtml = `<!DOCTYPE html>
37
+ <html lang="en" data-theme="dark">
40
38
  <head>
41
39
  <meta charset="UTF-8" />
42
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
43
- <title>{{title}}</title>
44
- <link rel="stylesheet" href="/css/style.css" />
40
+ <title>${titleCase}</title>
41
+ <link rel="stylesheet" href="/css/bluebird.min.css" />
45
42
  </head>
46
43
  <body>
47
44
  <h1>${titleCase}</h1>
48
- <p>{{description}}</p>
49
- <script src="/js/main.js" defer></script>
50
45
  </body>
51
46
  </html>
52
47
  `;
48
+ fs.writeFileSync(filePath, rawHtml, "utf-8");
49
+ console.log(colors.green(`[OK] Static HTML view created at app/views/${cleanName}.html`));
50
+ console.log(colors.cyan("To render:"));
51
+ console.log(colors.gray(` routerWeb.get("/${cleanName}", (req, res) => Render.html(res, "${cleanName}.html"));`));
52
+ process.exit(0);
53
+ }
53
54
 
54
- const ejsTemplate = `<!DOCTYPE html>
55
- <html lang="en">
56
- <head>
57
- <meta charset="UTF-8" />
58
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
59
- <title><%= title %></title>
60
- <link rel="stylesheet" href="/css/style.css" />
61
- </head>
62
- <body>
63
- <h1>${titleCase}</h1>
64
- <p><%= description %></p>
65
- <script src="/js/main.js" defer></script>
66
- </body>
67
- </html>
68
- `;
55
+ const filePath = path.join(VIEWS_DIR, `${cleanName}.js`);
56
+ if (fs.existsSync(filePath)) {
57
+ console.log(colors.yellow(`[WARN] View '${cleanName}.js' already exists at app/views/${cleanName}.js`));
58
+ process.exit(0);
59
+ }
69
60
 
70
- const content = useEjs ? ejsTemplate : htmlTemplate;
71
- fs.writeFileSync(filePath, content, "utf-8");
61
+ const serverTemplate = `import { html, script } from "@seip/bluebird-js/core/html.js";
62
+
63
+ export const layout = "main";
64
+
65
+ export const head = () => ({
66
+ title: "${titleCase} — Blue Bird",
67
+ description: "${titleCase} view",
68
+ });
69
+
70
+ /**
71
+ * ${titleCase} view module.
72
+ * @param {Object} props
73
+ * @returns {import('@seip/bluebird-js/core/html.js').SafeHtml}
74
+ */
75
+ export default function ${titleCase}View(props = {}) {
76
+ return html\`
77
+ <section class="hero">
78
+ <h1 class="text-gradient font-bold">${titleCase}</h1>
79
+ <p class="lead">Welcome to your new Bluebird view.</p>
80
+ </section>
81
+
82
+ <div class="mt-6">
83
+ <article class="card">
84
+ <p>Rendered with pure JavaScript ESM and zero build tools.</p>
85
+ </article>
86
+ </div>
87
+ \`;
88
+ }
89
+ `;
72
90
 
73
- console.log(colors.green(`[OK] View '${fileName}' created at app/views/${fileName}`));
91
+ fs.writeFileSync(filePath, serverTemplate, "utf-8");
92
+ console.log(colors.green(`[OK] View created at app/views/${cleanName}.js`));
74
93
  console.log("");
75
94
  console.log(colors.cyan("To render this view in a route:"));
76
95
  console.log(colors.gray(` import Render from "@seip/bluebird-js/core/render.js";`));
package/core/config.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Config, AppProps } from "./index.js";
2
- export default Config;
3
- export { Config, AppProps };
1
+ import { Config, AppProps } from "./index.js";
2
+ export default Config;
3
+ export { Config, AppProps };
package/core/config.js CHANGED
@@ -1,111 +1,111 @@
1
- import path from "node:path";
2
- import os from "node:os";
3
-
4
- let _cachedProps = null;
5
- let _customUserDataDir = null;
6
-
7
- /**
8
- * Configuration class to manage application-wide settings, environment variables,
9
- * and Electron/desktop writable data paths.
10
- */
11
- class Config {
12
- /**
13
- * Returns the base directory of the application (process.cwd()).
14
- * @returns {string}
15
- */
16
- static dirname() {
17
- return process.cwd();
18
- }
19
-
20
- /**
21
- * Checks whether the application is running in Electron or Desktop mode.
22
- * @returns {boolean}
23
- */
24
- static isDesktop() {
25
- return Boolean(
26
- process.versions?.electron ||
27
- process.env.DESKTOP_MODE === "true" ||
28
- process.env.ELECTRON_RUN_AS_NODE ||
29
- _customUserDataDir
30
- );
31
- }
32
-
33
- /**
34
- * Sets a custom writable directory for databases, logs, and file cache (ideal for Electron app.getPath("userData")).
35
- * @param {string} dirPath
36
- */
37
- static setUserDataDir(dirPath) {
38
- _customUserDataDir = dirPath ? path.resolve(dirPath) : null;
39
- _cachedProps = null;
40
- }
41
-
42
- /**
43
- * Returns a writable base directory for persistent runtime files (SQLite DB, file cache, logs).
44
- * In standard server environments, returns process.cwd().
45
- * In Electron / Desktop mode or when USER_DATA_PATH is set, returns a writable user data directory
46
- * to avoid EROFS errors inside read-only .asar archives.
47
- * @returns {string}
48
- */
49
- static userDataDir() {
50
- if (_customUserDataDir) return _customUserDataDir;
51
- if (process.env.USER_DATA_PATH) return path.resolve(process.env.USER_DATA_PATH);
52
-
53
- const cwd = process.cwd();
54
- if (cwd.includes(".asar") || process.versions?.electron || process.env.DESKTOP_MODE === "true") {
55
- const appName = (process.env.TITLE || "bluebird-app").toLowerCase().replace(/[^a-z0-9_-]/g, "-");
56
- const baseAppData =
57
- process.env.APPDATA ||
58
- (process.platform === "darwin"
59
- ? path.join(os.homedir(), "Library", "Application Support")
60
- : path.join(os.homedir(), ".local", "share"));
61
- return path.join(baseAppData, appName);
62
- }
63
-
64
- return cwd;
65
- }
66
-
67
- /**
68
- * Retrieves application properties from environment variables.
69
- * Results are cached after the first call.
70
- * @returns {{debug: boolean, desktop: boolean, userDataDir: string, title: string, description: string, version: string, host: string, appUrl: string, port: number, jwtSecret: string, langMeta: string, static: {path: string, options: Object}}} Configuration object.
71
- */
72
- static props() {
73
- if (_cachedProps) return _cachedProps;
74
-
75
- const portRaw = parseInt(process.env.PORT, 10);
76
-
77
- _cachedProps = {
78
- debug: process.env.DEBUG === "true",
79
- desktop: this.isDesktop(),
80
- userDataDir: this.userDataDir(),
81
- descriptionMeta: process.env.DESCRIPTION_META || "",
82
- keywordsMeta: process.env.KEYWORDS_META || "",
83
- titleMeta: process.env.TITLE_META || "",
84
- authorMeta: process.env.AUTHOR_META || "",
85
- description: process.env.DESCRIPTION || "",
86
- title: process.env.TITLE || "",
87
- version: process.env.VERSION || "1.0.0",
88
- langMeta: process.env.LANGMETA || "en",
89
- host: process.env.HOST || "http://localhost",
90
- appUrl: process.env.APP_URL || process.env.HOST || "http://localhost",
91
- port: Number.isNaN(portRaw) ? 3000 : portRaw,
92
- jwtSecret: process.env.JWT_SECRET,
93
- static: {
94
- path: process.env.STATIC_PATH || "public",
95
- options: {},
96
- },
97
- };
98
- return _cachedProps;
99
- }
100
-
101
- /**
102
- * Clears the cached configuration properties to re-read environment variables.
103
- * @returns {void}
104
- */
105
- static reload() {
106
- _cachedProps = null;
107
- }
108
- }
109
-
110
- export { Config };
111
- export default Config;
1
+ import path from "node:path";
2
+ import os from "node:os";
3
+
4
+ let _cachedProps = null;
5
+ let _customUserDataDir = null;
6
+
7
+ /**
8
+ * Configuration class to manage application-wide settings, environment variables,
9
+ * and Electron/desktop writable data paths.
10
+ */
11
+ class Config {
12
+ /**
13
+ * Returns the base directory of the application (process.cwd()).
14
+ * @returns {string}
15
+ */
16
+ static dirname() {
17
+ return process.cwd();
18
+ }
19
+
20
+ /**
21
+ * Checks whether the application is running in Electron or Desktop mode.
22
+ * @returns {boolean}
23
+ */
24
+ static isDesktop() {
25
+ return Boolean(
26
+ process.versions?.electron ||
27
+ process.env.DESKTOP_MODE === "true" ||
28
+ process.env.ELECTRON_RUN_AS_NODE ||
29
+ _customUserDataDir
30
+ );
31
+ }
32
+
33
+ /**
34
+ * Sets a custom writable directory for databases, logs, and file cache (ideal for Electron app.getPath("userData")).
35
+ * @param {string} dirPath
36
+ */
37
+ static setUserDataDir(dirPath) {
38
+ _customUserDataDir = dirPath ? path.resolve(dirPath) : null;
39
+ _cachedProps = null;
40
+ }
41
+
42
+ /**
43
+ * Returns a writable base directory for persistent runtime files (SQLite DB, file cache, logs).
44
+ * In standard server environments, returns process.cwd().
45
+ * In Electron / Desktop mode or when USER_DATA_PATH is set, returns a writable user data directory
46
+ * to avoid EROFS errors inside read-only .asar archives.
47
+ * @returns {string}
48
+ */
49
+ static userDataDir() {
50
+ if (_customUserDataDir) return _customUserDataDir;
51
+ if (process.env.USER_DATA_PATH) return path.resolve(process.env.USER_DATA_PATH);
52
+
53
+ const cwd = process.cwd();
54
+ if (cwd.includes(".asar") || process.versions?.electron || process.env.DESKTOP_MODE === "true") {
55
+ const appName = (process.env.TITLE || "bluebird-app").toLowerCase().replace(/[^a-z0-9_-]/g, "-");
56
+ const baseAppData =
57
+ process.env.APPDATA ||
58
+ (process.platform === "darwin"
59
+ ? path.join(os.homedir(), "Library", "Application Support")
60
+ : path.join(os.homedir(), ".local", "share"));
61
+ return path.join(baseAppData, appName);
62
+ }
63
+
64
+ return cwd;
65
+ }
66
+
67
+ /**
68
+ * Retrieves application properties from environment variables.
69
+ * Results are cached after the first call.
70
+ * @returns {{debug: boolean, desktop: boolean, userDataDir: string, title: string, description: string, version: string, host: string, appUrl: string, port: number, jwtSecret: string, langMeta: string, static: {path: string, options: Object}}} Configuration object.
71
+ */
72
+ static props() {
73
+ if (_cachedProps) return _cachedProps;
74
+
75
+ const portRaw = parseInt(process.env.PORT, 10);
76
+
77
+ _cachedProps = {
78
+ debug: process.env.DEBUG === "true",
79
+ desktop: this.isDesktop(),
80
+ userDataDir: this.userDataDir(),
81
+ descriptionMeta: process.env.DESCRIPTION_META || "",
82
+ keywordsMeta: process.env.KEYWORDS_META || "",
83
+ titleMeta: process.env.TITLE_META || "",
84
+ authorMeta: process.env.AUTHOR_META || "",
85
+ description: process.env.DESCRIPTION || "",
86
+ title: process.env.TITLE || "",
87
+ version: process.env.VERSION || "1.0.0",
88
+ langMeta: process.env.LANGMETA || "en",
89
+ host: process.env.HOST || "http://localhost",
90
+ appUrl: process.env.APP_URL || process.env.HOST || "http://localhost",
91
+ port: Number.isNaN(portRaw) ? 3000 : portRaw,
92
+ jwtSecret: process.env.JWT_SECRET,
93
+ static: {
94
+ path: process.env.STATIC_PATH || "public",
95
+ options: {},
96
+ },
97
+ };
98
+ return _cachedProps;
99
+ }
100
+
101
+ /**
102
+ * Clears the cached configuration properties to re-read environment variables.
103
+ * @returns {void}
104
+ */
105
+ static reload() {
106
+ _cachedProps = null;
107
+ }
108
+ }
109
+
110
+ export { Config };
111
+ export default Config;
package/core/csrf.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Csrf, CsrfOptions } from "./index.js";
2
- export default Csrf;
3
- export { Csrf, CsrfOptions };
1
+ import { Csrf, CsrfOptions } from "./index.js";
2
+ export default Csrf;
3
+ export { Csrf, CsrfOptions };