@seip/bluebird-js 0.1.7 → 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 (148) hide show
  1. package/AGENTS.md +726 -620
  2. package/README.md +615 -607
  3. package/app/models/user.js +19 -0
  4. package/app/resources/html/home.html +137 -0
  5. package/app/resources/html/layouts/main.html +54 -0
  6. package/app/resources/html/notFound.html +14 -0
  7. package/app/resources/html/terms.html +46 -0
  8. package/app/resources/index.html +27 -0
  9. package/app/resources/layouts/AppLayout.jsx +89 -0
  10. package/app/resources/main.jsx +18 -0
  11. package/app/resources/pages/Dashboard.jsx +98 -0
  12. package/app/resources/pages/Home.jsx +140 -0
  13. package/app/resources/pages/Login.jsx +35 -0
  14. package/app/resources/pages/NotFound.jsx +16 -0
  15. package/app/resources/pages/Register.jsx +55 -0
  16. package/app/resources/routes.jsx +54 -0
  17. package/app/resources/spa.js +67 -0
  18. package/app/resources/styles.css +9 -0
  19. package/app/routes/api.js +85 -50
  20. package/app/routes/auth.js +209 -0
  21. package/app/routes/web.js +59 -47
  22. package/core/ai.js +30 -10
  23. package/core/app.d.ts +2 -18
  24. package/core/app.js +987 -801
  25. package/core/auth.d.ts +2 -13
  26. package/core/auth.js +444 -326
  27. package/core/cli/build.js +37 -0
  28. package/core/cli/dev.js +155 -0
  29. package/core/cli/doctor.js +37 -2
  30. package/core/cli/export.js +191 -0
  31. package/core/cli/init.js +91 -322
  32. package/core/cli/nginx.js +1 -1
  33. package/core/cli/templates.js +139 -0
  34. package/core/cli/view.js +98 -161
  35. package/core/config.js +44 -2
  36. package/core/csrf.js +156 -24
  37. package/core/database.js +1184 -1131
  38. package/core/debug.js +1 -1
  39. package/core/html.js +8 -1
  40. package/core/index.d.ts +126 -310
  41. package/core/paths.js +55 -0
  42. package/core/ratelimit.js +10 -1
  43. package/core/react/client/api.js +237 -0
  44. package/core/react/client/auth.js +236 -0
  45. package/core/react/client/components.js +1321 -0
  46. package/core/react/client/i18n.js +338 -0
  47. package/core/react/client/index.d.ts +249 -0
  48. package/core/react/client/index.js +49 -0
  49. package/core/react/client/router.js +26 -0
  50. package/core/react/client/theme.css +512 -0
  51. package/core/render-cache.js +250 -212
  52. package/core/render.d.ts +25 -21
  53. package/core/render.js +738 -736
  54. package/core/router.d.ts +2 -3
  55. package/core/router.js +171 -171
  56. package/core/seo.js +10 -0
  57. package/core/spa.js +599 -0
  58. package/core/view-loader.js +155 -613
  59. package/core/vite-plugin.d.ts +18 -0
  60. package/core/vite-plugin.js +162 -0
  61. package/core/vite.js +250 -145
  62. package/index.js +22 -18
  63. package/jsconfig.json +5 -3
  64. package/package.json +114 -92
  65. package/production.md +8 -3
  66. package/public/js/bluebird.js +1160 -0
  67. package/templates/_auth/app/database.js +19 -0
  68. package/templates/_auth/app/models/user.js +22 -0
  69. package/templates/_auth/app/routes/auth-router.js +304 -0
  70. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  71. package/templates/_base/app/resources/html/notFound.html +14 -0
  72. package/templates/_base/app/resources/index.html +27 -0
  73. package/templates/_base/app/resources/styles.css +9 -0
  74. package/templates/api/app/models/note.js +18 -0
  75. package/templates/api/app/routes/api.js +82 -0
  76. package/templates/api/app/routes/auth.js +11 -0
  77. package/templates/api/index.js +19 -0
  78. package/templates/api/template.json +13 -0
  79. package/templates/auth/app/mail.js +11 -0
  80. package/templates/auth/app/models/password_reset.js +18 -0
  81. package/templates/auth/app/resources/html/home.html +21 -0
  82. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  83. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  84. package/templates/auth/app/resources/main.jsx +18 -0
  85. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  86. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  87. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  88. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  89. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  90. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  91. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  92. package/templates/auth/app/resources/routes.jsx +54 -0
  93. package/templates/auth/app/resources/spa.js +29 -0
  94. package/templates/auth/app/routes/api.js +17 -0
  95. package/templates/auth/app/routes/auth.js +13 -0
  96. package/templates/auth/app/routes/web.js +21 -0
  97. package/templates/auth/index.js +19 -0
  98. package/templates/auth/template.json +15 -0
  99. package/templates/blank/app/models/.gitkeep +0 -0
  100. package/templates/blank/app/resources/html/home.html +27 -0
  101. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  102. package/templates/blank/app/resources/main.jsx +16 -0
  103. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  104. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  105. package/templates/blank/app/resources/routes.jsx +15 -0
  106. package/templates/blank/app/resources/spa.js +24 -0
  107. package/templates/blank/app/routes/api.js +11 -0
  108. package/templates/blank/app/routes/web.js +21 -0
  109. package/templates/blank/index.js +13 -0
  110. package/templates/blank/template.json +12 -0
  111. package/templates/blog/app/lib/blog.js +149 -0
  112. package/templates/blog/app/models/post.js +22 -0
  113. package/templates/blog/app/resources/html/home.html +28 -0
  114. package/templates/blog/app/resources/html/not-found.html +5 -0
  115. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  116. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  117. package/templates/blog/app/resources/html/post.html +8 -0
  118. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  119. package/templates/blog/app/resources/main.jsx +18 -0
  120. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  121. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  122. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  123. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  124. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  125. package/templates/blog/app/resources/routes.jsx +51 -0
  126. package/templates/blog/app/resources/spa.js +25 -0
  127. package/templates/blog/app/resources/styles.css +40 -0
  128. package/templates/blog/app/routes/api.js +77 -0
  129. package/templates/blog/app/routes/auth.js +10 -0
  130. package/templates/blog/app/routes/web.js +114 -0
  131. package/templates/blog/index.js +21 -0
  132. package/templates/blog/template.json +14 -0
  133. package/vite.config.js +11 -0
  134. package/app/views/components/Header.jsx +0 -42
  135. package/app/views/components/LiveCounter.jsx +0 -67
  136. package/app/views/layouts/main/view.jsx +0 -201
  137. package/app/views/legal/terms.html +0 -29
  138. package/app/views/pages/about.jsx +0 -98
  139. package/app/views/pages/dashboard.jsx +0 -278
  140. package/app/views/pages/index.jsx +0 -123
  141. package/app/views/pages/login.jsx +0 -141
  142. package/core/actions.d.ts +0 -4
  143. package/core/actions.js +0 -355
  144. package/core/jsx.d.ts +0 -38
  145. package/core/jsx.js +0 -1597
  146. package/core/vite.d.ts +0 -3
  147. package/public/js/bluebird-client.js +0 -3265
  148. package/public/js/tailwind.js +0 -8
