@seip/bluebird-js 0.1.6 → 0.2.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.
Files changed (152) hide show
  1. package/.vscode/extensions.json +7 -7
  2. package/.vscode/settings.json +10 -10
  3. package/AGENTS.md +266 -116
  4. package/README.md +258 -245
  5. package/app/models/user.js +19 -0
  6. package/app/resources/html/home.html +137 -0
  7. package/app/resources/html/layouts/main.html +54 -0
  8. package/app/resources/html/notFound.html +14 -0
  9. package/app/resources/html/terms.html +46 -0
  10. package/app/resources/index.html +27 -0
  11. package/app/resources/layouts/AppLayout.jsx +89 -0
  12. package/app/resources/main.jsx +18 -0
  13. package/app/resources/pages/Dashboard.jsx +98 -0
  14. package/app/resources/pages/Home.jsx +140 -0
  15. package/app/resources/pages/Login.jsx +35 -0
  16. package/app/resources/pages/NotFound.jsx +16 -0
  17. package/app/resources/pages/Register.jsx +55 -0
  18. package/app/resources/routes.jsx +54 -0
  19. package/app/resources/spa.js +67 -0
  20. package/app/resources/styles.css +9 -0
  21. package/app/routes/api.js +85 -50
  22. package/app/routes/auth.js +209 -0
  23. package/app/routes/web.js +49 -37
  24. package/core/ai.d.ts +151 -151
  25. package/core/ai.js +1071 -1051
  26. package/core/app.d.ts +2 -18
  27. package/core/app.js +978 -792
  28. package/core/auth.d.ts +2 -13
  29. package/core/auth.js +444 -326
  30. package/core/cli/backup.js +167 -167
  31. package/core/cli/build.js +37 -0
  32. package/core/cli/dev.js +155 -0
  33. package/core/cli/doctor.js +37 -2
  34. package/core/cli/export.js +191 -0
  35. package/core/cli/init.js +101 -332
  36. package/core/cli/nginx.js +1 -1
  37. package/core/cli/templates.js +139 -0
  38. package/core/cli/view.js +73 -136
  39. package/core/config.js +44 -2
  40. package/core/csrf.js +156 -24
  41. package/core/database.js +737 -684
  42. package/core/debug.js +1 -1
  43. package/core/html.js +8 -1
  44. package/core/index.d.ts +1286 -1431
  45. package/core/paths.js +55 -0
  46. package/core/ratelimit.js +10 -1
  47. package/core/react/client/api.js +237 -0
  48. package/core/react/client/auth.js +236 -0
  49. package/core/react/client/components.js +1321 -0
  50. package/core/react/client/i18n.js +338 -0
  51. package/core/react/client/index.d.ts +249 -0
  52. package/core/react/client/index.js +49 -0
  53. package/core/react/client/router.js +26 -0
  54. package/core/react/client/theme.css +512 -0
  55. package/core/render-cache.js +250 -212
  56. package/core/render.d.ts +25 -21
  57. package/core/render.js +613 -603
  58. package/core/router.d.ts +2 -3
  59. package/core/router.js +171 -171
  60. package/core/seo.js +10 -0
  61. package/core/spa.js +599 -0
  62. package/core/view-loader.js +81 -455
  63. package/core/vite-plugin.d.ts +18 -0
  64. package/core/vite-plugin.js +162 -0
  65. package/core/vite.js +250 -145
  66. package/index.js +22 -18
  67. package/jsconfig.json +5 -3
  68. package/package.json +114 -92
  69. package/production.md +8 -3
  70. package/public/js/bluebird.js +1160 -0
  71. package/templates/_auth/app/database.js +19 -0
  72. package/templates/_auth/app/models/user.js +22 -0
  73. package/templates/_auth/app/routes/auth-router.js +304 -0
  74. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  75. package/templates/_base/app/resources/html/notFound.html +14 -0
  76. package/templates/_base/app/resources/index.html +27 -0
  77. package/templates/_base/app/resources/styles.css +9 -0
  78. package/templates/api/app/models/note.js +18 -0
  79. package/templates/api/app/routes/api.js +82 -0
  80. package/templates/api/app/routes/auth.js +11 -0
  81. package/templates/api/index.js +19 -0
  82. package/templates/api/template.json +13 -0
  83. package/templates/auth/app/mail.js +11 -0
  84. package/templates/auth/app/models/password_reset.js +18 -0
  85. package/templates/auth/app/resources/html/home.html +21 -0
  86. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  87. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  88. package/templates/auth/app/resources/main.jsx +18 -0
  89. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  90. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  91. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  92. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  93. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  94. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  95. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  96. package/templates/auth/app/resources/routes.jsx +54 -0
  97. package/templates/auth/app/resources/spa.js +29 -0
  98. package/templates/auth/app/routes/api.js +17 -0
  99. package/templates/auth/app/routes/auth.js +13 -0
  100. package/templates/auth/app/routes/web.js +21 -0
  101. package/templates/auth/index.js +19 -0
  102. package/templates/auth/template.json +15 -0
  103. package/templates/blank/app/models/.gitkeep +0 -0
  104. package/templates/blank/app/resources/html/home.html +27 -0
  105. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  106. package/templates/blank/app/resources/main.jsx +16 -0
  107. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  108. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  109. package/templates/blank/app/resources/routes.jsx +15 -0
  110. package/templates/blank/app/resources/spa.js +24 -0
  111. package/templates/blank/app/routes/api.js +11 -0
  112. package/templates/blank/app/routes/web.js +21 -0
  113. package/templates/blank/index.js +13 -0
  114. package/templates/blank/template.json +12 -0
  115. package/templates/blog/app/lib/blog.js +149 -0
  116. package/templates/blog/app/models/post.js +22 -0
  117. package/templates/blog/app/resources/html/home.html +28 -0
  118. package/templates/blog/app/resources/html/not-found.html +5 -0
  119. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  120. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  121. package/templates/blog/app/resources/html/post.html +8 -0
  122. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  123. package/templates/blog/app/resources/main.jsx +18 -0
  124. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  125. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  126. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  127. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  128. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  129. package/templates/blog/app/resources/routes.jsx +51 -0
  130. package/templates/blog/app/resources/spa.js +25 -0
  131. package/templates/blog/app/resources/styles.css +40 -0
  132. package/templates/blog/app/routes/api.js +77 -0
  133. package/templates/blog/app/routes/auth.js +10 -0
  134. package/templates/blog/app/routes/web.js +114 -0
  135. package/templates/blog/index.js +21 -0
  136. package/templates/blog/template.json +14 -0
  137. package/vite.config.js +11 -0
  138. package/app/views/about.jsx +0 -98
  139. package/app/views/components/Header.jsx +0 -42
  140. package/app/views/components/LiveCounter.jsx +0 -66
  141. package/app/views/dashboard.jsx +0 -300
  142. package/app/views/index.jsx +0 -123
  143. package/app/views/layouts/main/view.jsx +0 -201
  144. package/app/views/legal/terms.html +0 -29
  145. package/app/views/login.jsx +0 -141
  146. package/core/actions.d.ts +0 -4
  147. package/core/actions.js +0 -329
  148. package/core/jsx.d.ts +0 -38
  149. package/core/jsx.js +0 -1432
  150. package/core/vite.d.ts +0 -3
  151. package/public/js/bluebird-client.js +0 -3161
  152. package/public/js/tailwind.js +0 -8
