@forinda/kickjs 1.6.0 → 1.7.1-alpha.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 (104) hide show
  1. package/dist/chunk-DVVP7zzD.js +7 -0
  2. package/dist/core/adapter.d.ts +109 -0
  3. package/dist/core/adapter.d.ts.map +1 -0
  4. package/dist/core/adapter.js +0 -0
  5. package/dist/core/app-module.d.ts +28 -0
  6. package/dist/core/app-module.d.ts.map +1 -0
  7. package/dist/core/app-module.js +0 -0
  8. package/dist/core/cache.d.ts +93 -0
  9. package/dist/core/cache.d.ts.map +1 -0
  10. package/dist/core/cache.js +57 -0
  11. package/dist/core/container.d.ts +63 -0
  12. package/dist/core/container.d.ts.map +1 -0
  13. package/dist/core/container.js +117 -0
  14. package/dist/core/cron.d.ts +28 -0
  15. package/dist/core/cron.d.ts.map +1 -0
  16. package/dist/core/cron.js +22 -0
  17. package/dist/core/decorators.d.ts +152 -0
  18. package/dist/core/decorators.d.ts.map +1 -0
  19. package/dist/core/decorators.js +141 -0
  20. package/dist/core/errors.d.ts +64 -0
  21. package/dist/core/errors.d.ts.map +1 -0
  22. package/dist/core/errors.js +67 -0
  23. package/dist/core/index.d.ts +14 -0
  24. package/dist/core/index.d.ts.map +1 -0
  25. package/dist/core/interfaces.d.ts +44 -0
  26. package/dist/core/interfaces.d.ts.map +1 -0
  27. package/dist/core/interfaces.js +25 -0
  28. package/dist/core/logger.d.ts +43 -0
  29. package/dist/core/logger.d.ts.map +1 -0
  30. package/dist/core/logger.js +54 -0
  31. package/dist/core/path.d.ts +21 -0
  32. package/dist/core/path.d.ts.map +1 -0
  33. package/dist/core/path.js +12 -0
  34. package/dist/core/plugin.d.ts +90 -0
  35. package/dist/core/plugin.d.ts.map +1 -0
  36. package/dist/core/plugin.js +0 -0
  37. package/dist/core/reactivity.d.ts +83 -0
  38. package/dist/core/reactivity.d.ts.map +1 -0
  39. package/dist/core/reactivity.js +101 -0
  40. package/dist/core-B6Okew3W.js +7 -0
  41. package/dist/http/application.d.ts +103 -0
  42. package/dist/http/application.d.ts.map +1 -0
  43. package/dist/http/application.js +167 -0
  44. package/dist/http/bootstrap.d.ts +22 -0
  45. package/dist/http/bootstrap.d.ts.map +1 -0
  46. package/dist/http/bootstrap.js +40 -0
  47. package/dist/http/context.d.ts +129 -0
  48. package/dist/http/context.d.ts.map +1 -0
  49. package/dist/http/context.js +115 -0
  50. package/dist/http/index.d.ts +16 -0
  51. package/dist/http/index.d.ts.map +1 -0
  52. package/dist/http/middleware/cors.d.ts +43 -0
  53. package/dist/http/middleware/cors.d.ts.map +1 -0
  54. package/dist/http/middleware/cors.js +31 -0
  55. package/dist/http/middleware/csrf.d.ts +47 -0
  56. package/dist/http/middleware/csrf.d.ts.map +1 -0
  57. package/dist/http/middleware/csrf.js +25 -0
  58. package/dist/http/middleware/error-handler.d.ts +6 -0
  59. package/dist/http/middleware/error-handler.d.ts.map +1 -0
  60. package/dist/http/middleware/error-handler.js +37 -0
  61. package/dist/http/middleware/helmet.d.ts +36 -0
  62. package/dist/http/middleware/helmet.d.ts.map +1 -0
  63. package/dist/http/middleware/helmet.js +20 -0
  64. package/dist/http/middleware/rate-limit.d.ts +51 -0
  65. package/dist/http/middleware/rate-limit.d.ts.map +1 -0
  66. package/dist/http/middleware/rate-limit.js +46 -0
  67. package/dist/http/middleware/request-id.d.ts +5 -0
  68. package/dist/http/middleware/request-id.d.ts.map +1 -0
  69. package/dist/http/middleware/request-id.js +12 -0
  70. package/dist/http/middleware/request-logger.d.ts +27 -0
  71. package/dist/http/middleware/request-logger.d.ts.map +1 -0
  72. package/dist/http/middleware/request-logger.js +16 -0
  73. package/dist/http/middleware/session.d.ts +62 -0
  74. package/dist/http/middleware/session.d.ts.map +1 -0
  75. package/dist/http/middleware/session.js +76 -0
  76. package/dist/http/middleware/spa.d.ts +93 -0
  77. package/dist/http/middleware/spa.d.ts.map +1 -0
  78. package/dist/http/middleware/spa.js +52 -0
  79. package/dist/http/middleware/upload.d.ts +75 -0
  80. package/dist/http/middleware/upload.d.ts.map +1 -0
  81. package/dist/http/middleware/upload.js +119 -0
  82. package/dist/http/middleware/validate.d.ts +13 -0
  83. package/dist/http/middleware/validate.d.ts.map +1 -0
  84. package/dist/http/middleware/validate.js +45 -0
  85. package/dist/http/middleware/views.d.ts +56 -0
  86. package/dist/http/middleware/views.d.ts.map +1 -0
  87. package/dist/http/middleware/views.js +18 -0
  88. package/dist/http/query/index.d.ts +4 -0
  89. package/dist/http/query/index.d.ts.map +1 -0
  90. package/dist/http/query/index.js +10 -0
  91. package/dist/http/query/parse-query.d.ts +44 -0
  92. package/dist/http/query/parse-query.d.ts.map +1 -0
  93. package/dist/http/query/types.d.ts +100 -0
  94. package/dist/http/query/types.d.ts.map +1 -0
  95. package/dist/http/router-builder.d.ts +17 -0
  96. package/dist/http/router-builder.d.ts.map +1 -0
  97. package/dist/http/router-builder.js +37 -0
  98. package/dist/index.d.ts +23 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +99 -0
  101. package/dist/query-Bym31XRp.js +88 -0
  102. package/package.json +90 -29
  103. package/index.d.ts +0 -3
  104. package/index.js +0 -13