package/core/debug.js CHANGED
@@ -115,7 +115,7 @@ class Debug {
115
115
  <!DOCTYPE html>
116
116
  <html>
117
117
  <head>
118
- <script src="/js/tailwind.js"></script>
118
+ <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.16"></script>
119
119
  <title>Blue Bird Debug</title>
120
120
  </head>
121
121
  <body class="bg-gray-100 text-gray-800 p-10">
package/core/html.js CHANGED
@@ -55,7 +55,14 @@ export function escapeHtml(value) {
55
55
  * @returns {string}
56
56
  */
57
57
  export function safeJson(data) {
58
- return JSON.stringify(data)
58
+ let json;
59
+ try {
60
+ json = JSON.stringify(data, (key, value) => (typeof value === "bigint" ? value.toString() : value));
61
+ } catch {
62
+ json = "null";
63
+ }
64
+ if (json === undefined) json = "null";
65
+ return json
59
66
  .replace(/</g, "\\u003c")
60
67
  .replace(/>/g, "\\u003e")
61
68
  .replace(/&/g, "\\u0026")
package/core/index.d.ts CHANGED
@@ -116,6 +116,21 @@ declare global {
116
116
  pagination?: PaginationMeta,
117
117
  message?: string
118
118
  ): Response;
119
+
120
+ /**
121
+ * Initializes a Server-Sent Events (SSE) stream with automatic keep-alive and Nginx unbuffering.
122
+ */
123
+ sse(options?: {
124
+ keepAliveMs?: number;
125
+ retry?: number;
126
+ headers?: Record<string, string>;
127
+ }): {
128
+ send(data: any, eventName?: string | null, id?: string | number | null): boolean;
129
+ event(eventName: string, data: any, id?: string | number | null): boolean;
130
+ comment(text?: string): void;
131
+ onClose(cb: () => void): void;
132
+ close(): void;
133
+ };
119
134
  }
120
135
 
121
136
  interface Request {
@@ -141,14 +156,20 @@ export class AppError extends Error {
141
156
  * CORS configuration options.
142
157
  */
143
158
  export interface CorsOptions {
159
+ /**
160
+ * Allowed origins. `"*"` (default) never reflects the request origin and never sends credentials.
161
+ * Use an allowlist (string, array, RegExp, predicate) or `true` (reflect any origin) for credentialed CORS.
162
+ */
144
163
  origin?:
145
164
  | string
146
165
  | boolean
147
166
  | string[]
167
+ | RegExp
148
168
  | ((origin: string | undefined, req: Request) => boolean);
149
169
  methods?: string | string[];
150
170
  allowedHeaders?: string | string[];
151
171
  exposedHeaders?: string | string[];
172
+ /** Sends `Access-Control-Allow-Credentials: true` (ignored with `origin: "*"`). Defaults to `false`. */
152
173
  credentials?: boolean;
153
174
  maxAge?: number;
154
175
  }
@@ -157,7 +178,10 @@ export interface CorsOptions {
157
178
  * Security response headers options.
158
179
  */
159
180
  export interface SecurityHeadersOptions {
181
+ /** Content-Security-Policy. `{nonce}` is replaced by a per-request nonce exposed as `res.locals.cspNonce`. */
160
182
  csp?: string | false;
183
+ /** Generate a per-request CSP nonce even when the policy has no `{nonce}` placeholder. */
184
+ nonce?: boolean;
161
185
  frameOptions?: string;
162
186
  referrerPolicy?: string;
163
187
  permissionsPolicy?: string;
@@ -183,6 +207,8 @@ export interface RateLimitOptions {
183
207
  driver?: "memory" | "redis";
184
208
  keyGenerator?: (req: Request) => string;
185
209
  skip?: (req: Request) => boolean;
210
+ /** Bucket namespace (defaults to a per-limiter id so limiters never share counters). */
211
+ prefix?: string;
186
212
  }
187
213
 
188
214
  export class RateLimit {
@@ -192,6 +218,7 @@ export class RateLimit {
192
218
 
193
219
  export class Seo {
194
220
  static registerRoute(basePath: string, routePath: string | RegExp, languages?: string[]): void;
221
+ static unregisterRoute(fullPath: string): boolean;
195
222
  static getRoutes(): string[];
196
223
  static clear(): void;
197
224
  static generateSitemap(baseUrl?: string): string;
@@ -237,6 +264,11 @@ export class WebSocketManager {
237
264
  broadcast(data: any, room?: string | null): void;
238
265
  }
239
266
 
267
+ export interface ViteOptions {
268
+ dev?: boolean;
269
+ configFile?: string;
270
+ }
271
+
240
272
  /**
241
273
  * Application initialization options.
242
274
  */
@@ -257,13 +289,13 @@ export interface AppOptions {
257
289
  compression?: boolean;
258
290
  security?: boolean | SecurityHeadersOptions;
259
291
  rateLimit?: boolean | RateLimitOptions;
260
- autoRoutes?: boolean;
261
- noAutoDiscoverRoutes?: boolean;
292
+ vite?: boolean | ViteOptions;
262
293
  desktop?: boolean;
263
294
  userDataPath?: string;
264
295
  appPath?: string;
265
296
  allowLan?: boolean;
266
297
  trustProxy?: boolean | number | string;
298
+ debug?: boolean;
267
299
  }
268
300
 
269
301
  export class App {
@@ -330,6 +362,9 @@ export class Router {
330
362
  delete(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
331
363
  patch(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
332
364
  options(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
365
+ /** Mounts a React SPA with per-URL SEO metadata, JSON-LD, scripts/styles, and full-width skeleton. */
366
+ spa(path: string, options?: SpaOptions): void;
367
+ SPA(path: string, options?: SpaOptions): void;
333
368
  getRouter(): ExpressRouter;
334
369
  getPath(): string;
335
370
  }
@@ -437,7 +472,10 @@ export interface AuthProtectOptions {
437
472
  redirect?: string | null;
438
473
  key?: string;
439
474
  cookieKey?: string;
475
+ roles?: string | string[] | null;
440
476
  secret?: string;
477
+ /** Set false to skip the global `Auth.configure({ resolveUser })` hook for this route. */
478
+ resolveUser?: boolean;
441
479
  }
442
480
 
443
481
  /**
@@ -445,6 +483,9 @@ export interface AuthProtectOptions {
445
483
  */
446
484
  export interface AuthLoginOptions {
447
485
  expiresIn?: string | number;
486
+ rotateCsrf?: boolean;
487
+ /** Set false to return the token without setting the auth cookie (bearer clients). */
488
+ setCookie?: boolean;
448
489
  cookie?: Record<string, any>;
449
490
  secret?: string;
450
491
  }
@@ -463,9 +504,15 @@ export class Auth {
463
504
  static decrypt<T = any>(data: string, secret?: string): T | null;
464
505
  static generateToken(payload: any, secret?: string, expiresIn?: string | number): string;
465
506
  static verifyToken<T = any>(token: string, secret?: string): T | null;
507
+ static hasRole(user: any, roles?: string | string[] | null): boolean;
508
+ static optional(options?: Pick<AuthProtectOptions, "key" | "cookieKey" | "secret">): (req: Request, res: Response, next: NextFunction) => Promise<any>;
466
509
  static protect(options?: AuthProtectOptions): (req: Request, res: Response, next: NextFunction) => Promise<any>;
467
510
  static login(res: Response, data: any, key?: string, options?: AuthLoginOptions): Promise<string>;
468
511
  static logout(res: Response, key?: string, options?: Record<string, any>, req?: Request | null): Promise<boolean>;
512
+ /** Reloads the user on every authenticated request; return null to reject the session (deleted user, changed session version). */
513
+ static configure(options?: {
514
+ resolveUser?: ((payload: AuthTokenPayload, req: Request) => Promise<Record<string, any> | null> | Record<string, any> | null) | null;
515
+ }): void;
469
516
  }
470
517
 
471
518
  export type CacheDriver = "memory" | "redis" | "file";
@@ -510,222 +557,93 @@ export class Cache {
510
557
  export function getRedisClient(): any;
511
558
 
512
559
  /**
513
- * Render island / client component options.
514
- */
515
- export interface RenderIslandOptions {
516
- persist?: boolean;
517
- persistent?: boolean;
518
- fallback?: any;
519
- skeleton?: any;
520
- minHeight?: string | number;
521
- minWidth?: string | number;
522
- className?: string;
523
- style?: Record<string, any> | string;
524
- ssr?: boolean;
525
- tag?: string;
526
- client?: Function;
527
- onMount?: Function;
528
- }
529
-
530
- /**
531
- * Server Action definition options.
560
+ * Per-URL SEO and skeleton metadata entry inside `router.spa(..., { meta })`.
532
561
  */
533
- export interface ActionDefinitionOptions {
534
- schema?: ValidationSchema | Validator;
535
- maxBytes?: number | string;
536
- limit?: number | string;
537
- maxDepth?: number;
538
- maxKeys?: number;
539
- csrf?: boolean;
540
- }
562
+ export interface SpaMetaEntry {
563
+ title?: string;
564
+ titleTemplate?: string;
565
+ description?: string;
566
+ keywords?: string | string[];
567
+ author?: string;
568
+ canonical?: string | boolean;
569
+ baseUrl?: string;
570
+ image?: string;
571
+ ogType?: string;
572
+ robots?: boolean | string;
573
+ lang?: string;
574
+ jsonld?: Record<string, any> | Record<string, any>[];
575
+ jsonLd?: Record<string, any> | Record<string, any>[];
576
+ head?: Array<string | Record<string, any>> | string;
577
+ body?: Array<string | Record<string, any>> | string;
578
+ metaTags?: Array<Record<string, string>>;
579
+ links?: Array<Record<string, string>>;
580
+ htmlAttrs?: Record<string, string | boolean>;
581
+ bodyAttrs?: Record<string, string | boolean>;
582
+ skeleton?: "app" | "auth" | "page" | false | string;
583
+ rootClass?: string;
584
+ }
585
+
586
+ export type SpaMetaResolver =
587
+ | SpaMetaEntry
588
+ | ((req: Request, params: Record<string, string>) => SpaMetaEntry | Promise<SpaMetaEntry>);
541
589
 
542
590
  /**
543
- * Server Action execution context.
591
+ * Configuration options for `router.spa()`.
544
592
  */
545
- export interface ActionContext<TBody = Record<string, any>> {
546
- req: Request;
547
- res: Response;
548
- user?: any;
549
- body: TBody;
550
- params: Record<string, string>;
551
- query: Record<string, any>;
552
- action: string;
553
- }
554
-
555
- export class Actions {
556
- static define<TBody = Record<string, any>, TResult = any>(
557
- optionsOrHandler: ActionDefinitionOptions | ((ctx: ActionContext<TBody>, body: TBody) => Promise<TResult> | TResult),
558
- handlerFn?: (ctx: ActionContext<TBody>, body: TBody) => Promise<TResult> | TResult
559
- ): any;
560
- static createDispatcher(viewName: string, actionsMap: Record<string, any>): (req: Request, res: Response) => Promise<any>;
561
- static action: typeof action;
562
- static fn: typeof action;
563
- }
564
-
565
- export function action<TBody = Record<string, any>, TResult = any>(
566
- optionsOrHandler: ActionDefinitionOptions | ((ctx: ActionContext<TBody>, body: TBody) => Promise<TResult> | TResult),
567
- handlerFn?: (ctx: ActionContext<TBody>, body: TBody) => Promise<TResult> | TResult
568
- ): any;
569
-
570
- /**
571
- * Props for `<Island>` / `<Client>` JSX components.
572
- */
573
- export interface IslandComponentProps extends RenderIslandOptions {
574
- component?: string | Function;
575
- name?: string;
576
- props?: Record<string, any>;
577
- children?: any;
578
- [key: string]: any;
579
- }
580
-
581
- export interface ErrorBoundaryProps {
582
- fallback?: any | ((error: Error) => any);
583
- onError?: (error: Error) => void;
584
- children?: any;
585
- }
586
-
587
- export interface SuspenseProps {
588
- fallback?: any;
589
- children?: any;
590
- }
591
-
592
- export interface HeadProps {
593
- children?: any;
594
- }
595
-
596
- export interface TitleProps {
597
- children?: any;
598
- }
599
-
600
- export interface MetaProps {
601
- name?: string;
602
- property?: string;
603
- content?: string;
604
- charSet?: string;
605
- httpEquiv?: string;
606
- [key: string]: any;
607
- }
608
-
609
- export interface ScriptProps {
610
- data?: Record<string, any>;
611
- onPageLoad?: boolean;
612
- persist?: boolean;
613
- persistent?: boolean;
614
- src?: string;
615
- type?: string;
616
- defer?: boolean;
617
- async?: boolean;
618
- children?: ((data: any, info?: { url: string; initial: boolean }) => void | (() => void)) | string;
619
- [key: string]: any;
593
+ export interface SpaOptions extends SpaMetaEntry {
594
+ /** Mount path used by `npx bluebird-js export` and `routerWeb.spa(spa.mount, spa)` (e.g. "/app"). */
595
+ mount?: string;
596
+ meta?: Record<string, SpaMetaResolver>;
597
+ /** React entry (default "app/resources/main.jsx"). */
598
+ entry?: string;
599
+ /** Extra stylesheets linked in <head> (the entry already imports "./styles.css"). */
600
+ styles?: string | string[];
601
+ /** HTML shell (default "app/resources/index.html", false = built-in shell). */
602
+ template?: string | false;
603
+ cache?: number;
604
+ cacheQuery?: string[];
605
+ seo?: boolean;
620
606
  }
621
607
 
622
- export interface UseActionOptions {
623
- url?: string;
624
- partial?: boolean;
625
- onSuccess?: (data: any) => void;
626
- onError?: (error: any) => void;
627
- onSettled?: () => void;
628
- }
629
-
630
- export const ERROR_BOUNDARY: symbol;
631
- export const SUSPENSE_ELEMENT: symbol;
632
- export const HEAD_ELEMENT: symbol;
633
- export const TITLE_ELEMENT: symbol;
634
- export const META_ELEMENT: symbol;
635
- export const SCRIPT_ELEMENT: symbol;
636
-
637
- export function h(type: any, props?: Record<string, any> | null, ...children: any[]): any;
638
- export function createElement(type: any, props?: Record<string, any> | null, ...children: any[]): any;
639
- export function jsx(type: any, props: Record<string, any>, key?: string | number): any;
640
- export function jsxs(type: any, props: Record<string, any>, key?: string | number): any;
641
- export const Fragment: symbol;
642
- export function Island(options?: IslandComponentProps): Promise<any>;
643
- export function Client(options?: IslandComponentProps): Promise<any>;
644
- export function client<T extends Function>(Component: T, defaultOptions?: IslandComponentProps): T;
645
- export function ErrorBoundary(props?: ErrorBoundaryProps): any;
646
- export function Suspense(props?: SuspenseProps): any;
647
- export function Head(props?: HeadProps): any;
648
- export function Title(props?: TitleProps): any;
649
- export function Meta(props?: MetaProps): any;
650
- export function Script(props?: ScriptProps): any;
651
- export function isJsxElement(val: any): boolean;
652
- export function renderJsxToString(node: any, ctx?: Record<string, any>): Promise<string>;
653
- export function compileJsx(source: string, options?: { ts?: boolean; typescript?: boolean }): string;
654
- export function stripTsTypes(code: string): string;
655
- export function registerJsxLoader(): void;
656
- export function useState<T>(initial?: T | (() => T)): [T, (value: T | ((prev: T) => T)) => void];
657
- export function useEffect(effectFn: () => void | (() => void), deps?: any[]): void;
658
- export function useRef<T>(initial?: T): { current: T };
659
- export function useMemo<T>(fn: () => T, deps?: any[]): T;
660
- export function useCallback<T extends (...args: any[]) => any>(fn: T, deps?: any[]): T;
661
- export function useAction(
662
- actionName: string | Function,
663
- options?: UseActionOptions
664
- ): [
665
- execute: (payload?: any) => Promise<any>,
666
- isPending: boolean,
667
- data: any,
668
- error: any,
669
- reset: () => void
670
- ];
671
- export function useActionState<T>(
672
- actionFn: string | ((prevState: T, payload?: any) => Promise<T> | T),
673
- initialState: T
674
- ): [state: T, dispatch: (payload?: any) => Promise<T>, isPending: boolean];
675
-
676
608
  /**
677
- * Options for serving raw static HTML files.
609
+ * Options for rendering HTML views with `Render.html()`, `Render.send()`, and `Render.view()`.
678
610
  */
679
- export interface RenderHtmlOptions {
611
+ export interface RenderOptions {
612
+ layout?: string | false;
613
+ cache?: number;
680
614
  ttl?: number;
615
+ query?: string[];
616
+ cacheQuery?: string[];
617
+ raw?: boolean;
681
618
  }
682
619
 
683
620
  export class Render {
684
- static island(
685
- name: string | Function,
686
- props?: Record<string, any>,
687
- options?: RenderIslandOptions
688
- ): string;
689
- static component(partialName: string, props?: Record<string, any>): Promise<string>;
690
- static html(res: Response, relativePath: string, options?: RenderHtmlOptions): Promise<void>;
691
- static send(res: Response, viewName: string, data?: Record<string, any>, ttl?: number): Promise<void>;
692
- static partial(res: Response, partialName: string, data?: Record<string, any>, ttl?: number): Promise<void>;
693
- static stream(
621
+ static renderString(template: string, data?: Record<string, any>, ctx?: Record<string, any>): Promise<string>;
622
+ static component(viewName: string, data?: Record<string, any>, ctx?: Record<string, any>): Promise<string>;
623
+ static html(res: Response, viewName: string, data?: Record<string, any>, options?: number | RenderOptions): Promise<any>;
624
+ static send(
694
625
  res: Response,
695
626
  viewName: string,
696
627
  data?: Record<string, any>,
697
- options?: number | { ttl?: number }
698
- ): Promise<void>;
628
+ ttlOrOptions?: number | RenderOptions
629
+ ): Promise<any>;
630
+ static partial(res: Response, partialName: string, data?: Record<string, any>): Promise<any>;
699
631
  static view(
700
632
  viewName: string,
701
633
  dataOrFn?: Record<string, any> | ((req: Request, res: Response) => any),
702
- ttl?: number
703
- ): (req: Request, res: Response) => Promise<void>;
634
+ options?: number | RenderOptions
635
+ ): RequestHandler;
704
636
  static cache(
705
637
  seconds?: number,
706
- options?: { allowAuthenticated?: boolean }
638
+ options?: { allowAuthenticated?: boolean; query?: string[] }
707
639
  ): (req: Request, res: Response, next: NextFunction) => Promise<any>;
708
640
  static redirect(req: Request, res: Response, url: string, status?: number): void;
709
641
  static clearTemplateCache(): void;
710
642
  static invalidate(keys?: string | string[]): Promise<void>;
711
- static autoRoutes(targetRouter?: Router): Promise<Array<{ viewName: string; routePath: string; cache: number; seo: boolean }>>;
712
643
  }
713
644
 
714
645
  export * from "./html.js";
715
646
 
716
- /**
717
- * Vite integration options.
718
- */
719
- export interface ViteOptions {
720
- entry?: string;
721
- viteUrl?: string;
722
- debug?: boolean;
723
- }
724
-
725
- export class Vite {
726
- static tags(options?: ViteOptions): string;
727
- static clearCache(): void;
728
- }
729
647
 
730
648
  export const DB_TYPE: "sqlite" | "postgres" | "mysql" | "none" | string;
731
649
 
@@ -847,11 +765,25 @@ export interface CsrfOptions {
847
765
  bodyKey?: string;
848
766
  maxAgeMs?: number;
849
767
  secret?: string;
768
+ /** Exempt bearer-token requests sent without an auth cookie (default true). */
769
+ allowToken?: boolean;
770
+ authCookie?: string;
850
771
  }
851
772
 
852
773
  export class Csrf {
774
+ static cookieName: string;
853
775
  static generateToken(secret?: string): string;
854
776
  static verifyToken(token: string, secret?: string, maxAgeMs?: number): boolean;
777
+ static safeEqual(a: string, b: string): boolean;
778
+ static cookieOptions(): Record<string, any>;
779
+ /** Returns the request's valid CSRF token, issuing a fresh `_csrf` cookie when missing. */
780
+ static ensure(req: Request, res: Response): string;
781
+ /** Issues a new CSRF token cookie (called automatically on Auth.login/logout). */
782
+ static rotate(res: Response): string;
783
+ /** Timing-safe double-submit verification (header or body, never query string). */
784
+ static verifyRequest(req: Request, options?: CsrfOptions): boolean;
785
+ /** True for `Authorization: Bearer` / `X-Auth-Mode: token` requests without an auth cookie. */
786
+ static isTokenRequest(req: Request, authCookie?: string): boolean;
855
787
  static middleware(options?: CsrfOptions): (req: Request, res: Response, next: NextFunction) => void;
856
788
  }
857
789
 
@@ -1107,122 +1039,17 @@ declare module "@seip/bluebird-js/core/app.js" {
1107
1039
  }
1108
1040
 
1109
1041
  declare module "@seip/bluebird-js/core/router.js" {
1110
- import { Router, RouterOptions } from "@seip/bluebird-js";
1111
- export { Router, RouterOptions };
1042
+ import { Router, RouterOptions, SpaOptions, SpaMetaEntry } from "@seip/bluebird-js";
1043
+ export { Router, RouterOptions, SpaOptions, SpaMetaEntry };
1112
1044
  export default Router;
1113
1045
  }
1114
1046
 
1115
1047
  declare module "@seip/bluebird-js/core/render.js" {
1116
- import {
1117
- Render,
1118
- RenderIslandOptions,
1119
- RenderHtmlOptions,
1120
- IslandComponentProps,
1121
- h,
1122
- Fragment,
1123
- Island,
1124
- Client,
1125
- client,
1126
- ErrorBoundary,
1127
- Suspense,
1128
- Head,
1129
- Title,
1130
- Meta,
1131
- Script,
1132
- SCRIPT_ELEMENT,
1133
- action,
1134
- useAction,
1135
- useActionState,
1136
- } from "@seip/bluebird-js";
1137
- export {
1138
- Render,
1139
- RenderIslandOptions,
1140
- RenderHtmlOptions,
1141
- IslandComponentProps,
1142
- h,
1143
- Fragment,
1144
- Island,
1145
- Client,
1146
- client,
1147
- ErrorBoundary,
1148
- Suspense,
1149
- Head,
1150
- Title,
1151
- Meta,
1152
- Script,
1153
- SCRIPT_ELEMENT,
1154
- action,
1155
- useAction,
1156
- useActionState,
1157
- };
1048
+ import { Render, RenderOptions } from "@seip/bluebird-js";
1049
+ export { Render, RenderOptions };
1158
1050
  export default Render;
1159
1051
  }
1160
1052
 
1161
- declare module "@seip/bluebird-js/core/jsx.js" {
1162
- import {
1163
- h,
1164
- createElement,
1165
- jsx,
1166
- jsxs,
1167
- Fragment,
1168
- Island,
1169
- Client,
1170
- client,
1171
- ErrorBoundary,
1172
- Suspense,
1173
- Head,
1174
- Title,
1175
- Meta,
1176
- Script,
1177
- SCRIPT_ELEMENT,
1178
- action,
1179
- useAction,
1180
- useActionState,
1181
- useState,
1182
- useEffect,
1183
- useRef,
1184
- useMemo,
1185
- useCallback,
1186
- IslandComponentProps,
1187
- isJsxElement,
1188
- renderJsxToString,
1189
- compileJsx,
1190
- stripTsTypes,
1191
- registerJsxLoader,
1192
- } from "@seip/bluebird-js";
1193
- export {
1194
- h,
1195
- createElement,
1196
- jsx,
1197
- jsxs,
1198
- Fragment,
1199
- Island,
1200
- Client,
1201
- client,
1202
- ErrorBoundary,
1203
- Suspense,
1204
- Head,
1205
- Title,
1206
- Meta,
1207
- Script,
1208
- SCRIPT_ELEMENT,
1209
- action,
1210
- useAction,
1211
- useActionState,
1212
- useState,
1213
- useEffect,
1214
- useRef,
1215
- useMemo,
1216
- useCallback,
1217
- IslandComponentProps,
1218
- isJsxElement,
1219
- renderJsxToString,
1220
- compileJsx,
1221
- stripTsTypes,
1222
- registerJsxLoader,
1223
- };
1224
- }
1225
-
1226
1053
  declare module "@seip/bluebird-js/core/html.js" {
1227
1054
  import {
1228
1055
  SafeHtml,
@@ -1438,11 +1265,6 @@ declare module "@seip/bluebird-js/core/middleware.js" {
1438
1265
  export default Middleware;
1439
1266
  }
1440
1267
 
1441
- declare module "@seip/bluebird-js/core/vite.js" {
1442
- import { Vite, ViteOptions } from "@seip/bluebird-js";
1443
- export { Vite, ViteOptions };
1444
- export default Vite;
1445
- }
1446
1268
 
1447
1269
  declare module "@seip/bluebird-js/core/ratelimit.js" {
1448
1270
  import { RateLimit, RateLimitOptions } from "@seip/bluebird-js";
@@ -1456,12 +1278,6 @@ declare module "@seip/bluebird-js/core/seo.js" {
1456
1278
  export default Seo;
1457
1279
  }
1458
1280
 
1459
- declare module "@seip/bluebird-js/core/actions.js" {
1460
- import { Actions, action, ActionDefinitionOptions, ActionContext } from "@seip/bluebird-js";
1461
- export { Actions, action, ActionDefinitionOptions, ActionContext };
1462
- export default Actions;
1463
- }
1464
-
1465
1281
  declare module "@seip/bluebird-js/core/ai.js" {
1466
1282
  import { AI, ai, AIOptions, AIAskOptions, AIResult, AIStreamChunk } from "@seip/bluebird-js";
1467
1283
  export { AI, ai, AIOptions, AIAskOptions, AIResult, AIStreamChunk };
package/core/paths.js ADDED
@@ -0,0 +1,55 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ /**
5
+ * Conventional project-relative locations of client-side resources.
6
+ * - `resources`: React SPA sources, `index.html` shell, and `styles.css`.
7
+ * - `html`: HTML `{{ }}` SSR views, `layouts/`, and `partials/` rendered by `Render`.
8
+ * - `spaTemplate`: default `router.spa()` / `npx bluebird-js export` HTML shell.
9
+ */
10
+ export const PATHS = {
11
+ resources: "app/resources",
12
+ html: "app/resources/html",
13
+ spaTemplate: "app/resources/index.html",
14
+ spaConfig: "app/resources/spa.js",
15
+ entries: [
16
+ "app/resources/main.jsx",
17
+ "app/resources/main.tsx",
18
+ "app/resources/main.js",
19
+ "app/resources/main.ts",
20
+ ],
21
+ styles: ["app/resources/styles.css", "app/resources/css/app.css"],
22
+ };
23
+
24
+ /**
25
+ * Returns the first project-relative path from `candidates` that exists under `root`.
26
+ * @param {string} root
27
+ * @param {string[]} candidates
28
+ * @returns {string|null}
29
+ */
30
+ export function findFirst(root, candidates) {
31
+ for (const rel of candidates) {
32
+ if (fs.existsSync(path.join(root, rel))) return rel;
33
+ }
34
+ return null;
35
+ }
36
+
37
+ /**
38
+ * Resolves the default React SPA entry (`app/resources/main.jsx`, `.tsx`, `.js`, or `.ts`).
39
+ * @param {string} root
40
+ * @returns {string|null}
41
+ */
42
+ export function defaultEntry(root) {
43
+ return findFirst(root, PATHS.entries);
44
+ }
45
+
46
+ /**
47
+ * Resolves the default Tailwind CSS entry (`app/resources/styles.css`).
48
+ * @param {string} root
49
+ * @returns {string|null}
50
+ */
51
+ export function defaultStyles(root) {
52
+ return findFirst(root, PATHS.styles);
53
+ }
54
+
55
+ export default PATHS;