@seip/bluebird-js 0.0.0-stage → 0.1.0
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/.env_example +54 -0
- package/AGENTS.md +426 -0
- package/LICENSE +21 -0
- package/README.md +292 -3
- package/app/routes/api.js +50 -0
- package/app/routes/web.js +55 -0
- package/app/views/about.js +63 -0
- package/app/views/dashboard.js +147 -0
- package/app/views/index.js +80 -0
- package/app/views/layouts/main/view.js +81 -0
- package/app/views/legal/terms.html +19 -0
- package/app/views/login.js +80 -0
- package/core/app.d.ts +18 -0
- package/core/app.js +684 -0
- package/core/auth.d.ts +13 -0
- package/core/auth.js +326 -0
- package/core/cache.d.ts +17 -0
- package/core/cache.js +475 -0
- package/core/cli/doctor.js +287 -0
- package/core/cli/ecosystem.js +162 -0
- package/core/cli/init.js +779 -0
- package/core/cli/migrate.js +541 -0
- package/core/cli/model.js +66 -0
- package/core/cli/nginx.js +199 -0
- package/core/cli/route.js +121 -0
- package/core/cli/swagger.js +45 -0
- package/core/cli/view.js +96 -0
- package/core/config.d.ts +3 -0
- package/core/config.js +111 -0
- package/core/csrf.d.ts +3 -0
- package/core/csrf.js +114 -0
- package/core/database.d.ts +15 -0
- package/core/database.js +636 -0
- package/core/debug.d.ts +3 -0
- package/core/debug.js +250 -0
- package/core/hash.d.ts +3 -0
- package/core/hash.js +194 -0
- package/core/html.d.ts +42 -0
- package/core/html.js +217 -0
- package/core/index.d.ts +1176 -0
- package/core/logger.d.ts +3 -0
- package/core/logger.js +127 -0
- package/core/middleware.d.ts +3 -0
- package/core/middleware.js +28 -0
- package/core/model.d.ts +19 -0
- package/core/model.js +600 -0
- package/core/queue.d.ts +13 -0
- package/core/queue.js +172 -0
- package/core/ratelimit.d.ts +3 -0
- package/core/ratelimit.js +145 -0
- package/core/redis.d.ts +21 -0
- package/core/redis.js +230 -0
- package/core/render-cache.js +212 -0
- package/core/render.d.ts +3 -0
- package/core/render.js +320 -0
- package/core/router.d.ts +3 -0
- package/core/router.js +171 -0
- package/core/seo.d.ts +3 -0
- package/core/seo.js +106 -0
- package/core/swagger.d.ts +3 -0
- package/core/swagger.js +60 -0
- package/core/upload.d.ts +13 -0
- package/core/upload.js +102 -0
- package/core/util/colors.js +82 -0
- package/core/validate.d.ts +15 -0
- package/core/validate.js +364 -0
- package/core/view-loader.js +162 -0
- package/core/vite.d.ts +3 -0
- package/core/vite.js +145 -0
- package/core/ws.d.ts +13 -0
- package/core/ws.js +245 -0
- package/index.js +18 -0
- package/jsconfig.json +15 -0
- package/package.json +85 -5
- package/production.md +273 -0
- package/public/css/bluebird.min.css +2 -0
- package/public/images/favicon.ico +0 -0
- package/public/js/bluebird-client.js +1781 -0
- package/public/js/bluebird.min.js +1073 -0
package/core/seo.d.ts
ADDED
package/core/seo.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import Config from "./config.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Registry of SEO-enabled routes for automatic sitemap.xml and robots.txt generation.
|
|
5
|
+
* @type {Set<string>}
|
|
6
|
+
*/
|
|
7
|
+
const registeredSeoRoutes = new Set();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Native SEO module for registering indexable routes and serving sitemap.xml and robots.txt.
|
|
11
|
+
*/
|
|
12
|
+
class Seo {
|
|
13
|
+
/**
|
|
14
|
+
* Registers a GET route path for inclusion in sitemap.xml.
|
|
15
|
+
* Ignores parameterized dynamic segments (e.g. :id) and wildcards.
|
|
16
|
+
* @param {string} basePath - Router base path.
|
|
17
|
+
* @param {string|RegExp} routePath - Route relative path.
|
|
18
|
+
* @param {string[]} [languages=[]] - Optional language prefixes.
|
|
19
|
+
*/
|
|
20
|
+
static registerRoute(basePath, routePath, languages = []) {
|
|
21
|
+
if (typeof routePath !== "string") return;
|
|
22
|
+
if (routePath.includes("*") || routePath.includes(":")) return;
|
|
23
|
+
|
|
24
|
+
const normalizedBase = basePath === "/" ? "" : basePath.replace(/\/$/, "");
|
|
25
|
+
const normalizedRoute = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
26
|
+
const fullPath = `${normalizedBase}${normalizedRoute}` || "/";
|
|
27
|
+
|
|
28
|
+
if (languages && languages.length > 0) {
|
|
29
|
+
for (const lang of languages) {
|
|
30
|
+
const cleanLang = String(lang).trim().replace(/^\/|\/$/g, "");
|
|
31
|
+
if (cleanLang) {
|
|
32
|
+
const localizedPath = fullPath === "/" ? `/${cleanLang}` : `/${cleanLang}${fullPath}`;
|
|
33
|
+
registeredSeoRoutes.add(localizedPath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
registeredSeoRoutes.add(fullPath);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns all registered SEO route paths.
|
|
43
|
+
* @returns {string[]}
|
|
44
|
+
*/
|
|
45
|
+
static getRoutes() {
|
|
46
|
+
return Array.from(registeredSeoRoutes);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Clears all registered SEO routes.
|
|
51
|
+
*/
|
|
52
|
+
static clear() {
|
|
53
|
+
registeredSeoRoutes.clear();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generates the XML string for sitemap.xml.
|
|
58
|
+
* @param {string} [baseUrl] - Public base URL of the application.
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
static generateSitemap(baseUrl) {
|
|
62
|
+
const props = Config.props();
|
|
63
|
+
const rootUrl = (baseUrl || props.appUrl || `${props.host}:${props.port}`).replace(/\/$/, "");
|
|
64
|
+
const lastmod = new Date().toISOString().split("T")[0];
|
|
65
|
+
|
|
66
|
+
const urls = Array.from(registeredSeoRoutes).map((routePath) => {
|
|
67
|
+
const priority = routePath === "/" ? "1.0" : "0.8";
|
|
68
|
+
return [
|
|
69
|
+
" <url>",
|
|
70
|
+
` <loc>${rootUrl}${routePath}</loc>`,
|
|
71
|
+
` <lastmod>${lastmod}</lastmod>`,
|
|
72
|
+
" <changefreq>weekly</changefreq>",
|
|
73
|
+
` <priority>${priority}</priority>`,
|
|
74
|
+
" </url>",
|
|
75
|
+
].join("\n");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return [
|
|
79
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
80
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
81
|
+
...urls,
|
|
82
|
+
"</urlset>",
|
|
83
|
+
].join("\n");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Generates the plain text content for robots.txt.
|
|
88
|
+
* @param {string} [baseUrl] - Public base URL of the application.
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
static generateRobots(baseUrl) {
|
|
92
|
+
const props = Config.props();
|
|
93
|
+
const rootUrl = (baseUrl || props.appUrl || `${props.host}:${props.port}`).replace(/\/$/, "");
|
|
94
|
+
return [
|
|
95
|
+
"User-agent: *",
|
|
96
|
+
"Allow: /",
|
|
97
|
+
"Disallow: /api/",
|
|
98
|
+
"Disallow: /debug/",
|
|
99
|
+
`Sitemap: ${rootUrl}/sitemap.xml`,
|
|
100
|
+
"",
|
|
101
|
+
].join("\n");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { Seo };
|
|
106
|
+
export default Seo;
|
package/core/swagger.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swagger and OpenAPI documentation integration module.
|
|
3
|
+
* Dynamically loads swagger-ui-express and swagger-jsdoc when enabled.
|
|
4
|
+
*/
|
|
5
|
+
class Swagger {
|
|
6
|
+
/**
|
|
7
|
+
* Initializes Swagger UI documentation on the Express application.
|
|
8
|
+
* @param {import('express').Application} app - Express application instance.
|
|
9
|
+
* @param {Object} [options={}] - Configuration options.
|
|
10
|
+
* @param {string} [options.route="/docs"] - HTTP route for documentation.
|
|
11
|
+
* @param {Object} [options.info={}] - OpenAPI info object.
|
|
12
|
+
* @param {string[]} [options.apis=[]] - Glob paths for JSDoc documentation files.
|
|
13
|
+
* @returns {Promise<boolean>} Resolves to true if documentation was mounted.
|
|
14
|
+
*/
|
|
15
|
+
static async init(app, options = {}) {
|
|
16
|
+
const route = options.route || "/docs";
|
|
17
|
+
const apis = options.apis || ["./app/routes/*.js", "./app/routes/*.ts"];
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const [{ default: swaggerUi }, { default: swaggerJsdoc }] = await Promise.all([
|
|
21
|
+
import("swagger-ui-express"),
|
|
22
|
+
import("swagger-jsdoc"),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const swaggerDefinition = {
|
|
26
|
+
openapi: "3.0.0",
|
|
27
|
+
info: {
|
|
28
|
+
title: options.info?.title || "Blue Bird API",
|
|
29
|
+
version: options.info?.version || "1.0.0",
|
|
30
|
+
description: options.info?.description || "Blue Bird Framework API Documentation",
|
|
31
|
+
},
|
|
32
|
+
servers: [
|
|
33
|
+
{
|
|
34
|
+
url: options.url || "http://localhost:3000",
|
|
35
|
+
description: "API Server",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const swaggerSpec = swaggerJsdoc({
|
|
41
|
+
swaggerDefinition,
|
|
42
|
+
apis,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
app.use(route, swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
|
46
|
+
app.get(`${route}/json`, (req, res) => {
|
|
47
|
+
res.setHeader("Content-Type", "application/json");
|
|
48
|
+
res.send(swaggerSpec);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return true;
|
|
52
|
+
} catch {
|
|
53
|
+
console.warn("[SWAGGER WARN] 'swagger-ui-express' or 'swagger-jsdoc' is not installed. Run: npx blue-bird add swagger");
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Swagger };
|
|
60
|
+
export default Swagger;
|
package/core/upload.d.ts
ADDED
package/core/upload.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import Config from "./config.js";
|
|
4
|
+
|
|
5
|
+
const __dirname = Config.dirname();
|
|
6
|
+
const props = Config.props();
|
|
7
|
+
|
|
8
|
+
let multer = null;
|
|
9
|
+
try {
|
|
10
|
+
multer = (await import("multer")).default || (await import("multer"));
|
|
11
|
+
} catch {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Upload helper to manage file uploads using multer.
|
|
15
|
+
*/
|
|
16
|
+
class Upload {
|
|
17
|
+
/**
|
|
18
|
+
* Asserts that the multer package is available.
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
static _ensureMulter() {
|
|
22
|
+
if (!multer) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"[UPLOAD ERROR] 'multer' package is not installed. Install it with: npm install multer or npx blue-bird add upload",
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Configures storage for uploaded files.
|
|
31
|
+
* @param {string} folder - The destination folder within the static path.
|
|
32
|
+
* @returns {import('multer').StorageEngine}
|
|
33
|
+
* @example
|
|
34
|
+
* const storage = Upload.storage("uploads");
|
|
35
|
+
*/
|
|
36
|
+
static storage(folder = "uploads") {
|
|
37
|
+
this._ensureMulter();
|
|
38
|
+
const dest = path.join(__dirname, props.static.path, folder);
|
|
39
|
+
|
|
40
|
+
if (!fs.existsSync(dest)) {
|
|
41
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return multer.diskStorage({
|
|
45
|
+
destination: (req, file, cb) => {
|
|
46
|
+
cb(null, dest);
|
|
47
|
+
},
|
|
48
|
+
filename: (req, file, cb) => {
|
|
49
|
+
const uniqueSuffix =
|
|
50
|
+
Date.now() + "-" + Math.round(Math.random() * 1e9);
|
|
51
|
+
cb(null, uniqueSuffix + path.extname(file.originalname));
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns a multer instance for single or multiple file uploads.
|
|
58
|
+
* @param {Object} options - Multer options.
|
|
59
|
+
* @param {string} [options.folder='uploads'] - Destination folder.
|
|
60
|
+
* @param {number} [options.fileSize=5000000] - Max file size in bytes (default 5MB).
|
|
61
|
+
* @param {Array<string>} [options.allowedTypes=[]] - Allowed mime types (e.g. ['image/png', 'image/jpeg']).
|
|
62
|
+
* @returns {import('multer').Multer}
|
|
63
|
+
* @example
|
|
64
|
+
* const upload = Upload.disk({ folder: "uploads", fileSize: 5000000, allowedTypes: ["image/png", "image/jpeg"] });
|
|
65
|
+
*/
|
|
66
|
+
static disk(options = {}) {
|
|
67
|
+
this._ensureMulter();
|
|
68
|
+
const {
|
|
69
|
+
folder = "uploads",
|
|
70
|
+
fileSize = 5000000,
|
|
71
|
+
allowedTypes = [],
|
|
72
|
+
} = options;
|
|
73
|
+
|
|
74
|
+
return multer({
|
|
75
|
+
storage: this.storage(folder),
|
|
76
|
+
limits: { fileSize },
|
|
77
|
+
fileFilter: (req, file, cb) => {
|
|
78
|
+
if (allowedTypes.length > 0 && !allowedTypes.includes(file.mimetype)) {
|
|
79
|
+
return cb(new Error("File type not allowed"), false);
|
|
80
|
+
}
|
|
81
|
+
cb(null, true);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Helper to get the public URL of an uploaded file.
|
|
88
|
+
* @param {string} filename - The name of the file.
|
|
89
|
+
* @param {string} [folder='uploads'] - The folder where the file is stored.
|
|
90
|
+
* @returns {string} The full public URL.
|
|
91
|
+
* @example
|
|
92
|
+
* const url = Upload.url("file.jpg", "uploads");
|
|
93
|
+
*/
|
|
94
|
+
static url(filename, folder = "uploads") {
|
|
95
|
+
const appUrl = props.appUrl ?? `${props.host}:${props.port}`;
|
|
96
|
+
return `${appUrl}/${folder}/${filename}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { Upload };
|
|
101
|
+
export default Upload;
|
|
102
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ANSI color formatting utilities powered by Node.js native styleText.
|
|
5
|
+
* Provides a lightweight, zero-dependency alternative to chalk.
|
|
6
|
+
*/
|
|
7
|
+
const colors = {
|
|
8
|
+
/**
|
|
9
|
+
* Applies bold formatting.
|
|
10
|
+
* @param {string|number} text
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
bold: (text) => styleText("bold", String(text)),
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Applies green color.
|
|
17
|
+
* @param {string|number} text
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
green: (text) => styleText("green", String(text)),
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Applies red color.
|
|
24
|
+
* @param {string|number} text
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
red: (text) => styleText("red", String(text)),
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Applies blue color.
|
|
31
|
+
* @param {string|number} text
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
blue: (text) => styleText("blue", String(text)),
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Applies yellow color.
|
|
38
|
+
* @param {string|number} text
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
yellow: (text) => styleText("yellow", String(text)),
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Applies cyan color.
|
|
45
|
+
* @param {string|number} text
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
cyan: (text) => styleText("cyan", String(text)),
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Applies magenta color.
|
|
52
|
+
* @param {string|number} text
|
|
53
|
+
* @returns {string}
|
|
54
|
+
*/
|
|
55
|
+
magenta: (text) => styleText("magenta", String(text)),
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Applies gray color.
|
|
59
|
+
* @param {string|number} text
|
|
60
|
+
* @returns {string}
|
|
61
|
+
*/
|
|
62
|
+
gray: (text) => styleText("gray", String(text)),
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Applies white color.
|
|
66
|
+
* @param {string|number} text
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
white: (text) => styleText("white", String(text)),
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Bold color modifier functions.
|
|
74
|
+
*/
|
|
75
|
+
colors.bold.green = (text) => styleText(["bold", "green"], String(text));
|
|
76
|
+
colors.bold.red = (text) => styleText(["bold", "red"], String(text));
|
|
77
|
+
colors.bold.blue = (text) => styleText(["bold", "blue"], String(text));
|
|
78
|
+
colors.bold.cyan = (text) => styleText(["bold", "cyan"], String(text));
|
|
79
|
+
colors.bold.yellow = (text) => styleText(["bold", "yellow"], String(text));
|
|
80
|
+
colors.bold.magenta = (text) => styleText(["bold", "magenta"], String(text));
|
|
81
|
+
|
|
82
|
+
export default colors;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Validator,
|
|
3
|
+
ValidationRule,
|
|
4
|
+
ValidationSchema,
|
|
5
|
+
ValidationError,
|
|
6
|
+
ValidationResult,
|
|
7
|
+
} from "./index.js";
|
|
8
|
+
export default Validator;
|
|
9
|
+
export {
|
|
10
|
+
Validator,
|
|
11
|
+
ValidationRule,
|
|
12
|
+
ValidationSchema,
|
|
13
|
+
ValidationError,
|
|
14
|
+
ValidationResult,
|
|
15
|
+
};
|