@@ -0,0 +1,12 @@
1
+ import { randomUUID as s } from "node:crypto";
2
+ var o = "x-request-id";
3
+ function i() {
4
+ return (e, t, d) => {
5
+ const r = e.headers["x-request-id"] || s();
6
+ e.requestId = r, t.setHeader(o, r), d();
7
+ };
8
+ }
9
+ export {
10
+ o as REQUEST_ID_HEADER,
11
+ i as requestId
12
+ };
@@ -0,0 +1,27 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ export interface RequestLoggerOptions {
3
+ /** Logger name (default: 'HTTP') */
4
+ name?: string;
5
+ /** Log level for successful requests (default: 'info') */
6
+ level?: 'info' | 'debug' | 'trace';
7
+ /** Skip logging for paths matching these prefixes (e.g. ['/health', '/_debug']) */
8
+ skip?: string[];
9
+ }
10
+ /**
11
+ * Middleware that logs every request with method, URL, status, duration, and request ID.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * bootstrap({
16
+ * middleware: [requestId(), requestLogger(), express.json()],
17
+ * })
18
+ * ```
19
+ *
20
+ * Output:
21
+ * ```
22
+ * [HTTP] GET /api/v1/users 200 12ms req-abc123
23
+ * [HTTP] POST /api/v1/users 201 45ms req-def456
24
+ * ```
25
+ */
26
+ export declare function requestLogger(options?: RequestLoggerOptions): (req: Request, res: Response, next: NextFunction) => void;
27
+ //# sourceMappingURL=request-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-logger.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/request-logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG9D,MAAM,WAAW,oBAAoB;IACnC,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;IAClC,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,IAKtD,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,UAkBxD"}
@@ -0,0 +1,16 @@
1
+ import { createLogger as l } from "../../core/logger.js";
2
+ import "../../core-B6Okew3W.js";
3
+ function f(e = {}) {
4
+ const r = l(e.name ?? "HTTP"), a = e.level ?? "info", i = e.skip ?? [];
5
+ return (t, o, n) => {
6
+ if (i.some((s) => t.path.startsWith(s))) return n();
7
+ const u = Date.now();
8
+ o.on("finish", () => {
9
+ const s = Date.now() - u, c = t.requestId || t.headers["x-request-id"] || "-", d = o.statusCode;
10
+ r[a](`${t.method} ${t.originalUrl} ${d} ${s}ms ${c}`);
11
+ }), n();
12
+ };
13
+ }
14
+ export {
15
+ f as requestLogger
16
+ };
@@ -0,0 +1,62 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ export interface SessionData {
3
+ [key: string]: unknown;
4
+ }
5
+ export interface SessionStore {
6
+ get(sid: string): Promise<SessionData | null>;
7
+ set(sid: string, data: SessionData, maxAge: number): Promise<void>;
8
+ destroy(sid: string): Promise<void>;
9
+ touch?(sid: string, maxAge: number): Promise<void>;
10
+ }
11
+ export interface Session {
12
+ id: string;
13
+ data: SessionData;
14
+ regenerate(): Promise<void>;
15
+ destroy(): Promise<void>;
16
+ save(): Promise<void>;
17
+ }
18
+ export interface SessionOptions {
19
+ /** Secret used to sign the session cookie (required) */
20
+ secret: string;
21
+ /** Cookie name (default: 'kick.sid') */
22
+ cookieName?: string;
23
+ /** Session max age in milliseconds (default: 86400000 = 24h) */
24
+ maxAge?: number;
25
+ /** Reset maxAge on every response (default: false) */
26
+ rolling?: boolean;
27
+ /** Save new sessions that have not been modified (default: true) */
28
+ saveUninitialized?: boolean;
29
+ /** Cookie options */
30
+ cookie?: {
31
+ httpOnly?: boolean;
32
+ secure?: boolean;
33
+ sameSite?: 'strict' | 'lax' | 'none';
34
+ path?: string;
35
+ domain?: string;
36
+ };
37
+ /** Custom session store (default: in-memory store with TTL cleanup) */
38
+ store?: SessionStore;
39
+ }
40
+ /**
41
+ * Session management middleware.
42
+ *
43
+ * Attaches a `req.session` object with `id`, `data`, `regenerate()`,
44
+ * `destroy()`, and `save()` methods. Session IDs are signed with
45
+ * HMAC-SHA256 to prevent cookie tampering.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { session } from '@forinda/kickjs-http'
50
+ *
51
+ * bootstrap({
52
+ * modules,
53
+ * middleware: [
54
+ * cookieParser(),
55
+ * session({ secret: process.env.SESSION_SECRET! }),
56
+ * // ... other middleware
57
+ * ],
58
+ * })
59
+ * ```
60
+ */
61
+ export declare function session(options: SessionOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
62
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE9D,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC7C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAClE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,KAAK,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,WAAW,CAAA;IACjB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACxB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAA;IACd,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,sDAAsD;IACtD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,oEAAoE;IACpE,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,qBAAqB;IACrB,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,MAAM,CAAC,EAAE,OAAO,CAAA;QAChB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAA;QACpC,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,uEAAuE;IACvE,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AA8ED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,IAoB/B,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,mBAoF9D"}
@@ -0,0 +1,76 @@
1
+ import { createHmac as v, randomUUID as x, timingSafeEqual as I } from "node:crypto";
2
+ var O = class {
3
+ sessions = /* @__PURE__ */ new Map();
4
+ cleanupInterval;
5
+ constructor() {
6
+ this.cleanupInterval = setInterval(() => this.purge(), 6e4), this.cleanupInterval.unref();
7
+ }
8
+ async get(e) {
9
+ const t = this.sessions.get(e);
10
+ return t ? Date.now() > t.expires ? (this.sessions.delete(e), null) : t.data : null;
11
+ }
12
+ async set(e, t, s) {
13
+ this.sessions.set(e, {
14
+ data: t,
15
+ expires: Date.now() + s
16
+ });
17
+ }
18
+ async destroy(e) {
19
+ this.sessions.delete(e);
20
+ }
21
+ async touch(e, t) {
22
+ const s = this.sessions.get(e);
23
+ s && (s.expires = Date.now() + t);
24
+ }
25
+ purge() {
26
+ const e = Date.now();
27
+ for (const [t, s] of this.sessions) e > s.expires && this.sessions.delete(t);
28
+ }
29
+ };
30
+ function w(e, t) {
31
+ return `s:${e}.${v("sha256", t).update(e).digest("base64url")}`;
32
+ }
33
+ function S(e, t) {
34
+ if (!e.startsWith("s:")) return !1;
35
+ const s = e.slice(2), a = s.lastIndexOf(".");
36
+ if (a === -1) return !1;
37
+ const u = s.slice(0, a), p = s.slice(a + 1), i = v("sha256", t).update(u).digest("base64url"), o = Buffer.from(p), c = Buffer.from(i);
38
+ return o.length !== c.length || !I(o, c) ? !1 : u;
39
+ }
40
+ function N(e) {
41
+ const { secret: t, cookieName: s = "kick.sid", maxAge: a = 864e5, rolling: u = !1, saveUninitialized: p = !0, store: i = new O(), cookie: o = {} } = e, c = {
42
+ httpOnly: o.httpOnly ?? !0,
43
+ secure: o.secure ?? process.env.NODE_ENV === "production",
44
+ sameSite: o.sameSite ?? "lax",
45
+ path: o.path ?? "/",
46
+ ...o.domain ? { domain: o.domain } : {},
47
+ maxAge: a
48
+ };
49
+ return async (m, f, D) => {
50
+ const k = (m.cookies || {})[s];
51
+ let l = !1, h = null, d = !1;
52
+ k && (l = S(k, t), l && (h = await i.get(l))), (!l || !h) && (l = x(), h = {}, d = !0);
53
+ let n = l, r = { ...h }, y = !1;
54
+ const g = {
55
+ get id() {
56
+ return n;
57
+ },
58
+ data: r,
59
+ async regenerate() {
60
+ await i.destroy(n), n = x(), r = {}, g.data = r, await i.set(n, r, a), f.cookie(s, w(n, t), c);
61
+ },
62
+ async destroy() {
63
+ await i.destroy(n), y = !0, r = {}, g.data = r, f.clearCookie(s, { path: c.path });
64
+ },
65
+ async save() {
66
+ y || await i.set(n, r, a);
67
+ }
68
+ };
69
+ m.session = g, d && f.cookie(s, w(n, t), c), f.on("finish", async () => {
70
+ y || d && !p && Object.keys(r).length === 0 || (await i.set(n, r, a), u && !d && i.touch && await i.touch(n, a));
71
+ }), u && !d && f.cookie(s, w(n, t), c), D();
72
+ };
73
+ }
74
+ export {
75
+ N as session
76
+ };
@@ -0,0 +1,93 @@
1
+ import { type AppAdapter, type AdapterContext } from '../../core';
2
+ export interface SpaAdapterOptions {
3
+ /**
4
+ * Directory containing the built SPA files (index.html, assets, etc.)
5
+ * Default: 'dist/client'
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // Vue: 'dist'
10
+ * // React (Vite): 'dist'
11
+ * // React (CRA): 'build'
12
+ * // Svelte: 'build'
13
+ * // Angular: 'dist/my-app/browser'
14
+ * ```
15
+ */
16
+ clientDir?: string;
17
+ /**
18
+ * URL prefix for API routes. SPA fallback only applies to
19
+ * non-API routes (routes NOT starting with this prefix).
20
+ * Default: '/api'
21
+ *
22
+ * Set to an array for multiple prefixes:
23
+ * ```ts
24
+ * apiPrefix: ['/api', '/graphql', '/_debug']
25
+ * ```
26
+ */
27
+ apiPrefix?: string | string[];
28
+ /**
29
+ * Additional paths to exclude from SPA fallback.
30
+ * These paths will NOT serve index.html.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * exclude: ['/health', '/metrics', '/ws']
35
+ * ```
36
+ */
37
+ exclude?: string[];
38
+ /**
39
+ * Cache-Control header for static assets (default: 'public, max-age=31536000, immutable')
40
+ * Set to false to disable caching headers.
41
+ */
42
+ cacheControl?: string | false;
43
+ /**
44
+ * Cache-Control for index.html (default: 'no-cache')
45
+ * index.html should not be cached to ensure clients get fresh builds.
46
+ */
47
+ indexCacheControl?: string;
48
+ }
49
+ /**
50
+ * SPA adapter — serve a Vue, React, Svelte, or Angular build alongside
51
+ * your KickJS API. API routes are handled by controllers; everything else
52
+ * falls back to index.html for client-side routing.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { SpaAdapter } from '@forinda/kickjs-http/spa'
57
+ *
58
+ * bootstrap({
59
+ * modules,
60
+ * adapters: [
61
+ * new SpaAdapter({
62
+ * clientDir: 'dist/client', // or 'build', 'dist', etc.
63
+ * apiPrefix: '/api',
64
+ * }),
65
+ * ],
66
+ * })
67
+ * ```
68
+ *
69
+ * File structure:
70
+ * ```
71
+ * dist/
72
+ * client/ ← SPA build output
73
+ * index.html
74
+ * assets/
75
+ * app.js
76
+ * style.css
77
+ * server/ ← KickJS server
78
+ * ```
79
+ */
80
+ export declare class SpaAdapter implements AppAdapter {
81
+ private options;
82
+ name: string;
83
+ private clientDir;
84
+ private apiPrefixes;
85
+ private excludePaths;
86
+ private cacheControl;
87
+ private indexCacheControl;
88
+ private indexHtml;
89
+ constructor(options?: SpaAdapterOptions);
90
+ beforeMount({ app }: AdapterContext): void;
91
+ beforeStart({ app }: AdapterContext): void;
92
+ }
93
+ //# sourceMappingURL=spa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spa.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/spa.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AAIzE,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAE7B;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAElB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IAE7B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,UAAW,YAAW,UAAU;IAS/B,OAAO,CAAC,OAAO;IAR3B,IAAI,SAAe;IACnB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,SAAS,CAAsB;gBAEnB,OAAO,GAAE,iBAAsB;IAUnD,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,GAAG,IAAI;IAyC1C,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,GAAG,IAAI;CA2B3C"}
@@ -0,0 +1,52 @@
1
+ import { t as c } from "../../chunk-DVVP7zzD.js";
2
+ import { Logger as h } from "../../core/logger.js";
3
+ import "../../core-B6Okew3W.js";
4
+ import { join as l, resolve as d } from "node:path";
5
+ import { existsSync as a, readFileSync as f } from "node:fs";
6
+ var s = h.for("SpaAdapter"), P = class {
7
+ name = "SpaAdapter";
8
+ clientDir;
9
+ apiPrefixes;
10
+ excludePaths;
11
+ cacheControl;
12
+ indexCacheControl;
13
+ indexHtml = null;
14
+ constructor(e = {}) {
15
+ this.options = e, this.clientDir = d(e.clientDir ?? "dist/client"), this.excludePaths = e.exclude ?? [], this.cacheControl = e.cacheControl ?? "public, max-age=31536000, immutable", this.indexCacheControl = e.indexCacheControl ?? "no-cache";
16
+ const t = e.apiPrefix ?? "/api";
17
+ this.apiPrefixes = Array.isArray(t) ? t : [t];
18
+ }
19
+ beforeMount({ app: e }) {
20
+ if (!a(this.clientDir)) {
21
+ s.warn(`SPA client directory not found: ${this.clientDir}`), s.warn("Build your frontend first, or set clientDir to the correct path.");
22
+ return;
23
+ }
24
+ const t = l(this.clientDir, "index.html");
25
+ if (a(t)) this.indexHtml = f(t, "utf-8");
26
+ else {
27
+ s.warn(`index.html not found in ${this.clientDir}`);
28
+ return;
29
+ }
30
+ try {
31
+ const n = c("express"), i = {};
32
+ this.cacheControl && (i.setHeaders = (r, o) => {
33
+ o.endsWith(".html") ? r.setHeader("Cache-Control", this.indexCacheControl) : r.setHeader("Cache-Control", this.cacheControl);
34
+ }), e.use(n.static(this.clientDir, i));
35
+ } catch {
36
+ s.error("express.static not available — SPA static file serving disabled");
37
+ return;
38
+ }
39
+ s.info(`Serving SPA from ${this.clientDir}`);
40
+ }
41
+ beforeStart({ app: e }) {
42
+ this.indexHtml && e.use((t, n, i) => {
43
+ for (const r of this.apiPrefixes) if (t.path.startsWith(r)) return i();
44
+ for (const r of this.excludePaths) if (t.path.startsWith(r)) return i();
45
+ if (t.path.includes(".") || t.method !== "GET") return i();
46
+ n.setHeader("Content-Type", "text/html"), n.setHeader("Cache-Control", this.indexCacheControl), n.send(this.indexHtml);
47
+ });
48
+ }
49
+ };
50
+ export {
51
+ P as SpaAdapter
52
+ };
@@ -0,0 +1,75 @@
1
+ import type { Request, Response, NextFunction, RequestHandler } from 'express';
2
+ import { type Options as MulterOptions } from 'multer';
3
+ import type { BaseUploadOptions, FileUploadConfig } from '../../core';
4
+ /**
5
+ * Resolves a list of file type identifiers to MIME type strings.
6
+ * Accepts short extensions (`'jpg'`, `'pdf'`) or full MIME types (`'image/jpeg'`).
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * resolveMimeTypes(['jpg', 'png', 'application/pdf'])
11
+ * // → ['image/jpeg', 'image/png', 'application/pdf']
12
+ * ```
13
+ */
14
+ export declare function resolveMimeTypes(types: string[]): string[];
15
+ /**
16
+ * Upload options for the middleware.
17
+ * Extends BaseUploadOptions from core (shared with @FileUpload decorator)
18
+ * and adds Multer-specific storage options.
19
+ */
20
+ export interface UploadOptions extends BaseUploadOptions {
21
+ /** Multer storage config (default: memory storage) */
22
+ storage?: MulterOptions['storage'];
23
+ /** Multer dest for disk storage shorthand */
24
+ dest?: string;
25
+ }
26
+ /**
27
+ * Single file upload middleware. Attaches the file to `req.file`.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * @Post('/avatar')
32
+ * @Middleware(upload.single('avatar', { maxSize: 2 * 1024 * 1024, allowedTypes: ['jpg', 'png'] }))
33
+ * async uploadAvatar(ctx: RequestContext) {
34
+ * ctx.json({ filename: ctx.file.originalname })
35
+ * }
36
+ * ```
37
+ */
38
+ declare function single(fieldName: string, options?: UploadOptions): RequestHandler;
39
+ /**
40
+ * Multiple file upload middleware. Attaches files to `req.files`.
41
+ */
42
+ declare function array(fieldName: string, maxCount?: number, options?: UploadOptions): RequestHandler;
43
+ /**
44
+ * No file upload — just parse multipart form data without file fields.
45
+ */
46
+ declare function none(options?: UploadOptions): RequestHandler;
47
+ /**
48
+ * Removes temporary files from disk after the response is sent.
49
+ * Attach this as Express middleware after the upload middleware.
50
+ * Works with both `req.file` (single) and `req.files` (array).
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * @Post('/process')
55
+ * @Middleware(upload.single('document', { dest: '/tmp/uploads' }), cleanupFiles())
56
+ * async processDocument(ctx: RequestContext) {
57
+ * ctx.json({ ok: true })
58
+ * }
59
+ * ```
60
+ */
61
+ export declare function cleanupFiles(): (req: Request, res: Response, next: NextFunction) => void;
62
+ /**
63
+ * Build upload middleware from a @FileUpload decorator config.
64
+ * Used internally by the router builder when it detects FILE_UPLOAD metadata.
65
+ * Accepts the same FileUploadConfig interface used by the @FileUpload decorator.
66
+ */
67
+ export declare function buildUploadMiddleware(config: FileUploadConfig): RequestHandler;
68
+ /** Upload middleware factory with `.single()`, `.array()`, `.none()` methods */
69
+ export declare const upload: {
70
+ single: typeof single;
71
+ array: typeof array;
72
+ none: typeof none;
73
+ };
74
+ export {};
75
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/upload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC9E,OAAe,EAAE,KAAK,OAAO,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAA;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAyDrE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAK1D;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,sDAAsD;IACtD,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAA;IAClC,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAoDD;;;;;;;;;;;GAWG;AACH,iBAAS,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,cAAc,CAG9E;AAED;;GAEG;AACH,iBAAS,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,SAAK,EAAE,OAAO,GAAE,aAAkB,GAAG,cAAc,CAG5F;AAED;;GAEG;AACH,iBAAS,IAAI,CAAC,OAAO,GAAE,aAAkB,GAAG,cAAc,CAGzD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,KAClB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,UAwBxD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAgB9E;AAED,gFAAgF;AAChF,eAAO,MAAM,MAAM;;;;CAA0B,CAAA"}
@@ -0,0 +1,119 @@
1
+ import { unlink as u } from "node:fs/promises";
2
+ import v from "multer";
3
+ var m = {
4
+ jpg: "image/jpeg",
5
+ jpeg: "image/jpeg",
6
+ png: "image/png",
7
+ gif: "image/gif",
8
+ webp: "image/webp",
9
+ svg: "image/svg+xml",
10
+ bmp: "image/bmp",
11
+ ico: "image/x-icon",
12
+ tiff: "image/tiff",
13
+ tif: "image/tiff",
14
+ avif: "image/avif",
15
+ pdf: "application/pdf",
16
+ doc: "application/msword",
17
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
18
+ xls: "application/vnd.ms-excel",
19
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
20
+ ppt: "application/vnd.ms-powerpoint",
21
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
22
+ odt: "application/vnd.oasis.opendocument.text",
23
+ ods: "application/vnd.oasis.opendocument.spreadsheet",
24
+ odp: "application/vnd.oasis.opendocument.presentation",
25
+ rtf: "application/rtf",
26
+ txt: "text/plain",
27
+ csv: "text/csv",
28
+ zip: "application/zip",
29
+ gz: "application/gzip",
30
+ tar: "application/x-tar",
31
+ rar: "application/vnd.rar",
32
+ "7z": "application/x-7z-compressed",
33
+ mp3: "audio/mpeg",
34
+ wav: "audio/wav",
35
+ ogg: "audio/ogg",
36
+ flac: "audio/flac",
37
+ aac: "audio/aac",
38
+ mp4: "video/mp4",
39
+ webm: "video/webm",
40
+ avi: "video/x-msvideo",
41
+ mov: "video/quicktime",
42
+ mkv: "video/x-matroska",
43
+ json: "application/json",
44
+ xml: "application/xml",
45
+ html: "text/html"
46
+ };
47
+ function w(e) {
48
+ return e.map((a) => m[a.toLowerCase().replace(/^\./, "")] ?? a);
49
+ }
50
+ function s(e) {
51
+ const a = e.customMimeMap ? {
52
+ ...m,
53
+ ...e.customMimeMap
54
+ } : m, i = { fileSize: e.maxSize ?? 5 * 1024 * 1024 };
55
+ let t;
56
+ if (typeof e.allowedTypes == "function") {
57
+ const o = e.allowedTypes;
58
+ t = (r, p, n) => {
59
+ o(p.mimetype, p.originalname) ? n(null, !0) : n(/* @__PURE__ */ new Error(`File type ${p.mimetype} is not allowed`));
60
+ };
61
+ } else if (Array.isArray(e.allowedTypes)) {
62
+ const o = e.allowedTypes.map((r) => a[r.toLowerCase().replace(/^\./, "")] ?? r);
63
+ t = (r, p, n) => {
64
+ o.some((l) => l.endsWith("/*") ? p.mimetype.startsWith(l.replace("/*", "/")) : p.mimetype === l) ? n(null, !0) : n(/* @__PURE__ */ new Error(`File type ${p.mimetype} is not allowed`));
65
+ };
66
+ }
67
+ return v({
68
+ limits: i,
69
+ ...t ? { fileFilter: t } : {},
70
+ ...e.storage ? { storage: e.storage } : {},
71
+ ...e.dest ? { dest: e.dest } : {}
72
+ });
73
+ }
74
+ function c(e, a = {}) {
75
+ return s(a).single(e);
76
+ }
77
+ function d(e, a = 10, i = {}) {
78
+ return s(i).array(e, a);
79
+ }
80
+ function f(e = {}) {
81
+ return s(e).none();
82
+ }
83
+ function y() {
84
+ return (e, a, i) => {
85
+ a.on("finish", async () => {
86
+ const t = [];
87
+ if (e.file?.path && t.push(e.file), Array.isArray(e.files))
88
+ for (const o of e.files) o?.path && t.push(o);
89
+ for (const o of t) try {
90
+ await u(o.path);
91
+ } catch {
92
+ }
93
+ }), i();
94
+ };
95
+ }
96
+ function M(e) {
97
+ const a = {};
98
+ e.maxSize && (a.maxSize = e.maxSize), e.allowedTypes && (a.allowedTypes = e.allowedTypes), e.customMimeMap && (a.customMimeMap = e.customMimeMap);
99
+ const i = e.fieldName ?? "file";
100
+ switch (e.mode) {
101
+ case "single":
102
+ return c(i, a);
103
+ case "array":
104
+ return d(i, e.maxCount ?? 10, a);
105
+ case "none":
106
+ return f(a);
107
+ }
108
+ }
109
+ var h = {
110
+ single: c,
111
+ array: d,
112
+ none: f
113
+ };
114
+ export {
115
+ M as buildUploadMiddleware,
116
+ y as cleanupFiles,
117
+ w as resolveMimeTypes,
118
+ h as upload
119
+ };
@@ -0,0 +1,13 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ export interface ValidationSchema {
3
+ body?: any;
4
+ query?: any;
5
+ params?: any;
6
+ }
7
+ /**
8
+ * Express middleware that validates request body/query/params against schemas.
9
+ * Works with any validation library that exposes `.safeParse(data)` returning
10
+ * `{ success: true, data }` or `{ success: false, error: { issues } }`.
11
+ */
12
+ export declare function validate(schema: ValidationSchema): (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
13
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE9D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,MAAM,CAAC,EAAE,GAAG,CAAA;CACb;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,IACvC,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,oDAiDxD"}
@@ -0,0 +1,45 @@
1
+ function u(a) {
2
+ return (r, t, o) => {
3
+ try {
4
+ if (a.body) {
5
+ const s = a.body.safeParse(r.body);
6
+ if (!s.success) return t.status(422).json({
7
+ message: s.error.issues[0]?.message || "Validation failed",
8
+ errors: s.error.issues.map((e) => ({
9
+ field: e.path.join("."),
10
+ message: e.message
11
+ }))
12
+ });
13
+ r.body = s.data;
14
+ }
15
+ if (a.query) {
16
+ const s = a.query.safeParse(r.query);
17
+ if (!s.success) return t.status(422).json({
18
+ message: "Invalid query parameters",
19
+ errors: s.error.issues.map((e) => ({
20
+ field: e.path.join("."),
21
+ message: e.message
22
+ }))
23
+ });
24
+ r.query = s.data;
25
+ }
26
+ if (a.params) {
27
+ const s = a.params.safeParse(r.params);
28
+ if (!s.success) return t.status(422).json({
29
+ message: "Invalid path parameters",
30
+ errors: s.error.issues.map((e) => ({
31
+ field: e.path.join("."),
32
+ message: e.message
33
+ }))
34
+ });
35
+ r.params = s.data;
36
+ }
37
+ o();
38
+ } catch (s) {
39
+ o(s);
40
+ }
41
+ };
42
+ }
43
+ export {
44
+ u as validate
45
+ };
@@ -0,0 +1,56 @@
1
+ import { type AppAdapter, type AdapterContext } from '../../core';
2
+ export interface ViewAdapterOptions {
3
+ /**
4
+ * Template engine — pass the engine module or a render function.
5
+ * Supported engines: ejs, pug, handlebars, nunjucks, or any
6
+ * Express-compatible engine with a __express property.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import ejs from 'ejs'
11
+ * new ViewAdapter({ engine: ejs, ext: 'ejs' })
12
+ *
13
+ * import pug from 'pug'
14
+ * new ViewAdapter({ engine: pug, ext: 'pug' })
15
+ * ```
16
+ */
17
+ engine: any;
18
+ /** File extension for templates (e.g., 'ejs', 'pug', 'hbs') */
19
+ ext: string;
20
+ /** Directory containing template files (default: 'src/views') */
21
+ viewsDir?: string;
22
+ /** Default layout template (optional — depends on engine) */
23
+ layout?: string;
24
+ }
25
+ /**
26
+ * View/template adapter — pluggable template engine support for KickJS.
27
+ *
28
+ * Registers an Express view engine and sets the views directory.
29
+ * Use `ctx.render()` in controllers to render templates.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import ejs from 'ejs'
34
+ * import { ViewAdapter } from '@forinda/kickjs-http/views'
35
+ *
36
+ * bootstrap({
37
+ * modules,
38
+ * adapters: [
39
+ * new ViewAdapter({ engine: ejs, ext: 'ejs', viewsDir: 'src/views' }),
40
+ * ],
41
+ * })
42
+ *
43
+ * // In a controller:
44
+ * @Get('/dashboard')
45
+ * async dashboard(ctx: RequestContext) {
46
+ * ctx.render('dashboard', { user: currentUser, title: 'Dashboard' })
47
+ * }
48
+ * ```
49
+ */
50
+ export declare class ViewAdapter implements AppAdapter {
51
+ private options;
52
+ name: string;
53
+ constructor(options: ViewAdapterOptions);
54
+ beforeMount({ app }: AdapterContext): void;
55
+ }
56
+ //# sourceMappingURL=views.d.ts.map