@seip/bluebird-js 0.2.1 → 0.2.2

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/core/index.d.ts CHANGED
@@ -1,1286 +1,1288 @@
1
- import type { Server as HttpServer } from "node:http";
2
- import { Router as ExpressRouter, Request, Response, NextFunction, RequestHandler } from "express";
3
-
4
- export type { Request, Response, NextFunction, RequestHandler };
5
- export * from "./ai.js";
6
-
7
- /**
8
- * Standard pagination metadata structure.
9
- */
10
- export interface PaginationMeta {
11
- page?: number;
12
- limit?: number;
13
- total?: number;
14
- totalPages?: number;
15
- }
16
-
17
- /**
18
- * Uploaded file object populated by multer middleware.
19
- */
20
- export interface UploadedFile {
21
- fieldname: string;
22
- originalname: string;
23
- encoding: string;
24
- mimetype: string;
25
- size: number;
26
- destination: string;
27
- filename: string;
28
- path: string;
29
- buffer?: Buffer;
30
- }
31
-
32
- /**
33
- * Standard Bluebird API JSON response envelope.
34
- */
35
- export interface ApiResponse<T = any> {
36
- status: "success" | "error";
37
- message: string;
38
- data?: T;
39
- errors?: any;
40
- pagination?: PaginationMeta;
41
- }
42
-
43
- declare global {
44
- namespace Express {
45
- interface Response {
46
- /**
47
- * Sends a standardized JSON success response.
48
- * @param data Data payload to return.
49
- * @param message Success message.
50
- * @param statusCode HTTP status code (default: 200).
51
- */
52
- success<T = any>(data?: T, message?: string, statusCode?: number): Response;
53
-
54
- /**
55
- * Sends a standardized HTTP 200 OK success response.
56
- * @param data Data payload.
57
- * @param message Success message.
58
- */
59
- ok<T = any>(data?: T, message?: string): Response;
60
-
61
- /**
62
- * Sends a standardized HTTP 201 Created success response.
63
- * @param data Data payload.
64
- * @param message Success message.
65
- */
66
- created<T = any>(data?: T, message?: string): Response;
67
-
68
- /**
69
- * Sends a standardized HTTP 400 Bad Request error response.
70
- * @param message Error message.
71
- * @param errors Detailed errors array or object.
72
- */
73
- badRequest(message?: string, errors?: any): Response;
74
-
75
- /**
76
- * Sends a standardized HTTP 401 Unauthorized error response.
77
- * @param message Error message.
78
- */
79
- unauthorized(message?: string): Response;
80
-
81
- /**
82
- * Sends a standardized HTTP 403 Forbidden error response.
83
- * @param message Error message.
84
- */
85
- forbidden(message?: string): Response;
86
-
87
- /**
88
- * Sends a standardized HTTP 404 Not Found error response.
89
- * @param message Error message.
90
- */
91
- notFound(message?: string): Response;
92
-
93
- /**
94
- * Sends a standardized HTTP 500 Internal Server Error response.
95
- * @param message Error message.
96
- * @param errors Error details.
97
- */
98
- serverError(message?: string, errors?: any): Response;
99
-
100
- /**
101
- * Sends a standardized JSON error response.
102
- * @param message Error message.
103
- * @param statusCode HTTP status code (default: 400).
104
- * @param errors Array or object of detailed errors.
105
- */
106
- error(message?: string, statusCode?: number, errors?: any): Response;
107
-
108
- /**
109
- * Sends a standardized paginated JSON response.
110
- * @param data Array of records for current page.
111
- * @param pagination Object containing page, limit, and total count.
112
- * @param message Success message.
113
- */
114
- paginate<T = any>(
115
- data?: T[],
116
- pagination?: PaginationMeta,
117
- message?: string
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
- };
134
- }
135
-
136
- interface Request {
137
- lang?: string;
138
- user?: any;
139
- csrfToken?(): string;
140
- file?: UploadedFile;
141
- files?: UploadedFile[] | Record<string, UploadedFile[]>;
142
- [key: string]: any;
143
- }
144
- }
145
- }
146
-
147
- export class AppError extends Error {
148
- statusCode: number;
149
- errors: any;
150
- isOperational: boolean;
151
-
152
- constructor(message: string, statusCode?: number, errors?: any);
153
- }
154
-
155
- /**
156
- * CORS configuration options.
157
- */
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
- */
163
- origin?:
164
- | string
165
- | boolean
166
- | string[]
167
- | RegExp
168
- | ((origin: string | undefined, req: Request) => boolean);
169
- methods?: string | string[];
170
- allowedHeaders?: string | string[];
171
- exposedHeaders?: string | string[];
172
- /** Sends `Access-Control-Allow-Credentials: true` (ignored with `origin: "*"`). Defaults to `false`. */
173
- credentials?: boolean;
174
- maxAge?: number;
175
- }
176
-
177
- /**
178
- * Security response headers options.
179
- */
180
- export interface SecurityHeadersOptions {
181
- /** Content-Security-Policy. `{nonce}` is replaced by a per-request nonce exposed as `res.locals.cspNonce`. */
182
- csp?: string | false;
183
- /** Generate a per-request CSP nonce even when the policy has no `{nonce}` placeholder. */
184
- nonce?: boolean;
185
- frameOptions?: string;
186
- referrerPolicy?: string;
187
- permissionsPolicy?: string;
188
- }
189
-
190
- /**
191
- * Static asset serving options.
192
- */
193
- export interface AppStaticOptions {
194
- path: string;
195
- options?: Record<string, any>;
196
- }
197
-
198
- /**
199
- * Rate limit configuration options.
200
- */
201
- export interface RateLimitOptions {
202
- windowMs?: number;
203
- max?: number;
204
- message?: string;
205
- statusCode?: number;
206
- headers?: boolean;
207
- driver?: "memory" | "redis";
208
- keyGenerator?: (req: Request) => string;
209
- skip?: (req: Request) => boolean;
210
- /** Bucket namespace (defaults to a per-limiter id so limiters never share counters). */
211
- prefix?: string;
212
- }
213
-
214
- export class RateLimit {
215
- static middleware(options?: RateLimitOptions | boolean): (req: Request, res: Response, next: NextFunction) => Promise<any>;
216
- static clear(): void;
217
- }
218
-
219
- export class Seo {
220
- static registerRoute(basePath: string, routePath: string | RegExp, languages?: string[]): void;
221
- static unregisterRoute(fullPath: string): boolean;
222
- static getRoutes(): string[];
223
- static clear(): void;
224
- static generateSitemap(baseUrl?: string): string;
225
- static generateRobots(baseUrl?: string, disallow?: string[]): string;
226
- }
227
-
228
- /**
229
- * WebSocket manager configuration options.
230
- */
231
- export interface WebSocketOptions {
232
- path?: string;
233
- auth?: boolean;
234
- maxPayload?: number;
235
- }
236
-
237
- /**
238
- * Active WebSocket client connection interface.
239
- */
240
- export interface WebSocketClient {
241
- isAlive?: boolean;
242
- user?: any;
243
- rooms?: Set<string>;
244
- send(data: any): void;
245
- on(event: string, handler: (...args: any[]) => void): void;
246
- close(code?: number, reason?: string): void;
247
- [key: string]: any;
248
- }
249
-
250
- export type WebSocketConnectionHandler = (ws: WebSocketClient, req: Request) => void;
251
-
252
- export class WebSocketManager {
253
- server: HttpServer;
254
- path: string;
255
- requireAuth: boolean;
256
- maxPayload: number;
257
- rooms: Map<string, Set<WebSocketClient>>;
258
- clients: Set<WebSocketClient>;
259
-
260
- constructor(server: HttpServer | any, options?: WebSocketOptions);
261
- onConnection(handler: WebSocketConnectionHandler): void;
262
- join(room: string, ws: WebSocketClient): void;
263
- leave(room: string, ws: WebSocketClient): void;
264
- broadcast(data: any, room?: string | null): void;
265
- }
266
-
267
- export interface ViteOptions {
268
- dev?: boolean;
269
- configFile?: string;
270
- }
271
-
272
- /**
273
- * Application initialization options.
274
- */
275
- export interface AppOptions {
276
- routes?: Array<Router | ExpressRouter | any>;
277
- cors?: boolean | CorsOptions;
278
- middlewares?: Array<RequestHandler | any>;
279
- port?: number | string;
280
- host?: string;
281
- appUrl?: string;
282
- logger?: boolean;
283
- notFound?: boolean;
284
- json?: boolean | Record<string, any>;
285
- urlencoded?: boolean | Record<string, any>;
286
- static?: AppStaticOptions;
287
- cookieParser?: boolean;
288
- swagger?: boolean | SwaggerOptions;
289
- compression?: boolean;
290
- security?: boolean | SecurityHeadersOptions;
291
- rateLimit?: boolean | RateLimitOptions;
292
- vite?: boolean | ViteOptions;
293
- desktop?: boolean;
294
- userDataPath?: string;
295
- appPath?: string;
296
- allowLan?: boolean;
297
- trustProxy?: boolean | number | string;
298
- debug?: boolean;
299
- }
300
-
301
- export class App {
302
- app: ExpressRouter | any;
303
- server: HttpServer;
304
- wsManager: WebSocketManager | null;
305
- routes: any[];
306
- cors: boolean | CorsOptions;
307
- middlewares: any[];
308
- port: number | string;
309
- host: string;
310
- appUrl: string;
311
- logger: boolean;
312
- notFound: boolean;
313
- desktop: boolean;
314
- allowLan: boolean;
315
- trustProxy: boolean | number | string;
316
-
317
- constructor(options?: AppOptions);
318
-
319
- use(record: any): void;
320
- set(key: string, value: any): void;
321
- websocket(
322
- options?:
323
- | WebSocketConnectionHandler
324
- | WebSocketOptions
325
- ): WebSocketManager;
326
- getPort(): number;
327
- getUrl(): string;
328
- run(): Promise<any>;
329
- runDesktop(options?: {
330
- appPath?: string;
331
- userDataPath?: string;
332
- allowLan?: boolean;
333
- host?: string;
334
- port?: number;
335
- }): Promise<{ server: HttpServer; port: number; url: string; lanUrl?: string; lanIp?: string }>;
336
- close(): Promise<void>;
337
-
338
- static helmet(options?: any): (req: Request, res: Response, next: NextFunction) => void;
339
- static securityHeaders(options?: SecurityHeadersOptions): (req: Request, res: Response, next: NextFunction) => void;
340
- static rateLimit(options?: RateLimitOptions | boolean): (req: Request, res: Response, next: NextFunction) => Promise<any>;
341
- static ai(options?: any): any;
342
- }
343
-
344
- /**
345
- * Router configuration options.
346
- */
347
- export interface RouterOptions {
348
- seo?: boolean;
349
- languages?: string[];
350
- }
351
-
352
- export class Router {
353
- router: ExpressRouter;
354
- path: string;
355
-
356
- constructor(path?: string, options?: RouterOptions);
357
-
358
- use(...middleware: Array<RequestHandler | any>): void;
359
- get(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
360
- post(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
361
- put(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
362
- delete(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
363
- patch(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
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;
368
- getRouter(): ExpressRouter;
369
- getPath(): string;
370
- }
371
-
372
- /**
373
- * Validation rule configuration for a single field.
374
- */
375
- export interface ValidationRule {
376
- required?: boolean;
377
- min?: number;
378
- max?: number;
379
- email?: boolean;
380
- number?: boolean;
381
- alpha?: boolean;
382
- alphanumeric?: boolean;
383
- boolean?: boolean;
384
- date?: boolean;
385
- url?: boolean;
386
- in?: any[];
387
- equals?: any;
388
- password?: boolean;
389
- pattern?: RegExp | string;
390
- xss?: boolean;
391
- messages?: Partial<
392
- Record<
393
- | "required"
394
- | "min"
395
- | "max"
396
- | "email"
397
- | "number"
398
- | "alpha"
399
- | "alphanumeric"
400
- | "boolean"
401
- | "date"
402
- | "url"
403
- | "in"
404
- | "equals"
405
- | "password"
406
- | "pattern",
407
- string
408
- >
409
- >;
410
- }
411
-
412
- /**
413
- * Validator schema definition.
414
- */
415
- export type ValidationSchema = Record<string, ValidationRule>;
416
-
417
- /**
418
- * Validation failure item.
419
- */
420
- export interface ValidationError {
421
- field: string;
422
- message: string;
423
- }
424
-
425
- /**
426
- * Validation output result.
427
- */
428
- export interface ValidationResult {
429
- success: boolean;
430
- error: boolean;
431
- errors: ValidationError[];
432
- message: string[];
433
- html?: string[];
434
- }
435
-
436
- export class Validator {
437
- schema: ValidationSchema;
438
- lang_default: string | null;
439
- messages: Record<string, any>;
440
-
441
- constructor(schema: ValidationSchema, lang_default?: string, messages?: Record<string, any>);
442
- middleware(): (req: Request, res: Response, next: NextFunction) => void;
443
- validate(req: Request | Record<string, any>): Promise<ValidationResult>;
444
- static xssMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
445
- static sanitizeObject<T = any>(obj: T): T;
446
- static mutateSanitized(obj: any): void;
447
- }
448
-
449
- /**
450
- * Password hashing options.
451
- */
452
- export interface HashMakeOptions {
453
- driver?: "scrypt" | "bcrypt";
454
- rounds?: number;
455
- N?: number;
456
- r?: number;
457
- p?: number;
458
- }
459
-
460
- export class Hash {
461
- static make(password: string, options?: HashMakeOptions): Promise<string>;
462
- static hash(password: string, options?: HashMakeOptions): Promise<string>;
463
- static verify(password: string, hash: string): Promise<boolean>;
464
- static check(password: string, hash: string): Promise<boolean>;
465
- static needsRehash(hash: string, options?: HashMakeOptions): boolean;
466
- }
467
-
468
- /**
469
- * Auth protect middleware options.
470
- */
471
- export interface AuthProtectOptions {
472
- redirect?: string | null;
473
- key?: string;
474
- cookieKey?: string;
475
- roles?: string | string[] | null;
476
- secret?: string;
477
- /** Set false to skip the global `Auth.configure({ resolveUser })` hook for this route. */
478
- resolveUser?: boolean;
479
- }
480
-
481
- /**
482
- * Auth login options.
483
- */
484
- export interface AuthLoginOptions {
485
- expiresIn?: string | number;
486
- rotateCsrf?: boolean;
487
- /** Set false to return the token without setting the auth cookie (bearer clients). */
488
- setCookie?: boolean;
489
- cookie?: Record<string, any>;
490
- secret?: string;
491
- }
492
-
493
- /**
494
- * Decoded Auth JWT token payload.
495
- */
496
- export type AuthTokenPayload = Record<string, any> & {
497
- _sessionId?: string;
498
- exp?: number;
499
- iat?: number;
500
- };
501
-
502
- export class Auth {
503
- static encrypt(payload: any, secret?: string): string;
504
- static decrypt<T = any>(data: string, secret?: string): T | null;
505
- static generateToken(payload: any, secret?: string, expiresIn?: string | number): string;
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>;
509
- static protect(options?: AuthProtectOptions): (req: Request, res: Response, next: NextFunction) => Promise<any>;
510
- static login(res: Response, data: any, key?: string, options?: AuthLoginOptions): Promise<string>;
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;
516
- }
517
-
518
- export type CacheDriver = "memory" | "redis" | "file";
519
-
520
- /**
521
- * Cache middleware options.
522
- */
523
- export interface CacheMiddlewareOptions {
524
- driver?: "memory" | "redis";
525
- allowAuthenticated?: boolean;
526
- key?: (req: Request) => string;
527
- }
528
-
529
- /**
530
- * Cache read options.
531
- */
532
- export interface CacheGetOptions {
533
- driver?: CacheDriver;
534
- }
535
-
536
- /**
537
- * Cache write options.
538
- */
539
- export interface CacheSetOptions {
540
- driver?: CacheDriver;
541
- fallbackDriver?: CacheDriver;
542
- }
543
-
544
- export class Cache {
545
- static middleware(seconds?: number, options?: CacheMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<any>;
546
- static get<T = any>(key: string, options?: CacheGetOptions): Promise<T | null>;
547
- static set(key: string, value: any, seconds?: number, options?: CacheSetOptions): Promise<boolean>;
548
- static deduplicate<T = any>(key: string, loader: () => Promise<T>): Promise<T>;
549
- static delete(keys: string | string[]): Promise<boolean>;
550
- static del(keys: string | string[]): Promise<boolean>;
551
- static deletePrefix(prefix: string): Promise<boolean>;
552
- static clear(): Promise<boolean>;
553
- static getMode(): string;
554
- static size(): number;
555
- }
556
-
557
- export function getRedisClient(): any;
558
-
559
- /**
560
- * Per-URL SEO and skeleton metadata entry inside `router.spa(..., { meta })`.
561
- */
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>);
589
-
590
- /**
591
- * Configuration options for `router.spa()`.
592
- */
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;
606
- }
607
-
608
- /**
609
- * Options for rendering HTML views with `Render.html()`, `Render.send()`, and `Render.view()`.
610
- */
611
- export interface RenderOptions {
612
- layout?: string | false;
613
- cache?: number;
614
- ttl?: number;
615
- query?: string[];
616
- cacheQuery?: string[];
617
- raw?: boolean;
618
- }
619
-
620
- export class Render {
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(
625
- res: Response,
626
- viewName: string,
627
- data?: Record<string, any>,
628
- ttlOrOptions?: number | RenderOptions
629
- ): Promise<any>;
630
- static partial(res: Response, partialName: string, data?: Record<string, any>): Promise<any>;
631
- static view(
632
- viewName: string,
633
- dataOrFn?: Record<string, any> | ((req: Request, res: Response) => any),
634
- options?: number | RenderOptions
635
- ): RequestHandler;
636
- static cache(
637
- seconds?: number,
638
- options?: { allowAuthenticated?: boolean; query?: string[] }
639
- ): (req: Request, res: Response, next: NextFunction) => Promise<any>;
640
- static redirect(req: Request, res: Response, url: string, status?: number): void;
641
- static clearTemplateCache(): void;
642
- static invalidate(keys?: string | string[]): Promise<void>;
643
- }
644
-
645
- export * from "./html.js";
646
-
647
-
648
- export const DB_TYPE: "sqlite" | "postgres" | "mysql" | "none" | string;
649
-
650
- /**
651
- * Database query execution options.
652
- */
653
- export interface DatabaseQueryOptions {
654
- cache?: number;
655
- cachePrefix?: string;
656
- return_row?: boolean;
657
- [key: string]: any;
658
- }
659
-
660
- /**
661
- * Standard paginated query result.
662
- */
663
- export interface PaginatedResult<T = any> {
664
- data: T[];
665
- total: number;
666
- page: number;
667
- limit: number;
668
- totalPages: number;
669
- }
670
-
671
- /**
672
- * Transaction runner client.
673
- */
674
- export interface DatabaseTransactionClient {
675
- query<T = any>(sql: string, params?: any[], options?: "return_row" | DatabaseQueryOptions | any): Promise<T>;
676
- }
677
-
678
- export interface DatabaseBackupOptions {
679
- out?: string;
680
- compress?: boolean;
681
- keep?: number;
682
- filename?: string;
683
- dbInstance?: Database;
684
- dbType?: string;
685
- }
686
-
687
- export interface DatabaseBackupResult {
688
- success: boolean;
689
- file: string;
690
- filename: string;
691
- size: number;
692
- rotated: number;
693
- dbType: string;
694
- }
695
-
696
- export interface DatabaseRestoreOptions {
697
- safetyBackup?: boolean;
698
- verify?: boolean;
699
- dbInstance?: Database;
700
- dbType?: string;
701
- }
702
-
703
- export interface DatabaseRestoreResult {
704
- success: boolean;
705
- restoredFrom: string;
706
- targetFile: string;
707
- preRestoreBackup?: string | null;
708
- size?: number;
709
- dbType: string;
710
- }
711
-
712
- export class Database {
713
- backup(options?: DatabaseBackupOptions): Promise<DatabaseBackupResult>;
714
- restore(filePath: string, options?: DatabaseRestoreOptions): Promise<DatabaseRestoreResult>;
715
- static backup(options?: DatabaseBackupOptions): Promise<DatabaseBackupResult>;
716
- static restore(filePath: string, options?: DatabaseRestoreOptions): Promise<DatabaseRestoreResult>;
717
- type: string;
718
- constructor(connectionLimit?: number, queueLimit?: number, config?: any);
719
- init(retries?: number): Promise<boolean>;
720
- query<T = any>(sql: string, params?: any[], options?: "return_row" | DatabaseQueryOptions | any): Promise<T>;
721
- paginate<T = any>(
722
- sql: string,
723
- params?: any[],
724
- options?: { page?: number; limit?: number; cache?: number }
725
- ): Promise<PaginatedResult<T>>;
726
- transaction<T = any>(callback: (tx: DatabaseTransactionClient) => Promise<T>): Promise<T>;
727
- executeTransaction<T = any>(callback: (tx: DatabaseTransactionClient) => Promise<T>): Promise<T>;
728
- close(): Promise<void>;
729
- static closeAll(): Promise<void>;
730
- }
731
-
732
- /**
733
- * Queue dispatching options.
734
- */
735
- export interface QueueDispatchOptions {
736
- delayMs?: number;
737
- }
738
-
739
- /**
740
- * Queue job item structure.
741
- */
742
- export interface QueueJob<T = any> {
743
- id: string;
744
- name: string;
745
- payload: T;
746
- createdAt: string;
747
- }
748
-
749
- export type QueueHandler<T = any> = (payload: T) => Promise<any> | any;
750
-
751
- export class Queue {
752
- static process<T = any>(jobName: string, handler: QueueHandler<T>): void;
753
- static dispatch<T = any>(jobName: string, payload?: T, options?: QueueDispatchOptions): Promise<boolean>;
754
- static work(): Promise<void>;
755
- static stop(): void;
756
- static loadJobs(jobsDir?: string): Promise<void>;
757
- }
758
-
759
- /**
760
- * CSRF middleware options.
761
- */
762
- export interface CsrfOptions {
763
- cookieName?: string;
764
- headerName?: string;
765
- bodyKey?: string;
766
- maxAgeMs?: number;
767
- secret?: string;
768
- /** Exempt bearer-token requests sent without an auth cookie (default true). */
769
- allowToken?: boolean;
770
- authCookie?: string;
771
- }
772
-
773
- export class Csrf {
774
- static cookieName: string;
775
- static generateToken(secret?: string): string;
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;
787
- static middleware(options?: CsrfOptions): (req: Request, res: Response, next: NextFunction) => void;
788
- }
789
-
790
- export interface ModelSchemaColumn {
791
- type: "int" | "integer" | "bigint" | "string" | "text" | "boolean" | "date" | "float" | "json" | (string & {});
792
- primary?: boolean;
793
- auto?: boolean;
794
- unique?: boolean;
795
- required?: boolean;
796
- nullable?: boolean;
797
- default?: any;
798
- hidden?: boolean;
799
- length?: number;
800
- min?: number;
801
- max?: number;
802
- email?: boolean;
803
- hash?: boolean;
804
- in?: any[];
805
- references?: string;
806
- onDelete?: "cascade" | "set null" | "restrict" | "no action" | (string & {});
807
- }
808
-
809
- /**
810
- * Options for Model.find query.
811
- */
812
- export interface ModelFindOptions {
813
- withDeleted?: boolean;
814
- withHidden?: boolean;
815
- cache?: number;
816
- oneMany?: typeof Model | Array<typeof Model>;
817
- belongsTo?: typeof Model | Array<typeof Model>;
818
- }
819
-
820
- /**
821
- * Options for Model.all query.
822
- */
823
- export interface ModelAllOptions {
824
- where?: Record<string, any>;
825
- order?: string | string[];
826
- limit?: number;
827
- offset?: number;
828
- withDeleted?: boolean;
829
- withHidden?: boolean;
830
- cache?: number;
831
- oneMany?: typeof Model | Array<typeof Model>;
832
- belongsTo?: typeof Model | Array<typeof Model>;
833
- }
834
-
835
- /**
836
- * Options for Model.paginate query.
837
- */
838
- export interface ModelPaginateOptions {
839
- where?: Record<string, any>;
840
- order?: string | string[];
841
- page?: number;
842
- limit?: number;
843
- withDeleted?: boolean;
844
- withHidden?: boolean;
845
- cache?: number;
846
- }
847
-
848
- /**
849
- * Options for Model.delete operation.
850
- */
851
- export interface ModelDeleteOptions {
852
- force?: boolean;
853
- cascade?: Array<typeof Model>;
854
- }
855
-
856
- export class Model {
857
- static table: string;
858
- static primaryKey: string;
859
- static timestamps: boolean;
860
- static softDelete: boolean;
861
- static schema: Record<string, ModelSchemaColumn>;
862
- static fillable: string[];
863
- static guarded: string[];
864
-
865
- static getDatabase(): Database;
866
- static setDatabase(db: Database): void;
867
- static close(): Promise<void>;
868
- static query<T = any>(sql: string, params?: any[], options?: any): Promise<T>;
869
- static transaction<T = any>(callback: (tx: DatabaseTransactionClient | any) => Promise<T>): Promise<T>;
870
- static invalidateCache(): Promise<void>;
871
- static find<T = any>(
872
- idOrConditions: number | string | Record<string, any>,
873
- options?: ModelFindOptions
874
- ): Promise<T | null>;
875
- static first<T = any>(
876
- idOrConditions?: number | string | Record<string, any>,
877
- options?: ModelFindOptions
878
- ): Promise<T | null>;
879
- static count(where?: Record<string, any>): Promise<number>;
880
- static exists(where?: Record<string, any>): Promise<boolean>;
881
- static firstOrCreate<T = any>(where: Record<string, any>, defaults?: Record<string, any>): Promise<T>;
882
- static updateOrCreate<T = any>(where: Record<string, any>, values?: Record<string, any>): Promise<T>;
883
- static all<T = any>(options?: ModelAllOptions): Promise<T[]>;
884
- static paginate<T = any>(options?: ModelPaginateOptions): Promise<PaginatedResult<T>>;
885
- static create(data: Record<string, any>, options?: { only?: string[]; except?: string[] }): Promise<number | string>;
886
- static update(
887
- idOrConditions: number | string | Record<string, any>,
888
- data: Record<string, any>,
889
- options?: { only?: string[]; except?: string[] }
890
- ): Promise<number>;
891
- static delete(
892
- idOrConditions: number | string | Record<string, any>,
893
- options?: ModelDeleteOptions
894
- ): Promise<number>;
895
- static restore(idOrConditions: number | string | Record<string, any>): Promise<number>;
896
- static validator(mode?: "create" | "update", lang?: string): Validator;
897
- static columnToSQL(col: string, def: ModelSchemaColumn, dialect?: "sqlite" | "mysql" | "postgres"): string;
898
- static toDDL(dialect?: "sqlite" | "mysql" | "postgres"): string;
899
- }
900
-
901
- export interface UploadDiskOptions {
902
- folder?: string;
903
- fileSize?: number;
904
- allowedTypes?: string[];
905
- }
906
-
907
- export interface UploadMiddleware {
908
- single(fieldName: string): (req: Request, res: Response, next: NextFunction) => void;
909
- array(fieldName: string, maxCount?: number): (req: Request, res: Response, next: NextFunction) => void;
910
- fields(fields: Array<{ name: string; maxCount?: number }>): (req: Request, res: Response, next: NextFunction) => void;
911
- none(): (req: Request, res: Response, next: NextFunction) => void;
912
- any(): (req: Request, res: Response, next: NextFunction) => void;
913
- }
914
-
915
- export class Upload {
916
- static storage(folder?: string): any;
917
- static disk(options?: UploadDiskOptions): UploadMiddleware;
918
- static url(filename: string, folder?: string): string;
919
- }
920
-
921
- export interface SwaggerOptions {
922
- route?: string;
923
- url?: string;
924
- info?: {
925
- title?: string;
926
- version?: string;
927
- description?: string;
928
- };
929
- apis?: string[];
930
- }
931
-
932
- export class Swagger {
933
- static init(app: any, options?: SwaggerOptions): Promise<boolean>;
934
- }
935
-
936
- export interface AppProps {
937
- debug: boolean;
938
- desktop: boolean;
939
- userDataDir: string;
940
- appDir: string;
941
- title: string;
942
- description: string;
943
- version: string;
944
- host: string;
945
- appUrl: string;
946
- port: number;
947
- jwtSecret?: string;
948
- langMeta: string;
949
- static: { path: string; options: Record<string, any> };
950
- descriptionMeta?: string;
951
- keywordsMeta?: string;
952
- titleMeta?: string;
953
- authorMeta?: string;
954
- }
955
-
956
- export class Config {
957
- static dirname(): string;
958
- static appDir(): string;
959
- static setAppDir(dirPath: string): void;
960
- static isDesktop(): boolean;
961
- static setUserDataDir(customDir: string): void;
962
- static userDataDir(): string;
963
- static reload(): AppProps;
964
- static props(): AppProps;
965
- }
966
-
967
- export class Logger {
968
- folder: string;
969
- constructor();
970
- nowFolder(): string;
971
- now(): string;
972
- _log(file: string, level: string, message: string): void;
973
- log(file: string, level: string, message: string): void;
974
- info(message: string): void;
975
- error(message: string): void;
976
- warn(message: string): void;
977
- warning(message: string): void;
978
- debug(message: string): void;
979
- }
980
-
981
- export class Debug {
982
- constructor();
983
- static shouldTrack(req: Request): boolean;
984
- static middlewareMetrics(app: any): void;
985
- getRouter(): { path: string; router: ExpressRouter };
986
- }
987
-
988
- export interface CommonMiddleware {
989
- auth: (req: Request, res: Response, next: NextFunction) => Promise<any>;
990
- webAuth: (req: Request, res: Response, next: NextFunction) => Promise<any>;
991
- logger: (req: Request, res: Response, next: NextFunction) => void;
992
- }
993
-
994
- export const Middleware: CommonMiddleware;
995
-
996
- export default App;
997
-
998
- declare module "@seip/bluebird-js/core/model.js" {
999
- import {
1000
- Model,
1001
- ModelSchemaColumn,
1002
- ModelFindOptions,
1003
- ModelAllOptions,
1004
- ModelPaginateOptions,
1005
- ModelDeleteOptions,
1006
- PaginatedResult,
1007
- } from "@seip/bluebird-js";
1008
- export {
1009
- Model,
1010
- ModelSchemaColumn,
1011
- ModelFindOptions,
1012
- ModelAllOptions,
1013
- ModelPaginateOptions,
1014
- ModelDeleteOptions,
1015
- PaginatedResult,
1016
- };
1017
- export default Model;
1018
- }
1019
-
1020
- declare module "@seip/bluebird-js/core/app.js" {
1021
- import App, {
1022
- AppError,
1023
- WebSocketManager,
1024
- AppOptions,
1025
- CorsOptions,
1026
- SecurityHeadersOptions,
1027
- AppStaticOptions,
1028
- } from "@seip/bluebird-js";
1029
- export {
1030
- App,
1031
- AppError,
1032
- WebSocketManager,
1033
- AppOptions,
1034
- CorsOptions,
1035
- SecurityHeadersOptions,
1036
- AppStaticOptions,
1037
- };
1038
- export default App;
1039
- }
1040
-
1041
- declare module "@seip/bluebird-js/core/router.js" {
1042
- import { Router, RouterOptions, SpaOptions, SpaMetaEntry } from "@seip/bluebird-js";
1043
- export { Router, RouterOptions, SpaOptions, SpaMetaEntry };
1044
- export default Router;
1045
- }
1046
-
1047
- declare module "@seip/bluebird-js/core/render.js" {
1048
- import { Render, RenderOptions } from "@seip/bluebird-js";
1049
- export { Render, RenderOptions };
1050
- export default Render;
1051
- }
1052
-
1053
- declare module "@seip/bluebird-js/core/html.js" {
1054
- import {
1055
- SafeHtml,
1056
- isSafeHtml,
1057
- escapeHtml,
1058
- safeJson,
1059
- HtmlTag,
1060
- html,
1061
- ScriptTag,
1062
- script,
1063
- each,
1064
- cached,
1065
- defer,
1066
- } from "@seip/bluebird-js";
1067
- export {
1068
- SafeHtml,
1069
- isSafeHtml,
1070
- escapeHtml,
1071
- safeJson,
1072
- HtmlTag,
1073
- html,
1074
- ScriptTag,
1075
- script,
1076
- each,
1077
- cached,
1078
- defer,
1079
- };
1080
- export default html;
1081
- }
1082
-
1083
- declare module "@seip/bluebird-js/core/validate.js" {
1084
- import {
1085
- Validator,
1086
- ValidationRule,
1087
- ValidationSchema,
1088
- ValidationError,
1089
- ValidationResult,
1090
- } from "@seip/bluebird-js";
1091
- export {
1092
- Validator,
1093
- ValidationRule,
1094
- ValidationSchema,
1095
- ValidationError,
1096
- ValidationResult,
1097
- };
1098
- export default Validator;
1099
- }
1100
-
1101
- declare module "@seip/bluebird-js/core/database.js" {
1102
- import {
1103
- Database,
1104
- DB_TYPE,
1105
- DatabaseQueryOptions,
1106
- DatabaseTransactionClient,
1107
- PaginatedResult,
1108
- } from "@seip/bluebird-js";
1109
- export {
1110
- Database,
1111
- DB_TYPE,
1112
- DatabaseQueryOptions,
1113
- DatabaseTransactionClient,
1114
- PaginatedResult,
1115
- };
1116
- export default Database;
1117
- }
1118
-
1119
- declare module "@seip/bluebird-js/core/auth.js" {
1120
- import {
1121
- Auth,
1122
- AuthProtectOptions,
1123
- AuthLoginOptions,
1124
- AuthTokenPayload,
1125
- } from "@seip/bluebird-js";
1126
- export {
1127
- Auth,
1128
- AuthProtectOptions,
1129
- AuthLoginOptions,
1130
- AuthTokenPayload,
1131
- };
1132
- export default Auth;
1133
- }
1134
-
1135
- declare module "@seip/bluebird-js/core/cache.js" {
1136
- import {
1137
- Cache,
1138
- getRedisClient,
1139
- CacheDriver,
1140
- CacheMiddlewareOptions,
1141
- CacheGetOptions,
1142
- CacheSetOptions,
1143
- } from "@seip/bluebird-js";
1144
- export {
1145
- Cache,
1146
- getRedisClient,
1147
- CacheDriver,
1148
- CacheMiddlewareOptions,
1149
- CacheGetOptions,
1150
- CacheSetOptions,
1151
- };
1152
- export default Cache;
1153
- }
1154
-
1155
- declare module "@seip/bluebird-js/core/redis.js" {
1156
- export function initRedis(): Promise<any>;
1157
- export function getRedisClient(): any;
1158
- export function isRedisConnectedStatus(): boolean;
1159
- export function redisGet(key: string): Promise<any>;
1160
- export function redisSet(key: string, value: any, seconds?: number): Promise<boolean>;
1161
- export function redisDel(keys: string | string[]): Promise<boolean>;
1162
- export function redisClearPrefix(prefix: string): Promise<boolean>;
1163
- export function disconnectRedis(): Promise<void>;
1164
-
1165
- const redisHandler: {
1166
- initRedis: typeof initRedis;
1167
- getRedisClient: typeof getRedisClient;
1168
- isRedisConnectedStatus: typeof isRedisConnectedStatus;
1169
- redisGet: typeof redisGet;
1170
- redisSet: typeof redisSet;
1171
- redisDel: typeof redisDel;
1172
- redisClearPrefix: typeof redisClearPrefix;
1173
- disconnectRedis: typeof disconnectRedis;
1174
- };
1175
- export default redisHandler;
1176
- }
1177
-
1178
- declare module "@seip/bluebird-js/core/csrf.js" {
1179
- import { Csrf, CsrfOptions } from "@seip/bluebird-js";
1180
- export { Csrf, CsrfOptions };
1181
- export default Csrf;
1182
- }
1183
-
1184
- declare module "@seip/bluebird-js/core/hash.js" {
1185
- import { Hash, HashMakeOptions } from "@seip/bluebird-js";
1186
- export { Hash, HashMakeOptions };
1187
- export default Hash;
1188
- }
1189
-
1190
- declare module "@seip/bluebird-js/core/queue.js" {
1191
- import {
1192
- Queue,
1193
- QueueDispatchOptions,
1194
- QueueJob,
1195
- QueueHandler,
1196
- } from "@seip/bluebird-js";
1197
- export {
1198
- Queue,
1199
- QueueDispatchOptions,
1200
- QueueJob,
1201
- QueueHandler,
1202
- };
1203
- export default Queue;
1204
- }
1205
-
1206
- declare module "@seip/bluebird-js/core/upload.js" {
1207
- import {
1208
- Upload,
1209
- UploadDiskOptions,
1210
- UploadMiddleware,
1211
- UploadedFile,
1212
- } from "@seip/bluebird-js";
1213
- export {
1214
- Upload,
1215
- UploadDiskOptions,
1216
- UploadMiddleware,
1217
- UploadedFile,
1218
- };
1219
- export default Upload;
1220
- }
1221
-
1222
- declare module "@seip/bluebird-js/core/ws.js" {
1223
- import {
1224
- WebSocketManager,
1225
- WebSocketOptions,
1226
- WebSocketClient,
1227
- WebSocketConnectionHandler,
1228
- } from "@seip/bluebird-js";
1229
- export {
1230
- WebSocketManager,
1231
- WebSocketOptions,
1232
- WebSocketClient,
1233
- WebSocketConnectionHandler,
1234
- };
1235
- export default WebSocketManager;
1236
- }
1237
-
1238
- declare module "@seip/bluebird-js/core/swagger.js" {
1239
- import { Swagger, SwaggerOptions } from "@seip/bluebird-js";
1240
- export { Swagger, SwaggerOptions };
1241
- export default Swagger;
1242
- }
1243
-
1244
- declare module "@seip/bluebird-js/core/logger.js" {
1245
- import { Logger } from "@seip/bluebird-js";
1246
- export { Logger };
1247
- export default Logger;
1248
- }
1249
-
1250
- declare module "@seip/bluebird-js/core/config.js" {
1251
- import { Config, AppProps } from "@seip/bluebird-js";
1252
- export { Config, AppProps };
1253
- export default Config;
1254
- }
1255
-
1256
- declare module "@seip/bluebird-js/core/debug.js" {
1257
- import { Debug } from "@seip/bluebird-js";
1258
- export { Debug };
1259
- export default Debug;
1260
- }
1261
-
1262
- declare module "@seip/bluebird-js/core/middleware.js" {
1263
- import { Middleware, CommonMiddleware } from "@seip/bluebird-js";
1264
- export { Middleware, CommonMiddleware };
1265
- export default Middleware;
1266
- }
1267
-
1268
-
1269
- declare module "@seip/bluebird-js/core/ratelimit.js" {
1270
- import { RateLimit, RateLimitOptions } from "@seip/bluebird-js";
1271
- export { RateLimit, RateLimitOptions };
1272
- export default RateLimit;
1273
- }
1274
-
1275
- declare module "@seip/bluebird-js/core/seo.js" {
1276
- import { Seo } from "@seip/bluebird-js";
1277
- export { Seo };
1278
- export default Seo;
1279
- }
1280
-
1281
- declare module "@seip/bluebird-js/core/ai.js" {
1282
- import { AI, ai, AIOptions, AIAskOptions, AIResult, AIStreamChunk } from "@seip/bluebird-js";
1283
- export { AI, ai, AIOptions, AIAskOptions, AIResult, AIStreamChunk };
1284
- export default AI;
1285
- }
1286
-
1
+ import type { Server as HttpServer } from "node:http";
2
+ import { Router as ExpressRouter, Request, Response, NextFunction, RequestHandler } from "express";
3
+
4
+ export type { Request, Response, NextFunction, RequestHandler };
5
+ export * from "./ai.js";
6
+
7
+ /**
8
+ * Standard pagination metadata structure.
9
+ */
10
+ export interface PaginationMeta {
11
+ page?: number;
12
+ limit?: number;
13
+ total?: number;
14
+ totalPages?: number;
15
+ }
16
+
17
+ /**
18
+ * Uploaded file object populated by multer middleware.
19
+ */
20
+ export interface UploadedFile {
21
+ fieldname: string;
22
+ originalname: string;
23
+ encoding: string;
24
+ mimetype: string;
25
+ size: number;
26
+ destination: string;
27
+ filename: string;
28
+ path: string;
29
+ buffer?: Buffer;
30
+ }
31
+
32
+ /**
33
+ * Standard Bluebird API JSON response envelope.
34
+ */
35
+ export interface ApiResponse<T = any> {
36
+ status: "success" | "error";
37
+ message: string;
38
+ data?: T;
39
+ errors?: any;
40
+ pagination?: PaginationMeta;
41
+ }
42
+
43
+ declare global {
44
+ namespace Express {
45
+ interface Response {
46
+ /**
47
+ * Sends a standardized JSON success response.
48
+ * @param data Data payload to return.
49
+ * @param message Success message.
50
+ * @param statusCode HTTP status code (default: 200).
51
+ */
52
+ success<T = any>(data?: T, message?: string, statusCode?: number): Response;
53
+
54
+ /**
55
+ * Sends a standardized HTTP 200 OK success response.
56
+ * @param data Data payload.
57
+ * @param message Success message.
58
+ */
59
+ ok<T = any>(data?: T, message?: string): Response;
60
+
61
+ /**
62
+ * Sends a standardized HTTP 201 Created success response.
63
+ * @param data Data payload.
64
+ * @param message Success message.
65
+ */
66
+ created<T = any>(data?: T, message?: string): Response;
67
+
68
+ /**
69
+ * Sends a standardized HTTP 400 Bad Request error response.
70
+ * @param message Error message.
71
+ * @param errors Detailed errors array or object.
72
+ */
73
+ badRequest(message?: string, errors?: any): Response;
74
+
75
+ /**
76
+ * Sends a standardized HTTP 401 Unauthorized error response.
77
+ * @param message Error message.
78
+ */
79
+ unauthorized(message?: string): Response;
80
+
81
+ /**
82
+ * Sends a standardized HTTP 403 Forbidden error response.
83
+ * @param message Error message.
84
+ */
85
+ forbidden(message?: string): Response;
86
+
87
+ /**
88
+ * Sends a standardized HTTP 404 Not Found error response.
89
+ * @param message Error message.
90
+ */
91
+ notFound(message?: string): Response;
92
+
93
+ /**
94
+ * Sends a standardized HTTP 500 Internal Server Error response.
95
+ * @param message Error message.
96
+ * @param errors Error details.
97
+ */
98
+ serverError(message?: string, errors?: any): Response;
99
+
100
+ /**
101
+ * Sends a standardized JSON error response.
102
+ * @param message Error message.
103
+ * @param statusCode HTTP status code (default: 400).
104
+ * @param errors Array or object of detailed errors.
105
+ */
106
+ error(message?: string, statusCode?: number, errors?: any): Response;
107
+
108
+ /**
109
+ * Sends a standardized paginated JSON response.
110
+ * @param data Array of records for current page.
111
+ * @param pagination Object containing page, limit, and total count.
112
+ * @param message Success message.
113
+ */
114
+ paginate<T = any>(
115
+ data?: T[],
116
+ pagination?: PaginationMeta,
117
+ message?: string
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
+ };
134
+ }
135
+
136
+ interface Request {
137
+ lang?: string;
138
+ user?: any;
139
+ csrfToken?(): string;
140
+ file?: UploadedFile;
141
+ files?: UploadedFile[] | Record<string, UploadedFile[]>;
142
+ [key: string]: any;
143
+ }
144
+ }
145
+ }
146
+
147
+ export class AppError extends Error {
148
+ statusCode: number;
149
+ errors: any;
150
+ isOperational: boolean;
151
+
152
+ constructor(message: string, statusCode?: number, errors?: any);
153
+ }
154
+
155
+ /**
156
+ * CORS configuration options.
157
+ */
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
+ */
163
+ origin?:
164
+ | string
165
+ | boolean
166
+ | string[]
167
+ | RegExp
168
+ | ((origin: string | undefined, req: Request) => boolean);
169
+ methods?: string | string[];
170
+ allowedHeaders?: string | string[];
171
+ exposedHeaders?: string | string[];
172
+ /** Sends `Access-Control-Allow-Credentials: true` (ignored with `origin: "*"`). Defaults to `false`. */
173
+ credentials?: boolean;
174
+ maxAge?: number;
175
+ }
176
+
177
+ /**
178
+ * Security response headers options.
179
+ */
180
+ export interface SecurityHeadersOptions {
181
+ /** Content-Security-Policy. `{nonce}` is replaced by a per-request nonce exposed as `res.locals.cspNonce`. */
182
+ csp?: string | false;
183
+ /** Generate a per-request CSP nonce even when the policy has no `{nonce}` placeholder. */
184
+ nonce?: boolean;
185
+ frameOptions?: string;
186
+ referrerPolicy?: string;
187
+ permissionsPolicy?: string;
188
+ }
189
+
190
+ /**
191
+ * Static asset serving options.
192
+ */
193
+ export interface AppStaticOptions {
194
+ path: string;
195
+ options?: Record<string, any>;
196
+ }
197
+
198
+ /**
199
+ * Rate limit configuration options.
200
+ */
201
+ export interface RateLimitOptions {
202
+ windowMs?: number;
203
+ max?: number;
204
+ message?: string;
205
+ statusCode?: number;
206
+ headers?: boolean;
207
+ driver?: "memory" | "redis";
208
+ keyGenerator?: (req: Request) => string;
209
+ skip?: (req: Request) => boolean;
210
+ /** Bucket namespace (defaults to a per-limiter id so limiters never share counters). */
211
+ prefix?: string;
212
+ }
213
+
214
+ export class RateLimit {
215
+ static middleware(options?: RateLimitOptions | boolean): (req: Request, res: Response, next: NextFunction) => Promise<any>;
216
+ static clear(): void;
217
+ }
218
+
219
+ export class Seo {
220
+ static registerRoute(basePath: string, routePath: string | RegExp, languages?: string[]): void;
221
+ static unregisterRoute(fullPath: string): boolean;
222
+ static getRoutes(): string[];
223
+ static clear(): void;
224
+ static generateSitemap(baseUrl?: string): string;
225
+ static generateRobots(baseUrl?: string, disallow?: string[]): string;
226
+ }
227
+
228
+ /**
229
+ * WebSocket manager configuration options.
230
+ */
231
+ export interface WebSocketOptions {
232
+ path?: string;
233
+ auth?: boolean;
234
+ maxPayload?: number;
235
+ }
236
+
237
+ /**
238
+ * Active WebSocket client connection interface.
239
+ */
240
+ export interface WebSocketClient {
241
+ isAlive?: boolean;
242
+ user?: any;
243
+ rooms?: Set<string>;
244
+ send(data: any): void;
245
+ on(event: string, handler: (...args: any[]) => void): void;
246
+ close(code?: number, reason?: string): void;
247
+ [key: string]: any;
248
+ }
249
+
250
+ export type WebSocketConnectionHandler = (ws: WebSocketClient, req: Request) => void;
251
+
252
+ export class WebSocketManager {
253
+ server: HttpServer;
254
+ path: string;
255
+ requireAuth: boolean;
256
+ maxPayload: number;
257
+ rooms: Map<string, Set<WebSocketClient>>;
258
+ clients: Set<WebSocketClient>;
259
+
260
+ constructor(server: HttpServer | any, options?: WebSocketOptions);
261
+ onConnection(handler: WebSocketConnectionHandler): void;
262
+ join(room: string, ws: WebSocketClient): void;
263
+ leave(room: string, ws: WebSocketClient): void;
264
+ broadcast(data: any, room?: string | null): void;
265
+ }
266
+
267
+ export interface ViteOptions {
268
+ dev?: boolean;
269
+ configFile?: string;
270
+ }
271
+
272
+ /**
273
+ * Application initialization options.
274
+ */
275
+ export interface AppOptions {
276
+ routes?: Array<Router | ExpressRouter | any>;
277
+ cors?: boolean | CorsOptions;
278
+ middlewares?: Array<RequestHandler | any>;
279
+ port?: number | string;
280
+ host?: string;
281
+ appUrl?: string;
282
+ logger?: boolean;
283
+ notFound?: boolean;
284
+ json?: boolean | Record<string, any>;
285
+ urlencoded?: boolean | Record<string, any>;
286
+ static?: AppStaticOptions;
287
+ cookieParser?: boolean;
288
+ swagger?: boolean | SwaggerOptions;
289
+ compression?: boolean;
290
+ security?: boolean | SecurityHeadersOptions;
291
+ rateLimit?: boolean | RateLimitOptions;
292
+ vite?: boolean | ViteOptions;
293
+ desktop?: boolean;
294
+ userDataPath?: string;
295
+ appPath?: string;
296
+ allowLan?: boolean;
297
+ trustProxy?: boolean | number | string;
298
+ debug?: boolean;
299
+ }
300
+
301
+ export class App {
302
+ app: ExpressRouter | any;
303
+ server: HttpServer;
304
+ wsManager: WebSocketManager | null;
305
+ routes: any[];
306
+ cors: boolean | CorsOptions;
307
+ middlewares: any[];
308
+ port: number | string;
309
+ host: string;
310
+ appUrl: string;
311
+ logger: boolean;
312
+ notFound: boolean;
313
+ desktop: boolean;
314
+ allowLan: boolean;
315
+ trustProxy: boolean | number | string;
316
+
317
+ constructor(options?: AppOptions);
318
+
319
+ use(record: any): void;
320
+ set(key: string, value: any): void;
321
+ websocket(
322
+ options?:
323
+ | WebSocketConnectionHandler
324
+ | WebSocketOptions
325
+ ): WebSocketManager;
326
+ getPort(): number;
327
+ getUrl(): string;
328
+ run(): Promise<any>;
329
+ runDesktop(options?: {
330
+ appPath?: string;
331
+ userDataPath?: string;
332
+ allowLan?: boolean;
333
+ host?: string;
334
+ port?: number;
335
+ }): Promise<{ server: HttpServer; port: number; url: string; lanUrl?: string; lanIp?: string }>;
336
+ close(): Promise<void>;
337
+
338
+ static helmet(options?: any): (req: Request, res: Response, next: NextFunction) => void;
339
+ static securityHeaders(options?: SecurityHeadersOptions): (req: Request, res: Response, next: NextFunction) => void;
340
+ static rateLimit(options?: RateLimitOptions | boolean): (req: Request, res: Response, next: NextFunction) => Promise<any>;
341
+ static ai(options?: any): any;
342
+ }
343
+
344
+ /**
345
+ * Router configuration options.
346
+ */
347
+ export interface RouterOptions {
348
+ seo?: boolean;
349
+ languages?: string[];
350
+ }
351
+
352
+ export class Router {
353
+ router: ExpressRouter;
354
+ path: string;
355
+
356
+ constructor(path?: string, options?: RouterOptions);
357
+
358
+ use(...middleware: Array<RequestHandler | any>): void;
359
+ get(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
360
+ post(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
361
+ put(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
362
+ delete(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
363
+ patch(path: string | RegExp, ...callback: Array<RequestHandler | any>): void;
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;
368
+ getRouter(): ExpressRouter;
369
+ getPath(): string;
370
+ }
371
+
372
+ /**
373
+ * Validation rule configuration for a single field.
374
+ */
375
+ export interface ValidationRule {
376
+ required?: boolean;
377
+ min?: number;
378
+ max?: number;
379
+ email?: boolean;
380
+ number?: boolean;
381
+ alpha?: boolean;
382
+ alphanumeric?: boolean;
383
+ boolean?: boolean;
384
+ date?: boolean;
385
+ url?: boolean;
386
+ in?: any[];
387
+ equals?: any;
388
+ password?: boolean;
389
+ pattern?: RegExp | string;
390
+ xss?: boolean;
391
+ messages?: Partial<
392
+ Record<
393
+ | "required"
394
+ | "min"
395
+ | "max"
396
+ | "email"
397
+ | "number"
398
+ | "alpha"
399
+ | "alphanumeric"
400
+ | "boolean"
401
+ | "date"
402
+ | "url"
403
+ | "in"
404
+ | "equals"
405
+ | "password"
406
+ | "pattern",
407
+ string
408
+ >
409
+ >;
410
+ }
411
+
412
+ /**
413
+ * Validator schema definition.
414
+ */
415
+ export type ValidationSchema = Record<string, ValidationRule>;
416
+
417
+ /**
418
+ * Validation failure item.
419
+ */
420
+ export interface ValidationError {
421
+ field: string;
422
+ message: string;
423
+ }
424
+
425
+ /**
426
+ * Validation output result.
427
+ */
428
+ export interface ValidationResult {
429
+ success: boolean;
430
+ error: boolean;
431
+ errors: ValidationError[];
432
+ message: string[];
433
+ html?: string[];
434
+ }
435
+
436
+ export class Validator {
437
+ schema: ValidationSchema;
438
+ lang_default: string | null;
439
+ messages: Record<string, any>;
440
+
441
+ constructor(schema: ValidationSchema, lang_default?: string, messages?: Record<string, any>);
442
+ middleware(): (req: Request, res: Response, next: NextFunction) => void;
443
+ validate(req: Request | Record<string, any>): Promise<ValidationResult>;
444
+ static xssMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
445
+ static sanitizeObject<T = any>(obj: T): T;
446
+ static mutateSanitized(obj: any): void;
447
+ }
448
+
449
+ /**
450
+ * Password hashing options.
451
+ */
452
+ export interface HashMakeOptions {
453
+ driver?: "scrypt" | "bcrypt";
454
+ rounds?: number;
455
+ N?: number;
456
+ r?: number;
457
+ p?: number;
458
+ }
459
+
460
+ export class Hash {
461
+ static make(password: string, options?: HashMakeOptions): Promise<string>;
462
+ static hash(password: string, options?: HashMakeOptions): Promise<string>;
463
+ static verify(password: string, hash: string): Promise<boolean>;
464
+ static check(password: string, hash: string): Promise<boolean>;
465
+ static needsRehash(hash: string, options?: HashMakeOptions): boolean;
466
+ }
467
+
468
+ /**
469
+ * Auth protect middleware options.
470
+ */
471
+ export interface AuthProtectOptions {
472
+ redirect?: string | null;
473
+ key?: string;
474
+ cookieKey?: string;
475
+ roles?: string | string[] | null;
476
+ secret?: string;
477
+ /** Set false to skip the global `Auth.configure({ resolveUser })` hook for this route. */
478
+ resolveUser?: boolean;
479
+ }
480
+
481
+ /**
482
+ * Auth login options.
483
+ */
484
+ export interface AuthLoginOptions {
485
+ expiresIn?: string | number;
486
+ rotateCsrf?: boolean;
487
+ /** Set false to return the token without setting the auth cookie (bearer clients). */
488
+ setCookie?: boolean;
489
+ cookie?: Record<string, any>;
490
+ secret?: string;
491
+ }
492
+
493
+ /**
494
+ * Decoded Auth JWT token payload.
495
+ */
496
+ export type AuthTokenPayload = Record<string, any> & {
497
+ _sessionId?: string;
498
+ exp?: number;
499
+ iat?: number;
500
+ };
501
+
502
+ export class Auth {
503
+ static encrypt(payload: any, secret?: string): string;
504
+ static decrypt<T = any>(data: string, secret?: string): T | null;
505
+ static generateToken(payload: any, secret?: string, expiresIn?: string | number): string;
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>;
509
+ static protect(options?: AuthProtectOptions): (req: Request, res: Response, next: NextFunction) => Promise<any>;
510
+ static login(res: Response, data: any, key?: string, options?: AuthLoginOptions): Promise<string>;
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;
516
+ }
517
+
518
+ export type CacheDriver = "memory" | "redis" | "file";
519
+
520
+ /**
521
+ * Cache middleware options.
522
+ */
523
+ export interface CacheMiddlewareOptions {
524
+ driver?: "memory" | "redis";
525
+ allowAuthenticated?: boolean;
526
+ key?: (req: Request) => string;
527
+ }
528
+
529
+ /**
530
+ * Cache read options.
531
+ */
532
+ export interface CacheGetOptions {
533
+ driver?: CacheDriver;
534
+ }
535
+
536
+ /**
537
+ * Cache write options.
538
+ */
539
+ export interface CacheSetOptions {
540
+ driver?: CacheDriver;
541
+ fallbackDriver?: CacheDriver;
542
+ }
543
+
544
+ export class Cache {
545
+ static middleware(seconds?: number, options?: CacheMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<any>;
546
+ static get<T = any>(key: string, options?: CacheGetOptions): Promise<T | null>;
547
+ static set(key: string, value: any, seconds?: number, options?: CacheSetOptions): Promise<boolean>;
548
+ static deduplicate<T = any>(key: string, loader: () => Promise<T>): Promise<T>;
549
+ static delete(keys: string | string[]): Promise<boolean>;
550
+ static del(keys: string | string[]): Promise<boolean>;
551
+ static deletePrefix(prefix: string): Promise<boolean>;
552
+ /** Invalidates `Cache.middleware()` responses for a route path, its query variants, and sub-routes (`/:id`). */
553
+ static invalidateRoute(routePath: string): Promise<boolean>;
554
+ static clear(): Promise<boolean>;
555
+ static getMode(): string;
556
+ static size(): number;
557
+ }
558
+
559
+ export function getRedisClient(): any;
560
+
561
+ /**
562
+ * Per-URL SEO and skeleton metadata entry inside `router.spa(..., { meta })`.
563
+ */
564
+ export interface SpaMetaEntry {
565
+ title?: string;
566
+ titleTemplate?: string;
567
+ description?: string;
568
+ keywords?: string | string[];
569
+ author?: string;
570
+ canonical?: string | boolean;
571
+ baseUrl?: string;
572
+ image?: string;
573
+ ogType?: string;
574
+ robots?: boolean | string;
575
+ lang?: string;
576
+ jsonld?: Record<string, any> | Record<string, any>[];
577
+ jsonLd?: Record<string, any> | Record<string, any>[];
578
+ head?: Array<string | Record<string, any>> | string;
579
+ body?: Array<string | Record<string, any>> | string;
580
+ metaTags?: Array<Record<string, string>>;
581
+ links?: Array<Record<string, string>>;
582
+ htmlAttrs?: Record<string, string | boolean>;
583
+ bodyAttrs?: Record<string, string | boolean>;
584
+ skeleton?: "app" | "auth" | "page" | false | string;
585
+ rootClass?: string;
586
+ }
587
+
588
+ export type SpaMetaResolver =
589
+ | SpaMetaEntry
590
+ | ((req: Request, params: Record<string, string>) => SpaMetaEntry | Promise<SpaMetaEntry>);
591
+
592
+ /**
593
+ * Configuration options for `router.spa()`.
594
+ */
595
+ export interface SpaOptions extends SpaMetaEntry {
596
+ /** Mount path used by `npx bluebird-js export` and `routerWeb.spa(spa.mount, spa)` (e.g. "/app"). */
597
+ mount?: string;
598
+ meta?: Record<string, SpaMetaResolver>;
599
+ /** React entry (default "app/resources/main.jsx"). */
600
+ entry?: string;
601
+ /** Extra stylesheets linked in <head> (the entry already imports "./styles.css"). */
602
+ styles?: string | string[];
603
+ /** HTML shell (default "app/resources/index.html", false = built-in shell). */
604
+ template?: string | false;
605
+ cache?: number;
606
+ cacheQuery?: string[];
607
+ seo?: boolean;
608
+ }
609
+
610
+ /**
611
+ * Options for rendering HTML views with `Render.html()`, `Render.send()`, and `Render.view()`.
612
+ */
613
+ export interface RenderOptions {
614
+ layout?: string | false;
615
+ cache?: number;
616
+ ttl?: number;
617
+ query?: string[];
618
+ cacheQuery?: string[];
619
+ raw?: boolean;
620
+ }
621
+
622
+ export class Render {
623
+ static renderString(template: string, data?: Record<string, any>, ctx?: Record<string, any>): Promise<string>;
624
+ static component(viewName: string, data?: Record<string, any>, ctx?: Record<string, any>): Promise<string>;
625
+ static html(res: Response, viewName: string, data?: Record<string, any>, options?: number | RenderOptions): Promise<any>;
626
+ static send(
627
+ res: Response,
628
+ viewName: string,
629
+ data?: Record<string, any>,
630
+ ttlOrOptions?: number | RenderOptions
631
+ ): Promise<any>;
632
+ static partial(res: Response, partialName: string, data?: Record<string, any>): Promise<any>;
633
+ static view(
634
+ viewName: string,
635
+ dataOrFn?: Record<string, any> | ((req: Request, res: Response) => any),
636
+ options?: number | RenderOptions
637
+ ): RequestHandler;
638
+ static cache(
639
+ seconds?: number,
640
+ options?: { allowAuthenticated?: boolean; query?: string[] }
641
+ ): (req: Request, res: Response, next: NextFunction) => Promise<any>;
642
+ static redirect(req: Request, res: Response, url: string, status?: number): void;
643
+ static clearTemplateCache(): void;
644
+ static invalidate(keys?: string | string[]): Promise<void>;
645
+ }
646
+
647
+ export * from "./html.js";
648
+
649
+
650
+ export const DB_TYPE: "sqlite" | "postgres" | "mysql" | "none" | string;
651
+
652
+ /**
653
+ * Database query execution options.
654
+ */
655
+ export interface DatabaseQueryOptions {
656
+ cache?: number;
657
+ cachePrefix?: string;
658
+ return_row?: boolean;
659
+ [key: string]: any;
660
+ }
661
+
662
+ /**
663
+ * Standard paginated query result.
664
+ */
665
+ export interface PaginatedResult<T = any> {
666
+ data: T[];
667
+ total: number;
668
+ page: number;
669
+ limit: number;
670
+ totalPages: number;
671
+ }
672
+
673
+ /**
674
+ * Transaction runner client.
675
+ */
676
+ export interface DatabaseTransactionClient {
677
+ query<T = any>(sql: string, params?: any[], options?: "return_row" | DatabaseQueryOptions | any): Promise<T>;
678
+ }
679
+
680
+ export interface DatabaseBackupOptions {
681
+ out?: string;
682
+ compress?: boolean;
683
+ keep?: number;
684
+ filename?: string;
685
+ dbInstance?: Database;
686
+ dbType?: string;
687
+ }
688
+
689
+ export interface DatabaseBackupResult {
690
+ success: boolean;
691
+ file: string;
692
+ filename: string;
693
+ size: number;
694
+ rotated: number;
695
+ dbType: string;
696
+ }
697
+
698
+ export interface DatabaseRestoreOptions {
699
+ safetyBackup?: boolean;
700
+ verify?: boolean;
701
+ dbInstance?: Database;
702
+ dbType?: string;
703
+ }
704
+
705
+ export interface DatabaseRestoreResult {
706
+ success: boolean;
707
+ restoredFrom: string;
708
+ targetFile: string;
709
+ preRestoreBackup?: string | null;
710
+ size?: number;
711
+ dbType: string;
712
+ }
713
+
714
+ export class Database {
715
+ backup(options?: DatabaseBackupOptions): Promise<DatabaseBackupResult>;
716
+ restore(filePath: string, options?: DatabaseRestoreOptions): Promise<DatabaseRestoreResult>;
717
+ static backup(options?: DatabaseBackupOptions): Promise<DatabaseBackupResult>;
718
+ static restore(filePath: string, options?: DatabaseRestoreOptions): Promise<DatabaseRestoreResult>;
719
+ type: string;
720
+ constructor(connectionLimit?: number, queueLimit?: number, config?: any);
721
+ init(retries?: number): Promise<boolean>;
722
+ query<T = any>(sql: string, params?: any[], options?: "return_row" | DatabaseQueryOptions | any): Promise<T>;
723
+ paginate<T = any>(
724
+ sql: string,
725
+ params?: any[],
726
+ options?: { page?: number; limit?: number; cache?: number }
727
+ ): Promise<PaginatedResult<T>>;
728
+ transaction<T = any>(callback: (tx: DatabaseTransactionClient) => Promise<T>): Promise<T>;
729
+ executeTransaction<T = any>(callback: (tx: DatabaseTransactionClient) => Promise<T>): Promise<T>;
730
+ close(): Promise<void>;
731
+ static closeAll(): Promise<void>;
732
+ }
733
+
734
+ /**
735
+ * Queue dispatching options.
736
+ */
737
+ export interface QueueDispatchOptions {
738
+ delayMs?: number;
739
+ }
740
+
741
+ /**
742
+ * Queue job item structure.
743
+ */
744
+ export interface QueueJob<T = any> {
745
+ id: string;
746
+ name: string;
747
+ payload: T;
748
+ createdAt: string;
749
+ }
750
+
751
+ export type QueueHandler<T = any> = (payload: T) => Promise<any> | any;
752
+
753
+ export class Queue {
754
+ static process<T = any>(jobName: string, handler: QueueHandler<T>): void;
755
+ static dispatch<T = any>(jobName: string, payload?: T, options?: QueueDispatchOptions): Promise<boolean>;
756
+ static work(): Promise<void>;
757
+ static stop(): void;
758
+ static loadJobs(jobsDir?: string): Promise<void>;
759
+ }
760
+
761
+ /**
762
+ * CSRF middleware options.
763
+ */
764
+ export interface CsrfOptions {
765
+ cookieName?: string;
766
+ headerName?: string;
767
+ bodyKey?: string;
768
+ maxAgeMs?: number;
769
+ secret?: string;
770
+ /** Exempt bearer-token requests sent without an auth cookie (default true). */
771
+ allowToken?: boolean;
772
+ authCookie?: string;
773
+ }
774
+
775
+ export class Csrf {
776
+ static cookieName: string;
777
+ static generateToken(secret?: string): string;
778
+ static verifyToken(token: string, secret?: string, maxAgeMs?: number): boolean;
779
+ static safeEqual(a: string, b: string): boolean;
780
+ static cookieOptions(): Record<string, any>;
781
+ /** Returns the request's valid CSRF token, issuing a fresh `_csrf` cookie when missing. */
782
+ static ensure(req: Request, res: Response): string;
783
+ /** Issues a new CSRF token cookie (called automatically on Auth.login/logout). */
784
+ static rotate(res: Response): string;
785
+ /** Timing-safe double-submit verification (header or body, never query string). */
786
+ static verifyRequest(req: Request, options?: CsrfOptions): boolean;
787
+ /** True for `Authorization: Bearer` / `X-Auth-Mode: token` requests without an auth cookie. */
788
+ static isTokenRequest(req: Request, authCookie?: string): boolean;
789
+ static middleware(options?: CsrfOptions): (req: Request, res: Response, next: NextFunction) => void;
790
+ }
791
+
792
+ export interface ModelSchemaColumn {
793
+ type: "int" | "integer" | "bigint" | "string" | "text" | "boolean" | "date" | "float" | "json" | (string & {});
794
+ primary?: boolean;
795
+ auto?: boolean;
796
+ unique?: boolean;
797
+ required?: boolean;
798
+ nullable?: boolean;
799
+ default?: any;
800
+ hidden?: boolean;
801
+ length?: number;
802
+ min?: number;
803
+ max?: number;
804
+ email?: boolean;
805
+ hash?: boolean;
806
+ in?: any[];
807
+ references?: string;
808
+ onDelete?: "cascade" | "set null" | "restrict" | "no action" | (string & {});
809
+ }
810
+
811
+ /**
812
+ * Options for Model.find query.
813
+ */
814
+ export interface ModelFindOptions {
815
+ withDeleted?: boolean;
816
+ withHidden?: boolean;
817
+ cache?: number;
818
+ oneMany?: typeof Model | Array<typeof Model>;
819
+ belongsTo?: typeof Model | Array<typeof Model>;
820
+ }
821
+
822
+ /**
823
+ * Options for Model.all query.
824
+ */
825
+ export interface ModelAllOptions {
826
+ where?: Record<string, any>;
827
+ order?: string | string[];
828
+ limit?: number;
829
+ offset?: number;
830
+ withDeleted?: boolean;
831
+ withHidden?: boolean;
832
+ cache?: number;
833
+ oneMany?: typeof Model | Array<typeof Model>;
834
+ belongsTo?: typeof Model | Array<typeof Model>;
835
+ }
836
+
837
+ /**
838
+ * Options for Model.paginate query.
839
+ */
840
+ export interface ModelPaginateOptions {
841
+ where?: Record<string, any>;
842
+ order?: string | string[];
843
+ page?: number;
844
+ limit?: number;
845
+ withDeleted?: boolean;
846
+ withHidden?: boolean;
847
+ cache?: number;
848
+ }
849
+
850
+ /**
851
+ * Options for Model.delete operation.
852
+ */
853
+ export interface ModelDeleteOptions {
854
+ force?: boolean;
855
+ cascade?: Array<typeof Model>;
856
+ }
857
+
858
+ export class Model {
859
+ static table: string;
860
+ static primaryKey: string;
861
+ static timestamps: boolean;
862
+ static softDelete: boolean;
863
+ static schema: Record<string, ModelSchemaColumn>;
864
+ static fillable: string[];
865
+ static guarded: string[];
866
+
867
+ static getDatabase(): Database;
868
+ static setDatabase(db: Database): void;
869
+ static close(): Promise<void>;
870
+ static query<T = any>(sql: string, params?: any[], options?: any): Promise<T>;
871
+ static transaction<T = any>(callback: (tx: DatabaseTransactionClient | any) => Promise<T>): Promise<T>;
872
+ static invalidateCache(): Promise<void>;
873
+ static find<T = any>(
874
+ idOrConditions: number | string | Record<string, any>,
875
+ options?: ModelFindOptions
876
+ ): Promise<T | null>;
877
+ static first<T = any>(
878
+ idOrConditions?: number | string | Record<string, any>,
879
+ options?: ModelFindOptions
880
+ ): Promise<T | null>;
881
+ static count(where?: Record<string, any>): Promise<number>;
882
+ static exists(where?: Record<string, any>): Promise<boolean>;
883
+ static firstOrCreate<T = any>(where: Record<string, any>, defaults?: Record<string, any>): Promise<T>;
884
+ static updateOrCreate<T = any>(where: Record<string, any>, values?: Record<string, any>): Promise<T>;
885
+ static all<T = any>(options?: ModelAllOptions): Promise<T[]>;
886
+ static paginate<T = any>(options?: ModelPaginateOptions): Promise<PaginatedResult<T>>;
887
+ static create(data: Record<string, any>, options?: { only?: string[]; except?: string[] }): Promise<number | string>;
888
+ static update(
889
+ idOrConditions: number | string | Record<string, any>,
890
+ data: Record<string, any>,
891
+ options?: { only?: string[]; except?: string[] }
892
+ ): Promise<number>;
893
+ static delete(
894
+ idOrConditions: number | string | Record<string, any>,
895
+ options?: ModelDeleteOptions
896
+ ): Promise<number>;
897
+ static restore(idOrConditions: number | string | Record<string, any>): Promise<number>;
898
+ static validator(mode?: "create" | "update", lang?: string): Validator;
899
+ static columnToSQL(col: string, def: ModelSchemaColumn, dialect?: "sqlite" | "mysql" | "postgres"): string;
900
+ static toDDL(dialect?: "sqlite" | "mysql" | "postgres"): string;
901
+ }
902
+
903
+ export interface UploadDiskOptions {
904
+ folder?: string;
905
+ fileSize?: number;
906
+ allowedTypes?: string[];
907
+ }
908
+
909
+ export interface UploadMiddleware {
910
+ single(fieldName: string): (req: Request, res: Response, next: NextFunction) => void;
911
+ array(fieldName: string, maxCount?: number): (req: Request, res: Response, next: NextFunction) => void;
912
+ fields(fields: Array<{ name: string; maxCount?: number }>): (req: Request, res: Response, next: NextFunction) => void;
913
+ none(): (req: Request, res: Response, next: NextFunction) => void;
914
+ any(): (req: Request, res: Response, next: NextFunction) => void;
915
+ }
916
+
917
+ export class Upload {
918
+ static storage(folder?: string): any;
919
+ static disk(options?: UploadDiskOptions): UploadMiddleware;
920
+ static url(filename: string, folder?: string): string;
921
+ }
922
+
923
+ export interface SwaggerOptions {
924
+ route?: string;
925
+ url?: string;
926
+ info?: {
927
+ title?: string;
928
+ version?: string;
929
+ description?: string;
930
+ };
931
+ apis?: string[];
932
+ }
933
+
934
+ export class Swagger {
935
+ static init(app: any, options?: SwaggerOptions): Promise<boolean>;
936
+ }
937
+
938
+ export interface AppProps {
939
+ debug: boolean;
940
+ desktop: boolean;
941
+ userDataDir: string;
942
+ appDir: string;
943
+ title: string;
944
+ description: string;
945
+ version: string;
946
+ host: string;
947
+ appUrl: string;
948
+ port: number;
949
+ jwtSecret?: string;
950
+ langMeta: string;
951
+ static: { path: string; options: Record<string, any> };
952
+ descriptionMeta?: string;
953
+ keywordsMeta?: string;
954
+ titleMeta?: string;
955
+ authorMeta?: string;
956
+ }
957
+
958
+ export class Config {
959
+ static dirname(): string;
960
+ static appDir(): string;
961
+ static setAppDir(dirPath: string): void;
962
+ static isDesktop(): boolean;
963
+ static setUserDataDir(customDir: string): void;
964
+ static userDataDir(): string;
965
+ static reload(): AppProps;
966
+ static props(): AppProps;
967
+ }
968
+
969
+ export class Logger {
970
+ folder: string;
971
+ constructor();
972
+ nowFolder(): string;
973
+ now(): string;
974
+ _log(file: string, level: string, message: string): void;
975
+ log(file: string, level: string, message: string): void;
976
+ info(message: string): void;
977
+ error(message: string): void;
978
+ warn(message: string): void;
979
+ warning(message: string): void;
980
+ debug(message: string): void;
981
+ }
982
+
983
+ export class Debug {
984
+ constructor();
985
+ static shouldTrack(req: Request): boolean;
986
+ static middlewareMetrics(app: any): void;
987
+ getRouter(): { path: string; router: ExpressRouter };
988
+ }
989
+
990
+ export interface CommonMiddleware {
991
+ auth: (req: Request, res: Response, next: NextFunction) => Promise<any>;
992
+ webAuth: (req: Request, res: Response, next: NextFunction) => Promise<any>;
993
+ logger: (req: Request, res: Response, next: NextFunction) => void;
994
+ }
995
+
996
+ export const Middleware: CommonMiddleware;
997
+
998
+ export default App;
999
+
1000
+ declare module "@seip/bluebird-js/core/model.js" {
1001
+ import {
1002
+ Model,
1003
+ ModelSchemaColumn,
1004
+ ModelFindOptions,
1005
+ ModelAllOptions,
1006
+ ModelPaginateOptions,
1007
+ ModelDeleteOptions,
1008
+ PaginatedResult,
1009
+ } from "@seip/bluebird-js";
1010
+ export {
1011
+ Model,
1012
+ ModelSchemaColumn,
1013
+ ModelFindOptions,
1014
+ ModelAllOptions,
1015
+ ModelPaginateOptions,
1016
+ ModelDeleteOptions,
1017
+ PaginatedResult,
1018
+ };
1019
+ export default Model;
1020
+ }
1021
+
1022
+ declare module "@seip/bluebird-js/core/app.js" {
1023
+ import App, {
1024
+ AppError,
1025
+ WebSocketManager,
1026
+ AppOptions,
1027
+ CorsOptions,
1028
+ SecurityHeadersOptions,
1029
+ AppStaticOptions,
1030
+ } from "@seip/bluebird-js";
1031
+ export {
1032
+ App,
1033
+ AppError,
1034
+ WebSocketManager,
1035
+ AppOptions,
1036
+ CorsOptions,
1037
+ SecurityHeadersOptions,
1038
+ AppStaticOptions,
1039
+ };
1040
+ export default App;
1041
+ }
1042
+
1043
+ declare module "@seip/bluebird-js/core/router.js" {
1044
+ import { Router, RouterOptions, SpaOptions, SpaMetaEntry } from "@seip/bluebird-js";
1045
+ export { Router, RouterOptions, SpaOptions, SpaMetaEntry };
1046
+ export default Router;
1047
+ }
1048
+
1049
+ declare module "@seip/bluebird-js/core/render.js" {
1050
+ import { Render, RenderOptions } from "@seip/bluebird-js";
1051
+ export { Render, RenderOptions };
1052
+ export default Render;
1053
+ }
1054
+
1055
+ declare module "@seip/bluebird-js/core/html.js" {
1056
+ import {
1057
+ SafeHtml,
1058
+ isSafeHtml,
1059
+ escapeHtml,
1060
+ safeJson,
1061
+ HtmlTag,
1062
+ html,
1063
+ ScriptTag,
1064
+ script,
1065
+ each,
1066
+ cached,
1067
+ defer,
1068
+ } from "@seip/bluebird-js";
1069
+ export {
1070
+ SafeHtml,
1071
+ isSafeHtml,
1072
+ escapeHtml,
1073
+ safeJson,
1074
+ HtmlTag,
1075
+ html,
1076
+ ScriptTag,
1077
+ script,
1078
+ each,
1079
+ cached,
1080
+ defer,
1081
+ };
1082
+ export default html;
1083
+ }
1084
+
1085
+ declare module "@seip/bluebird-js/core/validate.js" {
1086
+ import {
1087
+ Validator,
1088
+ ValidationRule,
1089
+ ValidationSchema,
1090
+ ValidationError,
1091
+ ValidationResult,
1092
+ } from "@seip/bluebird-js";
1093
+ export {
1094
+ Validator,
1095
+ ValidationRule,
1096
+ ValidationSchema,
1097
+ ValidationError,
1098
+ ValidationResult,
1099
+ };
1100
+ export default Validator;
1101
+ }
1102
+
1103
+ declare module "@seip/bluebird-js/core/database.js" {
1104
+ import {
1105
+ Database,
1106
+ DB_TYPE,
1107
+ DatabaseQueryOptions,
1108
+ DatabaseTransactionClient,
1109
+ PaginatedResult,
1110
+ } from "@seip/bluebird-js";
1111
+ export {
1112
+ Database,
1113
+ DB_TYPE,
1114
+ DatabaseQueryOptions,
1115
+ DatabaseTransactionClient,
1116
+ PaginatedResult,
1117
+ };
1118
+ export default Database;
1119
+ }
1120
+
1121
+ declare module "@seip/bluebird-js/core/auth.js" {
1122
+ import {
1123
+ Auth,
1124
+ AuthProtectOptions,
1125
+ AuthLoginOptions,
1126
+ AuthTokenPayload,
1127
+ } from "@seip/bluebird-js";
1128
+ export {
1129
+ Auth,
1130
+ AuthProtectOptions,
1131
+ AuthLoginOptions,
1132
+ AuthTokenPayload,
1133
+ };
1134
+ export default Auth;
1135
+ }
1136
+
1137
+ declare module "@seip/bluebird-js/core/cache.js" {
1138
+ import {
1139
+ Cache,
1140
+ getRedisClient,
1141
+ CacheDriver,
1142
+ CacheMiddlewareOptions,
1143
+ CacheGetOptions,
1144
+ CacheSetOptions,
1145
+ } from "@seip/bluebird-js";
1146
+ export {
1147
+ Cache,
1148
+ getRedisClient,
1149
+ CacheDriver,
1150
+ CacheMiddlewareOptions,
1151
+ CacheGetOptions,
1152
+ CacheSetOptions,
1153
+ };
1154
+ export default Cache;
1155
+ }
1156
+
1157
+ declare module "@seip/bluebird-js/core/redis.js" {
1158
+ export function initRedis(): Promise<any>;
1159
+ export function getRedisClient(): any;
1160
+ export function isRedisConnectedStatus(): boolean;
1161
+ export function redisGet(key: string): Promise<any>;
1162
+ export function redisSet(key: string, value: any, seconds?: number): Promise<boolean>;
1163
+ export function redisDel(keys: string | string[]): Promise<boolean>;
1164
+ export function redisClearPrefix(prefix: string): Promise<boolean>;
1165
+ export function disconnectRedis(): Promise<void>;
1166
+
1167
+ const redisHandler: {
1168
+ initRedis: typeof initRedis;
1169
+ getRedisClient: typeof getRedisClient;
1170
+ isRedisConnectedStatus: typeof isRedisConnectedStatus;
1171
+ redisGet: typeof redisGet;
1172
+ redisSet: typeof redisSet;
1173
+ redisDel: typeof redisDel;
1174
+ redisClearPrefix: typeof redisClearPrefix;
1175
+ disconnectRedis: typeof disconnectRedis;
1176
+ };
1177
+ export default redisHandler;
1178
+ }
1179
+
1180
+ declare module "@seip/bluebird-js/core/csrf.js" {
1181
+ import { Csrf, CsrfOptions } from "@seip/bluebird-js";
1182
+ export { Csrf, CsrfOptions };
1183
+ export default Csrf;
1184
+ }
1185
+
1186
+ declare module "@seip/bluebird-js/core/hash.js" {
1187
+ import { Hash, HashMakeOptions } from "@seip/bluebird-js";
1188
+ export { Hash, HashMakeOptions };
1189
+ export default Hash;
1190
+ }
1191
+
1192
+ declare module "@seip/bluebird-js/core/queue.js" {
1193
+ import {
1194
+ Queue,
1195
+ QueueDispatchOptions,
1196
+ QueueJob,
1197
+ QueueHandler,
1198
+ } from "@seip/bluebird-js";
1199
+ export {
1200
+ Queue,
1201
+ QueueDispatchOptions,
1202
+ QueueJob,
1203
+ QueueHandler,
1204
+ };
1205
+ export default Queue;
1206
+ }
1207
+
1208
+ declare module "@seip/bluebird-js/core/upload.js" {
1209
+ import {
1210
+ Upload,
1211
+ UploadDiskOptions,
1212
+ UploadMiddleware,
1213
+ UploadedFile,
1214
+ } from "@seip/bluebird-js";
1215
+ export {
1216
+ Upload,
1217
+ UploadDiskOptions,
1218
+ UploadMiddleware,
1219
+ UploadedFile,
1220
+ };
1221
+ export default Upload;
1222
+ }
1223
+
1224
+ declare module "@seip/bluebird-js/core/ws.js" {
1225
+ import {
1226
+ WebSocketManager,
1227
+ WebSocketOptions,
1228
+ WebSocketClient,
1229
+ WebSocketConnectionHandler,
1230
+ } from "@seip/bluebird-js";
1231
+ export {
1232
+ WebSocketManager,
1233
+ WebSocketOptions,
1234
+ WebSocketClient,
1235
+ WebSocketConnectionHandler,
1236
+ };
1237
+ export default WebSocketManager;
1238
+ }
1239
+
1240
+ declare module "@seip/bluebird-js/core/swagger.js" {
1241
+ import { Swagger, SwaggerOptions } from "@seip/bluebird-js";
1242
+ export { Swagger, SwaggerOptions };
1243
+ export default Swagger;
1244
+ }
1245
+
1246
+ declare module "@seip/bluebird-js/core/logger.js" {
1247
+ import { Logger } from "@seip/bluebird-js";
1248
+ export { Logger };
1249
+ export default Logger;
1250
+ }
1251
+
1252
+ declare module "@seip/bluebird-js/core/config.js" {
1253
+ import { Config, AppProps } from "@seip/bluebird-js";
1254
+ export { Config, AppProps };
1255
+ export default Config;
1256
+ }
1257
+
1258
+ declare module "@seip/bluebird-js/core/debug.js" {
1259
+ import { Debug } from "@seip/bluebird-js";
1260
+ export { Debug };
1261
+ export default Debug;
1262
+ }
1263
+
1264
+ declare module "@seip/bluebird-js/core/middleware.js" {
1265
+ import { Middleware, CommonMiddleware } from "@seip/bluebird-js";
1266
+ export { Middleware, CommonMiddleware };
1267
+ export default Middleware;
1268
+ }
1269
+
1270
+
1271
+ declare module "@seip/bluebird-js/core/ratelimit.js" {
1272
+ import { RateLimit, RateLimitOptions } from "@seip/bluebird-js";
1273
+ export { RateLimit, RateLimitOptions };
1274
+ export default RateLimit;
1275
+ }
1276
+
1277
+ declare module "@seip/bluebird-js/core/seo.js" {
1278
+ import { Seo } from "@seip/bluebird-js";
1279
+ export { Seo };
1280
+ export default Seo;
1281
+ }
1282
+
1283
+ declare module "@seip/bluebird-js/core/ai.js" {
1284
+ import { AI, ai, AIOptions, AIAskOptions, AIResult, AIStreamChunk } from "@seip/bluebird-js";
1285
+ export { AI, ai, AIOptions, AIAskOptions, AIResult, AIStreamChunk };
1286
+ export default AI;
1287
+ }
1288
+