package/app/routes/web.js CHANGED
@@ -1,47 +1,59 @@
1
1
  import Router from "@seip/bluebird-js/core/router.js";
2
2
  import Render from "@seip/bluebird-js/core/render.js";
3
- import Auth from "@seip/bluebird-js/core/auth.js";
3
+ import { escapeHtml } from "@seip/bluebird-js/core/html.js";
4
+ import spa from "../resources/spa.js";
4
5
 
5
- /**
6
- * Web Router for custom actions and static HTML files.
7
- * Page GET routes (`/`, `/about`, `/login`, `/dashboard`) are automatically
8
- * generated from `app/views/*.jsx` via declarative exports (`route`, `cache`, `middlewares`, `layout`, `seo`).
9
- */
10
6
  const routerWeb = new Router("/", { seo: true });
11
7
 
12
- routerWeb.get("/terms", (req, res) => Render.html(res, "legal/terms.html", { ttl: 86400 }));
13
-
14
- routerWeb.post("/login", async (req, res) => {
15
- const email = req.body?.email || "alex@example.com";
16
- const rawPrefix = email.split("@")[0] || "alex";
17
- const name = req.body?.name || (rawPrefix.charAt(0).toUpperCase() + rawPrefix.slice(1));
18
-
19
- const user = {
20
- id: 1,
21
- name,
22
- email,
23
- role: "admin",
24
- };
25
-
26
- await Auth.login(res, user);
27
- return res.redirect("/dashboard");
8
+ routerWeb.get("/", (req, res) => {
9
+ const slides = [
10
+ {
11
+ badge: "HTML SSR",
12
+ title: "Fast HTML {{ }} Templates",
13
+ description: "Serve SEO-ready landings and storefronts directly from app/resources/html/ with layouts, partials, and {{if}} / {{each}}.",
14
+ },
15
+ {
16
+ badge: "React SPA",
17
+ title: "React Router + Vite on /app",
18
+ description: "Client-side React workspace with zero SSR friction, per-URL SEO metadata, and a full-width skeleton in #root.",
19
+ },
20
+ {
21
+ badge: "Auth & UI",
22
+ title: "Tailwind v4 Dark & Light Ready",
23
+ description: "Built-in AuthProvider with optional roles, vanilla data-* helpers, and reusable React UI components.",
24
+ },
25
+ ];
26
+
27
+ const features = [
28
+ { name: "HTML SSR Engine", detail: "{{var}}, {{{raw}}}, {{if}}/{{else}}, {{each}}, {{> partial}}" },
29
+ { name: "Router.spa()", detail: "Per-URL title, meta, keywords, JSON-LD, canonical, and skeleton" },
30
+ { name: "Auth + Roles", detail: "AuthProvider synced with /api/auth/me and Auth.protect({ roles })" },
31
+ ];
32
+
33
+ const badges = ["Express 5", "HTML {{ }}", "Vite 7", "React 19", "React Router", "Tailwind v4"];
34
+ const highlightsHtml = badges
35
+ .map(
36
+ (label) =>
37
+ `<span class="badge bg-card/80 text-foreground backdrop-blur-sm">${escapeHtml(label)}</span>`
38
+ )
39
+ .join("");
40
+
41
+ return Render.html(
42
+ res,
43
+ "home",
44
+ {
45
+ title: "Bluebird.js — HTML SSR + React SPA",
46
+ description: "Express + HTML {{ }} SSR templates + React Router SPA with Vite and Tailwind CSS v4.",
47
+ slides,
48
+ features,
49
+ highlightsHtml,
50
+ },
51
+ { layout: "main", cache: 300 }
52
+ );
28
53
  });
29
54
 
30
- routerWeb.get("/logout", async (req, res) => {
31
- if (
32
- req.headers["x-bluebird-prefetch"] ||
33
- req.headers.purpose === "prefetch" ||
34
- req.headers["sec-purpose"] === "prefetch"
35
- ) {
36
- return res.status(204).end();
37
- }
38
- await Auth.logout(res);
39
- return res.redirect("/login");
40
- });
55
+ routerWeb.get("/terms", Render.view("terms", { title: "Terms of Service" }, { cache: 86400, ttl: 86400 }));
41
56
 
42
- routerWeb.post("/logout", async (req, res) => {
43
- await Auth.logout(res);
44
- return res.redirect("/login");
45
- });
57
+ routerWeb.spa(spa.mount, spa);
46
58
 
47
59
  export default routerWeb;
package/core/ai.d.ts CHANGED
@@ -1,151 +1,151 @@
1
- import type { Request, Response, NextFunction, RequestHandler } from "express";
2
-
3
- export interface AIOptions {
4
- provider?: "deepseek" | "gemini" | "openai" | "custom";
5
- model?: string;
6
- apiKey?: string;
7
- baseURL?: string;
8
- temperature?: number;
9
- thinking?: boolean | { type: string };
10
- reasoningEffort?: "low" | "medium" | "high";
11
- rateLimit?: number | { minute?: number; day?: number } | { max: number; windowMs: number };
12
- rateWindow?: number;
13
- cacheTtl?: number | boolean;
14
- system?: string;
15
- }
16
-
17
- export interface AIAskOptions {
18
- data?: Record<string, any>;
19
- sensitiveKeys?: string[];
20
- request?: Request | any;
21
- req?: Request | any;
22
- user?: string;
23
- system?: string;
24
- json?: boolean;
25
- schema?: Record<string, any>;
26
- temperature?: number;
27
- model?: string;
28
- provider?: "deepseek" | "gemini" | "openai" | "custom";
29
- apiKey?: string;
30
- baseURL?: string;
31
- cache?: number | boolean;
32
- thinking?: boolean | { type: string };
33
- reasoningEffort?: "low" | "medium" | "high";
34
- maxTokens?: number;
35
- rateLimit?: number | { minute?: number; day?: number } | { max: number; windowMs: number };
36
- }
37
-
38
- export interface AIUsage {
39
- prompt_tokens?: number;
40
- completion_tokens?: number;
41
- total_tokens?: number;
42
- [key: string]: any;
43
- }
44
-
45
- export interface AIResult<T = any> {
46
- success: boolean;
47
- text?: string;
48
- rawText?: string;
49
- parsed?: T;
50
- valid?: boolean;
51
- errors?: any;
52
- reasoning?: string | null;
53
- cached?: boolean;
54
- latency?: number;
55
- provider?: string;
56
- model?: string;
57
- usage?: AIUsage;
58
- maskedKeys?: string[];
59
- error?: string;
60
- message?: string;
61
- retryAfter?: number;
62
- }
63
-
64
- export interface AIStreamChunk {
65
- text: string;
66
- done: boolean;
67
- }
68
-
69
- export interface MaskResult {
70
- maskedPrompt: string;
71
- maskedData: Record<string, any> | null;
72
- tokenMap: Record<string, string>;
73
- reverseTokenMap: Record<string, string>;
74
- }
75
-
76
- export declare function getClientIp(req: Request | any): string;
77
-
78
- export declare function maskSensitiveData(
79
- prompt?: string,
80
- data?: Record<string, any> | null,
81
- sensitiveKeys?: string[]
82
- ): MaskResult;
83
-
84
- export declare function unmaskSensitiveData(
85
- text?: string,
86
- reverseTokenMap?: Record<string, string>
87
- ): string;
88
-
89
- export declare function extractJsonString(text?: string): string;
90
-
91
- export declare class AI {
92
- provider: string;
93
- model: string;
94
- apiKey: string;
95
- baseURL: string;
96
- temperature: number;
97
- thinking: boolean | Object;
98
- reasoningEffort?: "low" | "medium" | "high";
99
- rateLimit?: any;
100
- rateWindow: number;
101
- cacheTtl: number | boolean;
102
- system: string;
103
-
104
- constructor(options?: AIOptions);
105
-
106
- checkRateLimit(
107
- clientKey: string,
108
- limitConfig?: any
109
- ): { allowed: boolean; retryAfter: number };
110
-
111
- ask<T = any>(prompt: string | any[], options?: AIAskOptions): Promise<AIResult<T>>;
112
-
113
- askStream(
114
- prompt: string | any[],
115
- options?: AIAskOptions
116
- ): AsyncGenerator<AIStreamChunk, void, unknown>;
117
-
118
- pipe(
119
- res: Response | any,
120
- prompt: string | any[],
121
- options?: AIAskOptions & { sse?: boolean }
122
- ): Promise<void>;
123
-
124
- stream(
125
- res: Response | any,
126
- prompt: string | any[],
127
- options?: AIAskOptions & { sse?: boolean }
128
- ): Promise<void>;
129
-
130
- middleware(options?: { rateLimit?: any; message?: string }): RequestHandler;
131
-
132
- protect(options?: { rateLimit?: any; message?: string }): RequestHandler;
133
-
134
- static getClientIp(req: Request | any): string;
135
-
136
- static mask(
137
- prompt: string,
138
- data?: Record<string, any> | null,
139
- sensitiveKeys?: string[]
140
- ): MaskResult;
141
-
142
- static unmask(text: string, reverseTokenMap: Record<string, string>): string;
143
-
144
- static protect(options?: AIOptions & { message?: string }): RequestHandler;
145
-
146
- static resetRateLimits(): void;
147
- }
148
-
149
- export declare const ai: AI;
150
- export default AI;
151
-
1
+ import type { Request, Response, NextFunction, RequestHandler } from "express";
2
+
3
+ export interface AIOptions {
4
+ provider?: "deepseek" | "gemini" | "openai" | "custom";
5
+ model?: string;
6
+ apiKey?: string;
7
+ baseURL?: string;
8
+ temperature?: number;
9
+ thinking?: boolean | { type: string };
10
+ reasoningEffort?: "low" | "medium" | "high";
11
+ rateLimit?: number | { minute?: number; day?: number } | { max: number; windowMs: number };
12
+ rateWindow?: number;
13
+ cacheTtl?: number | boolean;
14
+ system?: string;
15
+ }
16
+
17
+ export interface AIAskOptions {
18
+ data?: Record<string, any>;
19
+ sensitiveKeys?: string[];
20
+ request?: Request | any;
21
+ req?: Request | any;
22
+ user?: string;
23
+ system?: string;
24
+ json?: boolean;
25
+ schema?: Record<string, any>;
26
+ temperature?: number;
27
+ model?: string;
28
+ provider?: "deepseek" | "gemini" | "openai" | "custom";
29
+ apiKey?: string;
30
+ baseURL?: string;
31
+ cache?: number | boolean;
32
+ thinking?: boolean | { type: string };
33
+ reasoningEffort?: "low" | "medium" | "high";
34
+ maxTokens?: number;
35
+ rateLimit?: number | { minute?: number; day?: number } | { max: number; windowMs: number };
36
+ }
37
+
38
+ export interface AIUsage {
39
+ prompt_tokens?: number;
40
+ completion_tokens?: number;
41
+ total_tokens?: number;
42
+ [key: string]: any;
43
+ }
44
+
45
+ export interface AIResult<T = any> {
46
+ success: boolean;
47
+ text?: string;
48
+ rawText?: string;
49
+ parsed?: T;
50
+ valid?: boolean;
51
+ errors?: any;
52
+ reasoning?: string | null;
53
+ cached?: boolean;
54
+ latency?: number;
55
+ provider?: string;
56
+ model?: string;
57
+ usage?: AIUsage;
58
+ maskedKeys?: string[];
59
+ error?: string;
60
+ message?: string;
61
+ retryAfter?: number;
62
+ }
63
+
64
+ export interface AIStreamChunk {
65
+ text: string;
66
+ done: boolean;
67
+ }
68
+
69
+ export interface MaskResult {
70
+ maskedPrompt: string;
71
+ maskedData: Record<string, any> | null;
72
+ tokenMap: Record<string, string>;
73
+ reverseTokenMap: Record<string, string>;
74
+ }
75
+
76
+ export declare function getClientIp(req: Request | any): string;
77
+
78
+ export declare function maskSensitiveData(
79
+ prompt?: string,
80
+ data?: Record<string, any> | null,
81
+ sensitiveKeys?: string[]
82
+ ): MaskResult;
83
+
84
+ export declare function unmaskSensitiveData(
85
+ text?: string,
86
+ reverseTokenMap?: Record<string, string>
87
+ ): string;
88
+
89
+ export declare function extractJsonString(text?: string): string;
90
+
91
+ export declare class AI {
92
+ provider: string;
93
+ model: string;
94
+ apiKey: string;
95
+ baseURL: string;
96
+ temperature: number;
97
+ thinking: boolean | Object;
98
+ reasoningEffort?: "low" | "medium" | "high";
99
+ rateLimit?: any;
100
+ rateWindow: number;
101
+ cacheTtl: number | boolean;
102
+ system: string;
103
+
104
+ constructor(options?: AIOptions);
105
+
106
+ checkRateLimit(
107
+ clientKey: string,
108
+ limitConfig?: any
109
+ ): { allowed: boolean; retryAfter: number };
110
+
111
+ ask<T = any>(prompt: string | any[], options?: AIAskOptions): Promise<AIResult<T>>;
112
+
113
+ askStream(
114
+ prompt: string | any[],
115
+ options?: AIAskOptions
116
+ ): AsyncGenerator<AIStreamChunk, void, unknown>;
117
+
118
+ pipe(
119
+ res: Response | any,
120
+ prompt: string | any[],
121
+ options?: AIAskOptions & { sse?: boolean }
122
+ ): Promise<void>;
123
+
124
+ stream(
125
+ res: Response | any,
126
+ prompt: string | any[],
127
+ options?: AIAskOptions & { sse?: boolean }
128
+ ): Promise<void>;
129
+
130
+ middleware(options?: { rateLimit?: any; message?: string }): RequestHandler;
131
+
132
+ protect(options?: { rateLimit?: any; message?: string }): RequestHandler;
133
+
134
+ static getClientIp(req: Request | any): string;
135
+
136
+ static mask(
137
+ prompt: string,
138
+ data?: Record<string, any> | null,
139
+ sensitiveKeys?: string[]
140
+ ): MaskResult;
141
+
142
+ static unmask(text: string, reverseTokenMap: Record<string, string>): string;
143
+
144
+ static protect(options?: AIOptions & { message?: string }): RequestHandler;
145
+
146
+ static resetRateLimits(): void;
147
+ }
148
+
149
+ export declare const ai: AI;
150
+ export default AI;
151
+