@forinda/kickjs 3.2.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -212
- package/dist/{adapter-DLEHb0K6.d.mts → adapter-BNw2pGbg.d.mts} +117 -7
- package/dist/adapter-BNw2pGbg.d.mts.map +1 -0
- package/dist/{app-module-ERR9jhow.d.mts → app-module-CO0ksPCm.d.mts} +3 -3
- package/dist/{app-module-ERR9jhow.d.mts.map → app-module-CO0ksPCm.d.mts.map} +1 -1
- package/dist/{application-x8CXLOlv.mjs → application-Ce4DQN6m.mjs} +28 -9
- package/dist/application-Ce4DQN6m.mjs.map +1 -0
- package/dist/application-Czwm7Gty.d.mts +302 -0
- package/dist/application-Czwm7Gty.d.mts.map +1 -0
- package/dist/{bootstrap-CYnxozL_.mjs → bootstrap-CB7bJeJG.mjs} +6 -6
- package/dist/{bootstrap-CYnxozL_.mjs.map → bootstrap-CB7bJeJG.mjs.map} +1 -1
- package/dist/bootstrap-NxFRaNTh.d.mts +28 -0
- package/dist/bootstrap-NxFRaNTh.d.mts.map +1 -0
- package/dist/{cache-V91BNTIM.d.mts → cache-BStrqXSZ.d.mts} +2 -2
- package/dist/{cache-V91BNTIM.d.mts.map → cache-BStrqXSZ.d.mts.map} +1 -1
- package/dist/config/index.d.mts +1 -1
- package/dist/config/index.mjs +3 -3
- package/dist/{config-aWxKLk4A.mjs → config-wZ_TgBfs.mjs} +4 -4
- package/dist/{config-aWxKLk4A.mjs.map → config-wZ_TgBfs.mjs.map} +1 -1
- package/dist/{container-fIS1uLx-.d.mts → container-CnWDsxi-.d.mts} +9 -7
- package/dist/container-CnWDsxi-.d.mts.map +1 -0
- package/dist/{container-Dnk43k54.mjs → container-DYYSu58w.mjs} +313 -9
- package/dist/container-DYYSu58w.mjs.map +1 -0
- package/dist/{context-OktlOQBQ.mjs → context-BAGzqT7-.mjs} +33 -41
- package/dist/context-BAGzqT7-.mjs.map +1 -0
- package/dist/context-Ymvv-85x.d.mts +260 -0
- package/dist/context-Ymvv-85x.d.mts.map +1 -0
- package/dist/{context-decorator-GA8-hDLe.d.mts → context-decorator-B5v3VQCN.d.mts} +4 -4
- package/dist/{context-decorator-GA8-hDLe.d.mts.map → context-decorator-B5v3VQCN.d.mts.map} +1 -1
- package/dist/core/adapter.d.mts +1 -1
- package/dist/core/adapter.mjs +1 -1
- package/dist/core/app-module.d.mts +1 -1
- package/dist/core/app-module.mjs +1 -1
- package/dist/core/cache.d.mts +1 -1
- package/dist/core/cache.mjs +2 -2
- package/dist/core/cache.mjs.map +1 -1
- package/dist/core/container.d.mts +1 -1
- package/dist/core/container.mjs +2 -2
- package/dist/core/cron.d.mts +1 -1
- package/dist/core/cron.mjs +2 -2
- package/dist/core/decorators.d.mts +2 -2
- package/dist/core/decorators.mjs +48 -16
- package/dist/core/decorators.mjs.map +1 -1
- package/dist/core/errors.d.mts +1 -1
- package/dist/core/errors.mjs +1 -1
- package/dist/core/interfaces.d.mts +1 -1
- package/dist/core/interfaces.mjs +35 -18
- package/dist/core/interfaces.mjs.map +1 -1
- package/dist/core/logger.d.mts +2 -2
- package/dist/core/logger.mjs +2 -4
- package/dist/core/logger.mjs.map +1 -1
- package/dist/core/path.d.mts +1 -1
- package/dist/core/path.mjs +1 -1
- package/dist/core/plugin.d.mts +1 -1
- package/dist/core/plugin.mjs +1 -1
- package/dist/core/reactivity.d.mts +1 -1
- package/dist/core/reactivity.mjs +1 -1
- package/dist/{core-DANnH5-e.mjs → core-DBcoqPHM.mjs} +282 -8
- package/dist/core-DBcoqPHM.mjs.map +1 -0
- package/dist/cors-BfgqfLPd.d.mts +48 -0
- package/dist/cors-BfgqfLPd.d.mts.map +1 -0
- package/dist/{cron-CfsPdi7R.d.mts → cron-7zqvsmMI.d.mts} +1 -1
- package/dist/{cron-CfsPdi7R.d.mts.map → cron-7zqvsmMI.d.mts.map} +1 -1
- package/dist/csrf-DiK9zept.d.mts +52 -0
- package/dist/csrf-DiK9zept.d.mts.map +1 -0
- package/dist/{decorators-H42oPg0m.d.mts → decorators-BMvaLliz.d.mts} +147 -12
- package/dist/decorators-BMvaLliz.d.mts.map +1 -0
- package/dist/{env-Cs8Wt8A_.mjs → env-CdH5-dM_.mjs} +3 -4
- package/dist/{env-Cs8Wt8A_.mjs.map → env-CdH5-dM_.mjs.map} +1 -1
- package/dist/error-handler-Xud_3Lah.d.mts +20 -0
- package/dist/error-handler-Xud_3Lah.d.mts.map +1 -0
- package/dist/{errors-D_CWI7Bl.d.mts → errors-uaHCeXRz.d.mts} +1 -1
- package/dist/{errors-D_CWI7Bl.d.mts.map → errors-uaHCeXRz.d.mts.map} +1 -1
- package/dist/{execution-context-Dl2CKqSo.d.mts → execution-context-DKnt61pY.d.mts} +1 -1
- package/dist/{execution-context-Dl2CKqSo.d.mts.map → execution-context-DKnt61pY.d.mts.map} +1 -1
- package/dist/helmet-CaMbjzBG.d.mts +41 -0
- package/dist/helmet-CaMbjzBG.d.mts.map +1 -0
- package/dist/http/application.d.mts +2 -293
- package/dist/http/application.mjs +2 -2
- package/dist/http/bootstrap.d.mts +2 -27
- package/dist/http/bootstrap.mjs +2 -2
- package/dist/http/context.d.mts +3 -251
- package/dist/http/context.mjs +2 -2
- package/dist/http/middleware/cors.d.mts +2 -47
- package/dist/http/middleware/cors.mjs +1 -1
- package/dist/http/middleware/csrf.d.mts +2 -51
- package/dist/http/middleware/csrf.mjs +2 -2
- package/dist/http/middleware/csrf.mjs.map +1 -1
- package/dist/http/middleware/error-handler.d.mts +2 -19
- package/dist/http/middleware/error-handler.mjs +2 -2
- package/dist/http/middleware/helmet.d.mts +2 -40
- package/dist/http/middleware/helmet.mjs +1 -1
- package/dist/http/middleware/rate-limit.d.mts +2 -55
- package/dist/http/middleware/rate-limit.mjs +2 -2
- package/dist/http/middleware/rate-limit.mjs.map +1 -1
- package/dist/http/middleware/request-id.d.mts +2 -9
- package/dist/http/middleware/request-id.mjs +12 -3
- package/dist/http/middleware/request-id.mjs.map +1 -1
- package/dist/http/middleware/request-logger.d.mts +2 -31
- package/dist/http/middleware/request-logger.mjs +2 -2
- package/dist/http/middleware/session.d.mts +2 -69
- package/dist/http/middleware/session.mjs +1 -1
- package/dist/http/middleware/spa.d.mts +2 -100
- package/dist/http/middleware/spa.mjs +5 -5
- package/dist/http/middleware/spa.mjs.map +1 -1
- package/dist/http/middleware/upload.d.mts +2 -78
- package/dist/http/middleware/upload.mjs +1 -1
- package/dist/http/middleware/validate.d.mts +2 -22
- package/dist/http/middleware/validate.mjs +2 -2
- package/dist/http/middleware/views.d.mts +2 -61
- package/dist/http/middleware/views.mjs +16 -15
- package/dist/http/middleware/views.mjs.map +1 -1
- package/dist/http/query/index.d.mts +1 -1
- package/dist/http/query/index.mjs +2 -2
- package/dist/http/router-builder.d.mts +2 -32
- package/dist/http/router-builder.mjs +10 -14
- package/dist/http/router-builder.mjs.map +1 -1
- package/dist/{index-RNK41JPE.d.mts → index-B9cyOQAe.d.mts} +1 -1
- package/dist/{index-RNK41JPE.d.mts.map → index-B9cyOQAe.d.mts.map} +1 -1
- package/dist/{index-Cf-MGrqT.d.mts → index-D-qhXg9M.d.mts} +3 -3
- package/dist/{index-Cf-MGrqT.d.mts.map → index-D-qhXg9M.d.mts.map} +1 -1
- package/dist/{index-BQM9pJrV.d.mts → index-DQyWtyp0.d.mts} +241 -5
- package/dist/index-DQyWtyp0.d.mts.map +1 -0
- package/dist/index.d.mts +34 -152
- package/dist/index.mjs +14 -14
- package/dist/interfaces-B50n7dwl.d.mts +71 -0
- package/dist/{interfaces-CwcdqfNq.d.mts.map → interfaces-B50n7dwl.d.mts.map} +1 -1
- package/dist/{logger-GK8yT0BD.d.mts → logger-CLVRZf2N.d.mts} +2 -4
- package/dist/{logger-GK8yT0BD.d.mts.map → logger-CLVRZf2N.d.mts.map} +1 -1
- package/dist/{metadata-BFuoSEX6.mjs → metadata-VQM9wChy.mjs} +2 -2
- package/dist/{metadata-BFuoSEX6.mjs.map → metadata-VQM9wChy.mjs.map} +1 -1
- package/dist/{path-Bj3vZMUY.d.mts → path-Diviu6hv.d.mts} +1 -1
- package/dist/path-Diviu6hv.d.mts.map +1 -0
- package/dist/{plugin-3rKA0Loy.d.mts → plugin-WdrDgNzk.d.mts} +45 -7
- package/dist/plugin-WdrDgNzk.d.mts.map +1 -0
- package/dist/{query-BcYEjYyX.mjs → query-DJMxdx5r.mjs} +2 -2
- package/dist/{query-BcYEjYyX.mjs.map → query-DJMxdx5r.mjs.map} +1 -1
- package/dist/rate-limit-DUwoICtI.d.mts +56 -0
- package/dist/rate-limit-DUwoICtI.d.mts.map +1 -0
- package/dist/{reactivity-CczHu3R-.d.mts → reactivity-CfJceo4H.d.mts} +1 -1
- package/dist/{reactivity-CczHu3R-.d.mts.map → reactivity-CfJceo4H.d.mts.map} +1 -1
- package/dist/request-id-BgglvZHN.d.mts +19 -0
- package/dist/request-id-BgglvZHN.d.mts.map +1 -0
- package/dist/request-logger-CWHbAzTE.d.mts +32 -0
- package/dist/request-logger-CWHbAzTE.d.mts.map +1 -0
- package/dist/router-builder-C799BAf0.d.mts +31 -0
- package/dist/router-builder-C799BAf0.d.mts.map +1 -0
- package/dist/session-N0hActOO.d.mts +70 -0
- package/dist/session-N0hActOO.d.mts.map +1 -0
- package/dist/spa-CrFR2_cz.d.mts +101 -0
- package/dist/spa-CrFR2_cz.d.mts.map +1 -0
- package/dist/upload-BueOnnLw.d.mts +79 -0
- package/dist/upload-BueOnnLw.d.mts.map +1 -0
- package/dist/validate-HwAyWTwH.d.mts +23 -0
- package/dist/validate-HwAyWTwH.d.mts.map +1 -0
- package/dist/views-DhQSXV2P.d.mts +176 -0
- package/dist/views-DhQSXV2P.d.mts.map +1 -0
- package/package.json +6 -9
- package/dist/adapter-DLEHb0K6.d.mts.map +0 -1
- package/dist/application-x8CXLOlv.mjs.map +0 -1
- package/dist/chunk-Bt-rz0Tp.mjs +0 -15
- package/dist/container-Dnk43k54.mjs.map +0 -1
- package/dist/container-fIS1uLx-.d.mts.map +0 -1
- package/dist/context-OktlOQBQ.mjs.map +0 -1
- package/dist/core-DANnH5-e.mjs.map +0 -1
- package/dist/decorators-H42oPg0m.d.mts.map +0 -1
- package/dist/http/application.d.mts.map +0 -1
- package/dist/http/bootstrap.d.mts.map +0 -1
- package/dist/http/context.d.mts.map +0 -1
- package/dist/http/middleware/cors.d.mts.map +0 -1
- package/dist/http/middleware/csrf.d.mts.map +0 -1
- package/dist/http/middleware/error-handler.d.mts.map +0 -1
- package/dist/http/middleware/helmet.d.mts.map +0 -1
- package/dist/http/middleware/rate-limit.d.mts.map +0 -1
- package/dist/http/middleware/request-id.d.mts.map +0 -1
- package/dist/http/middleware/request-logger.d.mts.map +0 -1
- package/dist/http/middleware/session.d.mts.map +0 -1
- package/dist/http/middleware/spa.d.mts.map +0 -1
- package/dist/http/middleware/upload.d.mts.map +0 -1
- package/dist/http/middleware/validate.d.mts.map +0 -1
- package/dist/http/middleware/views.d.mts.map +0 -1
- package/dist/http/router-builder.d.mts.map +0 -1
- package/dist/index-BQM9pJrV.d.mts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/interfaces-CwcdqfNq.d.mts +0 -54
- package/dist/path-Bj3vZMUY.d.mts.map +0 -1
- package/dist/plugin-3rKA0Loy.d.mts.map +0 -1
|
@@ -1,52 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/http/middleware/csrf.d.ts
|
|
5
|
-
interface CsrfOptions {
|
|
6
|
-
/** Cookie name for the CSRF token (default: '_csrf') */
|
|
7
|
-
cookie?: string;
|
|
8
|
-
/** Header name to check for the token (default: 'x-csrf-token') */
|
|
9
|
-
header?: string;
|
|
10
|
-
/** HTTP methods that require CSRF validation (default: POST, PUT, PATCH, DELETE) */
|
|
11
|
-
methods?: string[];
|
|
12
|
-
/** Paths to exclude from CSRF checks (e.g. webhooks) */
|
|
13
|
-
ignorePaths?: string[];
|
|
14
|
-
/** Token byte length before hex encoding (default: 32 = 64 hex chars) */
|
|
15
|
-
tokenLength?: number;
|
|
16
|
-
/** Cookie options */
|
|
17
|
-
cookieOptions?: {
|
|
18
|
-
httpOnly?: boolean;
|
|
19
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
20
|
-
secure?: boolean;
|
|
21
|
-
path?: string;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Double-submit cookie CSRF protection middleware.
|
|
26
|
-
*
|
|
27
|
-
* On every request, sets a CSRF token cookie. For state-changing methods
|
|
28
|
-
* (POST, PUT, PATCH, DELETE), validates that the request header matches
|
|
29
|
-
* the cookie value.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* import { csrf } from '@forinda/kickjs-http'
|
|
34
|
-
*
|
|
35
|
-
* bootstrap({
|
|
36
|
-
* modules,
|
|
37
|
-
* middleware: [
|
|
38
|
-
* cookieParser(),
|
|
39
|
-
* csrf(),
|
|
40
|
-
* // ... other middleware
|
|
41
|
-
* ],
|
|
42
|
-
* })
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* Client usage:
|
|
46
|
-
* 1. Read the `_csrf` cookie value
|
|
47
|
-
* 2. Send it in the `x-csrf-token` header on every mutating request
|
|
48
|
-
*/
|
|
49
|
-
declare function csrf(options?: CsrfOptions): (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
50
|
-
//#endregion
|
|
51
|
-
export { CsrfOptions, csrf };
|
|
52
|
-
//# sourceMappingURL=csrf.d.mts.map
|
|
2
|
+
import { n as csrf, t as CsrfOptions } from "../../csrf-DiK9zept.mjs";
|
|
3
|
+
export { CsrfOptions, csrf };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs
|
|
2
|
+
* @forinda/kickjs v4.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -19,7 +19,7 @@ import { randomBytes } from "node:crypto";
|
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
|
-
* import { csrf } from '@forinda/kickjs
|
|
22
|
+
* import { csrf } from '@forinda/kickjs'
|
|
23
23
|
*
|
|
24
24
|
* bootstrap({
|
|
25
25
|
* modules,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csrf.mjs","names":[],"sources":["../../../src/http/middleware/csrf.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto'\nimport type { Request, Response, NextFunction } from 'express'\n\nexport interface CsrfOptions {\n /** Cookie name for the CSRF token (default: '_csrf') */\n cookie?: string\n /** Header name to check for the token (default: 'x-csrf-token') */\n header?: string\n /** HTTP methods that require CSRF validation (default: POST, PUT, PATCH, DELETE) */\n methods?: string[]\n /** Paths to exclude from CSRF checks (e.g. webhooks) */\n ignorePaths?: string[]\n /** Token byte length before hex encoding (default: 32 = 64 hex chars) */\n tokenLength?: number\n /** Cookie options */\n cookieOptions?: {\n httpOnly?: boolean\n sameSite?: 'strict' | 'lax' | 'none'\n secure?: boolean\n path?: string\n }\n}\n\n/**\n * Double-submit cookie CSRF protection middleware.\n *\n * On every request, sets a CSRF token cookie. For state-changing methods\n * (POST, PUT, PATCH, DELETE), validates that the request header matches\n * the cookie value.\n *\n * @example\n * ```ts\n * import { csrf } from '@forinda/kickjs
|
|
1
|
+
{"version":3,"file":"csrf.mjs","names":[],"sources":["../../../src/http/middleware/csrf.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto'\nimport type { Request, Response, NextFunction } from 'express'\n\nexport interface CsrfOptions {\n /** Cookie name for the CSRF token (default: '_csrf') */\n cookie?: string\n /** Header name to check for the token (default: 'x-csrf-token') */\n header?: string\n /** HTTP methods that require CSRF validation (default: POST, PUT, PATCH, DELETE) */\n methods?: string[]\n /** Paths to exclude from CSRF checks (e.g. webhooks) */\n ignorePaths?: string[]\n /** Token byte length before hex encoding (default: 32 = 64 hex chars) */\n tokenLength?: number\n /** Cookie options */\n cookieOptions?: {\n httpOnly?: boolean\n sameSite?: 'strict' | 'lax' | 'none'\n secure?: boolean\n path?: string\n }\n}\n\n/**\n * Double-submit cookie CSRF protection middleware.\n *\n * On every request, sets a CSRF token cookie. For state-changing methods\n * (POST, PUT, PATCH, DELETE), validates that the request header matches\n * the cookie value.\n *\n * @example\n * ```ts\n * import { csrf } from '@forinda/kickjs'\n *\n * bootstrap({\n * modules,\n * middleware: [\n * cookieParser(),\n * csrf(),\n * // ... other middleware\n * ],\n * })\n * ```\n *\n * Client usage:\n * 1. Read the `_csrf` cookie value\n * 2. Send it in the `x-csrf-token` header on every mutating request\n */\nexport function csrf(options: CsrfOptions = {}) {\n const cookieName = options.cookie ?? '_csrf'\n const headerName = options.header ?? 'x-csrf-token'\n const protectedMethods = new Set(\n (options.methods ?? ['POST', 'PUT', 'PATCH', 'DELETE']).map((m) => m.toUpperCase()),\n )\n const ignorePaths = new Set(options.ignorePaths ?? [])\n const tokenLength = options.tokenLength ?? 32\n const cookieOpts = {\n httpOnly: true,\n sameSite: 'strict' as const,\n secure: process.env.NODE_ENV === 'production',\n path: '/',\n ...options.cookieOptions,\n }\n\n return (req: Request, res: Response, next: NextFunction) => {\n // Generate or reuse CSRF token\n const cookies = (req as any).cookies || {}\n let token = cookies[cookieName]\n\n if (!token) {\n token = randomBytes(tokenLength).toString('hex')\n res.cookie(cookieName, token, cookieOpts)\n }\n\n // Skip validation for safe methods and ignored paths\n if (!protectedMethods.has(req.method.toUpperCase())) {\n return next()\n }\n\n if (ignorePaths.has(req.path)) {\n return next()\n }\n\n // Validate: header token must match cookie token\n const headerToken = req.headers[headerName] as string | undefined\n\n if (!headerToken || headerToken !== token) {\n return res.status(403).json({\n message: 'CSRF token mismatch',\n })\n }\n\n next()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,KAAK,UAAuB,EAAE,EAAE;CAC9C,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,mBAAmB,IAAI,KAC1B,QAAQ,WAAW;EAAC;EAAQ;EAAO;EAAS;EAAS,EAAE,KAAK,MAAM,EAAE,aAAa,CAAC,CACpF;CACD,MAAM,cAAc,IAAI,IAAI,QAAQ,eAAe,EAAE,CAAC;CACtD,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,aAAa;EACjB,UAAU;EACV,UAAU;EACV,QAAQ,QAAQ,IAAI,aAAa;EACjC,MAAM;EACN,GAAG,QAAQ;EACZ;AAED,SAAQ,KAAc,KAAe,SAAuB;EAG1D,IAAI,SADa,IAAY,WAAW,EAAE,EACtB;AAEpB,MAAI,CAAC,OAAO;AACV,WAAQ,YAAY,YAAY,CAAC,SAAS,MAAM;AAChD,OAAI,OAAO,YAAY,OAAO,WAAW;;AAI3C,MAAI,CAAC,iBAAiB,IAAI,IAAI,OAAO,aAAa,CAAC,CACjD,QAAO,MAAM;AAGf,MAAI,YAAY,IAAI,IAAI,KAAK,CAC3B,QAAO,MAAM;EAIf,MAAM,cAAc,IAAI,QAAQ;AAEhC,MAAI,CAAC,eAAe,gBAAgB,MAClC,QAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAC1B,SAAS,uBACV,CAAC;AAGJ,QAAM"}
|
|
@@ -1,20 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/http/middleware/error-handler.d.ts
|
|
5
|
-
/** Catch-all for unmatched routes */
|
|
6
|
-
declare function notFoundHandler(): (_req: Request, res: Response, _next: NextFunction) => void;
|
|
7
|
-
/**
|
|
8
|
-
* Global error handler.
|
|
9
|
-
*
|
|
10
|
-
* Default behavior strips error `details` from the response in production
|
|
11
|
-
* (NODE_ENV === 'production') so internal context (DB errors, validation
|
|
12
|
-
* issues, custom payloads) does not leak to clients. Apps that want to
|
|
13
|
-
* expose details in production — for client-facing field-level validation,
|
|
14
|
-
* for example — should pass their own `onError` to `bootstrap()` and decide
|
|
15
|
-
* the policy explicitly.
|
|
16
|
-
*/
|
|
17
|
-
declare function errorHandler(): (err: any, req: Request, res: Response, _next: NextFunction) => Response<any, Record<string, any>> | undefined;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { errorHandler, notFoundHandler };
|
|
20
|
-
//# sourceMappingURL=error-handler.d.mts.map
|
|
2
|
+
import { n as notFoundHandler, t as errorHandler } from "../../error-handler-Xud_3Lah.mjs";
|
|
3
|
+
export { errorHandler, notFoundHandler };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs
|
|
2
|
+
* @forinda/kickjs v4.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { createLogger } from "../../core/logger.mjs";
|
|
12
12
|
import { HttpException } from "../../core/errors.mjs";
|
|
13
|
-
import "../../core-
|
|
13
|
+
import "../../core-DBcoqPHM.mjs";
|
|
14
14
|
//#region src/http/middleware/error-handler.ts
|
|
15
15
|
const log = createLogger("ErrorHandler");
|
|
16
16
|
/** Catch-all for unmatched routes */
|
|
@@ -1,41 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/http/middleware/helmet.d.ts
|
|
5
|
-
interface HelmetOptions {
|
|
6
|
-
/** Set Content-Security-Policy header (default: self-only policy) */
|
|
7
|
-
contentSecurityPolicy?: boolean | Record<string, string[]>;
|
|
8
|
-
/** Set X-Content-Type-Options: nosniff (default: true) */
|
|
9
|
-
noSniff?: boolean;
|
|
10
|
-
/** Set X-Frame-Options (default: 'DENY') */
|
|
11
|
-
frameguard?: false | 'DENY' | 'SAMEORIGIN';
|
|
12
|
-
/** Set Strict-Transport-Security (default: max-age=31536000; includeSubDomains) */
|
|
13
|
-
hsts?: false | {
|
|
14
|
-
maxAge?: number;
|
|
15
|
-
includeSubDomains?: boolean;
|
|
16
|
-
preload?: boolean;
|
|
17
|
-
};
|
|
18
|
-
/** Set X-DNS-Prefetch-Control (default: off) */
|
|
19
|
-
dnsPrefetch?: boolean;
|
|
20
|
-
/** Remove X-Powered-By header (default: true) */
|
|
21
|
-
hidePoweredBy?: boolean;
|
|
22
|
-
/** Set Referrer-Policy (default: 'no-referrer') */
|
|
23
|
-
referrerPolicy?: false | string;
|
|
24
|
-
/** Set X-XSS-Protection: 0 (default: true — disables legacy XSS auditor) */
|
|
25
|
-
xssFilter?: boolean;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Security headers middleware. Lightweight alternative to the `helmet` npm package
|
|
29
|
-
* with sensible defaults for API servers.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* bootstrap({
|
|
34
|
-
* middleware: [helmet(), requestId(), express.json()],
|
|
35
|
-
* })
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
declare function helmet(options?: HelmetOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
39
|
-
//#endregion
|
|
40
|
-
export { HelmetOptions, helmet };
|
|
41
|
-
//# sourceMappingURL=helmet.d.mts.map
|
|
2
|
+
import { n as helmet, t as HelmetOptions } from "../../helmet-CaMbjzBG.mjs";
|
|
3
|
+
export { HelmetOptions, helmet };
|
|
@@ -1,56 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/http/middleware/rate-limit.d.ts
|
|
5
|
-
interface RateLimitStore {
|
|
6
|
-
increment(key: string): Promise<{
|
|
7
|
-
totalHits: number;
|
|
8
|
-
resetTime: Date;
|
|
9
|
-
}>;
|
|
10
|
-
decrement(key: string): Promise<void>;
|
|
11
|
-
reset(key: string): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
interface RateLimitOptions {
|
|
14
|
-
/** Maximum number of requests per window (default: 100) */
|
|
15
|
-
max?: number;
|
|
16
|
-
/** Time window in milliseconds (default: 60_000) */
|
|
17
|
-
windowMs?: number;
|
|
18
|
-
/** Response message when rate limit is exceeded (default: 'Too Many Requests') */
|
|
19
|
-
message?: string;
|
|
20
|
-
/** HTTP status code when rate limit is exceeded (default: 429) */
|
|
21
|
-
statusCode?: number;
|
|
22
|
-
/** Function to generate the key for rate limiting (default: req.ip) */
|
|
23
|
-
keyGenerator?: (req: Request) => string;
|
|
24
|
-
/** Whether to send rate limit headers (default: true) */
|
|
25
|
-
headers?: boolean;
|
|
26
|
-
/** Custom store implementation (default: in-memory Map) */
|
|
27
|
-
store?: RateLimitStore;
|
|
28
|
-
/** Function to skip rate limiting for certain requests */
|
|
29
|
-
skip?: (req: Request) => boolean;
|
|
30
|
-
/** Paths to exclude from rate limiting */
|
|
31
|
-
skipPaths?: string[];
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Rate limiting middleware.
|
|
35
|
-
*
|
|
36
|
-
* Limits the number of requests a client can make within a time window.
|
|
37
|
-
* Uses an in-memory store by default, but accepts a custom store for
|
|
38
|
-
* distributed deployments (e.g. Redis).
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* import { rateLimit } from '@forinda/kickjs-http'
|
|
43
|
-
*
|
|
44
|
-
* bootstrap({
|
|
45
|
-
* modules,
|
|
46
|
-
* middleware: [
|
|
47
|
-
* rateLimit({ max: 100, windowMs: 60_000 }),
|
|
48
|
-
* // ... other middleware
|
|
49
|
-
* ],
|
|
50
|
-
* })
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
declare function rateLimit(options?: RateLimitOptions): (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { RateLimitOptions, RateLimitStore, rateLimit };
|
|
56
|
-
//# sourceMappingURL=rate-limit.d.mts.map
|
|
2
|
+
import { n as RateLimitStore, r as rateLimit, t as RateLimitOptions } from "../../rate-limit-DUwoICtI.mjs";
|
|
3
|
+
export { RateLimitOptions, RateLimitStore, rateLimit };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs
|
|
2
|
+
* @forinda/kickjs v4.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -59,7 +59,7 @@ var MemoryStore = class {
|
|
|
59
59
|
*
|
|
60
60
|
* @example
|
|
61
61
|
* ```ts
|
|
62
|
-
* import { rateLimit } from '@forinda/kickjs
|
|
62
|
+
* import { rateLimit } from '@forinda/kickjs'
|
|
63
63
|
*
|
|
64
64
|
* bootstrap({
|
|
65
65
|
* modules,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.mjs","names":[],"sources":["../../../src/http/middleware/rate-limit.ts"],"sourcesContent":["import type { Request, Response, NextFunction } from 'express'\n\nexport interface RateLimitStore {\n increment(key: string): Promise<{ totalHits: number; resetTime: Date }>\n decrement(key: string): Promise<void>\n reset(key: string): Promise<void>\n}\n\nexport interface RateLimitOptions {\n /** Maximum number of requests per window (default: 100) */\n max?: number\n /** Time window in milliseconds (default: 60_000) */\n windowMs?: number\n /** Response message when rate limit is exceeded (default: 'Too Many Requests') */\n message?: string\n /** HTTP status code when rate limit is exceeded (default: 429) */\n statusCode?: number\n /** Function to generate the key for rate limiting (default: req.ip) */\n keyGenerator?: (req: Request) => string\n /** Whether to send rate limit headers (default: true) */\n headers?: boolean\n /** Custom store implementation (default: in-memory Map) */\n store?: RateLimitStore\n /** Function to skip rate limiting for certain requests */\n skip?: (req: Request) => boolean\n /** Paths to exclude from rate limiting */\n skipPaths?: string[]\n}\n\ninterface MemoryStoreEntry {\n totalHits: number\n resetTime: Date\n}\n\nclass MemoryStore implements RateLimitStore {\n private hits = new Map<string, MemoryStoreEntry>()\n private cleanupTimer: ReturnType<typeof setInterval>\n\n constructor(private windowMs: number) {\n this.cleanupTimer = setInterval(() => this.cleanup(), windowMs)\n // Allow the process to exit without waiting for the timer\n if (this.cleanupTimer.unref) {\n this.cleanupTimer.unref()\n }\n }\n\n async increment(key: string): Promise<{ totalHits: number; resetTime: Date }> {\n const now = Date.now()\n const entry = this.hits.get(key)\n\n if (entry && entry.resetTime.getTime() > now) {\n entry.totalHits++\n return { totalHits: entry.totalHits, resetTime: entry.resetTime }\n }\n\n const resetTime = new Date(now + this.windowMs)\n const newEntry: MemoryStoreEntry = { totalHits: 1, resetTime }\n this.hits.set(key, newEntry)\n return { totalHits: 1, resetTime }\n }\n\n async decrement(key: string): Promise<void> {\n const entry = this.hits.get(key)\n if (entry && entry.totalHits > 0) {\n entry.totalHits--\n }\n }\n\n async reset(key: string): Promise<void> {\n this.hits.delete(key)\n }\n\n private cleanup(): void {\n const now = Date.now()\n for (const [key, entry] of this.hits) {\n if (entry.resetTime.getTime() <= now) {\n this.hits.delete(key)\n }\n }\n }\n}\n\n/**\n * Rate limiting middleware.\n *\n * Limits the number of requests a client can make within a time window.\n * Uses an in-memory store by default, but accepts a custom store for\n * distributed deployments (e.g. Redis).\n *\n * @example\n * ```ts\n * import { rateLimit } from '@forinda/kickjs
|
|
1
|
+
{"version":3,"file":"rate-limit.mjs","names":[],"sources":["../../../src/http/middleware/rate-limit.ts"],"sourcesContent":["import type { Request, Response, NextFunction } from 'express'\n\nexport interface RateLimitStore {\n increment(key: string): Promise<{ totalHits: number; resetTime: Date }>\n decrement(key: string): Promise<void>\n reset(key: string): Promise<void>\n}\n\nexport interface RateLimitOptions {\n /** Maximum number of requests per window (default: 100) */\n max?: number\n /** Time window in milliseconds (default: 60_000) */\n windowMs?: number\n /** Response message when rate limit is exceeded (default: 'Too Many Requests') */\n message?: string\n /** HTTP status code when rate limit is exceeded (default: 429) */\n statusCode?: number\n /** Function to generate the key for rate limiting (default: req.ip) */\n keyGenerator?: (req: Request) => string\n /** Whether to send rate limit headers (default: true) */\n headers?: boolean\n /** Custom store implementation (default: in-memory Map) */\n store?: RateLimitStore\n /** Function to skip rate limiting for certain requests */\n skip?: (req: Request) => boolean\n /** Paths to exclude from rate limiting */\n skipPaths?: string[]\n}\n\ninterface MemoryStoreEntry {\n totalHits: number\n resetTime: Date\n}\n\nclass MemoryStore implements RateLimitStore {\n private hits = new Map<string, MemoryStoreEntry>()\n private cleanupTimer: ReturnType<typeof setInterval>\n\n constructor(private windowMs: number) {\n this.cleanupTimer = setInterval(() => this.cleanup(), windowMs)\n // Allow the process to exit without waiting for the timer\n if (this.cleanupTimer.unref) {\n this.cleanupTimer.unref()\n }\n }\n\n async increment(key: string): Promise<{ totalHits: number; resetTime: Date }> {\n const now = Date.now()\n const entry = this.hits.get(key)\n\n if (entry && entry.resetTime.getTime() > now) {\n entry.totalHits++\n return { totalHits: entry.totalHits, resetTime: entry.resetTime }\n }\n\n const resetTime = new Date(now + this.windowMs)\n const newEntry: MemoryStoreEntry = { totalHits: 1, resetTime }\n this.hits.set(key, newEntry)\n return { totalHits: 1, resetTime }\n }\n\n async decrement(key: string): Promise<void> {\n const entry = this.hits.get(key)\n if (entry && entry.totalHits > 0) {\n entry.totalHits--\n }\n }\n\n async reset(key: string): Promise<void> {\n this.hits.delete(key)\n }\n\n private cleanup(): void {\n const now = Date.now()\n for (const [key, entry] of this.hits) {\n if (entry.resetTime.getTime() <= now) {\n this.hits.delete(key)\n }\n }\n }\n}\n\n/**\n * Rate limiting middleware.\n *\n * Limits the number of requests a client can make within a time window.\n * Uses an in-memory store by default, but accepts a custom store for\n * distributed deployments (e.g. Redis).\n *\n * @example\n * ```ts\n * import { rateLimit } from '@forinda/kickjs'\n *\n * bootstrap({\n * modules,\n * middleware: [\n * rateLimit({ max: 100, windowMs: 60_000 }),\n * // ... other middleware\n * ],\n * })\n * ```\n */\nexport function rateLimit(options: RateLimitOptions = {}) {\n const max = options.max ?? 100\n const windowMs = options.windowMs ?? 60_000\n const message = options.message ?? 'Too Many Requests'\n const statusCode = options.statusCode ?? 429\n const keyGenerator = options.keyGenerator ?? ((req: Request) => req.ip ?? '127.0.0.1')\n const sendHeaders = options.headers ?? true\n const store = options.store ?? new MemoryStore(windowMs)\n const skip = options.skip\n const skipPaths = new Set(options.skipPaths ?? [])\n\n return async (req: Request, res: Response, next: NextFunction) => {\n // Skip if path is in the skip list\n if (skipPaths.has(req.path)) {\n return next()\n }\n\n // Skip if the skip function returns true\n if (skip && skip(req)) {\n return next()\n }\n\n const key = keyGenerator(req)\n const { totalHits, resetTime } = await store.increment(key)\n const remaining = Math.max(0, max - totalHits)\n\n if (sendHeaders) {\n res.setHeader('RateLimit-Limit', max)\n res.setHeader('RateLimit-Remaining', remaining)\n res.setHeader('RateLimit-Reset', Math.ceil(resetTime.getTime() / 1000))\n }\n\n if (totalHits > max) {\n return res.status(statusCode).json({ message })\n }\n\n next()\n }\n}\n"],"mappings":";;;;;;;;;;;AAkCA,IAAM,cAAN,MAA4C;CAC1C,uBAAe,IAAI,KAA+B;CAClD;CAEA,YAAY,UAA0B;AAAlB,OAAA,WAAA;AAClB,OAAK,eAAe,kBAAkB,KAAK,SAAS,EAAE,SAAS;AAE/D,MAAI,KAAK,aAAa,MACpB,MAAK,aAAa,OAAO;;CAI7B,MAAM,UAAU,KAA8D;EAC5E,MAAM,MAAM,KAAK,KAAK;EACtB,MAAM,QAAQ,KAAK,KAAK,IAAI,IAAI;AAEhC,MAAI,SAAS,MAAM,UAAU,SAAS,GAAG,KAAK;AAC5C,SAAM;AACN,UAAO;IAAE,WAAW,MAAM;IAAW,WAAW,MAAM;IAAW;;EAGnE,MAAM,YAAY,IAAI,KAAK,MAAM,KAAK,SAAS;EAC/C,MAAM,WAA6B;GAAE,WAAW;GAAG;GAAW;AAC9D,OAAK,KAAK,IAAI,KAAK,SAAS;AAC5B,SAAO;GAAE,WAAW;GAAG;GAAW;;CAGpC,MAAM,UAAU,KAA4B;EAC1C,MAAM,QAAQ,KAAK,KAAK,IAAI,IAAI;AAChC,MAAI,SAAS,MAAM,YAAY,EAC7B,OAAM;;CAIV,MAAM,MAAM,KAA4B;AACtC,OAAK,KAAK,OAAO,IAAI;;CAGvB,UAAwB;EACtB,MAAM,MAAM,KAAK,KAAK;AACtB,OAAK,MAAM,CAAC,KAAK,UAAU,KAAK,KAC9B,KAAI,MAAM,UAAU,SAAS,IAAI,IAC/B,MAAK,KAAK,OAAO,IAAI;;;;;;;;;;;;;;;;;;;;;;;AA0B7B,SAAgB,UAAU,UAA4B,EAAE,EAAE;CACxD,MAAM,MAAM,QAAQ,OAAO;CAC3B,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,eAAe,QAAQ,kBAAkB,QAAiB,IAAI,MAAM;CAC1E,MAAM,cAAc,QAAQ,WAAW;CACvC,MAAM,QAAQ,QAAQ,SAAS,IAAI,YAAY,SAAS;CACxD,MAAM,OAAO,QAAQ;CACrB,MAAM,YAAY,IAAI,IAAI,QAAQ,aAAa,EAAE,CAAC;AAElD,QAAO,OAAO,KAAc,KAAe,SAAuB;AAEhE,MAAI,UAAU,IAAI,IAAI,KAAK,CACzB,QAAO,MAAM;AAIf,MAAI,QAAQ,KAAK,IAAI,CACnB,QAAO,MAAM;EAGf,MAAM,MAAM,aAAa,IAAI;EAC7B,MAAM,EAAE,WAAW,cAAc,MAAM,MAAM,UAAU,IAAI;EAC3D,MAAM,YAAY,KAAK,IAAI,GAAG,MAAM,UAAU;AAE9C,MAAI,aAAa;AACf,OAAI,UAAU,mBAAmB,IAAI;AACrC,OAAI,UAAU,uBAAuB,UAAU;AAC/C,OAAI,UAAU,mBAAmB,KAAK,KAAK,UAAU,SAAS,GAAG,IAAK,CAAC;;AAGzE,MAAI,YAAY,IACd,QAAO,IAAI,OAAO,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC;AAGjD,QAAM"}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/http/middleware/request-id.d.ts
|
|
5
|
-
declare const REQUEST_ID_HEADER = "x-request-id";
|
|
6
|
-
/** Middleware that generates or propagates a unique request ID */
|
|
7
|
-
declare function requestId(): (req: Request, res: Response, next: NextFunction) => void;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { REQUEST_ID_HEADER, requestId };
|
|
10
|
-
//# sourceMappingURL=request-id.d.mts.map
|
|
2
|
+
import { n as requestId, t as REQUEST_ID_HEADER } from "../../request-id-BgglvZHN.mjs";
|
|
3
|
+
export { REQUEST_ID_HEADER, requestId };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs
|
|
2
|
+
* @forinda/kickjs v4.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -11,10 +11,19 @@
|
|
|
11
11
|
import { randomUUID } from "node:crypto";
|
|
12
12
|
//#region src/http/middleware/request-id.ts
|
|
13
13
|
const REQUEST_ID_HEADER = "x-request-id";
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Middleware that generates or propagates a unique request ID.
|
|
16
|
+
*
|
|
17
|
+
* Idempotent: if `req.requestId` is already set (e.g. by
|
|
18
|
+
* `requestScopeMiddleware` earlier in the pipeline), this middleware reuses
|
|
19
|
+
* it instead of generating a divergent second value. Keeps the
|
|
20
|
+
* X-Request-Id response header, the ALS store's `requestId`, and
|
|
21
|
+
* `RequestContext.requestId` in agreement for every request, regardless of
|
|
22
|
+
* mounting order.
|
|
23
|
+
*/
|
|
15
24
|
function requestId() {
|
|
16
25
|
return (req, res, next) => {
|
|
17
|
-
const id = req.headers["x-request-id"] || randomUUID();
|
|
26
|
+
const id = req.requestId || req.headers["x-request-id"] || randomUUID();
|
|
18
27
|
req.requestId = id;
|
|
19
28
|
res.setHeader(REQUEST_ID_HEADER, id);
|
|
20
29
|
next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-id.mjs","names":[],"sources":["../../../src/http/middleware/request-id.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\nimport type { Request, Response, NextFunction } from 'express'\n\nexport const REQUEST_ID_HEADER = 'x-request-id'\n\n
|
|
1
|
+
{"version":3,"file":"request-id.mjs","names":[],"sources":["../../../src/http/middleware/request-id.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\nimport type { Request, Response, NextFunction } from 'express'\n\nexport const REQUEST_ID_HEADER = 'x-request-id'\n\n/**\n * Middleware that generates or propagates a unique request ID.\n *\n * Idempotent: if `req.requestId` is already set (e.g. by\n * `requestScopeMiddleware` earlier in the pipeline), this middleware reuses\n * it instead of generating a divergent second value. Keeps the\n * X-Request-Id response header, the ALS store's `requestId`, and\n * `RequestContext.requestId` in agreement for every request, regardless of\n * mounting order.\n */\nexport function requestId() {\n return (req: Request, res: Response, next: NextFunction) => {\n const existing = (req as Request & { requestId?: string }).requestId\n const id = existing || (req.headers[REQUEST_ID_HEADER] as string) || randomUUID()\n ;(req as any).requestId = id\n res.setHeader(REQUEST_ID_HEADER, id)\n next()\n }\n}\n"],"mappings":";;;;;;;;;;;;AAGA,MAAa,oBAAoB;;;;;;;;;;;AAYjC,SAAgB,YAAY;AAC1B,SAAQ,KAAc,KAAe,SAAuB;EAE1D,MAAM,KADY,IAAyC,aACnC,IAAI,QAAA,mBAAyC,YAAY;AAC/E,MAAY,YAAY;AAC1B,MAAI,UAAU,mBAAmB,GAAG;AACpC,QAAM"}
|
|
@@ -1,32 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/http/middleware/request-logger.d.ts
|
|
5
|
-
interface RequestLoggerOptions {
|
|
6
|
-
/** Logger name (default: 'HTTP') */
|
|
7
|
-
name?: string;
|
|
8
|
-
/** Log level for successful requests (default: 'info') */
|
|
9
|
-
level?: 'info' | 'debug' | 'trace';
|
|
10
|
-
/** Skip logging for paths matching these prefixes (e.g. ['/health', '/_debug']) */
|
|
11
|
-
skip?: string[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Middleware that logs every request with method, URL, status, duration, and request ID.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* bootstrap({
|
|
19
|
-
* middleware: [requestId(), requestLogger(), express.json()],
|
|
20
|
-
* })
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* Output:
|
|
24
|
-
* ```
|
|
25
|
-
* [HTTP] GET /api/v1/users 200 12ms req-abc123
|
|
26
|
-
* [HTTP] POST /api/v1/users 201 45ms req-def456
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare function requestLogger(options?: RequestLoggerOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
30
|
-
//#endregion
|
|
31
|
-
export { RequestLoggerOptions, requestLogger };
|
|
32
|
-
//# sourceMappingURL=request-logger.d.mts.map
|
|
2
|
+
import { n as requestLogger, t as RequestLoggerOptions } from "../../request-logger-CWHbAzTE.mjs";
|
|
3
|
+
export { RequestLoggerOptions, requestLogger };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs
|
|
2
|
+
* @forinda/kickjs v4.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import { createLogger } from "../../core/logger.mjs";
|
|
12
|
-
import "../../core-
|
|
12
|
+
import "../../core-DBcoqPHM.mjs";
|
|
13
13
|
//#region src/http/middleware/request-logger.ts
|
|
14
14
|
/**
|
|
15
15
|
* Middleware that logs every request with method, URL, status, duration, and request ID.
|
|
@@ -1,70 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/http/middleware/session.d.ts
|
|
5
|
-
interface SessionData {
|
|
6
|
-
[key: string]: unknown;
|
|
7
|
-
}
|
|
8
|
-
interface SessionStore {
|
|
9
|
-
get(sid: string): Promise<SessionData | null>;
|
|
10
|
-
set(sid: string, data: SessionData, maxAge: number): Promise<void>;
|
|
11
|
-
destroy(sid: string): Promise<void>;
|
|
12
|
-
touch?(sid: string, maxAge: number): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
interface Session {
|
|
15
|
-
id: string;
|
|
16
|
-
data: SessionData;
|
|
17
|
-
regenerate(): Promise<void>;
|
|
18
|
-
destroy(): Promise<void>;
|
|
19
|
-
save(): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
interface SessionOptions {
|
|
22
|
-
/** Secret used to sign the session cookie (required) */
|
|
23
|
-
secret: string;
|
|
24
|
-
/** Cookie name (default: 'kick.sid') */
|
|
25
|
-
cookieName?: string;
|
|
26
|
-
/** Session max age in milliseconds (default: 86400000 = 24h) */
|
|
27
|
-
maxAge?: number;
|
|
28
|
-
/** Reset maxAge on every response (default: false) */
|
|
29
|
-
rolling?: boolean;
|
|
30
|
-
/** Save new sessions that have not been modified (default: true) */
|
|
31
|
-
saveUninitialized?: boolean;
|
|
32
|
-
/** Cookie options */
|
|
33
|
-
cookie?: {
|
|
34
|
-
httpOnly?: boolean;
|
|
35
|
-
secure?: boolean;
|
|
36
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
37
|
-
path?: string;
|
|
38
|
-
domain?: string;
|
|
39
|
-
};
|
|
40
|
-
/** Custom session store (default: in-memory store with TTL cleanup) */
|
|
41
|
-
store?: SessionStore;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Session management middleware.
|
|
45
|
-
*
|
|
46
|
-
* Attaches a `req.session` object with `id`, `data`, `regenerate()`,
|
|
47
|
-
* `destroy()`, and `save()` methods. Session IDs are signed with
|
|
48
|
-
* HMAC-SHA256 to prevent cookie tampering.
|
|
49
|
-
*
|
|
50
|
-
* Reads the session cookie from `req.cookies` when an upstream cookie
|
|
51
|
-
* parser is present; otherwise parses `req.headers.cookie` directly, so
|
|
52
|
-
* no cookie parser is required upstream.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* import { session } from '@forinda/kickjs'
|
|
57
|
-
*
|
|
58
|
-
* bootstrap({
|
|
59
|
-
* modules,
|
|
60
|
-
* middleware: [
|
|
61
|
-
* session({ secret: process.env.SESSION_SECRET! }),
|
|
62
|
-
* // ... other middleware
|
|
63
|
-
* ],
|
|
64
|
-
* })
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
declare function session(options: SessionOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
68
|
-
//#endregion
|
|
69
|
-
export { Session, SessionData, SessionOptions, SessionStore, session };
|
|
70
|
-
//# sourceMappingURL=session.d.mts.map
|
|
2
|
+
import { a as session, i as SessionStore, n as SessionData, r as SessionOptions, t as Session } from "../../session-N0hActOO.mjs";
|
|
3
|
+
export { Session, SessionData, SessionOptions, SessionStore, session };
|
|
@@ -1,101 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
interface SpaAdapterOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Directory containing the built SPA files (index.html, assets, etc.)
|
|
7
|
-
* Default: 'dist/client'
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* // Vue: 'dist'
|
|
12
|
-
* // React (Vite): 'dist'
|
|
13
|
-
* // React (CRA): 'build'
|
|
14
|
-
* // Svelte: 'build'
|
|
15
|
-
* // Angular: 'dist/my-app/browser'
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
clientDir?: string;
|
|
19
|
-
/**
|
|
20
|
-
* URL prefix for API routes. SPA fallback only applies to
|
|
21
|
-
* non-API routes (routes NOT starting with this prefix).
|
|
22
|
-
* Default: '/api'
|
|
23
|
-
*
|
|
24
|
-
* Set to an array for multiple prefixes:
|
|
25
|
-
* ```ts
|
|
26
|
-
* apiPrefix: ['/api', '/graphql', '/_debug']
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
apiPrefix?: string | string[];
|
|
30
|
-
/**
|
|
31
|
-
* Additional paths to exclude from SPA fallback.
|
|
32
|
-
* These paths will NOT serve index.html.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* exclude: ['/health', '/metrics', '/ws']
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
exclude?: string[];
|
|
40
|
-
/**
|
|
41
|
-
* Cache-Control header for static assets (default: 'public, max-age=31536000, immutable')
|
|
42
|
-
* Set to false to disable caching headers.
|
|
43
|
-
*/
|
|
44
|
-
cacheControl?: string | false;
|
|
45
|
-
/**
|
|
46
|
-
* Cache-Control for index.html (default: 'no-cache')
|
|
47
|
-
* index.html should not be cached to ensure clients get fresh builds.
|
|
48
|
-
*/
|
|
49
|
-
indexCacheControl?: string;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* SPA adapter — serve a Vue, React, Svelte, or Angular build alongside
|
|
53
|
-
* your KickJS API. API routes are handled by controllers; everything else
|
|
54
|
-
* falls back to index.html for client-side routing.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* import { SpaAdapter } from '@forinda/kickjs-http/spa'
|
|
59
|
-
*
|
|
60
|
-
* bootstrap({
|
|
61
|
-
* modules,
|
|
62
|
-
* adapters: [
|
|
63
|
-
* new SpaAdapter({
|
|
64
|
-
* clientDir: 'dist/client', // or 'build', 'dist', etc.
|
|
65
|
-
* apiPrefix: '/api',
|
|
66
|
-
* }),
|
|
67
|
-
* ],
|
|
68
|
-
* })
|
|
69
|
-
* ```
|
|
70
|
-
*
|
|
71
|
-
* File structure:
|
|
72
|
-
* ```
|
|
73
|
-
* dist/
|
|
74
|
-
* client/ ← SPA build output
|
|
75
|
-
* index.html
|
|
76
|
-
* assets/
|
|
77
|
-
* app.js
|
|
78
|
-
* style.css
|
|
79
|
-
* server/ ← KickJS server
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
declare class SpaAdapter implements AppAdapter {
|
|
83
|
-
private options;
|
|
84
|
-
name: string;
|
|
85
|
-
private clientDir;
|
|
86
|
-
private apiPrefixes;
|
|
87
|
-
private excludePaths;
|
|
88
|
-
private cacheControl;
|
|
89
|
-
private indexCacheControl;
|
|
90
|
-
private indexHtml;
|
|
91
|
-
constructor(options?: SpaAdapterOptions);
|
|
92
|
-
beforeMount({
|
|
93
|
-
app
|
|
94
|
-
}: AdapterContext): void;
|
|
95
|
-
beforeStart({
|
|
96
|
-
app
|
|
97
|
-
}: AdapterContext): void;
|
|
98
|
-
}
|
|
99
|
-
//#endregion
|
|
100
|
-
export { SpaAdapter, SpaAdapterOptions };
|
|
101
|
-
//# sourceMappingURL=spa.d.mts.map
|
|
2
|
+
import { n as SpaAdapterOptions, t as SpaAdapter } from "../../spa-CrFR2_cz.mjs";
|
|
3
|
+
export { SpaAdapter, SpaAdapterOptions };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs
|
|
2
|
+
* @forinda/kickjs v4.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import { p as __require } from "../../container-DYYSu58w.mjs";
|
|
12
12
|
import { Logger } from "../../core/logger.mjs";
|
|
13
|
-
import "../../core-
|
|
14
|
-
import { join, resolve } from "node:path";
|
|
13
|
+
import "../../core-DBcoqPHM.mjs";
|
|
15
14
|
import { existsSync, readFileSync } from "node:fs";
|
|
15
|
+
import { join, resolve } from "node:path";
|
|
16
16
|
//#region src/http/middleware/spa.ts
|
|
17
17
|
const log = Logger.for("SpaAdapter");
|
|
18
18
|
/**
|
|
@@ -22,7 +22,7 @@ const log = Logger.for("SpaAdapter");
|
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* ```ts
|
|
25
|
-
* import { SpaAdapter } from '@forinda/kickjs
|
|
25
|
+
* import { SpaAdapter } from '@forinda/kickjs/spa'
|
|
26
26
|
*
|
|
27
27
|
* bootstrap({
|
|
28
28
|
* modules,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spa.mjs","names":[],"sources":["../../../src/http/middleware/spa.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { resolve, join } from 'node:path'\nimport { Logger, type AppAdapter, type AdapterContext } from '../../core'\n\nconst log = Logger.for('SpaAdapter')\n\nexport interface SpaAdapterOptions {\n /**\n * Directory containing the built SPA files (index.html, assets, etc.)\n * Default: 'dist/client'\n *\n * @example\n * ```ts\n * // Vue: 'dist'\n * // React (Vite): 'dist'\n * // React (CRA): 'build'\n * // Svelte: 'build'\n * // Angular: 'dist/my-app/browser'\n * ```\n */\n clientDir?: string\n\n /**\n * URL prefix for API routes. SPA fallback only applies to\n * non-API routes (routes NOT starting with this prefix).\n * Default: '/api'\n *\n * Set to an array for multiple prefixes:\n * ```ts\n * apiPrefix: ['/api', '/graphql', '/_debug']\n * ```\n */\n apiPrefix?: string | string[]\n\n /**\n * Additional paths to exclude from SPA fallback.\n * These paths will NOT serve index.html.\n *\n * @example\n * ```ts\n * exclude: ['/health', '/metrics', '/ws']\n * ```\n */\n exclude?: string[]\n\n /**\n * Cache-Control header for static assets (default: 'public, max-age=31536000, immutable')\n * Set to false to disable caching headers.\n */\n cacheControl?: string | false\n\n /**\n * Cache-Control for index.html (default: 'no-cache')\n * index.html should not be cached to ensure clients get fresh builds.\n */\n indexCacheControl?: string\n}\n\n/**\n * SPA adapter — serve a Vue, React, Svelte, or Angular build alongside\n * your KickJS API. API routes are handled by controllers; everything else\n * falls back to index.html for client-side routing.\n *\n * @example\n * ```ts\n * import { SpaAdapter } from '@forinda/kickjs
|
|
1
|
+
{"version":3,"file":"spa.mjs","names":[],"sources":["../../../src/http/middleware/spa.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { resolve, join } from 'node:path'\nimport { Logger, type AppAdapter, type AdapterContext } from '../../core'\n\nconst log = Logger.for('SpaAdapter')\n\nexport interface SpaAdapterOptions {\n /**\n * Directory containing the built SPA files (index.html, assets, etc.)\n * Default: 'dist/client'\n *\n * @example\n * ```ts\n * // Vue: 'dist'\n * // React (Vite): 'dist'\n * // React (CRA): 'build'\n * // Svelte: 'build'\n * // Angular: 'dist/my-app/browser'\n * ```\n */\n clientDir?: string\n\n /**\n * URL prefix for API routes. SPA fallback only applies to\n * non-API routes (routes NOT starting with this prefix).\n * Default: '/api'\n *\n * Set to an array for multiple prefixes:\n * ```ts\n * apiPrefix: ['/api', '/graphql', '/_debug']\n * ```\n */\n apiPrefix?: string | string[]\n\n /**\n * Additional paths to exclude from SPA fallback.\n * These paths will NOT serve index.html.\n *\n * @example\n * ```ts\n * exclude: ['/health', '/metrics', '/ws']\n * ```\n */\n exclude?: string[]\n\n /**\n * Cache-Control header for static assets (default: 'public, max-age=31536000, immutable')\n * Set to false to disable caching headers.\n */\n cacheControl?: string | false\n\n /**\n * Cache-Control for index.html (default: 'no-cache')\n * index.html should not be cached to ensure clients get fresh builds.\n */\n indexCacheControl?: string\n}\n\n/**\n * SPA adapter — serve a Vue, React, Svelte, or Angular build alongside\n * your KickJS API. API routes are handled by controllers; everything else\n * falls back to index.html for client-side routing.\n *\n * @example\n * ```ts\n * import { SpaAdapter } from '@forinda/kickjs/spa'\n *\n * bootstrap({\n * modules,\n * adapters: [\n * new SpaAdapter({\n * clientDir: 'dist/client', // or 'build', 'dist', etc.\n * apiPrefix: '/api',\n * }),\n * ],\n * })\n * ```\n *\n * File structure:\n * ```\n * dist/\n * client/ ← SPA build output\n * index.html\n * assets/\n * app.js\n * style.css\n * server/ ← KickJS server\n * ```\n */\nexport class SpaAdapter implements AppAdapter {\n name = 'SpaAdapter'\n private clientDir: string\n private apiPrefixes: string[]\n private excludePaths: string[]\n private cacheControl: string | false\n private indexCacheControl: string\n private indexHtml: string | null = null\n\n constructor(private options: SpaAdapterOptions = {}) {\n this.clientDir = resolve(options.clientDir ?? 'dist/client')\n this.excludePaths = options.exclude ?? []\n this.cacheControl = options.cacheControl ?? 'public, max-age=31536000, immutable'\n this.indexCacheControl = options.indexCacheControl ?? 'no-cache'\n\n const prefix = options.apiPrefix ?? '/api'\n this.apiPrefixes = Array.isArray(prefix) ? prefix : [prefix]\n }\n\n beforeMount({ app }: AdapterContext): void {\n if (!existsSync(this.clientDir)) {\n log.warn(`SPA client directory not found: ${this.clientDir}`)\n log.warn('Build your frontend first, or set clientDir to the correct path.')\n return\n }\n\n // Read index.html into memory\n const indexPath = join(this.clientDir, 'index.html')\n if (existsSync(indexPath)) {\n this.indexHtml = readFileSync(indexPath, 'utf-8')\n } else {\n log.warn(`index.html not found in ${this.clientDir}`)\n return\n }\n\n // Serve static files with cache headers\n try {\n // Dynamic import to avoid hard dependency on express.static\n const express = require('express')\n const staticOpts: any = {}\n\n if (this.cacheControl) {\n staticOpts.setHeaders = (res: any, filePath: string) => {\n if (filePath.endsWith('.html')) {\n res.setHeader('Cache-Control', this.indexCacheControl)\n } else {\n res.setHeader('Cache-Control', this.cacheControl as string)\n }\n }\n }\n\n app.use(express.static(this.clientDir, staticOpts))\n } catch {\n log.error('express.static not available — SPA static file serving disabled')\n return\n }\n\n log.debug(`Serving SPA from ${this.clientDir}`)\n }\n\n beforeStart({ app }: AdapterContext): void {\n if (!this.indexHtml) return\n\n // SPA fallback: serve index.html for all non-API, non-file routes\n app.use((req: any, res: any, next: any) => {\n // Skip API routes\n for (const prefix of this.apiPrefixes) {\n if (req.path.startsWith(prefix)) return next()\n }\n\n // Skip excluded paths\n for (const path of this.excludePaths) {\n if (req.path.startsWith(path)) return next()\n }\n\n // Skip requests for files (have an extension)\n if (req.path.includes('.')) return next()\n\n // Skip non-GET requests\n if (req.method !== 'GET') return next()\n\n // Serve index.html\n res.setHeader('Content-Type', 'text/html')\n res.setHeader('Cache-Control', this.indexCacheControl)\n res.send(this.indexHtml)\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAIA,MAAM,MAAM,OAAO,IAAI,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFpC,IAAa,aAAb,MAA8C;CAC5C,OAAO;CACP;CACA;CACA;CACA;CACA;CACA,YAAmC;CAEnC,YAAY,UAAqC,EAAE,EAAE;AAAjC,OAAA,UAAA;AAClB,OAAK,YAAY,QAAQ,QAAQ,aAAa,cAAc;AAC5D,OAAK,eAAe,QAAQ,WAAW,EAAE;AACzC,OAAK,eAAe,QAAQ,gBAAgB;AAC5C,OAAK,oBAAoB,QAAQ,qBAAqB;EAEtD,MAAM,SAAS,QAAQ,aAAa;AACpC,OAAK,cAAc,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO;;CAG9D,YAAY,EAAE,OAA6B;AACzC,MAAI,CAAC,WAAW,KAAK,UAAU,EAAE;AAC/B,OAAI,KAAK,mCAAmC,KAAK,YAAY;AAC7D,OAAI,KAAK,mEAAmE;AAC5E;;EAIF,MAAM,YAAY,KAAK,KAAK,WAAW,aAAa;AACpD,MAAI,WAAW,UAAU,CACvB,MAAK,YAAY,aAAa,WAAW,QAAQ;OAC5C;AACL,OAAI,KAAK,2BAA2B,KAAK,YAAY;AACrD;;AAIF,MAAI;GAEF,MAAM,UAAA,UAAkB,UAAU;GAClC,MAAM,aAAkB,EAAE;AAE1B,OAAI,KAAK,aACP,YAAW,cAAc,KAAU,aAAqB;AACtD,QAAI,SAAS,SAAS,QAAQ,CAC5B,KAAI,UAAU,iBAAiB,KAAK,kBAAkB;QAEtD,KAAI,UAAU,iBAAiB,KAAK,aAAuB;;AAKjE,OAAI,IAAI,QAAQ,OAAO,KAAK,WAAW,WAAW,CAAC;UAC7C;AACN,OAAI,MAAM,kEAAkE;AAC5E;;AAGF,MAAI,MAAM,oBAAoB,KAAK,YAAY;;CAGjD,YAAY,EAAE,OAA6B;AACzC,MAAI,CAAC,KAAK,UAAW;AAGrB,MAAI,KAAK,KAAU,KAAU,SAAc;AAEzC,QAAK,MAAM,UAAU,KAAK,YACxB,KAAI,IAAI,KAAK,WAAW,OAAO,CAAE,QAAO,MAAM;AAIhD,QAAK,MAAM,QAAQ,KAAK,aACtB,KAAI,IAAI,KAAK,WAAW,KAAK,CAAE,QAAO,MAAM;AAI9C,OAAI,IAAI,KAAK,SAAS,IAAI,CAAE,QAAO,MAAM;AAGzC,OAAI,IAAI,WAAW,MAAO,QAAO,MAAM;AAGvC,OAAI,UAAU,gBAAgB,YAAY;AAC1C,OAAI,UAAU,iBAAiB,KAAK,kBAAkB;AACtD,OAAI,KAAK,KAAK,UAAU;IACxB"}
|