cpeak 2.4.3 → 2.6.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 +265 -39
- package/dist/index.d.ts +75 -16
- package/dist/index.js +515 -169
- package/dist/index.js.map +1 -1
- package/lib/index.ts +262 -217
- package/lib/types.ts +12 -10
- package/lib/utils/auth.ts +170 -0
- package/lib/utils/cookieParser.ts +189 -0
- package/lib/utils/index.ts +16 -1
- package/lib/utils/parseJSON.ts +77 -24
- package/lib/utils/serveStatic.ts +16 -5
- package/lib/utils/swagger.ts +31 -0
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/index.ts","../lib/utils/serveStatic.ts","../lib/utils/parseJSON.ts","../lib/utils/render.ts"],"sourcesContent":["import http from \"node:http\";\nimport fs from \"node:fs/promises\";\nimport { createReadStream } from \"node:fs\";\nimport { pipeline } from \"node:stream/promises\";\n\nimport type {\n StringMap,\n CpeakRequest,\n CpeakResponse,\n Middleware,\n RouteMiddleware,\n Handler,\n RoutesMap,\n} from \"./types\";\n\n// A utility function to create an error with a custom stack trace\nexport function frameworkError(\n message: string,\n skipFn: Function,\n code?: string\n) {\n const err = new Error(message) as Error & { code?: string };\n Error.captureStackTrace(err, skipFn);\n\n if (code) err.code = code;\n\n return err;\n}\n\nexport enum ErrorCode {\n MISSING_MIME = \"CPEAK_ERR_MISSING_MIME\",\n FILE_NOT_FOUND = \"CPEAK_ERR_FILE_NOT_FOUND\",\n NOT_A_FILE = \"CPEAK_ERR_NOT_A_FILE\",\n SEND_FILE_FAIL = \"CPEAK_ERR_SEND_FILE_FAIL\",\n}\n\nclass Cpeak {\n private server: http.Server;\n private routes: RoutesMap;\n private middleware: Middleware[];\n private _handleErr?: (\n err: unknown,\n req: CpeakRequest,\n res: CpeakResponse\n ) => void;\n\n constructor() {\n this.server = http.createServer();\n this.routes = {};\n this.middleware = [];\n\n this.server.on(\"request\", (req: CpeakRequest, res: CpeakResponse) => {\n // Send a file back to the client\n res.sendFile = async (path: string, mime: string) => {\n if (!mime) {\n throw frameworkError(\n 'MIME type is missing. Use res.sendFile(path, \"mime-type\").',\n res.sendFile,\n ErrorCode.MISSING_MIME\n );\n }\n\n try {\n const stat = await fs.stat(path);\n if (!stat.isFile()) {\n throw frameworkError(\n `Not a file: ${path}`,\n res.sendFile,\n ErrorCode.NOT_A_FILE\n );\n }\n\n res.setHeader(\"Content-Type\", mime);\n res.setHeader(\"Content-Length\", String(stat.size));\n\n // Properly propagate stream errors and respect backpressure\n await pipeline(createReadStream(path), res);\n } catch (err: any) {\n if (err?.code === \"ENOENT\") {\n throw frameworkError(\n `File not found: ${path}`,\n res.sendFile,\n ErrorCode.FILE_NOT_FOUND\n );\n }\n\n throw frameworkError(\n `Failed to send file: ${path}`,\n res.sendFile,\n ErrorCode.SEND_FILE_FAIL\n );\n }\n };\n\n // Set the status code of the response\n res.status = (code: number) => {\n res.statusCode = code;\n return res;\n };\n\n // Redirects to a new URL\n res.redirect = (location: string) => {\n res.writeHead(302, { Location: location });\n res.end();\n return res;\n };\n\n // Send a json data back to the client (for small json data, less than the highWaterMark)\n res.json = (data: any) => {\n // This is only good for bodies that their size is less than the highWaterMark value\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify(data));\n };\n\n // Get the url without the URL parameters\n const urlWithoutParams = req.url?.split(\"?\")[0];\n\n // Parse the URL parameters (like /users?key1=value1&key2=value2)\n // We put this here to also parse them for all the middleware functions\n const params = new URLSearchParams(req.url?.split(\"?\")[1]);\n\n const paramsObject = Object.fromEntries(params.entries());\n\n req.params = paramsObject;\n req.query = paramsObject; // only for compatibility with frameworks built for express\n\n // Run all the specific middleware functions for that router only and then run the handler\n const runHandler = (\n req: CpeakRequest,\n res: CpeakResponse,\n middleware: RouteMiddleware[],\n cb: Handler,\n index: number\n ) => {\n // Our exit point...\n if (index === middleware.length) {\n // Call the route handler with the modified req and res objects.\n // Also handle the promise errors by passing them to the handleErr to save developers from having to manually wrap every handler in try catch.\n try {\n const handlerResult = cb(req, res, (error) => {\n res.setHeader(\"Connection\", \"close\");\n this._handleErr?.(error, req, res);\n });\n\n if (handlerResult && typeof handlerResult.then === \"function\") {\n handlerResult.catch((error) => {\n res.setHeader(\"Connection\", \"close\");\n this._handleErr?.(error, req, res);\n });\n }\n\n return handlerResult;\n } catch (error) {\n res.setHeader(\"Connection\", \"close\");\n this._handleErr?.(error, req, res);\n }\n } else {\n // Handle the promise errors by passing them to the handleErr to save developers from having to manually wrap every handler middleware in try catch.\n try {\n const middlewareResult = middleware[index](\n req,\n res,\n // The next function\n (error) => {\n // this function only accepts an error argument to be more compatible with NPM modules that are built for express\n if (error) {\n res.setHeader(\"Connection\", \"close\");\n return this._handleErr?.(error, req, res);\n }\n runHandler(req, res, middleware, cb, index + 1);\n },\n // Error handler for a route middleware\n (error) => {\n res.setHeader(\"Connection\", \"close\");\n this._handleErr?.(error, req, res);\n }\n );\n\n // If the middleware is async, handle the promise rejection\n if (\n middlewareResult &&\n typeof middlewareResult.then === \"function\"\n ) {\n middlewareResult.catch((error) => {\n res.setHeader(\"Connection\", \"close\");\n this._handleErr?.(error, req, res);\n });\n }\n } catch (error) {\n res.setHeader(\"Connection\", \"close\");\n this._handleErr?.(error, req, res);\n }\n }\n };\n\n // Run all the middleware functions (beforeEach functions) before we run the corresponding route\n const runMiddleware = (\n req: CpeakRequest,\n res: CpeakResponse,\n middleware: Middleware[],\n index: number\n ) => {\n // Our exit point...\n if (index === middleware.length) {\n const routes = this.routes[req.method?.toLowerCase() || \"\"];\n if (routes && typeof routes[Symbol.iterator] === \"function\")\n for (const route of routes) {\n const match = urlWithoutParams?.match(route.regex);\n\n if (match) {\n // Parse the URL variables from the matched route (like /users/:id)\n const vars = this.#extractVars(route.path, match);\n req.vars = vars;\n\n return runHandler(req, res, route.middleware, route.cb, 0);\n }\n }\n\n // If the requested route dose not exist, return 404\n return res\n .status(404)\n .json({ error: `Cannot ${req.method} ${urlWithoutParams}` });\n } else {\n middleware[index](req, res, () => {\n runMiddleware(req, res, middleware, index + 1);\n });\n }\n };\n\n runMiddleware(req, res, this.middleware, 0);\n });\n }\n\n route(method: string, path: string, ...args: (RouteMiddleware | Handler)[]) {\n if (!this.routes[method]) this.routes[method] = [];\n\n // The last argument should always be our handler\n const cb = args.pop() as Handler;\n\n if (!cb || typeof cb !== \"function\") {\n throw new Error(\"Route definition must include a handler\");\n }\n\n // Rest will be our middleware functions\n const middleware = args.flat() as RouteMiddleware[];\n\n const regex = this.#pathToRegex(path);\n this.routes[method].push({ path, regex, middleware, cb });\n }\n\n beforeEach(cb: Middleware) {\n this.middleware.push(cb);\n }\n\n handleErr(cb: (err: unknown, req: CpeakRequest, res: CpeakResponse) => void) {\n this._handleErr = cb;\n }\n\n listen(port: number, cb?: () => void) {\n return this.server.listen(port, cb);\n }\n\n close(cb?: (err?: Error) => void) {\n this.server.close(cb);\n }\n\n // ------------------------------\n // PRIVATE METHODS:\n // ------------------------------\n #pathToRegex(path: string) {\n const varNames: string[] = [];\n const regexString =\n \"^\" +\n path.replace(/:\\w+/g, (match, offset) => {\n varNames.push(match.slice(1));\n return \"([^/]+)\";\n }) +\n \"$\";\n\n const regex = new RegExp(regexString);\n return regex;\n }\n\n #extractVars(path: string, match: RegExpMatchArray) {\n // Extract url variable values from the matched route\n const varNames = (path.match(/:\\w+/g) || []).map((varParam) =>\n varParam.slice(1)\n );\n const vars: StringMap = {};\n varNames.forEach((name, index) => {\n vars[name] = match[index + 1];\n });\n return vars;\n }\n}\n\n// Util functions\nexport { serveStatic } from \"./utils/serveStatic.js\";\nexport { parseJSON } from \"./utils/parseJSON.js\";\nexport { render } from \"./utils/render.js\";\n\nexport type {\n Cpeak,\n CpeakRequest,\n CpeakResponse,\n Next,\n HandleErr,\n Middleware,\n RouteMiddleware,\n Handler,\n RoutesMap,\n} from \"./types\";\n\nexport default function cpeak() {\n return new Cpeak();\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport type { StringMap, CpeakRequest, CpeakResponse, Next } from \"../types\";\n\nconst MIME_TYPES: StringMap = {\n html: \"text/html\",\n css: \"text/css\",\n js: \"application/javascript\",\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n png: \"image/png\",\n svg: \"image/svg+xml\",\n txt: \"text/plain\",\n eot: \"application/vnd.ms-fontobject\",\n otf: \"font/otf\",\n ttf: \"font/ttf\",\n woff: \"font/woff\",\n woff2: \"font/woff2\",\n};\n\nconst serveStatic = (folderPath: string, newMimeTypes?: StringMap) => {\n // For new user defined mime types\n if (newMimeTypes) {\n Object.assign(MIME_TYPES, newMimeTypes);\n }\n\n function processFolder(folderPath: string, parentFolder: string) {\n const staticFiles: string[] = [];\n\n // Read the contents of the folder\n const files = fs.readdirSync(folderPath);\n\n // Loop through the files and subfolders\n for (const file of files) {\n const fullPath = path.join(folderPath, file);\n\n // Check if it's a directory\n if (fs.statSync(fullPath).isDirectory()) {\n // If it's a directory, recursively process it\n const subfolderFiles = processFolder(fullPath, parentFolder);\n staticFiles.push(...subfolderFiles);\n } else {\n // If it's a file, add it to the array\n const relativePath = path.relative(parentFolder, fullPath);\n const fileExtension = path.extname(file).slice(1);\n if (MIME_TYPES[fileExtension]) staticFiles.push(\"/\" + relativePath);\n }\n }\n\n return staticFiles;\n }\n\n const filesArrayToFilesMap = (filesArray: string[]) => {\n const filesMap: Record<string, { path: string; mime: string }> = {};\n for (const file of filesArray) {\n const fileExtension = path.extname(file).slice(1);\n filesMap[file] = {\n path: folderPath + file,\n mime: MIME_TYPES[fileExtension],\n };\n }\n return filesMap;\n };\n\n // Start processing the folder\n const filesMap = filesArrayToFilesMap(processFolder(folderPath, folderPath));\n\n return function (req: CpeakRequest, res: CpeakResponse, next: Next) {\n const url = req.url;\n if (typeof url !== \"string\") return next();\n\n if (Object.prototype.hasOwnProperty.call(filesMap, url)) {\n const fileRoute = filesMap[url];\n return res.sendFile(fileRoute.path, fileRoute.mime);\n }\n\n next();\n };\n};\n\nexport { serveStatic };\n","import type { CpeakRequest, CpeakResponse, Next } from \"../types\";\n\n// Parsing JSON\nconst parseJSON = (req: CpeakRequest, res: CpeakResponse, next: Next) => {\n // This is only good for bodies that their size is less than the highWaterMark value\n\n function isJSON(contentType: string = \"\") {\n // Remove any params like \"; charset=UTF-8\"\n const [type] = contentType.split(\";\");\n return (\n type.trim().toLowerCase() === \"application/json\" ||\n /\\+json$/i.test(type.trim())\n );\n }\n\n if (!isJSON(req.headers[\"content-type\"] as string)) return next();\n\n let body = \"\";\n req.on(\"data\", (chunk: Buffer) => {\n body += chunk.toString(\"utf-8\");\n });\n\n req.on(\"end\", () => {\n body = JSON.parse(body);\n req.body = body;\n return next();\n });\n};\n\nexport { parseJSON };\n","import fs from \"node:fs/promises\";\nimport { frameworkError } from \"../\";\nimport type { CpeakRequest, CpeakResponse, Next } from \"../types\";\n\nfunction renderTemplate(\n templateStr: string,\n data: Record<string, unknown>\n): string {\n // Initialize variables\n let result: (string | unknown)[] = [];\n\n let currentIndex = 0;\n\n while (currentIndex < templateStr.length) {\n // Find the next opening placeholder\n const startIdx = templateStr.indexOf(\"{{\", currentIndex);\n if (startIdx === -1) {\n // No more placeholders, push the remaining string\n result.push(templateStr.slice(currentIndex));\n break;\n }\n\n // Push the part before the placeholder\n result.push(templateStr.slice(currentIndex, startIdx));\n\n // Find the closing placeholder\n const endIdx = templateStr.indexOf(\"}}\", startIdx);\n if (endIdx === -1) {\n // No closing brace found, treat the rest as plain text\n result.push(templateStr.slice(startIdx));\n break;\n }\n\n // Extract the variable name\n const varName = templateStr.slice(startIdx + 2, endIdx).trim();\n\n // Replace the variable with its value from the data, or use an empty string if not found\n const replacement = data[varName] !== undefined ? data[varName] : \"\";\n\n // Push the replacement to the result array\n result.push(replacement);\n\n // Move the index past the current closing placeholder\n currentIndex = endIdx + 2;\n }\n\n // Join all parts into a final string\n return result.join(\"\");\n}\n\n// Errors to return: recommend to not render files larger than 100KB\n// To Explore: Doing the operation in C++ and return the data as stream back to the client\n// @TODO: remove the file from static map\n// @TODO: escape the string to prevent XSS\n// @TODO: add another {{{ }}} option to not escape the string\nconst render = () => {\n console.log(\"render.ts loaded\");\n return function (req: CpeakRequest, res: CpeakResponse, next: Next): void {\n res.render = async (\n path: string,\n data: Record<string, unknown>,\n mime: string\n ) => {\n // check if mime is specified, if not return an error\n if (!mime) {\n throw frameworkError(\n `MIME type is missing. You called res.render(\"${path}\", ...) but forgot to provide the third \"mime\" argument.`,\n res.render\n );\n }\n\n let fileStr = await fs.readFile(path, \"utf-8\");\n const finalStr = renderTemplate(fileStr, data);\n res.setHeader(\"Content-Type\", mime);\n res.end(finalStr);\n };\n\n next();\n };\n};\n\nexport { render };\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAOA,SAAQ;AACf,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;;;ACHzB,OAAO,QAAQ;AACf,OAAO,UAAU;AAIjB,IAAM,aAAwB;AAAA,EAC5B,MAAM;AAAA,EACN,KAAK;AAAA,EACL,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AACT;AAEA,IAAM,cAAc,CAAC,YAAoB,iBAA6B;AAEpE,MAAI,cAAc;AAChB,WAAO,OAAO,YAAY,YAAY;AAAA,EACxC;AAEA,WAAS,cAAcC,aAAoB,cAAsB;AAC/D,UAAM,cAAwB,CAAC;AAG/B,UAAM,QAAQ,GAAG,YAAYA,WAAU;AAGvC,eAAW,QAAQ,OAAO;AACxB,YAAM,WAAW,KAAK,KAAKA,aAAY,IAAI;AAG3C,UAAI,GAAG,SAAS,QAAQ,EAAE,YAAY,GAAG;AAEvC,cAAM,iBAAiB,cAAc,UAAU,YAAY;AAC3D,oBAAY,KAAK,GAAG,cAAc;AA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U;AAChC,WAAK,IAAI,IAAI,MAAM,QAAQ,CAAC;AAAA,IAC9B,CAAC;AACD,WAAO;AAAA,EACT;AACF;AAmBe,SAAR,QAAyB;AAC9B,SAAO,IAAI,MAAM;AACnB;","names":["fs","folderPath","filesMap","fs","path","fs","ErrorCode","path","fs","req","res"]}
|
|
1
|
+
{"version":3,"sources":["../lib/index.ts","../lib/utils/parseJSON.ts","../lib/utils/serveStatic.ts","../lib/utils/render.ts","../lib/utils/swagger.ts","../lib/utils/auth.ts","../lib/utils/cookieParser.ts"],"sourcesContent":["import http from \"node:http\";\nimport fs from \"node:fs/promises\";\nimport { createReadStream } from \"node:fs\";\nimport { pipeline } from \"node:stream/promises\";\n\nimport type {\n StringMap,\n CpeakRequest,\n CpeakResponse,\n Middleware,\n RouteMiddleware,\n Handler,\n RoutesMap\n} from \"./types\";\n\n// A utility function to create an error with a custom stack trace\nexport function frameworkError(\n message: string,\n skipFn: Function,\n code?: string,\n status?: number\n) {\n const err = new Error(message) as Error & {\n code?: string;\n cpeak_err?: boolean;\n };\n Error.captureStackTrace(err, skipFn);\n\n err.cpeak_err = true;\n\n if (code) err.code = code;\n if (status) (err as any).status = status;\n\n return err;\n}\n\nexport enum ErrorCode {\n MISSING_MIME = \"CPEAK_ERR_MISSING_MIME\",\n FILE_NOT_FOUND = \"CPEAK_ERR_FILE_NOT_FOUND\",\n NOT_A_FILE = \"CPEAK_ERR_NOT_A_FILE\",\n SEND_FILE_FAIL = \"CPEAK_ERR_SEND_FILE_FAIL\",\n INVALID_JSON = \"CPEAK_ERR_INVALID_JSON\",\n PAYLOAD_TOO_LARGE = \"CPEAK_ERR_PAYLOAD_TOO_LARGE\",\n WEAK_SECRET = \"CPEAK_ERR_WEAK_SECRET\"\n}\n\nexport class CpeakIncomingMessage extends http.IncomingMessage {\n // We define body and params here for better V8 optimization (not changing the shape of the object at runtime)\n public body: any = undefined;\n public params: StringMap = {};\n\n #query?: StringMap;\n\n // Parse the URL parameters (like /users?key1=value1&key2=value2)\n // We will call this query to be more familiar with other node.js frameworks.\n // This is a getter method (accessed like a property)\n get query(): StringMap {\n // This way if a developer writes req.query multiple times, we don't parse it multiple times\n if (this.#query) return this.#query;\n\n const url = this.url || \"\";\n const qIndex = url.indexOf(\"?\");\n\n if (qIndex === -1) {\n this.#query = {};\n } else {\n const searchParams = new URLSearchParams(url.substring(qIndex + 1));\n this.#query = Object.fromEntries(searchParams.entries());\n }\n\n return this.#query;\n }\n}\n\nexport class CpeakServerResponse extends http.ServerResponse<CpeakIncomingMessage> {\n // Send a file back to the client\n async sendFile(path: string, mime: string) {\n if (!mime) {\n throw frameworkError(\n 'MIME type is missing. Use res.sendFile(path, \"mime-type\").',\n this.sendFile,\n ErrorCode.MISSING_MIME\n );\n }\n\n try {\n const stat = await fs.stat(path);\n if (!stat.isFile()) {\n throw frameworkError(\n `Not a file: ${path}`,\n this.sendFile,\n ErrorCode.NOT_A_FILE\n );\n }\n\n this.setHeader(\"Content-Type\", mime);\n this.setHeader(\"Content-Length\", String(stat.size));\n\n // Properly propagate stream errors and respect backpressure\n await pipeline(createReadStream(path), this);\n } catch (err: any) {\n if (err?.code === \"ENOENT\") {\n throw frameworkError(\n `File not found: ${path}`,\n this.sendFile,\n ErrorCode.FILE_NOT_FOUND\n );\n }\n\n throw frameworkError(\n `Failed to send file: ${path}`,\n this.sendFile,\n ErrorCode.SEND_FILE_FAIL\n );\n }\n }\n\n // Set the status code of the response\n status(code: number) {\n this.statusCode = code;\n return this;\n }\n\n // Set the Content-Disposition header to prompt the user to download a file\n attachment(filename?: string) {\n const contentDisposition = filename\n ? `attachment; filename=\"${filename}\"`\n : \"attachment\";\n this.setHeader(\"Content-Disposition\", contentDisposition);\n return this;\n }\n\n // Redirects to a new URL\n redirect(location: string) {\n this.writeHead(302, { Location: location });\n this.end();\n }\n\n // Send a json data back to the client (for small json data, less than the highWaterMark)\n json(data: any) {\n // This is only good for bodies that their size is less than the highWaterMark value\n this.setHeader(\"Content-Type\", \"application/json\");\n this.end(JSON.stringify(data));\n }\n}\n\nexport class Cpeak {\n #server: http.Server<typeof CpeakIncomingMessage, typeof CpeakServerResponse>;\n #routes: RoutesMap;\n #middleware: Middleware[];\n #handleErr?: (err: unknown, req: CpeakRequest, res: CpeakResponse) => void;\n\n constructor() {\n this.#server = http.createServer({\n IncomingMessage: CpeakIncomingMessage,\n ServerResponse: CpeakServerResponse\n });\n this.#routes = {};\n this.#middleware = [];\n\n this.#server.on(\n \"request\",\n async (req: CpeakRequest, res: CpeakResponse) => {\n // Get the url without the URL parameters (query strings)\n const qIndex = req.url?.indexOf(\"?\");\n const urlWithoutQueries =\n qIndex === -1 ? req.url || \"\" : req.url?.substring(0, qIndex);\n\n const dispatchError = (error: unknown) => {\n if (res.headersSent) {\n req.socket?.destroy();\n return;\n }\n res.setHeader(\"Connection\", \"close\");\n this.#handleErr?.(error, req, res);\n };\n\n // Run all the specific middleware functions for that router only and then run the handler\n const runHandler = async (\n req: CpeakRequest,\n res: CpeakResponse,\n middleware: RouteMiddleware[],\n cb: Handler,\n index: number\n ) => {\n // Our exit point...\n if (index === middleware.length) {\n // Call the route handler with the modified req and res objects.\n // Also handle the promise errors by passing them to the handleErr to save developers from having to manually wrap every handler in try catch.\n try {\n await cb(req, res, dispatchError);\n } catch (error) {\n dispatchError(error);\n }\n } else {\n // Handle the promise errors by passing them to the handleErr to save developers from having to manually wrap every handler middleware in try catch.\n try {\n await middleware[index](\n req,\n res,\n // The next function\n async (error) => {\n // this function only accepts an error argument to be more compatible with NPM modules that are built for express\n if (error) {\n return dispatchError(error);\n }\n await runHandler(req, res, middleware, cb, index + 1);\n },\n // Error handler for a route middleware\n dispatchError\n );\n } catch (error) {\n dispatchError(error);\n }\n }\n };\n\n // Run all the middleware functions (beforeEach functions) before we run the corresponding route\n const runMiddleware = async (\n req: CpeakRequest,\n res: CpeakResponse,\n middleware: Middleware[],\n index: number\n ) => {\n // Our exit point...\n if (index === middleware.length) {\n const routes = this.#routes[req.method?.toLowerCase() || \"\"];\n if (routes && typeof routes[Symbol.iterator] === \"function\")\n for (const route of routes) {\n const match = urlWithoutQueries?.match(route.regex);\n\n if (match) {\n // Parse the URL path variables from the matched route (like /users/:id)\n const pathVariables = this.#extractPathVariables(\n route.path,\n match\n );\n\n // We will call this params to be more familiar with other node.js frameworks.\n req.params = pathVariables;\n\n return await runHandler(\n req,\n res,\n route.middleware,\n route.cb,\n 0\n );\n }\n }\n\n // If the requested route dose not exist, return 404\n return res\n .status(404)\n .json({ error: `Cannot ${req.method} ${urlWithoutQueries}` });\n } else {\n try {\n await middleware[index](req, res, async (err?: unknown) => {\n if (err) {\n return dispatchError(err);\n }\n await runMiddleware(req, res, middleware, index + 1);\n });\n } catch (error) {\n dispatchError(error);\n }\n }\n };\n\n await runMiddleware(req, res, this.#middleware, 0);\n }\n );\n }\n\n route(method: string, path: string, ...args: (RouteMiddleware | Handler)[]) {\n if (!this.#routes[method]) this.#routes[method] = [];\n\n // The last argument should always be our handler\n const cb = args.pop() as Handler;\n\n if (!cb || typeof cb !== \"function\") {\n throw new Error(\"Route definition must include a handler\");\n }\n\n // Rest will be our middleware functions\n const middleware = args.flat() as RouteMiddleware[];\n\n const regex = this.#pathToRegex(path);\n this.#routes[method].push({ path, regex, middleware, cb });\n }\n\n beforeEach(cb: Middleware) {\n this.#middleware.push(cb);\n }\n\n handleErr(cb: (err: unknown, req: CpeakRequest, res: CpeakResponse) => void) {\n this.#handleErr = cb;\n }\n\n listen(port: number, cb?: () => void) {\n return this.#server.listen(port, cb);\n }\n\n address() {\n return this.#server.address();\n }\n\n close(cb?: (err?: Error) => void) {\n this.#server.close(cb);\n }\n\n // ------------------------------\n // PRIVATE METHODS:\n // ------------------------------\n #pathToRegex(path: string) {\n const regexString =\n \"^\" + path.replace(/:\\w+/g, \"([^/]+)\").replace(/\\*/g, \".*\") + \"$\";\n\n return new RegExp(regexString);\n }\n\n #extractPathVariables(path: string, match: RegExpMatchArray) {\n // Extract path url variable values from the matched route\n const paramNames = (path.match(/:\\w+/g) || []).map((param) =>\n param.slice(1)\n );\n const params: StringMap = {};\n paramNames.forEach((name, index) => {\n params[name] = match[index + 1];\n });\n return params;\n }\n}\n\n// Util functions\nexport {\n serveStatic,\n parseJSON,\n render,\n swagger,\n auth,\n hashPassword,\n verifyPassword,\n cookieParser\n} from \"./utils\";\nexport type { AuthOptions, PbkdfOptions, CookieOptions } from \"./utils\";\n\nexport type {\n CpeakRequest,\n CpeakResponse,\n Next,\n HandleErr,\n Middleware,\n RouteMiddleware,\n Handler,\n RoutesMap\n} from \"./types\";\n\nexport default function cpeak(): Cpeak {\n return new Cpeak();\n}\n","import type { CpeakRequest, CpeakResponse, Next } from \"../types\";\nimport { Buffer } from \"node:buffer\";\nimport { frameworkError, ErrorCode } from \"../index\";\n\n// Check if Content-Type is JSON\nfunction isJSON(contentType: string | undefined) {\n if (!contentType) return false;\n if (contentType === \"application/json\") return true;\n return (\n contentType.startsWith(\"application/json\") || contentType.includes(\"+json\")\n );\n}\n\n// Parsing JSON\nconst parseJSON = (options: { limit?: number } = {}) => {\n // Default limit to 1MB\n const limit = options.limit || 1024 * 1024;\n\n return (req: CpeakRequest, res: CpeakResponse, next: Next) => {\n if (!isJSON(req.headers[\"content-type\"])) return next();\n\n const chunks: Buffer[] = [];\n let bytesReceived = 0;\n\n const onData = (chunk: Buffer) => {\n bytesReceived += chunk.length;\n\n // To prevent Denial of Service (DoS) attacks, enforce a maximum body size\n if (bytesReceived > limit) {\n // Stop listening to data\n req.pause();\n\n // Remove listeners so we don't trigger 'end' or more 'data'\n req.removeListener(\"data\", onData);\n req.removeListener(\"end\", onEnd);\n\n next(\n frameworkError(\n \"JSON body too large\",\n onData,\n ErrorCode.PAYLOAD_TOO_LARGE,\n 413 // HTTP 413 Payload Too Large\n )\n );\n\n return;\n }\n\n chunks.push(chunk);\n };\n\n const onEnd = () => {\n try {\n // For better performance, we concat buffers once, then convert to string\n // Optimization: If only one chunk exists, avoid the memory copy of concat\n const rawBody =\n chunks.length === 1\n ? chunks[0].toString(\"utf-8\")\n : Buffer.concat(chunks).toString(\"utf-8\");\n\n // Handle empty body case\n req.body = rawBody ? JSON.parse(rawBody) : {};\n\n next();\n } catch (err) {\n // Handle Invalid JSON without crashing\n next(\n frameworkError(\n \"Invalid JSON format\",\n onEnd,\n ErrorCode.INVALID_JSON,\n 400 // HTTP 400 Bad Request\n )\n );\n }\n };\n\n req.on(\"data\", onData);\n req.on(\"end\", onEnd);\n };\n};\n\nexport { parseJSON };\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport type { StringMap, CpeakRequest, CpeakResponse, Next } from \"../types\";\n\nconst MIME_TYPES: StringMap = {\n html: \"text/html\",\n css: \"text/css\",\n js: \"application/javascript\",\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n png: \"image/png\",\n svg: \"image/svg+xml\",\n txt: \"text/plain\",\n eot: \"application/vnd.ms-fontobject\",\n otf: \"font/otf\",\n ttf: \"font/ttf\",\n woff: \"font/woff\",\n woff2: \"font/woff2\",\n gif: \"image/gif\",\n ico: \"image/x-icon\",\n json: \"application/json\",\n webmanifest: \"application/manifest+json\"\n};\n\nconst serveStatic = (\n folderPath: string,\n newMimeTypes?: StringMap,\n options?: { prefix?: string }\n) => {\n // For new user defined mime types\n if (newMimeTypes) {\n Object.assign(MIME_TYPES, newMimeTypes);\n }\n\n const prefix = options?.prefix ?? \"\";\n\n function processFolder(folderPath: string, parentFolder: string) {\n const staticFiles: string[] = [];\n\n // Read the contents of the folder\n const files = fs.readdirSync(folderPath);\n\n // Loop through the files and subfolders\n for (const file of files) {\n const fullPath = path.join(folderPath, file);\n\n // Check if it's a directory\n if (fs.statSync(fullPath).isDirectory()) {\n // If it's a directory, recursively process it\n const subfolderFiles = processFolder(fullPath, parentFolder);\n staticFiles.push(...subfolderFiles);\n } else {\n // If it's a file, add it to the array\n const relativePath = path.relative(parentFolder, fullPath);\n const fileExtension = path.extname(file).slice(1);\n if (MIME_TYPES[fileExtension]) staticFiles.push(\"/\" + relativePath);\n }\n }\n\n return staticFiles;\n }\n\n const filesArrayToFilesMap = (filesArray: string[]) => {\n const filesMap: Record<string, { path: string; mime: string }> = {};\n for (const file of filesArray) {\n const fileExtension = path.extname(file).slice(1);\n filesMap[prefix + file] = {\n path: folderPath + file,\n mime: MIME_TYPES[fileExtension]\n };\n }\n return filesMap;\n };\n\n // Start processing the folder\n const filesMap = filesArrayToFilesMap(processFolder(folderPath, folderPath));\n\n return function (req: CpeakRequest, res: CpeakResponse, next: Next) {\n const url = req.url;\n if (typeof url !== \"string\") return next();\n\n const pathname = url.split(\"?\")[0];\n if (Object.prototype.hasOwnProperty.call(filesMap, pathname)) {\n const fileRoute = filesMap[pathname];\n return res.sendFile(fileRoute.path, fileRoute.mime);\n }\n\n next();\n };\n};\n\nexport { serveStatic };\n","import fs from \"node:fs/promises\";\nimport { frameworkError } from \"../\";\nimport type { CpeakRequest, CpeakResponse, Next } from \"../types\";\n\nfunction renderTemplate(\n templateStr: string,\n data: Record<string, unknown>\n): string {\n // Initialize variables\n let result: (string | unknown)[] = [];\n\n let currentIndex = 0;\n\n while (currentIndex < templateStr.length) {\n // Find the next opening placeholder\n const startIdx = templateStr.indexOf(\"{{\", currentIndex);\n if (startIdx === -1) {\n // No more placeholders, push the remaining string\n result.push(templateStr.slice(currentIndex));\n break;\n }\n\n // Push the part before the placeholder\n result.push(templateStr.slice(currentIndex, startIdx));\n\n // Find the closing placeholder\n const endIdx = templateStr.indexOf(\"}}\", startIdx);\n if (endIdx === -1) {\n // No closing brace found, treat the rest as plain text\n result.push(templateStr.slice(startIdx));\n break;\n }\n\n // Extract the variable name\n const varName = templateStr.slice(startIdx + 2, endIdx).trim();\n\n // Replace the variable with its value from the data, or use an empty string if not found\n const replacement = data[varName] !== undefined ? data[varName] : \"\";\n\n // Push the replacement to the result array\n result.push(replacement);\n\n // Move the index past the current closing placeholder\n currentIndex = endIdx + 2;\n }\n\n // Join all parts into a final string\n return result.join(\"\");\n}\n\n// Errors to return: recommend to not render files larger than 100KB\n// To Explore: Doing the operation in C++ and return the data as stream back to the client\n// @TODO: remove the file from static map\n// @TODO: escape the string to prevent XSS\n// @TODO: add another {{{ }}} option to not escape the string\nconst render = () => {\n return function (req: CpeakRequest, res: CpeakResponse, next: Next): void {\n res.render = async (\n path: string,\n data: Record<string, unknown>,\n mime: string\n ) => {\n // check if mime is specified, if not return an error\n if (!mime) {\n throw frameworkError(\n `MIME type is missing. You called res.render(\"${path}\", ...) but forgot to provide the third \"mime\" argument.`,\n res.render\n );\n }\n\n let fileStr = await fs.readFile(path, \"utf-8\");\n const finalStr = renderTemplate(fileStr, data);\n res.setHeader(\"Content-Type\", mime);\n res.end(finalStr);\n };\n\n next();\n };\n};\n\nexport { render };\n","import type { CpeakRequest, CpeakResponse, Next } from \"../types\";\n\nconst swagger = (spec: object, prefix = \"/api-docs\") => {\n const initializerJs = `window.onload = function() {\n SwaggerUIBundle({\n url: \"${prefix}/spec.json\",\n dom_id: '#swagger-ui',\n presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],\n layout: \"StandaloneLayout\"\n });\n};`;\n\n return (req: CpeakRequest, res: CpeakResponse, next: Next) => {\n if (req.url === prefix || req.url === `${prefix}/`) {\n res.writeHead(302, { Location: `${prefix}/index.html` });\n res.end();\n return;\n }\n if (req.url === `${prefix}/spec.json`) {\n return res.json(spec);\n }\n if (req.url === `${prefix}/swagger-initializer.js`) {\n res.setHeader(\"Content-Type\", \"application/javascript\");\n res.end(initializerJs);\n return;\n }\n next();\n };\n};\n\nexport { swagger };\n","import { randomBytes, pbkdf2, createHmac, timingSafeEqual } from \"node:crypto\";\nimport { promisify } from \"node:util\";\nimport type { Middleware } from \"../types\";\nimport { frameworkError, ErrorCode } from \"../index\";\n\nconst pbkdf2Async = promisify(pbkdf2);\n\nconst DEFAULTS = {\n iterations: 210_000,\n keylen: 64,\n digest: \"sha512\",\n saltSize: 32,\n hmacAlgorithm: \"sha256\",\n tokenIdSize: 20,\n tokenExpiry: 7 * 24 * 60 * 60 * 1000 // 7 days in ms\n} as const;\n\nexport interface PbkdfOptions {\n iterations?: number;\n keylen?: number;\n digest?: string;\n saltSize?: number;\n}\n\nexport interface AuthOptions extends PbkdfOptions {\n secret: string;\n saveToken: (\n tokenId: string,\n userId: string,\n expiresAt: Date\n ) => Promise<void>;\n findToken: (\n tokenId: string\n ) => Promise<{ userId: string; expiresAt: Date } | null>;\n tokenExpiry?: number;\n hmacAlgorithm?: string;\n tokenIdSize?: number;\n revokeToken?: (tokenId: string) => Promise<void>;\n}\n\nexport async function hashPassword(\n password: string,\n options?: PbkdfOptions\n): Promise<string> {\n const iterations = options?.iterations ?? DEFAULTS.iterations;\n const keylen = options?.keylen ?? DEFAULTS.keylen;\n const digest = options?.digest ?? DEFAULTS.digest;\n const saltSize = options?.saltSize ?? DEFAULTS.saltSize;\n const salt = randomBytes(saltSize);\n const hash = await pbkdf2Async(password, salt, iterations, keylen, digest);\n return `pbkdf2:${iterations}:${keylen}:${digest}:${salt.toString(\"hex\")}:${hash.toString(\"hex\")}`;\n}\n\nexport async function verifyPassword(\n password: string,\n stored: string\n): Promise<boolean> {\n // When argon2 is added, dispatch on the prefix here.\n const withoutPrefix = stored.slice(stored.indexOf(\":\") + 1);\n const parts = withoutPrefix.split(\":\");\n if (parts.length !== 5) return false;\n const [itersStr, keylenStr, digest, saltHex, hashHex] = parts;\n const iterations = parseInt(itersStr, 10);\n const keylen = parseInt(keylenStr, 10);\n if (!digest || !saltHex || !hashHex || isNaN(iterations) || isNaN(keylen))\n return false;\n const salt = Buffer.from(saltHex, \"hex\");\n const hash = await pbkdf2Async(password, salt, iterations, keylen, digest);\n const storedHash = Buffer.from(hashHex, \"hex\");\n if (storedHash.length !== hash.length) return false;\n return timingSafeEqual(hash, storedHash);\n}\n\nfunction signToken(tokenId: string, secret: string, algorithm: string): string {\n const sig = createHmac(algorithm, secret).update(tokenId).digest(\"hex\");\n return `${tokenId}.${sig}`;\n}\n\nfunction extractTokenId(\n token: string,\n secret: string,\n algorithm: string\n): string | null {\n const dot = token.indexOf(\".\");\n if (dot === -1) return null;\n const tokenId = token.slice(0, dot);\n const sig = token.slice(dot + 1);\n const expected = createHmac(algorithm, secret).update(tokenId).digest(\"hex\");\n const expectedBuf = Buffer.from(expected, \"hex\");\n const actualBuf = Buffer.from(sig, \"hex\");\n if (expectedBuf.length !== actualBuf.length) return null;\n if (!timingSafeEqual(expectedBuf, actualBuf)) return null;\n return tokenId;\n}\n\nexport function auth(options: AuthOptions): Middleware {\n if (!options.secret || options.secret.length < 32) {\n throw frameworkError(\n \"Secret must be at least 32 characters. HMAC security is only as strong as the key.\",\n auth,\n ErrorCode.WEAK_SECRET\n );\n }\n\n const {\n secret,\n saveToken,\n findToken,\n revokeToken,\n tokenExpiry = DEFAULTS.tokenExpiry,\n hmacAlgorithm = DEFAULTS.hmacAlgorithm,\n tokenIdSize = DEFAULTS.tokenIdSize\n } = options;\n\n const pbkdfOpts: PbkdfOptions = {\n iterations: options.iterations,\n keylen: options.keylen,\n digest: options.digest,\n saltSize: options.saltSize\n };\n\n const _hashPassword = ({ password }: { password: string }) =>\n hashPassword(password, pbkdfOpts);\n\n const login = async ({\n password,\n hashedPassword,\n userId\n }: {\n password: string;\n hashedPassword: string;\n userId: string;\n }): Promise<string | null> => {\n const isMatch = await verifyPassword(password, hashedPassword);\n if (!isMatch) return null;\n const tokenId = randomBytes(tokenIdSize).toString(\"hex\");\n const token = signToken(tokenId, secret, hmacAlgorithm);\n await saveToken(tokenId, userId, new Date(Date.now() + tokenExpiry));\n return token;\n };\n\n const verifyToken = async (\n token: string\n ): Promise<{ userId: string } | null> => {\n if (!token) return null;\n const tokenId = extractTokenId(token, secret, hmacAlgorithm);\n if (!tokenId) return null;\n const record = await findToken(tokenId);\n if (!record) return null;\n if (new Date(record.expiresAt) < new Date()) return null;\n return { userId: record.userId };\n };\n\n const logout = revokeToken\n ? async (token: string): Promise<boolean> => {\n const tokenId = extractTokenId(token, secret, hmacAlgorithm);\n if (!tokenId) return false;\n await revokeToken(tokenId);\n return true;\n }\n : undefined;\n\n return (req, _res, next) => {\n req.hashPassword = _hashPassword;\n req.login = login;\n req.verifyToken = verifyToken;\n if (logout) req.logout = logout;\n next();\n };\n}\n","import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport type { CpeakRequest, CpeakResponse, Next } from \"../types\";\nimport { frameworkError, ErrorCode } from \"../index\";\n\nexport interface CookieOptions {\n signed?: boolean;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: \"strict\" | \"lax\" | \"none\";\n maxAge?: number; // ms\n expires?: Date;\n path?: string;\n domain?: string;\n}\n\n// This will sign the cookie value with HMAC with the secret.\n// Ideal for data like user IDs or session IDs, where you want to ensure the integrity of the cookie value without encryption.\n// So this way, imagine you save a user ID in the cookie. By signing it, you can detect if the client has tampered with the cookie value\n// (e.g., changing the user ID to impersonate another user).\n// However, since it's not encrypted, the actual user ID is still visible to the client.\n// This is a common approach for session cookies where you want to prevent tampering but don't mind if the value is visible.\nfunction sign(value: string, secret: string): string {\n const sig = createHmac(\"sha256\", secret).update(value).digest(\"base64url\");\n return `s:${value}.${sig}`;\n}\n\nfunction unsign(signed: string, secret: string): string | false {\n if (!signed.startsWith(\"s:\")) return false;\n const withoutPrefix = signed.slice(2);\n const lastDot = withoutPrefix.lastIndexOf(\".\");\n if (lastDot === -1) return false;\n const value = withoutPrefix.slice(0, lastDot);\n const sig = withoutPrefix.slice(lastDot + 1);\n const expected = createHmac(\"sha256\", secret)\n .update(value)\n .digest(\"base64url\");\n const expectedBuf = Buffer.from(expected);\n const actualBuf = Buffer.from(sig);\n if (expectedBuf.length !== actualBuf.length) return false;\n if (!timingSafeEqual(expectedBuf, actualBuf)) return false;\n return value;\n}\n\n// Parses the raw value of an HTTP `Cookie` request header into a name->value\n// This should be compatible with the RFC 6265 HTTP specification\nfunction parseRawCookies(header: string): Record<string, string> {\n // Use a null-prototype object to prevent prototype pollution attacks when assigning cookie names like \"__proto__\" or \"constructor\".\n const cookies: Record<string, string> = Object.create(null);\n if (!header) return cookies;\n\n const pairs = header.split(\";\");\n\n for (let i = 0; i < pairs.length; i++) {\n const pair = pairs[i];\n const equalSignIndex = pair.indexOf(\"=\");\n\n // RFC 6265: cookie-pair requires '='. Pairs without one (e.g. a\n // bare flag like `Cookie: foo`) are not valid cookie-pairs and we skip them.\n // Note we use the FIRST '=' only. So values like base64 padding (`token=YWJjPT0=`) must keep trailing '='s.\n if (equalSignIndex === -1) continue;\n\n const key = pair.slice(0, equalSignIndex).trim();\n // Drop empty names and honour the FIRST occurrence on duplicates (Specs say servers SHOULD NOT rely on order.\n // We pick first-wins for stability).\n if (!key || cookies[key] !== undefined) continue;\n\n let val = pair.slice(equalSignIndex + 1).trim();\n\n // Cookie values are sometimes sent wrapped in double quotes (like name=\"hello world\"), so we strip the outer \"\n // characters to get the actual value hello world.\n // The val.length > 1 guard handles the edge case where the value is literally just a single \" — without it, that one\n // character would match both the \"starts with quote\" and \"ends with quote\" checks, and slice(1, -1) would wipe it out\n // to an empty string.\n if (val.length > 1 && val[0] === '\"' && val[val.length - 1] === '\"') {\n val = val.slice(1, -1);\n }\n\n // Percent-decoding cookie values is a server-side convention (not part of\n // RFC 6265 itself), but it's what Express and most ecosystem libraries do,\n // so we follow suit for compatibility. Skip the decode entirely when there's no\n // '%' to save work on the common case, and fall back to the raw value if\n // decodeURIComponent throws on malformed input rather than crashing the\n // whole request.\n try {\n cookies[key] = val.indexOf(\"%\") !== -1 ? decodeURIComponent(val) : val;\n } catch (e) {\n cookies[key] = val;\n }\n }\n return cookies;\n}\n\n// One example output: \"session=abc123; Path=/dashboard; Domain=example.com; Max-Age=86400; Expires=Thu, 31 Dec 2026 00:00:00 GMT; HttpOnly; Secure; SameSite=Strict\"\nfunction buildSetCookieHeader(\n name: string,\n value: string,\n options: CookieOptions\n): string {\n const parts: string[] = [`${name}=${encodeURIComponent(value)}`];\n const path = options.path ?? \"/\";\n parts.push(`Path=${path}`);\n if (options.domain) parts.push(`Domain=${options.domain}`);\n if (options.maxAge !== undefined)\n parts.push(`Max-Age=${Math.floor(options.maxAge / 1000)}`);\n if (options.expires) parts.push(`Expires=${options.expires.toUTCString()}`);\n if (options.httpOnly) parts.push(\"HttpOnly\");\n if (options.secure) parts.push(\"Secure\");\n if (options.sameSite) parts.push(`SameSite=${options.sameSite}`);\n return parts.join(\"; \");\n}\n\n// Without this helper, calling res.cookie(\"a\", \"1\") then res.cookie(\"b\", \"2\") would overwrite the first cookie instead\n// of sending both.\nfunction appendSetCookie(res: CpeakResponse, header: string) {\n const existing = res.getHeader(\"Set-Cookie\");\n if (!existing) {\n res.setHeader(\"Set-Cookie\", [header]);\n } else if (Array.isArray(existing)) {\n res.setHeader(\"Set-Cookie\", [...existing, header]);\n } else {\n res.setHeader(\"Set-Cookie\", [String(existing), header]);\n }\n}\n\nexport function cookieParser(options: { secret?: string } = {}) {\n const { secret } = options;\n\n if (secret !== undefined && secret.length < 32) {\n throw frameworkError(\n \"Secret must be at least 32 characters. HMAC security is only as strong as the key.\",\n cookieParser,\n ErrorCode.WEAK_SECRET\n );\n }\n\n return (req: CpeakRequest, res: CpeakResponse, next: Next) => {\n const rawHeader = req.headers[\"cookie\"] || \"\";\n const raw = parseRawCookies(rawHeader);\n\n // Mirror parseRawCookies and use null-prototype maps here too. If we used\n // a regular `{}`, the assignment below would invoke Object.prototype's\n // __proto__ setter (no-op for string values), silently dropping any\n // cookie literally named __proto__ — undoing the fix in parseRawCookies.\n const cookies: Record<string, string> = Object.create(null);\n const signedCookies: Record<string, string | false> = Object.create(null);\n\n for (const [key, val] of Object.entries(raw)) {\n // The \"s:\" prefix is the marker we add in `sign()` for HMAC-signed\n // cookies. Route those through unsign so the handler sees the original\n // value (or `false` if the signature didn't verify).\n if (val.startsWith(\"s:\") && secret) {\n signedCookies[key] = unsign(val, secret);\n } else {\n cookies[key] = val;\n }\n }\n\n // The separation is intentional signal: \"these were signed and verified, trust them more.\"\n req.cookies = cookies;\n req.signedCookies = signedCookies;\n\n res.cookie = (name: string, value: string, options: CookieOptions = {}) => {\n let finalValue = value;\n if (options.signed) {\n if (!secret)\n throw new Error(\n \"cookieParser: secret is required to use signed cookies\"\n );\n finalValue = sign(value, secret);\n }\n appendSetCookie(res, buildSetCookieHeader(name, finalValue, options));\n return res;\n };\n\n res.clearCookie = (name: string, options: CookieOptions = {}) => {\n appendSetCookie(\n res,\n buildSetCookieHeader(name, \"\", {\n ...options,\n maxAge: 0,\n expires: new Date(0)\n })\n );\n return res;\n };\n\n next();\n };\n}\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAOA,SAAQ;AACf,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;;;ACFzB,SAAS,UAAAC,eAAc;AAIvB,SAAS,OAAO,aAAiC;AAC/C,MAAI,CAAC,YAAa,QAAO;AACzB,MAAI,gBAAgB,mBAAoB,QAAO;AAC/C,SACE,YAAY,WAAW,kBAAkB,KAAK,YAAY,SAAS,OAAO;AAE9E;AAGA,IAAM,YAAY,CAAC,UAA8B,CAAC,MAAM;AAEtD,QAAM,QAAQ,QAAQ,SAAS,OAAO;AAEtC,SAAO,CAAC,KAAmB,KAAoB,SAAe;AAC5D,QAAI,CAAC,OAAO,IAAI,QAAQ,cAAc,CAAC,EAAG,QAAO,KAAK;AAEtD,UAAM,SAAmB,CAAC;AAC1B,QAAI,gBAAgB;AAEpB,UAAM,SAAS,CAAC,UAAkB;AAChC,uBAAiB,MAAM;AAGvB,UAAI,gBAAgB,OAAO;AAEzB,YAAI,MAAM;AAGV,YAAI,eAAe,QAAQ,MAAM;AACjC,YAAI,eAAe,OAAO,KAAK;AAE/B;AAAA,UACE;AAAA,YACE;AAAA,YACA;AAAA;AAAA,YAEA;AAAA;AAAA,UACF;AAAA,QACF;AAEA;AAAA,MACF;AAEA,aAAO,KAAK,KAAK;AAAA,IACnB;AAEA,UAAM,QAAQ,MAAM;AAClB,UAAI;AAGF,cAAM,UACJ,OAAO,WAAW,IACd,O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AAI,MAAM;AACnB;","names":["fs","Buffer","Buffer","folderPath","filesMap","fs","path","fs","createHmac","timingSafeEqual","createHmac","timingSafeEqual","path","options","ErrorCode","path","fs","req","res"]}
|