@h4ad/serverless-adapter 4.2.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/lib/adapters/apollo-server/index.cjs +3 -3
  2. package/lib/adapters/apollo-server/index.cjs.map +1 -1
  3. package/lib/adapters/apollo-server/index.d.cts +3 -3
  4. package/lib/adapters/apollo-server/index.d.ts +3 -3
  5. package/lib/adapters/apollo-server/index.mjs +1 -1
  6. package/lib/adapters/apollo-server/index.mjs.map +1 -1
  7. package/lib/adapters/aws/index.cjs +3 -3
  8. package/lib/adapters/aws/index.cjs.map +1 -1
  9. package/lib/adapters/aws/index.d.cts +6 -0
  10. package/lib/adapters/aws/index.d.ts +6 -0
  11. package/lib/adapters/aws/index.mjs +1 -1
  12. package/lib/adapters/aws/index.mjs.map +1 -1
  13. package/lib/adapters/azure/index.cjs +2 -2
  14. package/lib/adapters/azure/index.cjs.map +1 -1
  15. package/lib/adapters/azure/index.mjs +1 -1
  16. package/lib/adapters/digital-ocean/index.cjs +2 -2
  17. package/lib/adapters/digital-ocean/index.cjs.map +1 -1
  18. package/lib/adapters/digital-ocean/index.mjs +1 -1
  19. package/lib/adapters/dummy/index.cjs +3 -3
  20. package/lib/adapters/dummy/index.cjs.map +1 -1
  21. package/lib/adapters/dummy/index.mjs +1 -1
  22. package/lib/adapters/huawei/index.cjs +2 -2
  23. package/lib/adapters/huawei/index.cjs.map +1 -1
  24. package/lib/adapters/huawei/index.mjs +1 -1
  25. package/lib/{chunk-57ZKWTH4.mjs → chunk-BLHUHVMU.mjs} +2 -2
  26. package/lib/{chunk-VPGUOREQ.mjs → chunk-TVNUJWDB.mjs} +2 -2
  27. package/lib/chunk-ZSZTKYDB.mjs +12 -0
  28. package/lib/chunk-ZSZTKYDB.mjs.map +1 -0
  29. package/lib/frameworks/apollo-server/index.cjs +2 -2
  30. package/lib/frameworks/apollo-server/index.cjs.map +1 -1
  31. package/lib/frameworks/apollo-server/index.mjs +1 -1
  32. package/lib/frameworks/body-parser/index.cjs +2 -2
  33. package/lib/frameworks/body-parser/index.cjs.map +1 -1
  34. package/lib/frameworks/body-parser/index.mjs +1 -1
  35. package/lib/frameworks/cors/index.cjs +3 -3
  36. package/lib/frameworks/cors/index.cjs.map +1 -1
  37. package/lib/frameworks/cors/index.mjs +1 -1
  38. package/lib/frameworks/deepkit/index.cjs +2 -2
  39. package/lib/frameworks/deepkit/index.cjs.map +1 -1
  40. package/lib/frameworks/deepkit/index.mjs +1 -1
  41. package/lib/frameworks/lazy/index.cjs +2 -2
  42. package/lib/frameworks/lazy/index.cjs.map +1 -1
  43. package/lib/frameworks/lazy/index.mjs +1 -1
  44. package/lib/frameworks/trpc/index.cjs +2 -2
  45. package/lib/frameworks/trpc/index.cjs.map +1 -1
  46. package/lib/frameworks/trpc/index.mjs +1 -1
  47. package/lib/handlers/aws/index.cjs +7 -7
  48. package/lib/handlers/aws/index.cjs.map +1 -1
  49. package/lib/handlers/aws/index.mjs +1 -1
  50. package/lib/handlers/aws/index.mjs.map +1 -1
  51. package/lib/handlers/azure/index.cjs +2 -2
  52. package/lib/handlers/azure/index.cjs.map +1 -1
  53. package/lib/handlers/azure/index.mjs +1 -1
  54. package/lib/handlers/default/index.cjs +2 -2
  55. package/lib/handlers/default/index.cjs.map +1 -1
  56. package/lib/handlers/default/index.mjs +1 -1
  57. package/lib/handlers/digital-ocean/index.cjs +2 -2
  58. package/lib/handlers/digital-ocean/index.cjs.map +1 -1
  59. package/lib/handlers/digital-ocean/index.mjs +1 -1
  60. package/lib/handlers/firebase/index.cjs +2 -2
  61. package/lib/handlers/firebase/index.cjs.map +1 -1
  62. package/lib/handlers/firebase/index.mjs +1 -1
  63. package/lib/handlers/gcp/index.cjs +2 -2
  64. package/lib/handlers/gcp/index.cjs.map +1 -1
  65. package/lib/handlers/gcp/index.mjs +1 -1
  66. package/lib/handlers/huawei/index.cjs +2 -2
  67. package/lib/handlers/huawei/index.cjs.map +1 -1
  68. package/lib/handlers/huawei/index.mjs +1 -1
  69. package/lib/index.cjs +7 -7
  70. package/lib/index.cjs.map +1 -1
  71. package/lib/index.d.cts +4 -1
  72. package/lib/index.d.ts +4 -1
  73. package/lib/index.mjs +1 -1
  74. package/lib/index.mjs.map +1 -1
  75. package/package.json +1 -1
  76. package/lib/chunk-PQDB5AVF.mjs +0 -12
  77. package/lib/chunk-PQDB5AVF.mjs.map +0 -1
  78. /package/lib/{chunk-57ZKWTH4.mjs.map → chunk-BLHUHVMU.mjs.map} +0 -0
  79. /package/lib/{chunk-VPGUOREQ.mjs.map → chunk-TVNUJWDB.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapters/aws/index.ts","../../../src/network/request.ts","../../../src/network/response.ts","../../../src/network/utils.ts","../../../src/network/response-stream.ts","../../../src/core/constants.ts","../../../src/core/event-body.ts","../../../src/core/headers.ts","../../../src/core/no-op.ts","../../../src/core/logger.ts","../../../src/core/optional.ts","../../../src/core/path.ts","../../../src/core/stream.ts","../../../src/adapters/aws/alb.adapter.ts","../../../src/adapters/aws/api-gateway-v1.adapter.ts","../../../src/adapters/aws/api-gateway-v2.adapter.ts","../../../src/adapters/aws/base/aws-simple-adapter.ts","../../../src/adapters/aws/dynamodb.adapter.ts","../../../src/adapters/aws/event-bridge.adapter.ts","../../../src/adapters/aws/lambda-edge.adapter.ts","../../../src/adapters/aws/s3.adapter.ts","../../../src/adapters/aws/sns.adapter.ts","../../../src/adapters/aws/sqs.adapter.ts","../../../src/adapters/aws/request-lambda-edge.adapter.ts"],"sourcesContent":["export * from './alb.adapter';\nexport * from './api-gateway-v1.adapter';\nexport * from './api-gateway-v2.adapter';\nexport * from './dynamodb.adapter';\nexport * from './event-bridge.adapter';\nexport * from './lambda-edge.adapter';\nexport * from './s3.adapter';\nexport * from './sns.adapter';\nexport * from './sqs.adapter';\nexport * from './base';\nexport * from './request-lambda-edge.adapter';\n","// ATTRIBUTION: https://github.com/dougmoscrop/serverless-http\nimport { IncomingMessage } from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport type { SingleValueHeaders } from '../@types';\nimport { NO_OP } from '../core';\n\nconst HTTPS_PORT = 443;\n\n/**\n * The properties to create a {@link ServerlessRequest}\n *\n * @breadcrumb Network / ServerlessRequest\n * @public\n */\nexport interface ServerlessRequestProps {\n /**\n * The HTTP Method of the request\n */\n method: string;\n\n /**\n * The URL requested\n */\n url: string;\n\n /**\n * The headers from the event source\n */\n headers: SingleValueHeaders;\n\n /**\n * The body from the event source\n */\n body?: Buffer | Uint8Array;\n\n /**\n * The IP Address from caller\n */\n remoteAddress?: string;\n}\n\n/**\n * The class that represents an {@link http#IncomingMessage} created by the library to represent an actual request to the framework.\n *\n * @breadcrumb Network / ServerlessRequest\n * @public\n */\nexport class ServerlessRequest extends IncomingMessage {\n constructor({\n method,\n url,\n headers,\n body,\n remoteAddress,\n }: ServerlessRequestProps) {\n super({\n encrypted: true,\n readable: false,\n remoteAddress,\n address: () => ({ port: HTTPS_PORT }) as AddressInfo,\n end: NO_OP,\n destroy: NO_OP,\n } as any);\n\n this.statusCode = 200;\n this.statusMessage = 'OK';\n this.complete = true;\n this.httpVersion = '1.1';\n this.httpVersionMajor = 1;\n this.httpVersionMinor = 1;\n this.method = method;\n this.headers = headers;\n this.body = body;\n this.url = url;\n this.ip = remoteAddress;\n\n this._read = () => {\n this.push(body);\n this.push(null);\n };\n }\n\n ip?: string;\n body?: Buffer | Uint8Array;\n}\n","// ATTRIBUTION: https://github.com/dougmoscrop/serverless-http\nimport { IncomingMessage, ServerResponse } from 'node:http';\nimport type { Socket } from 'node:net';\nimport { NO_OP } from '../core';\nimport { getString } from './utils';\n\nconst headerEnd = '\\r\\n\\r\\n';\nconst endChunked = '0\\r\\n\\r\\n';\n\nconst BODY = Symbol('Response body');\nconst HEADERS = Symbol('Response headers');\n\nfunction addData(stream: ServerlessResponse, data: Uint8Array | string) {\n if (\n Buffer.isBuffer(data) ||\n typeof data === 'string' ||\n data instanceof Uint8Array\n )\n stream[BODY].push(Buffer.from(data));\n else throw new Error(`response.write() of unexpected type: ${typeof data}`);\n}\n\n/**\n * The properties to create a {@link ServerlessResponse}.\n *\n * @breadcrumb Network / ServerlessResponse\n * @public\n */\nexport interface ServerlessResponseProps {\n /**\n * The HTTP Method from request\n */\n method?: string;\n}\n\n/**\n * The class that represents a response instance used to send to the framework and wait until the framework finishes processing the request.\n * Once it's happens, we use the properties from this response to built the response to the cloud.\n *\n * @breadcrumb Network / ServerlessResponse\n * @public\n */\nexport class ServerlessResponse extends ServerResponse {\n constructor({ method }: ServerlessResponseProps) {\n super({ method } as any);\n\n this[BODY] = [];\n this[HEADERS] = {};\n\n this.useChunkedEncodingByDefault = false;\n this.chunkedEncoding = false;\n this._header = '';\n\n // this ignore is used because I need to ignore these write calls:\n // https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L934-L935\n // https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L937\n let writesToIgnore = 1;\n\n const socket: Partial<Socket> & { _writableState: any } = {\n _writableState: {},\n writable: true,\n on: NO_OP,\n removeListener: NO_OP,\n destroy: NO_OP,\n cork: NO_OP,\n uncork: NO_OP,\n write: (\n data: Uint8Array | string,\n encoding?: string | null | (() => void),\n cb?: () => void,\n ): any => {\n if (typeof encoding === 'function') {\n cb = encoding;\n encoding = null;\n }\n\n if (this._header === '' || this._wroteHeader) {\n if (!this.chunkedEncoding) addData(this, data);\n else {\n if (writesToIgnore > 0) writesToIgnore--;\n else if (data !== endChunked) {\n addData(this, data);\n writesToIgnore = 3;\n }\n }\n } else {\n const string = getString(data);\n const index = string.indexOf(headerEnd);\n\n if (index !== -1) {\n const remainder = string.slice(index + headerEnd.length);\n\n if (remainder && !this.chunkedEncoding) addData(this, remainder);\n\n this._wroteHeader = true;\n }\n }\n\n if (typeof cb === 'function') cb();\n },\n };\n\n this.assignSocket(socket as unknown as Socket);\n }\n\n _header: string;\n _headers?: Record<any, any>;\n _wroteHeader?: boolean;\n\n [BODY]: any[];\n [HEADERS]: Record<any, any>;\n\n get headers(): Record<any, any> {\n return this[HEADERS];\n }\n\n static from(res: IncomingMessage) {\n const response = new ServerlessResponse({ method: res.method });\n\n response.statusCode = res.statusCode || 0;\n response[HEADERS] = res.headers;\n response[BODY] = (res as any).body ? [Buffer.from((res as any).body)] : [];\n response.end();\n\n return response;\n }\n\n static body(res: ServerlessResponse): Buffer {\n return Buffer.concat(res[BODY]);\n }\n\n static headers(res: ServerlessResponse) {\n const headers = res.getHeaders();\n\n return Object.assign(headers, res[HEADERS]);\n }\n\n override setHeader(\n key: string,\n value: number | string | readonly string[],\n ): any {\n if (this._wroteHeader) this[HEADERS][key] = value;\n else super.setHeader(key, value);\n }\n\n override writeHead(\n statusCode: number,\n statusMessage?: string | any | any[],\n obj?: any | any[],\n ): any {\n const headersObjOrArray =\n typeof statusMessage === 'string' ? obj : statusMessage;\n\n const arrayHeaders = Array.isArray(headersObjOrArray)\n ? headersObjOrArray\n : [headersObjOrArray || {}];\n\n for (const headers of arrayHeaders) {\n for (const name in headers) {\n this.setHeader(name, headers[name]!);\n\n if (!this._wroteHeader) {\n // we only need to initiate super.headers once\n // writeHead will add the other headers itself\n break;\n }\n }\n }\n\n return this.callNativeWriteHead(statusCode, statusMessage, obj);\n }\n\n /**\n * I use ignore here because in nodejs 12.x, statusMessage can be string | OutgoingHttpHeaders\n * But in nodejs \\>=14.x, statusMessage can also be OutgoingHttpHeaders[]\n * I take care of these cases above, but here I can't handle it well, so I give up\n * nodejs 12.x ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v12/http.d.ts#L229\n * nodejs 14.x ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v14/http.d.ts#L263\n */\n protected callNativeWriteHead(\n statusCode: number,\n statusMessage?: string | any | any[],\n obj?: any | any[],\n ): this {\n return super.writeHead(statusCode, statusMessage, obj);\n }\n}\n","/**\n * Get the data from a buffer, string, or Uint8Array\n *\n * @breadcrumb Network\n * @param data - The data that was written inside the stream\n */\nexport function getString(data: Buffer | string | unknown) {\n if (Buffer.isBuffer(data)) return data.toString('utf8');\n else if (typeof data === 'string') return data;\n else if (data instanceof Uint8Array) return new TextDecoder().decode(data);\n else throw new Error(`response.write() of unexpected type: ${typeof data}`);\n}\n","import { ServerResponse } from 'node:http';\nimport type { Socket } from 'node:net';\nimport type { Writable } from 'node:stream';\nimport type { BothValueHeaders } from '../@types';\nimport { type ILogger, NO_OP, parseHeaders } from '../core';\nimport { getString } from './utils';\n\nconst endChunked = '0\\r\\n\\r\\n';\nconst headerEnd = '\\r\\n\\r\\n';\nconst endStatusSeparator = '\\r\\n';\n\n/**\n * The properties to create a {@link ServerlessStreamResponse}.\n *\n * @breadcrumb Network / ServerlessStreamResponse\n * @public\n */\nexport interface ServerlessStreamResponseProps {\n /**\n * The HTTP Method from request\n */\n method?: string;\n\n /**\n * The callback to receive the headers when they are written to the stream\n * You need to return a writable stream be able to continue writing the response\n *\n * @param statusCode - The status code of the response\n * @param headers - The headers of the response\n */\n onReceiveHeaders: (statusCode: number, headers: BothValueHeaders) => Writable;\n\n /**\n * Instance of the logger\n */\n log: ILogger;\n}\n\n/**\n * The class that represents a response instance used to send to the framework and wait until the framework finishes processing the request.\n * This response is specially built to deal with transfer-encoding: chunked\n *\n * @breadcrumb Network / ServerlessStreamResponse\n * @public\n */\nexport class ServerlessStreamResponse extends ServerResponse {\n constructor({\n method,\n onReceiveHeaders,\n log,\n }: ServerlessStreamResponseProps) {\n super({ method } as any);\n\n this.useChunkedEncodingByDefault = true;\n this.chunkedEncoding = true;\n\n let internalWritable: Writable | null = null;\n let isFirstCall = true;\n // this ignore is used because I need to ignore these write calls:\n // https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L934-L935\n // https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L937\n let writesToIgnore = 0;\n\n const socket: Partial<Socket> & { _writableState: any } = {\n _writableState: {},\n writable: true,\n on: NO_OP,\n removeListener: NO_OP,\n destroy: NO_OP,\n cork: NO_OP,\n uncork: NO_OP,\n write: (\n data: Uint8Array | string,\n encoding?: string | null | (() => void),\n cb?: () => void,\n ): any => {\n // very unlikely, I don't even know how to reproduce this, but exist on types\n // istanbul ignore if\n if (typeof encoding === 'function') {\n cb = encoding;\n encoding = null;\n }\n\n log.debug('SERVERLESS_ADAPTER:RESPONSE_STREAM:DATA', () => ({\n data: Buffer.isBuffer(data) ? data.toString('utf8') : data,\n encoding,\n }));\n\n if (!isFirstCall && internalWritable) {\n if (data === endChunked) {\n internalWritable.end(cb);\n\n return true;\n }\n\n if (writesToIgnore > 0) {\n writesToIgnore--;\n return true;\n }\n\n internalWritable.write(data, cb);\n writesToIgnore = 3;\n } else if (isFirstCall) {\n isFirstCall = false;\n\n const stringData = getString(data);\n const endStatusIndex = stringData.indexOf(endStatusSeparator);\n const status = +stringData.slice(0, endStatusIndex).split(' ')[1];\n\n const headerData = stringData.slice(\n endStatusIndex + 2,\n stringData.indexOf(headerEnd),\n );\n const headers = parseHeaders(headerData);\n log.debug('SERVERLESS_ADAPTER:RESPONSE_STREAM:FRAMEWORK_HEADERS', {\n headers,\n });\n\n writesToIgnore = 1;\n internalWritable = onReceiveHeaders(status, headers);\n }\n\n return true;\n },\n };\n\n this.assignSocket(socket as unknown as Socket);\n }\n}\n","/**\n * Default encodings that are treated as binary, they are compared with the `Content-Encoding` header.\n *\n * @breadcrumb Core / Constants\n * @defaultValue ['gzip', 'deflate', 'br']\n * @public\n */\nexport const DEFAULT_BINARY_ENCODINGS: string[] = ['gzip', 'deflate', 'br'];\n\n/**\n * Default content types that are treated as binary, they are compared with the `Content-Type` header.\n *\n * @breadcrumb Core / Constants\n * @defaultValue ['image/png', 'image/jpeg', 'image/jpg', 'image/avif', 'image/bmp', 'image/x-png', 'image/gif', 'image/webp', 'video/mp4', 'application/pdf']\n * @public\n */\nexport const DEFAULT_BINARY_CONTENT_TYPES: string[] = [\n 'image/png',\n 'image/jpeg',\n 'image/jpg',\n 'image/avif',\n 'image/bmp',\n 'image/x-png',\n 'image/gif',\n 'image/webp',\n 'video/mp4',\n 'application/pdf',\n];\n\n/**\n * Type alias for empty response and can be used on some adapters when the adapter does not need to return a response.\n *\n * @breadcrumb Core / Constants\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type IEmptyResponse = {};\n\n/**\n * Constant for empty response and can be used on some adapters when the adapter does not need to return a response.\n *\n * @breadcrumb Core / Constants\n * @public\n */\nexport const EmptyResponse: IEmptyResponse = {};\n","/**\n * Get the event body as buffer from body string with content length\n *\n * @example\n * ```typescript\n * const body = '{}';\n * const [buffer, contentLength] = getEventBodyAsBuffer(body, false);\n * console.log(buffer);\n * // <Buffer 7b 7d>\n * console.log(contentLength);\n * // 2\n * ```\n *\n * @param body - The body string that can be encoded or not\n * @param isBase64Encoded - Tells if body string is encoded in base64\n *\n * @breadcrumb Core\n * @public\n */\nexport function getEventBodyAsBuffer(\n body: string,\n isBase64Encoded: boolean,\n): [body: Buffer, contentLength: number] {\n const encoding: BufferEncoding = isBase64Encoded ? 'base64' : 'utf8';\n\n const buffer = Buffer.from(body, encoding);\n const contentLength = Buffer.byteLength(buffer, encoding);\n\n return [buffer, contentLength];\n}\n","//#region Imports\n\nimport type { BothValueHeaders } from '../@types';\n\n//#endregion\n\n/**\n * Transform a header map and make sure the value is not an array\n *\n * @example\n * ```typescript\n * const headers = { 'accept-encoding': 'gzip', 'accept-language': ['en-US', 'en;q=0.9'] };\n * const flattenedHeaders = getFlattenedHeadersMap(headers, ',', true);\n * console.log(flattenedHeaders);\n * // { 'accept-encoding': 'gzip', 'accept-language': 'en-US,en;q=0.9' }\n * ```\n *\n * @param headersMap - The initial headers\n * @param separator - The separator used when we join the array of header's value\n * @param lowerCaseKey - Should put all keys in lowercase\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getFlattenedHeadersMap(\n headersMap: BothValueHeaders,\n separator: string = ',',\n lowerCaseKey: boolean = false,\n): Record<string, string> {\n return Object.keys(headersMap).reduce((acc, headerKey) => {\n const newKey = lowerCaseKey ? headerKey.toLowerCase() : headerKey;\n const headerValue = headersMap[headerKey];\n\n if (Array.isArray(headerValue)) acc[newKey] = headerValue.join(separator);\n else acc[newKey] = (headerValue ?? '') + '';\n\n return acc;\n }, {});\n}\n\n/**\n * Transforms a header map into a multi-value map header.\n *\n * @example\n * ```typescript\n * const headers = { 'accept-encoding': 'gzip', 'connection': ['keep-alive'] };\n * const multiValueHeaders = getMultiValueHeadersMap(headers);\n * console.log(multiValueHeaders);\n * // { 'accept-encoding': ['gzip'], 'connection': ['keep-alive'] }\n * ```\n *\n * @param headersMap - The initial headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getMultiValueHeadersMap(\n headersMap: BothValueHeaders,\n): Record<string, string[]> {\n return Object.keys(headersMap).reduce((acc, headerKey) => {\n const headerValue = headersMap[headerKey];\n\n acc[headerKey.toLowerCase()] = Array.isArray(headerValue)\n ? headerValue.map(String)\n : [String(headerValue)];\n\n return acc;\n }, {});\n}\n\n/**\n * The wrapper that holds the information about single value headers and cookies\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport type FlattenedHeadersAndCookies = {\n /**\n * Just the single value headers\n */\n headers: Record<string, string>;\n\n /**\n * The list of cookies\n */\n cookies: string[];\n};\n\n/**\n * Transforms a header map into a single value headers and cookies\n *\n * @param headersMap - The initial headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getFlattenedHeadersMapAndCookies(\n headersMap: BothValueHeaders,\n): FlattenedHeadersAndCookies {\n return Object.keys(headersMap).reduce(\n (acc, headerKey) => {\n const headerValue = headersMap[headerKey];\n const lowerHeaderKey = headerKey.toLowerCase();\n\n if (Array.isArray(headerValue)) {\n if (lowerHeaderKey !== 'set-cookie')\n acc.headers[headerKey] = headerValue.join(',');\n else acc.cookies.push(...headerValue);\n } else {\n if (lowerHeaderKey === 'set-cookie' && headerValue !== undefined)\n acc.cookies.push(headerValue ?? '');\n else acc.headers[headerKey] = String(headerValue ?? '');\n }\n\n return acc;\n },\n {\n cookies: [],\n headers: {},\n } as FlattenedHeadersAndCookies,\n );\n}\n\n/**\n * Parse HTTP Raw Headers\n * Attribution to {@link https://github.com/kesla/parse-headers/blob/master/parse-headers.js}\n *\n * @param headers - The raw headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function parseHeaders(\n headers: string,\n): Record<string, string | string[]> {\n if (!headers) return {};\n\n const result = {};\n const headersArr = headers.trim().split('\\n');\n\n for (let i = 0; i < headersArr.length; i++) {\n const row = headersArr[i];\n const index = row.indexOf(':');\n const key = row.slice(0, index).trim().toLowerCase();\n const value = row.slice(index + 1).trim();\n\n if (typeof result[key] === 'undefined') result[key] = value;\n else if (Array.isArray(result[key])) result[key].push(value);\n else result[key] = [result[key], value];\n }\n\n return result;\n}\n","/**\n * No operation function is used when we need to pass a function, but we don't want to specify any behavior.\n *\n * @breadcrumb Core\n * @public\n */\nexport const NO_OP: (...args: any[]) => any = () => void 0;\n","import { NO_OP } from './no-op';\n\n/**\n * The type representing the possible log levels to choose from.\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport type LogLevels =\n | 'debug'\n | 'verbose'\n | 'info'\n | 'warn'\n | 'error'\n | 'none';\n\n/**\n * The options to customize {@link ILogger}\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport type LoggerOptions = {\n /**\n * Select the log level, {@link LogLevels | see more}.\n *\n * @defaultValue error\n */\n level: LogLevels;\n};\n\n/**\n * The log function used in any level.\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport type LoggerFN = (message: any, ...additional: any[]) => void;\n\n/**\n * The interface representing the logger, you can provide a custom logger by implementing this interface.\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport type ILogger = Record<Exclude<LogLevels, 'none'>, LoggerFN>;\n\n/**\n * The symbol used to check against an ILogger instace to verify if that ILogger was created by this library\n *\n * @breadcrumb Core / Logger\n * @public\n */\nconst InternalLoggerSymbol = Symbol('InternalLogger');\n\nconst logLevels: Record<\n LogLevels,\n [level: LogLevels, consoleMethod: keyof Console][]\n> = {\n debug: [\n ['debug', 'debug'],\n ['verbose', 'debug'],\n ['info', 'info'],\n ['error', 'error'],\n ['warn', 'warn'],\n ],\n verbose: [\n ['verbose', 'debug'],\n ['info', 'info'],\n ['error', 'error'],\n ['warn', 'warn'],\n ],\n info: [\n ['info', 'info'],\n ['error', 'error'],\n ['warn', 'warn'],\n ],\n warn: [\n ['warn', 'warn'],\n ['error', 'error'],\n ],\n error: [['error', 'error']],\n none: [],\n};\n\nconst lazyPrint = (value: () => any | unknown) => {\n if (typeof value === 'function') return value();\n\n return value;\n};\n\nconst print =\n (fn: string) =>\n (message: any, ...additional: (() => any)[]) =>\n console[fn](message, ...additional.map(lazyPrint));\n\n/**\n * The method used to create a simple logger instance to use in this library.\n *\n * @remarks Behind the scenes, this simple logger sends the message to the `console` methods.\n *\n * @example\n * ```typescript\n * const logger = createDefaultLogger();\n *\n * logger.error('An error happens.');\n * // An error happens.\n * ```\n *\n * @param level - Select the level of the log\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport function createDefaultLogger(\n { level }: LoggerOptions = { level: 'error' },\n): ILogger {\n const levels = logLevels[level];\n\n if (!levels) throw new Error('Invalid log level');\n\n const logger = {\n [InternalLoggerSymbol]: true,\n error: NO_OP,\n debug: NO_OP,\n info: NO_OP,\n verbose: NO_OP,\n warn: NO_OP,\n } as ILogger;\n\n for (const [level, consoleMethod] of levels)\n logger[level] = print(consoleMethod);\n\n return logger;\n}\n\n/**\n * The method used to chck if logger was created by this library, or it was defined by the user.\n *\n * @param logger - The instance of the logger to check\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport function isInternalLogger(logger: ILogger): boolean {\n return !!logger[InternalLoggerSymbol];\n}\n","/**\n * Return the defaultValue whether the value is undefined, otherwise, return the value.\n *\n * @example\n * ```typescript\n * const value1 = getDefaultIfUndefined(undefined, true);\n * const value2 = getDefaultIfUndefined(false, true);\n *\n * console.log(value1);\n * // true\n * console.log(value2);\n * // false\n * ```\n *\n * @param value - The value to be checked\n * @param defaultValue - The default value when value is undefined\n *\n * @breadcrumb Core\n * @public\n */\nexport function getDefaultIfUndefined<T>(\n value: T | undefined,\n defaultValue: T,\n): T {\n if (value === undefined) return defaultValue;\n\n return value;\n}\n","/**\n * Transform the path and a map of query params to a string with formatted query params\n *\n * @example\n * ```typescript\n * const path = '/pets/search';\n * const queryParams = { batata: undefined, petType: [ 'dog', 'fish' ] };\n * const result = getPathWithQueryStringParams(path, queryParams);\n * console.log(result);\n * // /pets/search?batata=&petType=dog&petType=fish\n * ```\n *\n * @param path - The path\n * @param queryParams - The query params\n *\n * @breadcrumb Core / Path\n * @public\n */\nexport function getPathWithQueryStringParams(\n path: string,\n queryParams:\n | string\n | Record<string, string | string[] | undefined>\n | undefined\n | null,\n): string {\n if (String(queryParams || '').length === 0) return path;\n\n if (typeof queryParams === 'string') return `${path}?${queryParams}`;\n\n const queryParamsString = getQueryParamsStringFromRecord(queryParams);\n\n if (!queryParamsString) return path;\n\n return `${path}?${queryParamsString}`;\n}\n\n/**\n * Map query params to a string with formatted query params\n *\n * @example\n * ```typescript\n * const queryParams = { batata: undefined, petType: [ 'dog', 'fish' ] };\n * const result = getQueryParamsStringFromRecord(queryParams);\n * console.log(result);\n * // batata=&petType=dog&petType=fish\n * ```\n *\n * @param queryParamsRecord - The query params record\n *\n * @breadcrumb Core / Path\n * @public\n */\nexport function getQueryParamsStringFromRecord(\n queryParamsRecord:\n | Record<string, string | string[] | undefined>\n | undefined\n | null,\n): string {\n const searchParams = new URLSearchParams();\n\n const multiValueHeadersEntries: [string, string | string[] | undefined][] =\n Object.entries(queryParamsRecord || {});\n\n if (multiValueHeadersEntries.length === 0) return '';\n\n for (const [key, value] of multiValueHeadersEntries) {\n if (!Array.isArray(value)) {\n searchParams.append(key, value || '');\n continue;\n }\n\n for (const arrayValue of value) searchParams.append(key, arrayValue);\n }\n\n return searchParams.toString();\n}\n\n/**\n * Type of the function to strip base path\n *\n * @breadcrumb Core / Path\n * @public\n */\nexport type StripBasePathFn = (path: string) => string;\n\nconst NOOPBasePath: StripBasePathFn = (path: string) => path;\n\n/**\n * Get the strip base path function\n *\n * @param basePath - The base path\n *\n * @breadcrumb Core / Path\n * @public\n */\nexport function buildStripBasePath(\n basePath: string | undefined,\n): StripBasePathFn {\n if (!basePath) return NOOPBasePath;\n\n const length = basePath.length;\n\n return (path: string) => {\n if (path.startsWith(basePath))\n return path.slice(path.indexOf(basePath) + length, path.length) || '/';\n\n return path;\n };\n}\n","//#region Imports\n\nimport { Readable, Writable } from 'node:stream';\n\n//#endregion\n\n/**\n * Check if stream already ended\n *\n * @param stream - The stream\n *\n * @breadcrumb Core / Stream\n * @public\n */\nexport function isStreamEnded(stream: Readable | Writable): boolean {\n if ('readableEnded' in stream && stream.readableEnded) return true;\n\n if ('writableEnded' in stream && stream.writableEnded) return true;\n\n return false;\n}\n\n/**\n * Wait asynchronous the stream to complete\n *\n * @param stream - The stream\n *\n * @breadcrumb Core / Stream\n * @public\n */\nexport function waitForStreamComplete<TStream extends Readable | Writable>(\n stream: TStream,\n): Promise<TStream> {\n if (isStreamEnded(stream)) return Promise.resolve(stream);\n\n return new Promise<TStream>((resolve, reject) => {\n // Reading the {@link https://github.com/nodejs/node/blob/v12.22.9/lib/events.js#L262 | emit source code},\n // it's almost impossible to complete being called twice because the emit function runs synchronously and removes the other listeners,\n // but I'll leave it at that because I didn't write that code, so I couldn't figure out what the author thought when he wrote this.\n let isComplete = false;\n\n function complete(err: any) {\n /* istanbul ignore next */\n if (isComplete) return;\n\n isComplete = true;\n\n stream.removeListener('error', complete);\n stream.removeListener('end', complete);\n stream.removeListener('finish', complete);\n\n if (err) reject(err);\n else resolve(stream);\n }\n\n stream.once('error', complete);\n stream.once('end', complete);\n stream.once('finish', complete);\n });\n}\n","//#region Imports\n\nimport type { ALBEvent, ALBResult, Context } from 'aws-lambda';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n type StripBasePathFn,\n buildStripBasePath,\n getEventBodyAsBuffer,\n getFlattenedHeadersMap,\n getMultiValueHeadersMap,\n getPathWithQueryStringParams,\n} from '../../core';\n\n//#endregion\n\n/**\n * The options to customize the {@link AlbAdapter}\n *\n * @breadcrumb Adapters / AWS / AlbAdapter\n * @public\n */\nexport interface AlbAdapterOptions {\n /**\n * Strip base path for custom domains\n *\n * @defaultValue ''\n */\n stripBasePath?: string;\n}\n\n/**\n * The adapter to handle requests from AWS ALB\n *\n * @example\n * ```typescript\n * const stripBasePath = '/any/custom/base/path'; // default ''\n * const adapter = new AlbAdapter({ stripBasePath });\n * ```\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html | Event Reference}\n *\n * @breadcrumb Adapters / AWS / AlbAdapter\n * @public\n */\nexport class AlbAdapter\n implements AdapterContract<ALBEvent, Context, ALBResult>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link AlbAdapter}\n */\n constructor(protected readonly options?: AlbAdapterOptions) {\n this.stripPathFn = buildStripBasePath(this.options?.stripBasePath);\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Strip base path function\n */\n protected stripPathFn: StripBasePathFn;\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return AlbAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is ALBEvent {\n const albEvent = event as Partial<ALBEvent>;\n\n return !!(albEvent?.requestContext && albEvent.requestContext.elb);\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: ALBEvent): AdapterRequest {\n const method = event.httpMethod;\n const path = this.getPathFromEvent(event);\n\n const headers = event.multiValueHeaders\n ? getFlattenedHeadersMap(event.multiValueHeaders, ',', true)\n : event.headers!;\n\n let body: Buffer | undefined;\n\n if (event.body) {\n const [bufferBody, contentLength] = getEventBodyAsBuffer(\n event.body,\n event.isBase64Encoded,\n );\n\n body = bufferBody;\n headers['content-length'] = String(contentLength);\n }\n\n let remoteAddress = '';\n\n // ref: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html#x-forwarded-for\n if (headers['x-forwarded-for']) remoteAddress = headers['x-forwarded-for'];\n\n return {\n method,\n headers,\n body,\n remoteAddress,\n path,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n event,\n headers: responseHeaders,\n body,\n isBase64Encoded,\n statusCode,\n }: GetResponseAdapterProps<ALBEvent>): ALBResult {\n const multiValueHeaders = !event.headers\n ? getMultiValueHeadersMap(responseHeaders)\n : undefined;\n\n const headers = event.headers\n ? getFlattenedHeadersMap(responseHeaders)\n : undefined;\n\n if (headers && headers['transfer-encoding'] === 'chunked')\n delete headers['transfer-encoding'];\n\n if (\n multiValueHeaders &&\n multiValueHeaders['transfer-encoding']?.includes('chunked')\n )\n delete multiValueHeaders['transfer-encoding'];\n\n return {\n statusCode,\n body,\n headers,\n multiValueHeaders,\n isBase64Encoded,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n respondWithErrors,\n event,\n log,\n }: OnErrorProps<ALBEvent, ALBResult>): void {\n const body = respondWithErrors ? error.stack || '' : '';\n const errorResponse = this.getResponse({\n event,\n statusCode: 500,\n body,\n headers: {},\n isBase64Encoded: false,\n log,\n });\n\n delegatedResolver.succeed(errorResponse);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Get path from event with query strings\n *\n * @param event - The event sent by serverless\n */\n protected getPathFromEvent(event: ALBEvent): string {\n const path = this.stripPathFn(event.path);\n\n const queryParams = event.headers\n ? event.queryStringParameters\n : event.multiValueQueryStringParameters;\n\n return getPathWithQueryStringParams(path, queryParams || {});\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { APIGatewayProxyResult, Context } from 'aws-lambda';\nimport type { APIGatewayProxyEvent } from 'aws-lambda/trigger/api-gateway-proxy';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n type StripBasePathFn,\n buildStripBasePath,\n getDefaultIfUndefined,\n getEventBodyAsBuffer,\n getMultiValueHeadersMap,\n getPathWithQueryStringParams,\n} from '../../core';\n\n//#endregion\n\n/**\n * The options to customize the {@link ApiGatewayV1Adapter}\n *\n * @breadcrumb Adapters / AWS / ApiGatewayV1Adapter\n * @public\n */\nexport interface ApiGatewayV1Options {\n /**\n * Strip base path for custom domains\n *\n * @defaultValue ''\n */\n stripBasePath?: string;\n\n /**\n * Throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer.\n * If this is set to `false`, we will remove the `transfer-encoding` header from the response and buffer the response body\n * while we remove the special characters inserted by the chunked encoding.\n *\n * @remarks To learn more https://github.com/H4ad/serverless-adapter/issues/165\n * @defaultValue true\n */\n throwOnChunkedTransferEncoding?: boolean;\n}\n\n/**\n * The adapter to handle requests from AWS Api Gateway V1\n *\n * As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer.\n *\n * @remarks This adapter is not fully compatible with \\@vendia/serverless-express, on \\@vendia they filter `transfer-encoding=chunked` but we throw an exception.\n *\n * @example\n * ```typescript\n * const stripBasePath = '/any/custom/base/path'; // default ''\n * const adapter = new ApiGatewayV1Adapter({ stripBasePath });\n * ```\n *\n * {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html | Event Reference}\n *\n * @breadcrumb Adapters / AWS / ApiGatewayV1Adapter\n * @public\n */\nexport class ApiGatewayV1Adapter\n implements\n AdapterContract<APIGatewayProxyEvent, Context, APIGatewayProxyResult>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link ApiGatewayV1Adapter}\n */\n constructor(protected readonly options?: ApiGatewayV1Options) {\n this.stripPathFn = buildStripBasePath(this.options?.stripBasePath);\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Strip base path function\n */\n protected stripPathFn: StripBasePathFn;\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return ApiGatewayV1Adapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is APIGatewayProxyEvent {\n const partialEventV1 = event as Partial<APIGatewayProxyEvent> & {\n version?: '2.0';\n };\n\n return !!(\n partialEventV1?.requestContext &&\n partialEventV1.version !== '2.0' &&\n partialEventV1.headers &&\n partialEventV1.multiValueHeaders &&\n ((partialEventV1.queryStringParameters === null &&\n partialEventV1.multiValueQueryStringParameters === null) ||\n (partialEventV1.queryStringParameters &&\n partialEventV1.multiValueQueryStringParameters))\n );\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: APIGatewayProxyEvent): AdapterRequest {\n const method = event.httpMethod;\n const headers = { ...event.headers };\n\n for (const multiValueHeaderKey of Object.keys(\n event.multiValueHeaders || {},\n )) {\n const headerValue = event.multiValueHeaders[multiValueHeaderKey];\n\n // event.headers by default only stick with first value if they see multiple headers\n // the other values will only appear on multiValueHeaderKey, in this case\n // we look for headers with more than 1 length which is the wrong values on event.headers\n // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html\n if (!headerValue || headerValue?.length <= 1) continue;\n\n headers[multiValueHeaderKey] = headerValue.join(',');\n }\n\n const path = this.getPathFromEvent(event);\n\n let body: Buffer | undefined;\n\n if (event.body) {\n const [bufferBody, contentLength] = getEventBodyAsBuffer(\n event.body,\n event.isBase64Encoded,\n );\n\n body = bufferBody;\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n headers['content-length'] = contentLength + '';\n }\n\n const remoteAddress = event.requestContext.identity.sourceIp;\n\n return {\n method,\n headers,\n body,\n remoteAddress,\n path,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n headers: responseHeaders,\n body,\n isBase64Encoded,\n statusCode,\n response,\n }: GetResponseAdapterProps<APIGatewayProxyEvent>): APIGatewayProxyResult {\n const multiValueHeaders = getMultiValueHeadersMap(responseHeaders);\n\n const shouldThrowOnChunkedTransferEncoding = getDefaultIfUndefined(\n this.options?.throwOnChunkedTransferEncoding,\n true,\n );\n const transferEncodingHeader = multiValueHeaders['transfer-encoding'];\n const hasTransferEncodingChunked = transferEncodingHeader?.some(value =>\n value.includes('chunked'),\n );\n\n if (hasTransferEncodingChunked || response?.chunkedEncoding) {\n if (shouldThrowOnChunkedTransferEncoding) {\n throw new Error(\n 'chunked encoding in headers is not supported by API Gateway V1',\n );\n } else delete multiValueHeaders['transfer-encoding'];\n }\n\n return {\n statusCode,\n body,\n multiValueHeaders,\n isBase64Encoded,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n respondWithErrors,\n event,\n log,\n }: OnErrorProps<APIGatewayProxyEvent, APIGatewayProxyResult>): void {\n const body = respondWithErrors ? error.stack : '';\n const errorResponse = this.getResponse({\n event,\n statusCode: 500,\n body: body || '',\n headers: {},\n isBase64Encoded: false,\n log,\n });\n\n delegatedResolver.succeed(errorResponse);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Get path from event with query strings\n *\n * @param event - The event sent by serverless\n */\n protected getPathFromEvent(event: APIGatewayProxyEvent): string {\n const path = this.stripPathFn(event.path);\n const queryParams = event.multiValueQueryStringParameters || {};\n\n if (event.queryStringParameters) {\n for (const queryStringKey of Object.keys(event.queryStringParameters)) {\n const queryStringValue = event.queryStringParameters[queryStringKey];\n\n if (queryStringValue === undefined) continue;\n\n if (!Array.isArray(queryParams[queryStringKey]))\n queryParams[queryStringKey] = [];\n\n if (queryParams[queryStringKey]!.includes(queryStringValue)) continue;\n\n queryParams[queryStringKey]!.push(queryStringValue);\n }\n }\n\n return getPathWithQueryStringParams(path, queryParams);\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { APIGatewayProxyEventV2, Context } from 'aws-lambda';\nimport type { APIGatewayProxyStructuredResultV2 } from 'aws-lambda/trigger/api-gateway-proxy';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n type StripBasePathFn,\n buildStripBasePath,\n getDefaultIfUndefined,\n getEventBodyAsBuffer,\n getFlattenedHeadersMapAndCookies,\n getPathWithQueryStringParams,\n} from '../../core';\n\n//#endregion\n\n/**\n * The options to customize the {@link ApiGatewayV2Adapter}\n *\n * @breadcrumb Adapters / AWS / ApiGatewayV2Adapter\n * @public\n */\nexport interface ApiGatewayV2Options {\n /**\n * Strip base path for custom domains\n *\n * @defaultValue ''\n */\n stripBasePath?: string;\n\n /**\n * Throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer.\n * If this is set to `false`, we will remove the `transfer-encoding` header from the response and buffer the response body\n * while we remove the special characters inserted by the chunked encoding.\n *\n * @remarks To learn more https://github.com/H4ad/serverless-adapter/issues/165\n * @defaultValue true\n */\n throwOnChunkedTransferEncoding?: boolean;\n}\n\n/**\n * The adapter to handle requests from AWS Api Gateway V2\n *\n * As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked`.\n * But, if you use this adapter to accept requests from Function URL, you can accept the `transfer-encoding=chunked` changing the method of invocation from `BUFFERED` to `RESPONSE_STREAM`.\n *\n * @example\n * ```typescript\n * const stripBasePath = '/any/custom/base/path'; // default ''\n * const adapter = new ApiGatewayV2Adapter({ stripBasePath });\n * ```\n *\n * {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html | Event Reference}\n *\n * @breadcrumb Adapters / AWS / ApiGatewayV2Adapter\n * @public\n */\nexport class ApiGatewayV2Adapter\n implements\n AdapterContract<\n APIGatewayProxyEventV2,\n Context,\n APIGatewayProxyStructuredResultV2\n >\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link ApiGatewayV2Adapter}\n */\n constructor(protected readonly options?: ApiGatewayV2Options) {\n this.stripPathFn = buildStripBasePath(this.options?.stripBasePath);\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Strip base path function\n */\n protected stripPathFn: StripBasePathFn;\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return ApiGatewayV2Adapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is APIGatewayProxyEventV2 {\n const apiGatewayEvent = event as Partial<APIGatewayProxyEventV2> & {\n version?: string;\n };\n\n return !!(\n apiGatewayEvent?.requestContext && apiGatewayEvent.version === '2.0'\n );\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: APIGatewayProxyEventV2): AdapterRequest {\n const method = event.requestContext.http.method;\n const path = this.getPathFromEvent(event);\n // accords https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html\n // all headers are lowercased and cannot be array\n // so no need to format, just a shallow copy will work here\n const headers = { ...event.headers };\n\n if (event.cookies) headers.cookie = event.cookies.join('; ');\n\n let body: Buffer | undefined;\n\n if (event.body) {\n const [bufferBody, contentLength] = getEventBodyAsBuffer(\n event.body,\n event.isBase64Encoded,\n );\n\n body = bufferBody;\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n headers['content-length'] = contentLength + '';\n }\n\n const remoteAddress = event.requestContext.http.sourceIp;\n\n return {\n method,\n headers,\n body,\n remoteAddress,\n path,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n headers: responseHeaders,\n body,\n isBase64Encoded,\n statusCode,\n response,\n }: GetResponseAdapterProps<APIGatewayProxyEventV2>): APIGatewayProxyStructuredResultV2 {\n const { cookies, headers } =\n getFlattenedHeadersMapAndCookies(responseHeaders);\n\n const shouldThrowOnChunkedTransferEncoding = getDefaultIfUndefined(\n this.options?.throwOnChunkedTransferEncoding,\n true,\n );\n\n const transferEncodingHeader: string | undefined =\n headers['transfer-encoding'];\n\n const hasTransferEncodingChunked =\n transferEncodingHeader && transferEncodingHeader.includes('chunked');\n\n if (hasTransferEncodingChunked || response?.chunkedEncoding) {\n if (shouldThrowOnChunkedTransferEncoding) {\n throw new Error(\n 'chunked encoding in headers is not supported by API Gateway V2',\n );\n } else delete headers['transfer-encoding'];\n }\n\n return {\n statusCode,\n body,\n headers,\n isBase64Encoded,\n cookies,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n respondWithErrors,\n event,\n log,\n }: OnErrorProps<\n APIGatewayProxyEventV2,\n APIGatewayProxyStructuredResultV2\n >): void {\n const body = respondWithErrors ? error.stack : '';\n const errorResponse = this.getResponse({\n event,\n statusCode: 500,\n body: body || '',\n headers: {},\n isBase64Encoded: false,\n log,\n });\n\n delegatedResolver.succeed(errorResponse);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Get path from event with query strings\n *\n * @param event - The event sent by serverless\n */\n protected getPathFromEvent(event: APIGatewayProxyEventV2): string {\n const path = this.stripPathFn(event.rawPath);\n const queryParams = event.rawQueryString;\n\n return getPathWithQueryStringParams(path, queryParams || {});\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { Context, SQSBatchItemFailure } from 'aws-lambda';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../../contracts';\nimport {\n EmptyResponse,\n type IEmptyResponse,\n getEventBodyAsBuffer,\n} from '../../../core';\n\n//#endregion\n\n/**\n * The options to customize the {@link AwsSimpleAdapter}\n *\n * @breadcrumb Adapters / AWS / AWS Simple Adapter\n * @public\n */\nexport interface AWSSimpleAdapterOptions {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n */\n forwardPath: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n */\n forwardMethod: string;\n\n /**\n * The AWS Service host that will be injected inside headers to developer being able to validate if request originate from the library.\n */\n host: string;\n\n /**\n * Tells if this adapter should support batch item failures.\n */\n batch?: true | false;\n}\n\n/**\n * The batch item failure response expected from the API server\n *\n * @breadcrumb Adapters / AWS / AWS Simple Adapter\n * @public\n */\nexport type BatchItemFailureResponse = SQSBatchItemFailure;\n\n/**\n * The possible options of response for {@link AwsSimpleAdapter}\n *\n * @breadcrumb Adapters / AWS / AWS Simple Adapter\n * @public\n */\nexport type AWSSimpleAdapterResponseType =\n | BatchItemFailureResponse\n | IEmptyResponse;\n\n/**\n * The abstract adapter to use to implement other simple AWS adapters\n *\n * @breadcrumb Adapters / AWS / AWS Simple Adapter\n * @public\n */\nexport abstract class AwsSimpleAdapter<TEvent>\n implements AdapterContract<TEvent, Context, AWSSimpleAdapterResponseType>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link AwsSimpleAdapter}\n */\n constructor(protected readonly options: AWSSimpleAdapterOptions) {}\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n throw new Error('not implemented.');\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(_: unknown): _ is TEvent {\n throw new Error('not implemented.');\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: TEvent): AdapterRequest {\n const path = this.options.forwardPath;\n const method = this.options.forwardMethod;\n\n const [body, contentLength] = getEventBodyAsBuffer(\n JSON.stringify(event),\n false,\n );\n\n const headers = {\n host: this.options.host,\n 'content-type': 'application/json',\n 'content-length': String(contentLength),\n };\n\n return {\n method,\n headers,\n body,\n path,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n body,\n headers,\n isBase64Encoded,\n event,\n statusCode,\n }: GetResponseAdapterProps<TEvent>): AWSSimpleAdapterResponseType {\n if (this.hasInvalidStatusCode(statusCode)) {\n throw new Error(\n JSON.stringify({ body, headers, isBase64Encoded, event, statusCode }),\n );\n }\n\n if (!this.options.batch) return EmptyResponse;\n\n if (isBase64Encoded) {\n throw new Error(\n 'SERVERLESS_ADAPTER: The response could not be base64 encoded when you set batch: true, the response should be a JSON.',\n );\n }\n\n if (!body) return EmptyResponse;\n\n return JSON.parse(body);\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n }: OnErrorProps<TEvent, AWSSimpleAdapterResponseType>): void {\n delegatedResolver.fail(error);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Check if the status code is invalid\n *\n * @param statusCode - The status code\n */\n protected hasInvalidStatusCode(statusCode: number): boolean {\n return statusCode < 200 || statusCode >= 400;\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { DynamoDBStreamEvent } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { type AWSSimpleAdapterOptions, AwsSimpleAdapter } from './base/index';\n\n//#endregion\n\n/**\n * The options to customize the {@link DynamoDBAdapter}\n *\n * @breadcrumb Adapters / AWS / DynamoDBAdapter\n * @public\n */\nexport interface DynamoDBAdapterOptions\n extends Pick<AWSSimpleAdapterOptions, 'batch'> {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /dynamo\n */\n dynamoDBForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n dynamoDBForwardMethod?: string;\n}\n\n/**\n * The adapter to handle requests from AWS DynamoDB.\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html | Event Reference}\n *\n * @example\n * ```typescript\n * const dynamoDBForwardPath = '/your/route/dynamo'; // default /dynamo\n * const dynamoDBForwardMethod = 'POST'; // default POST\n * const adapter = new DynamoDBAdapter({ dynamoDBForwardPath, dynamoDBForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / DynamoDBAdapter\n * @public\n */\nexport class DynamoDBAdapter extends AwsSimpleAdapter<DynamoDBStreamEvent> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link DynamoDBAdapter}\n */\n constructor(options?: DynamoDBAdapterOptions) {\n super({\n forwardPath: getDefaultIfUndefined(\n options?.dynamoDBForwardPath,\n '/dynamo',\n ),\n forwardMethod: getDefaultIfUndefined(\n options?.dynamoDBForwardMethod,\n 'POST',\n ),\n batch: options?.batch,\n host: 'dynamodb.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return DynamoDBAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is DynamoDBStreamEvent {\n const dynamoDBevent = event as Partial<DynamoDBStreamEvent>;\n\n if (!Array.isArray(dynamoDBevent?.Records)) return false;\n\n const eventSource = dynamoDBevent.Records[0]?.eventSource;\n\n return eventSource === 'aws:dynamodb';\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { EventBridgeEvent } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { AwsSimpleAdapter } from './base';\n\n//#endregion\n\n/**\n * The options to customize the {@link EventBridgeAdapter}\n *\n * @breadcrumb Adapters / AWS / EventBridgeAdapter\n * @public\n */\nexport interface EventBridgeOptions {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /eventbridge\n */\n eventBridgeForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n eventBridgeForwardMethod?: string;\n}\n\n/**\n * Just a type alias to ignore generic types in the event\n *\n * @breadcrumb Adapters / AWS / EventBridgeAdapter\n * @public\n */\nexport type EventBridgeEventAll = EventBridgeEvent<any, any>;\n\n/**\n * The adapter to handle requests from AWS EventBridge (Cloudwatch Events).\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html | Event Reference}\n *\n * @example\n * ```typescript\n * const eventBridgeForwardPath = '/your/route/eventbridge'; // default /eventbridge\n * const eventBridgeForwardMethod = 'POST'; // default POST\n * const adapter = new EventBridgeAdapter({ eventBridgeForwardPath, eventBridgeForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / EventBridgeAdapter\n * @public\n */\nexport class EventBridgeAdapter extends AwsSimpleAdapter<EventBridgeEventAll> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link EventBridgeAdapter}\n */\n constructor(options?: EventBridgeOptions) {\n super({\n forwardPath: getDefaultIfUndefined(\n options?.eventBridgeForwardPath,\n '/eventbridge',\n ),\n forwardMethod: getDefaultIfUndefined(\n options?.eventBridgeForwardMethod,\n 'POST',\n ),\n batch: false,\n host: 'events.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return EventBridgeAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is EventBridgeEventAll {\n const eventBridgeEvent = event as Partial<EventBridgeEventAll>;\n\n // thanks to @cnuss in https://github.com/vendia/serverless-express/blob/b5da6070b8dd2fb674c1f7035dd7edfef1dc83a2/src/event-sources/utils.js#L87\n return !!(\n eventBridgeEvent &&\n eventBridgeEvent.version &&\n eventBridgeEvent.version === '0' &&\n eventBridgeEvent.id &&\n eventBridgeEvent['detail-type'] &&\n eventBridgeEvent.source &&\n eventBridgeEvent.account &&\n eventBridgeEvent.time &&\n eventBridgeEvent.region &&\n eventBridgeEvent.resources &&\n Array.isArray(eventBridgeEvent.resources) &&\n eventBridgeEvent.detail &&\n typeof eventBridgeEvent.detail === 'object' &&\n !Array.isArray(eventBridgeEvent.detail)\n );\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { CloudFrontRequest, Context } from 'aws-lambda';\nimport type {\n CloudFrontEvent,\n CloudFrontHeaders,\n CloudFrontResultResponse,\n} from 'aws-lambda/common/cloudfront';\nimport type {\n CloudFrontRequestEvent,\n CloudFrontRequestResult,\n} from 'aws-lambda/trigger/cloudfront-request';\nimport type {\n BothValueHeaders,\n Concrete,\n SingleValueHeaders,\n} from '../../@types';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n getDefaultIfUndefined,\n getEventBodyAsBuffer,\n getPathWithQueryStringParams,\n} from '../../core';\n\n//#endregion\n\n/**\n * The type alias to indicate where we get the default value of query string to create the request.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport type DefaultQueryString =\n CloudFrontRequestEvent['Records'][number]['cf']['request']['querystring'];\n\n/**\n * The type alias to indicate where we get the default value of path to create the request.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport type DefaultForwardPath =\n CloudFrontRequestEvent['Records'][number]['cf']['request']['uri'];\n\n/**\n * Represents the body of the new version of Lambda\\@edge, which uses the `body` property inside `request` as the body (library) of the request.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport type NewLambdaEdgeBody =\n CloudFrontRequestEvent['Records'][number]['cf']['request']['body'];\n\n/**\n * Represents the body of the old version of Lambda\\@edge supported by \\@vendia/serverless-express which returns the `data` property within `body` for the body (library) of the request.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport type OldLambdaEdgeBody = Concrete<\n CloudFrontRequestEvent['Records'][number]['cf']['request']\n>['body']['data'];\n\n/**\n * The list was created based on {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-restrictions.html | these docs} in the \"Disallowed Headers\" section.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants\n * @public\n */\nexport const DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS: (string | RegExp)[] = [\n 'Connection',\n 'Expect',\n 'Keep-Alive',\n 'Proxy-Authenticate',\n 'Proxy-Authorization',\n 'Proxy-Connection',\n 'Trailer',\n 'Upgrade',\n 'X-Accel-Buffering',\n 'X-Accel-Charset',\n 'X-Accel-Limit-Rate',\n 'X-Accel-Redirect',\n /(X-Amz-Cf-)(.*)/gim,\n 'X-Cache',\n /(X-Edge-)(.*)/gim,\n 'X-Forwarded-Proto',\n 'X-Real-IP',\n];\n\n/**\n * The default max response size in bytes of viewer request and viewer response.\n *\n * @defaultValue 1024 * 40 = 40960 = 40KB\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants\n * @public\n */\nexport const DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES = 1024 * 40;\n\n/**\n * The default max response size in bytes of origin request and origin response.\n *\n * @defaultValue 1024 * 1024 = 1048576 = 1MB\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants\n * @public\n */\nexport const DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES = 1024 * 1024;\n\n/**\n * The options to customize the {@link LambdaEdgeAdapter}.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport interface LambdaEdgeAdapterOptions {\n /**\n * The max response size in bytes of viewer request and viewer response.\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @defaultValue {@link DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES}\n */\n viewerMaxResponseSizeInBytes?: number;\n\n /**\n * The max response size in bytes of origin request and origin response.\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @defaultValue {@link DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES}\n */\n originMaxResponseSizeInBytes?: number;\n\n /**\n * The function called when the response size exceed the max limits of the Lambda\\@edge\n *\n * @param response - The response from framework that exceed the limit of Lambda\\@edge\n * @defaultValue undefined\n */\n onResponseSizeExceedLimit?: (\n response: CloudFrontRequestResult,\n ) => CloudFrontRequestResult;\n\n /**\n * Return the path to be used to create a request to the framework\n *\n * @remarks You MUST append the query params from {@link DefaultQueryString}, you can use the helper {@link getPathWithQueryStringParams}.\n *\n * @param event - The event sent by the serverless\n * @defaultValue The value from {@link DefaultForwardPath}\n */\n getPathFromEvent?: (\n event: CloudFrontRequestEvent['Records'][number],\n ) => string;\n\n /**\n * The headers that will be stripped from the headers object because Lambda\\@edge will fail if these headers are passed in the response.\n *\n * @remarks All headers will be compared with other headers using toLowerCase, but for the RegExp, if you modify this list, you must put the flag `/gmi` at the end of the RegExp (ex: `/(X-Amz-Cf-)(.*)/gim`)\n *\n * @defaultValue To get the full list, see {@link DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS}.\n */\n disallowedHeaders?: (string | RegExp)[];\n\n /**\n * If you want to change how we check against the header if it should be stripped, you can pass a function to this property.\n *\n * @param header - The header of the response\n * @defaultValue The default method is implemented to test the header against the list {@link LambdaEdgeAdapterOptions.disallowedHeaders}.\n */\n shouldStripHeader?: (header: string) => boolean;\n\n /**\n * By default, the {@link aws-lambda#CloudFrontRequestResult} has the `headers` property, but we also have the headers sent by the framework too.\n * So this setting tells us how to handle this case, if you pass `true` to this property, we will use the framework headers.\n * Otherwise, we will forward the body back to cloudfront without modifying or trying to set the `headers` property inside {@link aws-lambda#CloudFrontRequestResult}.\n *\n * @defaultValue false\n */\n shouldUseHeadersFromFramework?: boolean;\n}\n\n/**\n * The adapter to handle requests from AWS Lambda\\@Edge.\n *\n * This adapter is not fully compatible with Lambda\\@edge supported by \\@vendia/serverless-express, the request body was modified to return {@link NewLambdaEdgeBody} instead {@link OldLambdaEdgeBody}.\n * Also, the response has been modified to return entire body sent by the framework, in this form you MUST return the body from the framework in the format of {@link aws-lambda#CloudFrontRequestResult}.\n * And when we get an error during the forwarding to the framework, we call `resolver.fail` instead of trying to return status 500 like the old implementation was.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html | Lambda edge docs}\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html | Event Reference}\n *\n * @example\n * ```typescript\n * const getPathFromEvent = () => '/lambda/edge'; // will forward all requests to the same endpoint\n * const adapter = new LambdaEdgeAdapter({ getPathFromEvent });\n * ```\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport class LambdaEdgeAdapter\n implements\n AdapterContract<CloudFrontRequestEvent, Context, CloudFrontRequestResult>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link LambdaEdgeAdapter}\n */\n constructor(protected readonly options?: LambdaEdgeAdapterOptions) {\n const disallowedHeaders = getDefaultIfUndefined(\n this.options?.disallowedHeaders,\n DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS,\n );\n\n this.cachedDisallowedHeaders = disallowedHeaders.map(disallowedHeader => {\n if (disallowedHeader instanceof RegExp) return disallowedHeader;\n\n return new RegExp(`(${disallowedHeader})`, 'gim');\n });\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * This property is used to cache the disallowed headers in `RegExp` version, even if you provide a string in `disallowedHeader`, we will cache it in an instance of `RegExp`.\n */\n protected readonly cachedDisallowedHeaders: RegExp[];\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return LambdaEdgeAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is CloudFrontRequestEvent {\n const lambdaEdgeEvent = event as Partial<CloudFrontRequestEvent>;\n\n if (!Array.isArray(lambdaEdgeEvent?.Records)) return false;\n\n const eventType = lambdaEdgeEvent.Records[0]?.cf?.config?.eventType;\n const validEventTypes: CloudFrontEvent['config']['eventType'][] = [\n 'origin-response',\n 'origin-request',\n 'viewer-response',\n 'viewer-request',\n ];\n\n return validEventTypes.includes(eventType);\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: CloudFrontRequestEvent): AdapterRequest {\n const request = event.Records[0];\n const cloudFrontRequest = request.cf.request;\n\n const method = cloudFrontRequest.method;\n\n const pathFromOptions = this.options?.getPathFromEvent\n ? this.options.getPathFromEvent(request)\n : undefined;\n const defaultPath = getPathWithQueryStringParams(\n cloudFrontRequest.uri,\n cloudFrontRequest.querystring,\n );\n const path = getDefaultIfUndefined(pathFromOptions, defaultPath);\n\n const remoteAddress = cloudFrontRequest.clientIp;\n\n const headers =\n this.getFlattenedHeadersFromCloudfrontRequest(cloudFrontRequest);\n\n let body: Buffer | undefined;\n\n if (cloudFrontRequest.body) {\n const [buffer, contentLength] = getEventBodyAsBuffer(\n JSON.stringify(cloudFrontRequest.body),\n false,\n );\n\n body = buffer;\n headers['content-length'] = contentLength.toString();\n }\n\n const { host } = headers;\n\n return {\n method,\n path,\n headers,\n body,\n remoteAddress,\n host,\n hostname: host,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse(\n props: GetResponseAdapterProps<CloudFrontRequestEvent>,\n ): CloudFrontRequestResult {\n const response = this.getResponseToLambdaEdge(props);\n const responseToServiceBytes = new TextEncoder().encode(\n JSON.stringify(response),\n ).length;\n\n const isOriginRequestOrResponse = this.isEventTypeOrigin(\n props.event.Records[0].cf.config,\n );\n const maxSizeInBytes = isOriginRequestOrResponse\n ? getDefaultIfUndefined(\n this.options?.originMaxResponseSizeInBytes,\n DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES,\n )\n : getDefaultIfUndefined(\n this.options?.viewerMaxResponseSizeInBytes,\n DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES,\n );\n\n if (responseToServiceBytes <= maxSizeInBytes) return response;\n\n if (this.options?.onResponseSizeExceedLimit)\n this.options.onResponseSizeExceedLimit(response);\n else {\n props.log.error(\n `SERVERLESS_ADAPTER:LAMBDA_EDGE_ADAPTER: Max response size exceeded: ${responseToServiceBytes} of the max of ${maxSizeInBytes}.`,\n );\n }\n\n return response;\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n }: OnErrorProps<CloudFrontRequestEvent, CloudFrontRequestResult>): void {\n delegatedResolver.fail(error);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Returns the headers with the flattened (non-list) values of the cloudfront request headers\n *\n * @param cloudFrontRequest - The cloudfront request\n */\n protected getFlattenedHeadersFromCloudfrontRequest(\n cloudFrontRequest: CloudFrontRequest,\n ): SingleValueHeaders {\n return Object.keys(cloudFrontRequest.headers).reduce((acc, headerKey) => {\n const headerValue = cloudFrontRequest.headers[headerKey];\n\n acc[headerKey] = headerValue.map(header => header.value).join(',');\n\n return acc;\n }, {} as SingleValueHeaders);\n }\n\n /**\n * Returns the framework response in the format required by the Lambda\\@edge.\n *\n * @param body - The body of the response\n * @param frameworkHeaders - The headers from the framework\n */\n protected getResponseToLambdaEdge({\n body,\n headers: frameworkHeaders,\n }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontRequestResult {\n const shouldUseHeadersFromFramework = getDefaultIfUndefined(\n this.options?.shouldUseHeadersFromFramework,\n false,\n );\n\n const parsedBody: CloudFrontResultResponse | CloudFrontRequest =\n JSON.parse(body);\n\n if (parsedBody.headers) {\n parsedBody.headers = Object.keys(parsedBody.headers).reduce(\n (acc, header) => {\n if (this.shouldStripHeader(header)) return acc;\n\n acc[header] = parsedBody.headers![header];\n\n return acc;\n },\n {} as CloudFrontHeaders,\n );\n }\n\n if (!shouldUseHeadersFromFramework) return parsedBody;\n\n parsedBody.headers = this.getHeadersForCloudfrontResponse(frameworkHeaders);\n\n return parsedBody;\n }\n\n /**\n * Returns headers in Cloudfront Response format.\n *\n * @param originalHeaders - The original version of the request sent by the framework\n */\n protected getHeadersForCloudfrontResponse(\n originalHeaders: BothValueHeaders,\n ): CloudFrontHeaders {\n return Object.keys(originalHeaders).reduce((acc, headerKey) => {\n if (this.shouldStripHeader(headerKey)) return acc;\n\n if (!acc[headerKey]) acc[headerKey] = [];\n\n const headerValue = originalHeaders[headerKey];\n\n if (!Array.isArray(headerValue)) {\n acc[headerKey].push({\n key: headerKey,\n value: headerValue || '',\n });\n\n return acc;\n }\n\n const headersArray = headerValue.map(value => ({\n key: headerKey,\n value: value,\n }));\n\n acc[headerKey].push(...headersArray);\n\n return acc;\n }, {} as CloudFrontHeaders);\n }\n\n /**\n * Returns the information if we should remove the response header\n *\n * @param headerKey - The header that will be tested\n */\n protected shouldStripHeader(headerKey: string): boolean {\n if (this.options?.shouldStripHeader)\n return this.options.shouldStripHeader(headerKey);\n\n const headerKeyLowerCase = headerKey.toLowerCase();\n\n for (const stripHeaderIf of this.cachedDisallowedHeaders) {\n if (!stripHeaderIf.test(headerKeyLowerCase)) continue;\n\n return true;\n }\n\n return false;\n }\n\n /**\n * Determines whether the event is from origin or is from viewer.\n *\n * @param content - The event sent by AWS or the response sent by the framework\n */\n protected isEventTypeOrigin(content: CloudFrontEvent['config']): boolean {\n return content.eventType.includes('origin');\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { S3Event } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { AwsSimpleAdapter } from './base/index';\n\n//#endregion\n\n/**\n * The options to customize the {@link S3Adapter}\n *\n * @breadcrumb Adapters / AWS / S3Adapter\n * @public\n */\nexport interface S3AdapterOptions {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /s3\n */\n s3ForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n s3ForwardMethod?: string;\n}\n\n/**\n * The adapter to handle requests from AWS S3.\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html | Event Reference}\n *\n * @example\n * ```typescript\n * const s3ForwardPath = '/your/route/s3'; // default /s3\n * const s3ForwardMethod = 'POST'; // default POST\n * const adapter = new S3Adapter({ s3ForwardPath, s3ForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / S3Adapter\n * @public\n */\nexport class S3Adapter extends AwsSimpleAdapter<S3Event> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link SNSAdapter}\n */\n constructor(options?: S3AdapterOptions) {\n super({\n forwardPath: getDefaultIfUndefined(options?.s3ForwardPath, '/s3'),\n forwardMethod: getDefaultIfUndefined(options?.s3ForwardMethod, 'POST'),\n batch: false,\n host: 's3.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return S3Adapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is S3Event {\n const s3Event = event as Partial<S3Event>;\n\n if (!Array.isArray(s3Event?.Records)) return false;\n\n const eventSource = s3Event.Records[0]?.eventSource;\n\n return eventSource === 'aws:s3';\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { SNSEvent } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { AwsSimpleAdapter } from './base';\n\n//#endregion\n\n/**\n * The options to customize the {@link SNSAdapter}\n *\n * @breadcrumb Adapters / AWS / SNSAdapter\n * @public\n */\nexport interface SNSAdapterOptions {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /sns\n */\n snsForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n snsForwardMethod?: string;\n}\n\n/**\n * The adapter to handle requests from AWS SNS.\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html | Event Reference}\n *\n * @example\n * ```typescript\n * const snsForwardPath = '/your/route/sns'; // default /sns\n * const snsForwardMethod = 'POST'; // default POST\n * const adapter = new SNSAdapter({ snsForwardPath, snsForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / SNSAdapter\n * @public\n */\nexport class SNSAdapter extends AwsSimpleAdapter<SNSEvent> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link SNSAdapter}\n */\n constructor(options?: SNSAdapterOptions) {\n super({\n forwardPath: getDefaultIfUndefined(options?.snsForwardPath, '/sns'),\n forwardMethod: getDefaultIfUndefined(options?.snsForwardMethod, 'POST'),\n batch: false,\n host: 'sns.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return SNSAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is SNSEvent {\n const snsEvent = event as Partial<SNSEvent>;\n\n if (!Array.isArray(snsEvent?.Records)) return false;\n\n const eventSource = snsEvent.Records[0]?.EventSource;\n\n return eventSource === 'aws:sns';\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { SQSEvent } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { type AWSSimpleAdapterOptions, AwsSimpleAdapter } from './base/index';\n\n//#endregion\n\n/**\n * The options to customize the {@link SQSAdapter}\n *\n * @breadcrumb Adapters / AWS / SQSAdapter\n * @public\n */\nexport interface SQSAdapterOptions\n extends Pick<AWSSimpleAdapterOptions, 'batch'> {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /sqs\n */\n sqsForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n sqsForwardMethod?: string;\n}\n\n/**\n * The adapter to handle requests from AWS SQS.\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html | Event Reference}\n *\n * @example\n * ```typescript\n * const sqsForwardPath = '/your/route/sqs'; // default /sqs\n * const sqsForwardMethod = 'POST'; // default POST\n * const adapter = new SQSAdapter({ sqsForwardPath, sqsForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / SQSAdapter\n * @public\n */\nexport class SQSAdapter extends AwsSimpleAdapter<SQSEvent> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link SNSAdapter}\n */\n constructor(options?: SQSAdapterOptions) {\n super({\n forwardPath: getDefaultIfUndefined(options?.sqsForwardPath, '/sqs'),\n forwardMethod: getDefaultIfUndefined(options?.sqsForwardMethod, 'POST'),\n batch: options?.batch,\n host: 'sqs.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return SQSAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is SQSEvent {\n const sqsEvent = event as Partial<SQSEvent>;\n\n if (!Array.isArray(sqsEvent?.Records)) return false;\n\n const eventSource = sqsEvent.Records[0]?.eventSource;\n\n return eventSource === 'aws:sqs';\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { CloudFrontRequest, Context } from 'aws-lambda';\nimport type {\n CloudFrontHeaders,\n CloudFrontResultResponse,\n} from 'aws-lambda/common/cloudfront';\nimport type {\n CloudFrontRequestEvent,\n CloudFrontRequestResult,\n} from 'aws-lambda/trigger/cloudfront-request';\nimport type { BothValueHeaders, SingleValueHeaders } from '../../@types';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n type StripBasePathFn,\n buildStripBasePath,\n getDefaultIfUndefined,\n getEventBodyAsBuffer,\n getPathWithQueryStringParams,\n} from '../../core';\nimport {\n DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS,\n DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES,\n DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES,\n} from './lambda-edge.adapter';\n\n//#endregion\n\n//#endregion\n\n/**\n * The options to customize the {@link RequestLambdaEdgeAdapter}.\n *\n * @breadcrumb Adapters / AWS / RequestLambdaEdgeAdapter\n * @public\n */\nexport interface RequestLambdaEdgeAdapterOptions {\n /**\n * Strip base path for custom paths, like `/api`.\n *\n * @defaultValue ''\n */\n stripBasePath?: string;\n\n /**\n * The max response size in bytes of viewer request and viewer response.\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @defaultValue {@link DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES}\n */\n viewerMaxResponseSizeInBytes?: number;\n\n /**\n * The max response size in bytes of origin request and origin response.\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @defaultValue {@link DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES}\n */\n originMaxResponseSizeInBytes?: number;\n\n /**\n * The function called when the response size exceed the max limits of the Lambda\\@edge\n *\n * @param response - The response from framework that exceed the limit of Lambda\\@edge\n * @defaultValue undefined\n */\n onResponseSizeExceedLimit?: (\n response: CloudFrontRequestResult,\n ) => CloudFrontRequestResult;\n\n /**\n * The headers that will be stripped from the headers object because Lambda\\@edge will fail if these headers are passed in the response.\n *\n * @remarks All headers will be compared with other headers using toLowerCase, but for the RegExp, if you modify this list, you must put the flag `/gmi` at the end of the RegExp (ex: `/(X-Amz-Cf-)(.*)/gim`)\n *\n * @defaultValue To get the full list, see {@link DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS}.\n */\n disallowedHeaders?: (string | RegExp)[];\n\n /**\n * If you want to change how we check against the header if it should be stripped, you can pass a function to this property.\n *\n * @param header - The header of the response\n * @defaultValue The default method is implemented to test the header against the list {@link RequestLambdaEdgeAdapterOptions.disallowedHeaders}.\n */\n shouldStripHeader?: (header: string) => boolean;\n}\n\n/**\n * The adapter to handle requests from AWS Lambda\\@Edge of the type Viewer Request.\n *\n * The idea of this Adapter is to you be able to expose your framework to the Edge, like when you build for Cloudfront.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html | Lambda edge docs}\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html | Event Reference}\n *\n * @example\n * ```typescript\n * const stripBasePath = '/api'; // in case you have configure the cloudfront to forward the path /api to your lambda\n * const adapter = new RequestLambdaEdgeAdapter({ stripBasePath });\n * ```\n *\n * @breadcrumb Adapters / AWS / RequestLambdaEdgeAdapter\n * @public\n */\nexport class RequestLambdaEdgeAdapter\n implements\n AdapterContract<CloudFrontRequestEvent, Context, CloudFrontResultResponse>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link RequestLambdaEdgeAdapter}\n */\n constructor(protected readonly options?: RequestLambdaEdgeAdapterOptions) {\n this.stripPathFn = buildStripBasePath(this.options?.stripBasePath);\n\n const disallowedHeaders = getDefaultIfUndefined(\n this.options?.disallowedHeaders,\n DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS,\n );\n\n this.cachedDisallowedHeaders = disallowedHeaders.map(disallowedHeader => {\n if (disallowedHeader instanceof RegExp) return disallowedHeader;\n\n return new RegExp(`(${disallowedHeader})`, 'gim');\n });\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Strip base path function\n */\n protected readonly stripPathFn: StripBasePathFn;\n\n /**\n * This property is used to cache the disallowed headers in `RegExp` version, even if you provide a string in `disallowedHeader`, we will cache it in an instance of `RegExp`.\n */\n protected readonly cachedDisallowedHeaders: RegExp[];\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return RequestLambdaEdgeAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is CloudFrontRequestEvent {\n const lambdaEdgeEvent = event as Partial<CloudFrontRequestEvent>;\n\n if (!Array.isArray(lambdaEdgeEvent?.Records)) return false;\n\n const eventType = lambdaEdgeEvent.Records[0]?.cf?.config?.eventType;\n\n return eventType === 'viewer-request' || eventType === 'origin-request';\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: CloudFrontRequestEvent): AdapterRequest {\n const request = event.Records[0];\n const cloudFrontRequest = request.cf.request;\n\n const method = cloudFrontRequest.method;\n\n const path = this.stripPathFn(\n getPathWithQueryStringParams(\n cloudFrontRequest.uri,\n cloudFrontRequest.querystring,\n ),\n );\n const remoteAddress = cloudFrontRequest.clientIp;\n\n const headers =\n this.getFlattenedHeadersFromCloudfrontRequest(cloudFrontRequest);\n\n let body: Buffer | undefined;\n\n if (cloudFrontRequest.body) {\n const [buffer, contentLength] = getEventBodyAsBuffer(\n cloudFrontRequest.body.data,\n cloudFrontRequest.body.encoding === 'base64',\n );\n\n body = buffer;\n headers['content-length'] = contentLength.toString();\n }\n\n const { host } = headers;\n\n return {\n method,\n path,\n headers,\n body,\n remoteAddress,\n host,\n hostname: host,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n body,\n headers: frameworkHeaders,\n isBase64Encoded,\n statusCode,\n log,\n event,\n }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontResultResponse {\n const headers = this.getHeadersForCloudfrontResponse(frameworkHeaders);\n\n const maxSizeInBytes =\n event.Records[0].cf.config.eventType === 'origin-request'\n ? getDefaultIfUndefined(\n this.options?.originMaxResponseSizeInBytes,\n DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES,\n )\n : getDefaultIfUndefined(\n this.options?.viewerMaxResponseSizeInBytes,\n DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES,\n );\n\n const response: CloudFrontResultResponse = {\n body,\n status: statusCode.toString(),\n bodyEncoding: isBase64Encoded ? 'base64' : 'text',\n headers,\n };\n\n // probably is not correctly accurate, but it's a good approximation\n const bodyLength = body.length;\n\n if (bodyLength <= maxSizeInBytes) return response;\n\n if (this.options?.onResponseSizeExceedLimit)\n this.options.onResponseSizeExceedLimit(response);\n else {\n log.error(\n `SERVERLESS_ADAPTER:LAMBDA_EDGE_ADAPTER: Max response size exceeded: ${bodyLength} of the max of ${maxSizeInBytes}.`,\n );\n }\n\n return response;\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n respondWithErrors,\n log,\n event,\n }: OnErrorProps<CloudFrontRequestEvent, CloudFrontRequestResult>): void {\n const body = respondWithErrors ? error.stack : '';\n const errorResponse = this.getResponse({\n event,\n statusCode: 500,\n body: body || '',\n headers: {},\n isBase64Encoded: false,\n log,\n });\n\n delegatedResolver.succeed(errorResponse);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Returns the headers with the flattened (non-list) values of the cloudfront request headers\n *\n * @param cloudFrontRequest - The cloudfront request\n */\n protected getFlattenedHeadersFromCloudfrontRequest(\n cloudFrontRequest: CloudFrontRequest,\n ): SingleValueHeaders {\n return Object.keys(cloudFrontRequest.headers).reduce((acc, headerKey) => {\n const headerValue = cloudFrontRequest.headers[headerKey];\n\n if (headerValue.length === 1) acc[headerKey] = headerValue[0].value;\n else acc[headerKey] = headerValue.map(header => header.value).join(',');\n\n return acc;\n }, {} as SingleValueHeaders);\n }\n\n /**\n * Returns headers in Cloudfront Response format.\n *\n * @param originalHeaders - The original version of the request sent by the framework\n */\n protected getHeadersForCloudfrontResponse(\n originalHeaders: BothValueHeaders,\n ): CloudFrontHeaders {\n return Object.keys(originalHeaders).reduce((acc, headerKey) => {\n if (this.shouldStripHeader(headerKey)) return acc;\n\n const lowercaseHeaderKey = headerKey.toLowerCase();\n\n if (!acc[lowercaseHeaderKey]) acc[lowercaseHeaderKey] = [];\n\n const headerValue = originalHeaders[headerKey];\n\n if (!Array.isArray(headerValue)) {\n acc[lowercaseHeaderKey].push({\n key: headerKey,\n value: headerValue || '',\n });\n\n return acc;\n }\n\n const headersArray = headerValue.map(value => ({\n key: headerKey,\n value: value,\n }));\n\n acc[lowercaseHeaderKey].push(...headersArray);\n\n return acc;\n }, {} as CloudFrontHeaders);\n }\n\n /**\n * Returns the information if we should remove the response header\n *\n * @param headerKey - The header that will be tested\n */\n protected shouldStripHeader(headerKey: string): boolean {\n if (this.options?.shouldStripHeader)\n return this.options.shouldStripHeader(headerKey);\n\n const headerKeyLowerCase = headerKey.toLowerCase();\n\n for (const stripHeaderIf of this.cachedDisallowedHeaders) {\n if (!stripHeaderIf.test(headerKeyLowerCase)) continue;\n\n return true;\n }\n\n return false;\n }\n\n //#endregion\n}\n"],"mappings":"4dAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,gBAAAE,EAAA,wBAAAC,EAAA,wBAAAC,EAAA,qBAAAC,EAAA,2CAAAC,EAAA,8CAAAC,EAAA,8CAAAC,EAAA,oBAAAC,EAAA,uBAAAC,EAAA,sBAAAC,EAAA,6BAAAC,EAAA,cAAAC,EAAA,eAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAhB,ICCA,IAAAiB,EAAgC,gBCAhC,IAAAC,EAAgD,gBCKzC,SAASC,EAAUC,EAAiC,CACzD,GAAI,OAAO,SAASA,CAAI,EAAG,OAAOA,EAAK,SAAS,MAAM,EACjD,GAAI,OAAOA,GAAS,SAAU,OAAOA,EACrC,GAAIA,aAAgB,WAAY,OAAO,IAAI,YAAY,EAAE,OAAOA,CAAI,EACpE,MAAM,IAAI,MAAM,wCAAwC,OAAOA,CAAI,EAAE,CAC5E,CALgBC,EAAAF,EAAA,aDAhB,IAAMG,EAAY;AAAA;AAAA,EACZC,EAAa;AAAA;AAAA,EAEbC,EAAO,OAAO,eAAe,EAC7BC,EAAU,OAAO,kBAAkB,EAEzC,SAASC,EAAQC,EAA4BC,EAA2B,CACtE,GACE,OAAO,SAASA,CAAI,GACpB,OAAOA,GAAS,UAChBA,aAAgB,WAEhBD,EAAOH,CA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K,IAAU,CAC7C,IAAKN,EACL,MAAOM,CACT,EAAE,EAEF,OAAAP,EAAIK,CAAkB,EAAE,KAAK,GAAGC,CAAY,EAErCN,CACT,EAAG,CAAC,CAAsB,CAC5B,CAOU,kBAAkBC,EAA4B,CACtD,GAAI,KAAK,SAAS,kBAChB,OAAO,KAAK,QAAQ,kBAAkBA,CAAS,EAEjD,IAAMO,EAAqBP,EAAU,YAAY,EAEjD,QAAWQ,KAAiB,KAAK,wBAC/B,GAAKA,EAAc,KAAKD,CAAkB,EAE1C,MAAO,GAGT,MAAO,EACT,CAGF","names":["aws_exports","__export","AlbAdapter","ApiGatewayV1Adapter","ApiGatewayV2Adapter","AwsSimpleAdapter","DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS","DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES","DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES","DynamoDBAdapter","EventBridgeAdapter","LambdaEdgeAdapter","RequestLambdaEdgeAdapter","S3Adapter","SNSAdapter","SQSAdapter","__toCommonJS","import_node_http","import_node_http","getString","data","__name","headerEnd","endChunked","BODY","HEADERS","addData","stream","data","__name","ServerlessResponse","_ServerlessResponse","method","writesToIgnore","socket","NO_OP","encoding","cb","string","getString","index","remainder","res","response","headers","key","value","statusCode","statusMessage","obj","headersObjOrArray","arrayHeaders","name","import_node_http","EmptyResponse","getEventBodyAsBuffer","body","isBase64Encoded","encoding","buffer","contentLength","__name","getFlattenedHeadersMap","headersMap","separator","lowerCaseKey","acc","headerKey","newKey","headerValue","__name","getMultiValueHeadersMap","getFlattenedHeadersMapAndCookies","lowerHeaderKey","NO_OP","__name","InternalLoggerSymbol","getDefaultIfUndefined","value","defaultValue","__name","getPathWithQueryStringParams","path","queryParams","queryParamsString","getQueryParamsStringFromRecord","__name","queryParamsRecord","searchParams","multiValueHeadersEntries","key","value","arrayValue","NOOPBasePath","buildStripBasePath","basePath","length","import_node_stream","AlbAdapter","_AlbAdapter","options","buildStripBasePath","__name","event","albEvent","method","path","headers","getFlattenedHeadersMap","body","bufferBody","contentLength","getEventBodyAsBuffer","remoteAddress","responseHeaders","isBase64Encoded","statusCode","multiValueHeaders","getMultiValueHeadersMap","error","delegatedResolver","respondWithErrors","log","errorResponse","queryParams","getPathWithQueryStringParams","ApiGatewayV1Adapter","_ApiGatewayV1Adapter","options","buildStripBasePath","__name","event","partialEventV1","method","headers","multiValueHeaderKey","headerValue","path","body","bufferBody","contentLength","getEventBodyAsBuffer","remoteAddress","responseHeaders","isBase64Encoded","statusCode","response","multiValueHeaders","getMultiValueHeadersMap","shouldThrowOnChunkedTransferEncoding","getDefaultIfUndefined","value","error","delegatedResolver","respondWithErrors","log","errorResponse","queryParams","queryStringKey","queryStringValue","getPathWithQueryStringParams","ApiGatewayV2Adapter","_ApiGatewayV2Adapter","options","buildStripBasePath","__name","event","apiGatewayEvent","method","path","headers","body","bufferBody","contentLength","getEventBodyAsBuffer","remoteAddress","responseHeaders","isBase64Encoded","statusCode","response","cookies","getFlattenedHeadersMapAndCookies","shouldThrowOnChunkedTransferEncoding","getDefaultIfUndefined","transferEncodingHeader","error","delegatedResolver","respondWithErrors","log","errorResponse","queryParams","getPathWithQueryStringParams","AwsSimpleAdapter","options","__name","_","event","path","method","body","contentLength","getEventBodyAsBuffer","headers","isBase64Encoded","statusCode","EmptyResponse","error","delegatedResolver","DynamoDBAdapter","_DynamoDBAdapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","dynamoDBevent","EventBridgeAdapter","_EventBridgeAdapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","eventBridgeEvent","DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS","DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES","DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES","LambdaEdgeAdapter","_LambdaEdgeAdapter","options","disallowedHeaders","getDefaultIfUndefined","disallowedHeader","__name","event","lambdaEdgeEvent","eventType","request","cloudFrontRequest","method","pathFromOptions","defaultPath","getPathWithQueryStringParams","path","remoteAddress","headers","body","buffer","contentLength","getEventBodyAsBuffer","host","props","response","responseToServiceBytes","maxSizeInBytes","error","delegatedResolver","acc","headerKey","headerValue","header","frameworkHeaders","shouldUseHeadersFromFramework","parsedBody","originalHeaders","headersArray","value","headerKeyLowerCase","stripHeaderIf","content","S3Adapter","_S3Adapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","s3Event","SNSAdapter","_SNSAdapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","snsEvent","SQSAdapter","_SQSAdapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","sqsEvent","RequestLambdaEdgeAdapter","_RequestLambdaEdgeAdapter","options","buildStripBasePath","disallowedHeaders","getDefaultIfUndefined","DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS","disallowedHeader","__name","event","lambdaEdgeEvent","eventType","cloudFrontRequest","method","path","getPathWithQueryStringParams","remoteAddress","headers","body","buffer","contentLength","getEventBodyAsBuffer","host","frameworkHeaders","isBase64Encoded","statusCode","log","maxSizeInBytes","DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES","DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES","response","bodyLength","error","delegatedResolver","respondWithErrors","errorResponse","acc","headerKey","headerValue","header","originalHeaders","lowercaseHeaderKey","headersArray","value","headerKeyLowerCase","stripHeaderIf"]}
1
+ {"version":3,"sources":["../../../src/adapters/aws/index.ts","../../../src/network/request.ts","../../../src/network/response.ts","../../../src/network/utils.ts","../../../src/network/response-stream.ts","../../../src/core/constants.ts","../../../src/core/event-body.ts","../../../src/core/headers.ts","../../../src/core/no-op.ts","../../../src/core/logger.ts","../../../src/core/optional.ts","../../../src/core/path.ts","../../../src/core/stream.ts","../../../src/adapters/aws/alb.adapter.ts","../../../src/adapters/aws/api-gateway-v1.adapter.ts","../../../src/adapters/aws/api-gateway-v2.adapter.ts","../../../src/adapters/aws/base/aws-simple-adapter.ts","../../../src/adapters/aws/dynamodb.adapter.ts","../../../src/adapters/aws/event-bridge.adapter.ts","../../../src/adapters/aws/lambda-edge.adapter.ts","../../../src/adapters/aws/s3.adapter.ts","../../../src/adapters/aws/sns.adapter.ts","../../../src/adapters/aws/sqs.adapter.ts","../../../src/adapters/aws/request-lambda-edge.adapter.ts"],"sourcesContent":["export * from './alb.adapter';\nexport * from './api-gateway-v1.adapter';\nexport * from './api-gateway-v2.adapter';\nexport * from './dynamodb.adapter';\nexport * from './event-bridge.adapter';\nexport * from './lambda-edge.adapter';\nexport * from './s3.adapter';\nexport * from './sns.adapter';\nexport * from './sqs.adapter';\nexport * from './base';\nexport * from './request-lambda-edge.adapter';\n","// ATTRIBUTION: https://github.com/dougmoscrop/serverless-http\nimport { IncomingMessage } from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport type { SingleValueHeaders } from '../@types';\nimport { NO_OP } from '../core';\n\nconst HTTPS_PORT = 443;\n\n/**\n * The properties to create a {@link ServerlessRequest}\n *\n * @breadcrumb Network / ServerlessRequest\n * @public\n */\nexport interface ServerlessRequestProps {\n /**\n * The HTTP Method of the request\n */\n method: string;\n\n /**\n * The URL requested\n */\n url: string;\n\n /**\n * The headers from the event source\n */\n headers: SingleValueHeaders;\n\n /**\n * The body from the event source\n */\n body?: Buffer | Uint8Array;\n\n /**\n * The IP Address from caller\n */\n remoteAddress?: string;\n}\n\n/**\n * The class that represents an {@link http#IncomingMessage} created by the library to represent an actual request to the framework.\n *\n * @breadcrumb Network / ServerlessRequest\n * @public\n */\nexport class ServerlessRequest extends IncomingMessage {\n constructor({\n method,\n url,\n headers,\n body,\n remoteAddress,\n }: ServerlessRequestProps) {\n super({\n encrypted: true,\n readable: false,\n remoteAddress,\n address: () => ({ port: HTTPS_PORT }) as AddressInfo,\n end: NO_OP,\n destroy: NO_OP,\n } as any);\n\n this.statusCode = 200;\n this.statusMessage = 'OK';\n this.complete = true;\n this.httpVersion = '1.1';\n this.httpVersionMajor = 1;\n this.httpVersionMinor = 1;\n this.method = method;\n this.headers = headers;\n this.body = body;\n this.url = url;\n this.ip = remoteAddress;\n\n this._read = () => {\n this.push(body);\n this.push(null);\n };\n }\n\n ip?: string;\n body?: Buffer | Uint8Array;\n}\n","// ATTRIBUTION: https://github.com/dougmoscrop/serverless-http\nimport { IncomingMessage, ServerResponse } from 'node:http';\nimport type { Socket } from 'node:net';\nimport { NO_OP } from '../core';\nimport { getString } from './utils';\n\nconst headerEnd = '\\r\\n\\r\\n';\nconst endChunked = '0\\r\\n\\r\\n';\n\nconst BODY = Symbol('Response body');\nconst HEADERS = Symbol('Response headers');\n\nfunction addData(stream: ServerlessResponse, data: Uint8Array | string) {\n if (\n Buffer.isBuffer(data) ||\n typeof data === 'string' ||\n data instanceof Uint8Array\n )\n stream[BODY].push(Buffer.from(data));\n else throw new Error(`response.write() of unexpected type: ${typeof data}`);\n}\n\n/**\n * The properties to create a {@link ServerlessResponse}.\n *\n * @breadcrumb Network / ServerlessResponse\n * @public\n */\nexport interface ServerlessResponseProps {\n /**\n * The HTTP Method from request\n */\n method?: string;\n}\n\n/**\n * The class that represents a response instance used to send to the framework and wait until the framework finishes processing the request.\n * Once it's happens, we use the properties from this response to built the response to the cloud.\n *\n * @breadcrumb Network / ServerlessResponse\n * @public\n */\nexport class ServerlessResponse extends ServerResponse {\n constructor({ method }: ServerlessResponseProps) {\n super({ method } as any);\n\n this[BODY] = [];\n this[HEADERS] = {};\n\n this.useChunkedEncodingByDefault = false;\n this.chunkedEncoding = false;\n this._header = '';\n\n // this ignore is used because I need to ignore these write calls:\n // https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L934-L935\n // https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L937\n let writesToIgnore = 1;\n\n const socket: Partial<Socket> & { _writableState: any } = {\n _writableState: {},\n writable: true,\n on: NO_OP,\n removeListener: NO_OP,\n destroy: NO_OP,\n cork: NO_OP,\n uncork: NO_OP,\n write: (\n data: Uint8Array | string,\n encoding?: string | null | (() => void),\n cb?: () => void,\n ): any => {\n if (typeof encoding === 'function') {\n cb = encoding;\n encoding = null;\n }\n\n if (this._header === '' || this._wroteHeader) {\n if (!this.chunkedEncoding) addData(this, data);\n else {\n if (writesToIgnore > 0) writesToIgnore--;\n else if (data !== endChunked) {\n addData(this, data);\n writesToIgnore = 3;\n }\n }\n } else {\n const string = getString(data);\n const index = string.indexOf(headerEnd);\n\n if (index !== -1) {\n const remainder = string.slice(index + headerEnd.length);\n\n if (remainder && !this.chunkedEncoding) addData(this, remainder);\n\n this._wroteHeader = true;\n }\n }\n\n if (typeof cb === 'function') cb();\n },\n };\n\n this.assignSocket(socket as unknown as Socket);\n }\n\n _header: string;\n _headers?: Record<any, any>;\n _wroteHeader?: boolean;\n\n [BODY]: any[];\n [HEADERS]: Record<any, any>;\n\n get headers(): Record<any, any> {\n return this[HEADERS];\n }\n\n static from(res: IncomingMessage) {\n const response = new ServerlessResponse({ method: res.method });\n\n response.statusCode = res.statusCode || 0;\n response[HEADERS] = res.headers;\n response[BODY] = (res as any).body ? [Buffer.from((res as any).body)] : [];\n response.end();\n\n return response;\n }\n\n static body(res: ServerlessResponse): Buffer {\n return Buffer.concat(res[BODY]);\n }\n\n static headers(res: ServerlessResponse) {\n const headers = res.getHeaders();\n\n return Object.assign(headers, res[HEADERS]);\n }\n\n override setHeader(\n key: string,\n value: number | string | readonly string[],\n ): any {\n if (this._wroteHeader) this[HEADERS][key] = value;\n else super.setHeader(key, value);\n }\n\n override writeHead(\n statusCode: number,\n statusMessage?: string | any | any[],\n obj?: any | any[],\n ): any {\n const headersObjOrArray =\n typeof statusMessage === 'string' ? obj : statusMessage;\n\n const arrayHeaders = Array.isArray(headersObjOrArray)\n ? headersObjOrArray\n : [headersObjOrArray || {}];\n\n for (const headers of arrayHeaders) {\n for (const name in headers) {\n this.setHeader(name, headers[name]!);\n\n if (!this._wroteHeader) {\n // we only need to initiate super.headers once\n // writeHead will add the other headers itself\n break;\n }\n }\n }\n\n return this.callNativeWriteHead(statusCode, statusMessage, obj);\n }\n\n /**\n * I use ignore here because in nodejs 12.x, statusMessage can be string | OutgoingHttpHeaders\n * But in nodejs \\>=14.x, statusMessage can also be OutgoingHttpHeaders[]\n * I take care of these cases above, but here I can't handle it well, so I give up\n * nodejs 12.x ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v12/http.d.ts#L229\n * nodejs 14.x ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v14/http.d.ts#L263\n */\n protected callNativeWriteHead(\n statusCode: number,\n statusMessage?: string | any | any[],\n obj?: any | any[],\n ): this {\n return super.writeHead(statusCode, statusMessage, obj);\n }\n}\n","/**\n * Get the data from a buffer, string, or Uint8Array\n *\n * @breadcrumb Network\n * @param data - The data that was written inside the stream\n */\nexport function getString(data: Buffer | string | unknown) {\n if (Buffer.isBuffer(data)) return data.toString('utf8');\n else if (typeof data === 'string') return data;\n else if (data instanceof Uint8Array) return new TextDecoder().decode(data);\n else throw new Error(`response.write() of unexpected type: ${typeof data}`);\n}\n","import { ServerResponse } from 'node:http';\nimport type { Socket } from 'node:net';\nimport type { Writable } from 'node:stream';\nimport type { BothValueHeaders } from '../@types';\nimport { type ILogger, NO_OP, parseHeaders } from '../core';\nimport { getString } from './utils';\n\nconst endChunked = '0\\r\\n\\r\\n';\nconst headerEnd = '\\r\\n\\r\\n';\nconst endStatusSeparator = '\\r\\n';\n\n/**\n * The properties to create a {@link ServerlessStreamResponse}.\n *\n * @breadcrumb Network / ServerlessStreamResponse\n * @public\n */\nexport interface ServerlessStreamResponseProps {\n /**\n * The HTTP Method from request\n */\n method?: string;\n\n /**\n * The callback to receive the headers when they are written to the stream\n * You need to return a writable stream be able to continue writing the response\n *\n * @param statusCode - The status code of the response\n * @param headers - The headers of the response\n */\n onReceiveHeaders: (statusCode: number, headers: BothValueHeaders) => Writable;\n\n /**\n * Instance of the logger\n */\n log: ILogger;\n}\n\n/**\n * The class that represents a response instance used to send to the framework and wait until the framework finishes processing the request.\n * This response is specially built to deal with transfer-encoding: chunked\n *\n * @breadcrumb Network / ServerlessStreamResponse\n * @public\n */\nexport class ServerlessStreamResponse extends ServerResponse {\n constructor({\n method,\n onReceiveHeaders,\n log,\n }: ServerlessStreamResponseProps) {\n super({ method } as any);\n\n this.useChunkedEncodingByDefault = true;\n this.chunkedEncoding = true;\n\n let internalWritable: Writable | null = null;\n let isFirstCall = true;\n // this ignore is used because I need to ignore these write calls:\n // https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L934-L935\n // https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L937\n let writesToIgnore = 0;\n\n const socket: Partial<Socket> & { _writableState: any } = {\n _writableState: {},\n writable: true,\n on: NO_OP,\n removeListener: NO_OP,\n destroy: NO_OP,\n cork: NO_OP,\n uncork: NO_OP,\n write: (\n data: Uint8Array | string,\n encoding?: string | null | (() => void),\n cb?: () => void,\n ): any => {\n // very unlikely, I don't even know how to reproduce this, but exist on types\n // istanbul ignore if\n if (typeof encoding === 'function') {\n cb = encoding;\n encoding = null;\n }\n\n log.debug('SERVERLESS_ADAPTER:RESPONSE_STREAM:DATA', () => ({\n data: Buffer.isBuffer(data) ? data.toString('utf8') : data,\n encoding,\n }));\n\n if (!isFirstCall && internalWritable) {\n if (data === endChunked) {\n internalWritable.end(cb);\n\n return true;\n }\n\n if (writesToIgnore > 0) {\n writesToIgnore--;\n return true;\n }\n\n internalWritable.write(data, cb);\n writesToIgnore = 3;\n } else if (isFirstCall) {\n isFirstCall = false;\n\n const stringData = getString(data);\n const endStatusIndex = stringData.indexOf(endStatusSeparator);\n const status = +stringData.slice(0, endStatusIndex).split(' ')[1];\n const endHeaderIndex = stringData.indexOf(headerEnd);\n\n const headerData = stringData.slice(\n endStatusIndex + 2,\n endHeaderIndex,\n );\n const headers = parseHeaders(headerData);\n log.debug(\n 'SERVERLESS_ADAPTER:RESPONSE_STREAM:FRAMEWORK_HEADERS',\n () => ({\n headers,\n }),\n );\n\n writesToIgnore = 1;\n internalWritable = onReceiveHeaders(status, headers);\n\n // If we get an endChunked right after header which means the response body is empty, we need to immediately end the writable\n if (stringData.substring(endHeaderIndex + 4) === endChunked)\n internalWritable.end();\n }\n\n return true;\n },\n };\n\n this.assignSocket(socket as unknown as Socket);\n }\n}\n","/**\n * Default encodings that are treated as binary, they are compared with the `Content-Encoding` header.\n *\n * @breadcrumb Core / Constants\n * @defaultValue ['gzip', 'deflate', 'br']\n * @public\n */\nexport const DEFAULT_BINARY_ENCODINGS: string[] = ['gzip', 'deflate', 'br'];\n\n/**\n * Default content types that are treated as binary, they are compared with the `Content-Type` header.\n *\n * @breadcrumb Core / Constants\n * @defaultValue ['image/png', 'image/jpeg', 'image/jpg', 'image/avif', 'image/bmp', 'image/x-png', 'image/gif', 'image/webp', 'video/mp4', 'application/pdf']\n * @public\n */\nexport const DEFAULT_BINARY_CONTENT_TYPES: string[] = [\n 'image/png',\n 'image/jpeg',\n 'image/jpg',\n 'image/avif',\n 'image/bmp',\n 'image/x-png',\n 'image/gif',\n 'image/webp',\n 'video/mp4',\n 'application/pdf',\n];\n\n/**\n * Type alias for empty response and can be used on some adapters when the adapter does not need to return a response.\n *\n * @breadcrumb Core / Constants\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type IEmptyResponse = {};\n\n/**\n * Constant for empty response and can be used on some adapters when the adapter does not need to return a response.\n *\n * @breadcrumb Core / Constants\n * @public\n */\nexport const EmptyResponse: IEmptyResponse = {};\n","/**\n * Get the event body as buffer from body string with content length\n *\n * @example\n * ```typescript\n * const body = '{}';\n * const [buffer, contentLength] = getEventBodyAsBuffer(body, false);\n * console.log(buffer);\n * // <Buffer 7b 7d>\n * console.log(contentLength);\n * // 2\n * ```\n *\n * @param body - The body string that can be encoded or not\n * @param isBase64Encoded - Tells if body string is encoded in base64\n *\n * @breadcrumb Core\n * @public\n */\nexport function getEventBodyAsBuffer(\n body: string,\n isBase64Encoded: boolean,\n): [body: Buffer, contentLength: number] {\n const encoding: BufferEncoding = isBase64Encoded ? 'base64' : 'utf8';\n\n const buffer = Buffer.from(body, encoding);\n const contentLength = Buffer.byteLength(buffer, encoding);\n\n return [buffer, contentLength];\n}\n","//#region Imports\n\nimport type { BothValueHeaders } from '../@types';\n\n//#endregion\n\n/**\n * Transform a header map and make sure the value is not an array\n *\n * @example\n * ```typescript\n * const headers = { 'accept-encoding': 'gzip', 'accept-language': ['en-US', 'en;q=0.9'] };\n * const flattenedHeaders = getFlattenedHeadersMap(headers, ',', true);\n * console.log(flattenedHeaders);\n * // { 'accept-encoding': 'gzip', 'accept-language': 'en-US,en;q=0.9' }\n * ```\n *\n * @param headersMap - The initial headers\n * @param separator - The separator used when we join the array of header's value\n * @param lowerCaseKey - Should put all keys in lowercase\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getFlattenedHeadersMap(\n headersMap: BothValueHeaders,\n separator: string = ',',\n lowerCaseKey: boolean = false,\n): Record<string, string> {\n return Object.keys(headersMap).reduce((acc, headerKey) => {\n const newKey = lowerCaseKey ? headerKey.toLowerCase() : headerKey;\n const headerValue = headersMap[headerKey];\n\n if (Array.isArray(headerValue)) acc[newKey] = headerValue.join(separator);\n else acc[newKey] = (headerValue ?? '') + '';\n\n return acc;\n }, {});\n}\n\n/**\n * Transforms a header map into a multi-value map header.\n *\n * @example\n * ```typescript\n * const headers = { 'accept-encoding': 'gzip', 'connection': ['keep-alive'] };\n * const multiValueHeaders = getMultiValueHeadersMap(headers);\n * console.log(multiValueHeaders);\n * // { 'accept-encoding': ['gzip'], 'connection': ['keep-alive'] }\n * ```\n *\n * @param headersMap - The initial headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getMultiValueHeadersMap(\n headersMap: BothValueHeaders,\n): Record<string, string[]> {\n return Object.keys(headersMap).reduce((acc, headerKey) => {\n const headerValue = headersMap[headerKey];\n\n acc[headerKey.toLowerCase()] = Array.isArray(headerValue)\n ? headerValue.map(String)\n : [String(headerValue)];\n\n return acc;\n }, {});\n}\n\n/**\n * The wrapper that holds the information about single value headers and cookies\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport type FlattenedHeadersAndCookies = {\n /**\n * Just the single value headers\n */\n headers: Record<string, string>;\n\n /**\n * The list of cookies\n */\n cookies: string[];\n};\n\n/**\n * Transforms a header map into a single value headers and cookies\n *\n * @param headersMap - The initial headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getFlattenedHeadersMapAndCookies(\n headersMap: BothValueHeaders,\n): FlattenedHeadersAndCookies {\n return Object.keys(headersMap).reduce(\n (acc, headerKey) => {\n const headerValue = headersMap[headerKey];\n const lowerHeaderKey = headerKey.toLowerCase();\n\n if (Array.isArray(headerValue)) {\n if (lowerHeaderKey !== 'set-cookie')\n acc.headers[headerKey] = headerValue.join(',');\n else acc.cookies.push(...headerValue);\n } else {\n if (lowerHeaderKey === 'set-cookie' && headerValue !== undefined)\n acc.cookies.push(headerValue ?? '');\n else acc.headers[headerKey] = String(headerValue ?? '');\n }\n\n return acc;\n },\n {\n cookies: [],\n headers: {},\n } as FlattenedHeadersAndCookies,\n );\n}\n\n/**\n * Parse HTTP Raw Headers\n * Attribution to {@link https://github.com/kesla/parse-headers/blob/master/parse-headers.js}\n *\n * @param headers - The raw headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function parseHeaders(\n headers: string,\n): Record<string, string | string[]> {\n if (!headers) return {};\n\n const result = {};\n const headersArr = headers.trim().split('\\n');\n\n for (let i = 0; i < headersArr.length; i++) {\n const row = headersArr[i];\n const index = row.indexOf(':');\n const key = row.slice(0, index).trim().toLowerCase();\n const value = row.slice(index + 1).trim();\n\n if (typeof result[key] === 'undefined') result[key] = value;\n else if (Array.isArray(result[key])) result[key].push(value);\n else result[key] = [result[key], value];\n }\n\n return result;\n}\n\nexport function keysToLowercase<T extends Record<string, unknown>>(\n obj: T,\n): { [K in keyof T as Lowercase<string & K>]: T[K] } {\n const result: any = {};\n for (const [k, v] of Object.entries(obj)) result[k.toLowerCase()] = v;\n\n return result as { [K in keyof T as Lowercase<string & K>]: T[K] };\n}\n","/**\n * No operation function is used when we need to pass a function, but we don't want to specify any behavior.\n *\n * @breadcrumb Core\n * @public\n */\nexport const NO_OP: (...args: any[]) => any = () => void 0;\n","import { NO_OP } from './no-op';\n\n/**\n * The type representing the possible log levels to choose from.\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport type LogLevels =\n | 'debug'\n | 'verbose'\n | 'info'\n | 'warn'\n | 'error'\n | 'none';\n\n/**\n * The options to customize {@link ILogger}\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport type LoggerOptions = {\n /**\n * Select the log level, {@link LogLevels | see more}.\n *\n * @defaultValue error\n */\n level: LogLevels;\n};\n\n/**\n * The log function used in any level.\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport type LoggerFN = (message: any, ...additional: any[]) => void;\n\n/**\n * The interface representing the logger, you can provide a custom logger by implementing this interface.\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport type ILogger = Record<Exclude<LogLevels, 'none'>, LoggerFN>;\n\n/**\n * The symbol used to check against an ILogger instace to verify if that ILogger was created by this library\n *\n * @breadcrumb Core / Logger\n * @public\n */\nconst InternalLoggerSymbol = Symbol('InternalLogger');\n\nconst logLevels: Record<\n LogLevels,\n [level: LogLevels, consoleMethod: keyof Console][]\n> = {\n debug: [\n ['debug', 'debug'],\n ['verbose', 'debug'],\n ['info', 'info'],\n ['error', 'error'],\n ['warn', 'warn'],\n ],\n verbose: [\n ['verbose', 'debug'],\n ['info', 'info'],\n ['error', 'error'],\n ['warn', 'warn'],\n ],\n info: [\n ['info', 'info'],\n ['error', 'error'],\n ['warn', 'warn'],\n ],\n warn: [\n ['warn', 'warn'],\n ['error', 'error'],\n ],\n error: [['error', 'error']],\n none: [],\n};\n\nconst lazyPrint = (value: () => any | unknown) => {\n if (typeof value === 'function') return value();\n\n return value;\n};\n\nconst print =\n (fn: string) =>\n (message: any, ...additional: (() => any)[]) =>\n console[fn](message, ...additional.map(lazyPrint));\n\n/**\n * The method used to create a simple logger instance to use in this library.\n *\n * @remarks Behind the scenes, this simple logger sends the message to the `console` methods.\n *\n * @example\n * ```typescript\n * const logger = createDefaultLogger();\n *\n * logger.error('An error happens.');\n * // An error happens.\n * ```\n *\n * @param level - Select the level of the log\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport function createDefaultLogger(\n { level }: LoggerOptions = { level: 'error' },\n): ILogger {\n const levels = logLevels[level];\n\n if (!levels) throw new Error('Invalid log level');\n\n const logger = {\n [InternalLoggerSymbol]: true,\n error: NO_OP,\n debug: NO_OP,\n info: NO_OP,\n verbose: NO_OP,\n warn: NO_OP,\n } as ILogger;\n\n for (const [level, consoleMethod] of levels)\n logger[level] = print(consoleMethod);\n\n return logger;\n}\n\n/**\n * The method used to chck if logger was created by this library, or it was defined by the user.\n *\n * @param logger - The instance of the logger to check\n *\n * @breadcrumb Core / Logger\n * @public\n */\nexport function isInternalLogger(logger: ILogger): boolean {\n return !!logger[InternalLoggerSymbol];\n}\n","/**\n * Return the defaultValue whether the value is undefined, otherwise, return the value.\n *\n * @example\n * ```typescript\n * const value1 = getDefaultIfUndefined(undefined, true);\n * const value2 = getDefaultIfUndefined(false, true);\n *\n * console.log(value1);\n * // true\n * console.log(value2);\n * // false\n * ```\n *\n * @param value - The value to be checked\n * @param defaultValue - The default value when value is undefined\n *\n * @breadcrumb Core\n * @public\n */\nexport function getDefaultIfUndefined<T>(\n value: T | undefined,\n defaultValue: T,\n): T {\n if (value === undefined) return defaultValue;\n\n return value;\n}\n","/**\n * Transform the path and a map of query params to a string with formatted query params\n *\n * @example\n * ```typescript\n * const path = '/pets/search';\n * const queryParams = { batata: undefined, petType: [ 'dog', 'fish' ] };\n * const result = getPathWithQueryStringParams(path, queryParams);\n * console.log(result);\n * // /pets/search?batata=&petType=dog&petType=fish\n * ```\n *\n * @param path - The path\n * @param queryParams - The query params\n *\n * @breadcrumb Core / Path\n * @public\n */\nexport function getPathWithQueryStringParams(\n path: string,\n queryParams:\n | string\n | Record<string, string | string[] | undefined>\n | undefined\n | null,\n): string {\n if (String(queryParams || '').length === 0) return path;\n\n if (typeof queryParams === 'string') return `${path}?${queryParams}`;\n\n const queryParamsString = getQueryParamsStringFromRecord(queryParams);\n\n if (!queryParamsString) return path;\n\n return `${path}?${queryParamsString}`;\n}\n\n/**\n * Map query params to a string with formatted query params\n *\n * @example\n * ```typescript\n * const queryParams = { batata: undefined, petType: [ 'dog', 'fish' ] };\n * const result = getQueryParamsStringFromRecord(queryParams);\n * console.log(result);\n * // batata=&petType=dog&petType=fish\n * ```\n *\n * @param queryParamsRecord - The query params record\n *\n * @breadcrumb Core / Path\n * @public\n */\nexport function getQueryParamsStringFromRecord(\n queryParamsRecord:\n | Record<string, string | string[] | undefined>\n | undefined\n | null,\n): string {\n const searchParams = new URLSearchParams();\n\n const multiValueHeadersEntries: [string, string | string[] | undefined][] =\n Object.entries(queryParamsRecord || {});\n\n if (multiValueHeadersEntries.length === 0) return '';\n\n for (const [key, value] of multiValueHeadersEntries) {\n if (!Array.isArray(value)) {\n searchParams.append(key, value || '');\n continue;\n }\n\n for (const arrayValue of value) searchParams.append(key, arrayValue);\n }\n\n return searchParams.toString();\n}\n\n/**\n * Type of the function to strip base path\n *\n * @breadcrumb Core / Path\n * @public\n */\nexport type StripBasePathFn = (path: string) => string;\n\nconst NOOPBasePath: StripBasePathFn = (path: string) => path;\n\n/**\n * Get the strip base path function\n *\n * @param basePath - The base path\n *\n * @breadcrumb Core / Path\n * @public\n */\nexport function buildStripBasePath(\n basePath: string | undefined,\n): StripBasePathFn {\n if (!basePath) return NOOPBasePath;\n\n const length = basePath.length;\n\n return (path: string) => {\n if (path.startsWith(basePath))\n return path.slice(path.indexOf(basePath) + length, path.length) || '/';\n\n return path;\n };\n}\n","//#region Imports\n\nimport { Readable, Writable } from 'node:stream';\n\n//#endregion\n\n/**\n * Check if stream already ended\n *\n * @param stream - The stream\n *\n * @breadcrumb Core / Stream\n * @public\n */\nexport function isStreamEnded(stream: Readable | Writable): boolean {\n if ('readableEnded' in stream && stream.readableEnded) return true;\n\n if ('writableEnded' in stream && stream.writableEnded) return true;\n\n return false;\n}\n\n/**\n * Wait asynchronous the stream to complete\n *\n * @param stream - The stream\n *\n * @breadcrumb Core / Stream\n * @public\n */\nexport function waitForStreamComplete<TStream extends Readable | Writable>(\n stream: TStream,\n): Promise<TStream> {\n if (isStreamEnded(stream)) return Promise.resolve(stream);\n\n return new Promise<TStream>((resolve, reject) => {\n // Reading the {@link https://github.com/nodejs/node/blob/v12.22.9/lib/events.js#L262 | emit source code},\n // it's almost impossible to complete being called twice because the emit function runs synchronously and removes the other listeners,\n // but I'll leave it at that because I didn't write that code, so I couldn't figure out what the author thought when he wrote this.\n let isComplete = false;\n\n function complete(err: any) {\n /* istanbul ignore next */\n if (isComplete) return;\n\n isComplete = true;\n\n stream.removeListener('error', complete);\n stream.removeListener('end', complete);\n stream.removeListener('finish', complete);\n\n if (err) reject(err);\n else resolve(stream);\n }\n\n stream.once('error', complete);\n stream.once('end', complete);\n stream.once('finish', complete);\n });\n}\n","//#region Imports\n\nimport type { ALBEvent, ALBResult, Context } from 'aws-lambda';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n type StripBasePathFn,\n buildStripBasePath,\n getEventBodyAsBuffer,\n getFlattenedHeadersMap,\n getMultiValueHeadersMap,\n getPathWithQueryStringParams,\n} from '../../core';\n\n//#endregion\n\n/**\n * The options to customize the {@link AlbAdapter}\n *\n * @breadcrumb Adapters / AWS / AlbAdapter\n * @public\n */\nexport interface AlbAdapterOptions {\n /**\n * Strip base path for custom domains\n *\n * @defaultValue ''\n */\n stripBasePath?: string;\n}\n\n/**\n * The adapter to handle requests from AWS ALB\n *\n * @example\n * ```typescript\n * const stripBasePath = '/any/custom/base/path'; // default ''\n * const adapter = new AlbAdapter({ stripBasePath });\n * ```\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html | Event Reference}\n *\n * @breadcrumb Adapters / AWS / AlbAdapter\n * @public\n */\nexport class AlbAdapter\n implements AdapterContract<ALBEvent, Context, ALBResult>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link AlbAdapter}\n */\n constructor(protected readonly options?: AlbAdapterOptions) {\n this.stripPathFn = buildStripBasePath(this.options?.stripBasePath);\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Strip base path function\n */\n protected stripPathFn: StripBasePathFn;\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return AlbAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is ALBEvent {\n const albEvent = event as Partial<ALBEvent>;\n\n return !!(albEvent?.requestContext && albEvent.requestContext.elb);\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: ALBEvent): AdapterRequest {\n const method = event.httpMethod;\n const path = this.getPathFromEvent(event);\n\n const headers = event.multiValueHeaders\n ? getFlattenedHeadersMap(event.multiValueHeaders, ',', true)\n : event.headers!;\n\n let body: Buffer | undefined;\n\n if (event.body) {\n const [bufferBody, contentLength] = getEventBodyAsBuffer(\n event.body,\n event.isBase64Encoded,\n );\n\n body = bufferBody;\n headers['content-length'] = String(contentLength);\n }\n\n let remoteAddress = '';\n\n // ref: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html#x-forwarded-for\n if (headers['x-forwarded-for']) remoteAddress = headers['x-forwarded-for'];\n\n return {\n method,\n headers,\n body,\n remoteAddress,\n path,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n event,\n headers: responseHeaders,\n body,\n isBase64Encoded,\n statusCode,\n }: GetResponseAdapterProps<ALBEvent>): ALBResult {\n const multiValueHeaders = !event.headers\n ? getMultiValueHeadersMap(responseHeaders)\n : undefined;\n\n const headers = event.headers\n ? getFlattenedHeadersMap(responseHeaders)\n : undefined;\n\n if (headers && headers['transfer-encoding'] === 'chunked')\n delete headers['transfer-encoding'];\n\n if (\n multiValueHeaders &&\n multiValueHeaders['transfer-encoding']?.includes('chunked')\n )\n delete multiValueHeaders['transfer-encoding'];\n\n return {\n statusCode,\n body,\n headers,\n multiValueHeaders,\n isBase64Encoded,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n respondWithErrors,\n event,\n log,\n }: OnErrorProps<ALBEvent, ALBResult>): void {\n const body = respondWithErrors ? error.stack || '' : '';\n const errorResponse = this.getResponse({\n event,\n statusCode: 500,\n body,\n headers: {},\n isBase64Encoded: false,\n log,\n });\n\n delegatedResolver.succeed(errorResponse);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Get path from event with query strings\n *\n * @param event - The event sent by serverless\n */\n protected getPathFromEvent(event: ALBEvent): string {\n const path = this.stripPathFn(event.path);\n\n const queryParams = event.headers\n ? event.queryStringParameters\n : event.multiValueQueryStringParameters;\n\n return getPathWithQueryStringParams(path, queryParams || {});\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { APIGatewayProxyResult, Context } from 'aws-lambda';\nimport type { APIGatewayProxyEvent } from 'aws-lambda/trigger/api-gateway-proxy';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport { keysToLowercase } from '../../core';\nimport {\n type StripBasePathFn,\n buildStripBasePath,\n getDefaultIfUndefined,\n getEventBodyAsBuffer,\n getMultiValueHeadersMap,\n getPathWithQueryStringParams,\n} from '../../core';\n\n//#endregion\n\n/**\n * The options to customize the {@link ApiGatewayV1Adapter}\n *\n * @breadcrumb Adapters / AWS / ApiGatewayV1Adapter\n * @public\n */\nexport interface ApiGatewayV1Options {\n /**\n * Strip base path for custom domains\n *\n * @defaultValue ''\n */\n stripBasePath?: string;\n\n /**\n * Throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer.\n * If this is set to `false`, we will remove the `transfer-encoding` header from the response and buffer the response body\n * while we remove the special characters inserted by the chunked encoding.\n *\n * @remarks To learn more https://github.com/H4ad/serverless-adapter/issues/165\n * @defaultValue true\n */\n throwOnChunkedTransferEncoding?: boolean;\n\n /**\n * Emulates the behavior of Node.js `http` module by ensuring all request headers are lowercase.\n *\n * @defaultValue false\n */\n lowercaseRequestHeaders?: boolean;\n}\n\n/**\n * The adapter to handle requests from AWS Api Gateway V1\n *\n * As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer.\n *\n * @remarks This adapter is not fully compatible with \\@vendia/serverless-express, on \\@vendia they filter `transfer-encoding=chunked` but we throw an exception.\n *\n * @example\n * ```typescript\n * const stripBasePath = '/any/custom/base/path'; // default ''\n * const adapter = new ApiGatewayV1Adapter({ stripBasePath });\n * ```\n *\n * {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html | Event Reference}\n *\n * @breadcrumb Adapters / AWS / ApiGatewayV1Adapter\n * @public\n */\nexport class ApiGatewayV1Adapter\n implements\n AdapterContract<APIGatewayProxyEvent, Context, APIGatewayProxyResult>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link ApiGatewayV1Adapter}\n */\n constructor(protected readonly options?: ApiGatewayV1Options) {\n this.stripPathFn = buildStripBasePath(this.options?.stripBasePath);\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Strip base path function\n */\n protected stripPathFn: StripBasePathFn;\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return ApiGatewayV1Adapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is APIGatewayProxyEvent {\n const partialEventV1 = event as Partial<APIGatewayProxyEvent> & {\n version?: '2.0';\n };\n\n return !!(\n partialEventV1?.requestContext &&\n partialEventV1.version !== '2.0' &&\n partialEventV1.headers &&\n partialEventV1.multiValueHeaders &&\n ((partialEventV1.queryStringParameters === null &&\n partialEventV1.multiValueQueryStringParameters === null) ||\n (partialEventV1.queryStringParameters &&\n partialEventV1.multiValueQueryStringParameters))\n );\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: APIGatewayProxyEvent): AdapterRequest {\n const method = event.httpMethod;\n const headers = this.options?.lowercaseRequestHeaders\n ? keysToLowercase(event.headers)\n : { ...event.headers };\n\n for (const multiValueHeaderKey of Object.keys(\n event.multiValueHeaders || {},\n )) {\n const headerValue = event.multiValueHeaders[multiValueHeaderKey];\n\n // event.headers by default only stick with first value if they see multiple headers\n // the other values will only appear on multiValueHeaderKey, in this case\n // we look for headers with more than 1 length which is the wrong values on event.headers\n // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html\n if (!headerValue || headerValue?.length <= 1) continue;\n\n headers[multiValueHeaderKey] = headerValue.join(',');\n }\n\n const path = this.getPathFromEvent(event);\n\n let body: Buffer | undefined;\n\n if (event.body) {\n const [bufferBody, contentLength] = getEventBodyAsBuffer(\n event.body,\n event.isBase64Encoded,\n );\n\n body = bufferBody;\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n headers['content-length'] = contentLength + '';\n }\n\n const remoteAddress = event.requestContext.identity.sourceIp;\n\n return {\n method,\n headers,\n body,\n remoteAddress,\n path,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n headers: responseHeaders,\n body,\n isBase64Encoded,\n statusCode,\n response,\n }: GetResponseAdapterProps<APIGatewayProxyEvent>): APIGatewayProxyResult {\n const multiValueHeaders = getMultiValueHeadersMap(responseHeaders);\n\n const shouldThrowOnChunkedTransferEncoding = getDefaultIfUndefined(\n this.options?.throwOnChunkedTransferEncoding,\n true,\n );\n const transferEncodingHeader = multiValueHeaders['transfer-encoding'];\n const hasTransferEncodingChunked = transferEncodingHeader?.some(value =>\n value.includes('chunked'),\n );\n\n if (hasTransferEncodingChunked || response?.chunkedEncoding) {\n if (shouldThrowOnChunkedTransferEncoding) {\n throw new Error(\n 'chunked encoding in headers is not supported by API Gateway V1',\n );\n } else delete multiValueHeaders['transfer-encoding'];\n }\n\n return {\n statusCode,\n body,\n multiValueHeaders,\n isBase64Encoded,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n respondWithErrors,\n event,\n log,\n }: OnErrorProps<APIGatewayProxyEvent, APIGatewayProxyResult>): void {\n const body = respondWithErrors ? error.stack : '';\n const errorResponse = this.getResponse({\n event,\n statusCode: 500,\n body: body || '',\n headers: {},\n isBase64Encoded: false,\n log,\n });\n\n delegatedResolver.succeed(errorResponse);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Get path from event with query strings\n *\n * @param event - The event sent by serverless\n */\n protected getPathFromEvent(event: APIGatewayProxyEvent): string {\n const path = this.stripPathFn(event.path);\n const queryParams = event.multiValueQueryStringParameters || {};\n\n if (event.queryStringParameters) {\n for (const queryStringKey of Object.keys(event.queryStringParameters)) {\n const queryStringValue = event.queryStringParameters[queryStringKey];\n\n if (queryStringValue === undefined) continue;\n\n if (!Array.isArray(queryParams[queryStringKey]))\n queryParams[queryStringKey] = [];\n\n if (queryParams[queryStringKey]!.includes(queryStringValue)) continue;\n\n queryParams[queryStringKey]!.push(queryStringValue);\n }\n }\n\n return getPathWithQueryStringParams(path, queryParams);\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { APIGatewayProxyEventV2, Context } from 'aws-lambda';\nimport type { APIGatewayProxyStructuredResultV2 } from 'aws-lambda/trigger/api-gateway-proxy';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n type StripBasePathFn,\n buildStripBasePath,\n getDefaultIfUndefined,\n getEventBodyAsBuffer,\n getFlattenedHeadersMapAndCookies,\n getPathWithQueryStringParams,\n} from '../../core';\n\n//#endregion\n\n/**\n * The options to customize the {@link ApiGatewayV2Adapter}\n *\n * @breadcrumb Adapters / AWS / ApiGatewayV2Adapter\n * @public\n */\nexport interface ApiGatewayV2Options {\n /**\n * Strip base path for custom domains\n *\n * @defaultValue ''\n */\n stripBasePath?: string;\n\n /**\n * Throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer.\n * If this is set to `false`, we will remove the `transfer-encoding` header from the response and buffer the response body\n * while we remove the special characters inserted by the chunked encoding.\n *\n * @remarks To learn more https://github.com/H4ad/serverless-adapter/issues/165\n * @defaultValue true\n */\n throwOnChunkedTransferEncoding?: boolean;\n}\n\n/**\n * The adapter to handle requests from AWS Api Gateway V2\n *\n * As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked`.\n * But, if you use this adapter to accept requests from Function URL, you can accept the `transfer-encoding=chunked` changing the method of invocation from `BUFFERED` to `RESPONSE_STREAM`.\n *\n * @example\n * ```typescript\n * const stripBasePath = '/any/custom/base/path'; // default ''\n * const adapter = new ApiGatewayV2Adapter({ stripBasePath });\n * ```\n *\n * {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html | Event Reference}\n *\n * @breadcrumb Adapters / AWS / ApiGatewayV2Adapter\n * @public\n */\nexport class ApiGatewayV2Adapter\n implements\n AdapterContract<\n APIGatewayProxyEventV2,\n Context,\n APIGatewayProxyStructuredResultV2\n >\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link ApiGatewayV2Adapter}\n */\n constructor(protected readonly options?: ApiGatewayV2Options) {\n this.stripPathFn = buildStripBasePath(this.options?.stripBasePath);\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Strip base path function\n */\n protected stripPathFn: StripBasePathFn;\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return ApiGatewayV2Adapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is APIGatewayProxyEventV2 {\n const apiGatewayEvent = event as Partial<APIGatewayProxyEventV2> & {\n version?: string;\n };\n\n return !!(\n apiGatewayEvent?.requestContext && apiGatewayEvent.version === '2.0'\n );\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: APIGatewayProxyEventV2): AdapterRequest {\n const method = event.requestContext.http.method;\n const path = this.getPathFromEvent(event);\n // accords https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html\n // all headers are lowercased and cannot be array\n // so no need to format, just a shallow copy will work here\n const headers = { ...event.headers };\n\n if (event.cookies) headers.cookie = event.cookies.join('; ');\n\n let body: Buffer | undefined;\n\n if (event.body) {\n const [bufferBody, contentLength] = getEventBodyAsBuffer(\n event.body,\n event.isBase64Encoded,\n );\n\n body = bufferBody;\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n headers['content-length'] = contentLength + '';\n }\n\n const remoteAddress = event.requestContext.http.sourceIp;\n\n return {\n method,\n headers,\n body,\n remoteAddress,\n path,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n headers: responseHeaders,\n body,\n isBase64Encoded,\n statusCode,\n response,\n }: GetResponseAdapterProps<APIGatewayProxyEventV2>): APIGatewayProxyStructuredResultV2 {\n const { cookies, headers } =\n getFlattenedHeadersMapAndCookies(responseHeaders);\n\n const shouldThrowOnChunkedTransferEncoding = getDefaultIfUndefined(\n this.options?.throwOnChunkedTransferEncoding,\n true,\n );\n\n const transferEncodingHeader: string | undefined =\n headers['transfer-encoding'];\n\n const hasTransferEncodingChunked =\n transferEncodingHeader && transferEncodingHeader.includes('chunked');\n\n if (hasTransferEncodingChunked || response?.chunkedEncoding) {\n if (shouldThrowOnChunkedTransferEncoding) {\n throw new Error(\n 'chunked encoding in headers is not supported by API Gateway V2',\n );\n } else delete headers['transfer-encoding'];\n }\n\n return {\n statusCode,\n body,\n headers,\n isBase64Encoded,\n cookies,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n respondWithErrors,\n event,\n log,\n }: OnErrorProps<\n APIGatewayProxyEventV2,\n APIGatewayProxyStructuredResultV2\n >): void {\n const body = respondWithErrors ? error.stack : '';\n const errorResponse = this.getResponse({\n event,\n statusCode: 500,\n body: body || '',\n headers: {},\n isBase64Encoded: false,\n log,\n });\n\n delegatedResolver.succeed(errorResponse);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Get path from event with query strings\n *\n * @param event - The event sent by serverless\n */\n protected getPathFromEvent(event: APIGatewayProxyEventV2): string {\n const path = this.stripPathFn(event.rawPath);\n const queryParams = event.rawQueryString;\n\n return getPathWithQueryStringParams(path, queryParams || {});\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { Context, SQSBatchItemFailure } from 'aws-lambda';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../../contracts';\nimport {\n EmptyResponse,\n type IEmptyResponse,\n getEventBodyAsBuffer,\n} from '../../../core';\n\n//#endregion\n\n/**\n * The options to customize the {@link AwsSimpleAdapter}\n *\n * @breadcrumb Adapters / AWS / AWS Simple Adapter\n * @public\n */\nexport interface AWSSimpleAdapterOptions {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n */\n forwardPath: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n */\n forwardMethod: string;\n\n /**\n * The AWS Service host that will be injected inside headers to developer being able to validate if request originate from the library.\n */\n host: string;\n\n /**\n * Tells if this adapter should support batch item failures.\n */\n batch?: true | false;\n}\n\n/**\n * The batch item failure response expected from the API server\n *\n * @breadcrumb Adapters / AWS / AWS Simple Adapter\n * @public\n */\nexport type BatchItemFailureResponse = SQSBatchItemFailure;\n\n/**\n * The possible options of response for {@link AwsSimpleAdapter}\n *\n * @breadcrumb Adapters / AWS / AWS Simple Adapter\n * @public\n */\nexport type AWSSimpleAdapterResponseType =\n | BatchItemFailureResponse\n | IEmptyResponse;\n\n/**\n * The abstract adapter to use to implement other simple AWS adapters\n *\n * @breadcrumb Adapters / AWS / AWS Simple Adapter\n * @public\n */\nexport abstract class AwsSimpleAdapter<TEvent>\n implements AdapterContract<TEvent, Context, AWSSimpleAdapterResponseType>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link AwsSimpleAdapter}\n */\n constructor(protected readonly options: AWSSimpleAdapterOptions) {}\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n throw new Error('not implemented.');\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(_: unknown): _ is TEvent {\n throw new Error('not implemented.');\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: TEvent): AdapterRequest {\n const path = this.options.forwardPath;\n const method = this.options.forwardMethod;\n\n const [body, contentLength] = getEventBodyAsBuffer(\n JSON.stringify(event),\n false,\n );\n\n const headers = {\n host: this.options.host,\n 'content-type': 'application/json',\n 'content-length': String(contentLength),\n };\n\n return {\n method,\n headers,\n body,\n path,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n body,\n headers,\n isBase64Encoded,\n event,\n statusCode,\n }: GetResponseAdapterProps<TEvent>): AWSSimpleAdapterResponseType {\n if (this.hasInvalidStatusCode(statusCode)) {\n throw new Error(\n JSON.stringify({ body, headers, isBase64Encoded, event, statusCode }),\n );\n }\n\n if (!this.options.batch) return EmptyResponse;\n\n if (isBase64Encoded) {\n throw new Error(\n 'SERVERLESS_ADAPTER: The response could not be base64 encoded when you set batch: true, the response should be a JSON.',\n );\n }\n\n if (!body) return EmptyResponse;\n\n return JSON.parse(body);\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n }: OnErrorProps<TEvent, AWSSimpleAdapterResponseType>): void {\n delegatedResolver.fail(error);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Check if the status code is invalid\n *\n * @param statusCode - The status code\n */\n protected hasInvalidStatusCode(statusCode: number): boolean {\n return statusCode < 200 || statusCode >= 400;\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { DynamoDBStreamEvent } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { type AWSSimpleAdapterOptions, AwsSimpleAdapter } from './base/index';\n\n//#endregion\n\n/**\n * The options to customize the {@link DynamoDBAdapter}\n *\n * @breadcrumb Adapters / AWS / DynamoDBAdapter\n * @public\n */\nexport interface DynamoDBAdapterOptions\n extends Pick<AWSSimpleAdapterOptions, 'batch'> {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /dynamo\n */\n dynamoDBForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n dynamoDBForwardMethod?: string;\n}\n\n/**\n * The adapter to handle requests from AWS DynamoDB.\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html | Event Reference}\n *\n * @example\n * ```typescript\n * const dynamoDBForwardPath = '/your/route/dynamo'; // default /dynamo\n * const dynamoDBForwardMethod = 'POST'; // default POST\n * const adapter = new DynamoDBAdapter({ dynamoDBForwardPath, dynamoDBForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / DynamoDBAdapter\n * @public\n */\nexport class DynamoDBAdapter extends AwsSimpleAdapter<DynamoDBStreamEvent> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link DynamoDBAdapter}\n */\n constructor(options?: DynamoDBAdapterOptions) {\n super({\n forwardPath: getDefaultIfUndefined(\n options?.dynamoDBForwardPath,\n '/dynamo',\n ),\n forwardMethod: getDefaultIfUndefined(\n options?.dynamoDBForwardMethod,\n 'POST',\n ),\n batch: options?.batch,\n host: 'dynamodb.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return DynamoDBAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is DynamoDBStreamEvent {\n const dynamoDBevent = event as Partial<DynamoDBStreamEvent>;\n\n if (!Array.isArray(dynamoDBevent?.Records)) return false;\n\n const eventSource = dynamoDBevent.Records[0]?.eventSource;\n\n return eventSource === 'aws:dynamodb';\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { EventBridgeEvent } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { AwsSimpleAdapter } from './base';\n\n//#endregion\n\n/**\n * The options to customize the {@link EventBridgeAdapter}\n *\n * @breadcrumb Adapters / AWS / EventBridgeAdapter\n * @public\n */\nexport interface EventBridgeOptions {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /eventbridge\n */\n eventBridgeForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n eventBridgeForwardMethod?: string;\n}\n\n/**\n * Just a type alias to ignore generic types in the event\n *\n * @breadcrumb Adapters / AWS / EventBridgeAdapter\n * @public\n */\nexport type EventBridgeEventAll = EventBridgeEvent<any, any>;\n\n/**\n * The adapter to handle requests from AWS EventBridge (Cloudwatch Events).\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html | Event Reference}\n *\n * @example\n * ```typescript\n * const eventBridgeForwardPath = '/your/route/eventbridge'; // default /eventbridge\n * const eventBridgeForwardMethod = 'POST'; // default POST\n * const adapter = new EventBridgeAdapter({ eventBridgeForwardPath, eventBridgeForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / EventBridgeAdapter\n * @public\n */\nexport class EventBridgeAdapter extends AwsSimpleAdapter<EventBridgeEventAll> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link EventBridgeAdapter}\n */\n constructor(options?: EventBridgeOptions) {\n super({\n forwardPath: getDefaultIfUndefined(\n options?.eventBridgeForwardPath,\n '/eventbridge',\n ),\n forwardMethod: getDefaultIfUndefined(\n options?.eventBridgeForwardMethod,\n 'POST',\n ),\n batch: false,\n host: 'events.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return EventBridgeAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is EventBridgeEventAll {\n const eventBridgeEvent = event as Partial<EventBridgeEventAll>;\n\n // thanks to @cnuss in https://github.com/vendia/serverless-express/blob/b5da6070b8dd2fb674c1f7035dd7edfef1dc83a2/src/event-sources/utils.js#L87\n return !!(\n eventBridgeEvent &&\n eventBridgeEvent.version &&\n eventBridgeEvent.version === '0' &&\n eventBridgeEvent.id &&\n eventBridgeEvent['detail-type'] &&\n eventBridgeEvent.source &&\n eventBridgeEvent.account &&\n eventBridgeEvent.time &&\n eventBridgeEvent.region &&\n eventBridgeEvent.resources &&\n Array.isArray(eventBridgeEvent.resources) &&\n eventBridgeEvent.detail &&\n typeof eventBridgeEvent.detail === 'object' &&\n !Array.isArray(eventBridgeEvent.detail)\n );\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { CloudFrontRequest, Context } from 'aws-lambda';\nimport type {\n CloudFrontEvent,\n CloudFrontHeaders,\n CloudFrontResultResponse,\n} from 'aws-lambda/common/cloudfront';\nimport type {\n CloudFrontRequestEvent,\n CloudFrontRequestResult,\n} from 'aws-lambda/trigger/cloudfront-request';\nimport type {\n BothValueHeaders,\n Concrete,\n SingleValueHeaders,\n} from '../../@types';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n getDefaultIfUndefined,\n getEventBodyAsBuffer,\n getPathWithQueryStringParams,\n} from '../../core';\n\n//#endregion\n\n/**\n * The type alias to indicate where we get the default value of query string to create the request.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport type DefaultQueryString =\n CloudFrontRequestEvent['Records'][number]['cf']['request']['querystring'];\n\n/**\n * The type alias to indicate where we get the default value of path to create the request.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport type DefaultForwardPath =\n CloudFrontRequestEvent['Records'][number]['cf']['request']['uri'];\n\n/**\n * Represents the body of the new version of Lambda\\@edge, which uses the `body` property inside `request` as the body (library) of the request.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport type NewLambdaEdgeBody =\n CloudFrontRequestEvent['Records'][number]['cf']['request']['body'];\n\n/**\n * Represents the body of the old version of Lambda\\@edge supported by \\@vendia/serverless-express which returns the `data` property within `body` for the body (library) of the request.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport type OldLambdaEdgeBody = Concrete<\n CloudFrontRequestEvent['Records'][number]['cf']['request']\n>['body']['data'];\n\n/**\n * The list was created based on {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-restrictions.html | these docs} in the \"Disallowed Headers\" section.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants\n * @public\n */\nexport const DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS: (string | RegExp)[] = [\n 'Connection',\n 'Expect',\n 'Keep-Alive',\n 'Proxy-Authenticate',\n 'Proxy-Authorization',\n 'Proxy-Connection',\n 'Trailer',\n 'Upgrade',\n 'X-Accel-Buffering',\n 'X-Accel-Charset',\n 'X-Accel-Limit-Rate',\n 'X-Accel-Redirect',\n /(X-Amz-Cf-)(.*)/gim,\n 'X-Cache',\n /(X-Edge-)(.*)/gim,\n 'X-Forwarded-Proto',\n 'X-Real-IP',\n];\n\n/**\n * The default max response size in bytes of viewer request and viewer response.\n *\n * @defaultValue 1024 * 40 = 40960 = 40KB\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants\n * @public\n */\nexport const DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES = 1024 * 40;\n\n/**\n * The default max response size in bytes of origin request and origin response.\n *\n * @defaultValue 1024 * 1024 = 1048576 = 1MB\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants\n * @public\n */\nexport const DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES = 1024 * 1024;\n\n/**\n * The options to customize the {@link LambdaEdgeAdapter}.\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport interface LambdaEdgeAdapterOptions {\n /**\n * The max response size in bytes of viewer request and viewer response.\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @defaultValue {@link DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES}\n */\n viewerMaxResponseSizeInBytes?: number;\n\n /**\n * The max response size in bytes of origin request and origin response.\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @defaultValue {@link DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES}\n */\n originMaxResponseSizeInBytes?: number;\n\n /**\n * The function called when the response size exceed the max limits of the Lambda\\@edge\n *\n * @param response - The response from framework that exceed the limit of Lambda\\@edge\n * @defaultValue undefined\n */\n onResponseSizeExceedLimit?: (\n response: CloudFrontRequestResult,\n ) => CloudFrontRequestResult;\n\n /**\n * Return the path to be used to create a request to the framework\n *\n * @remarks You MUST append the query params from {@link DefaultQueryString}, you can use the helper {@link getPathWithQueryStringParams}.\n *\n * @param event - The event sent by the serverless\n * @defaultValue The value from {@link DefaultForwardPath}\n */\n getPathFromEvent?: (\n event: CloudFrontRequestEvent['Records'][number],\n ) => string;\n\n /**\n * The headers that will be stripped from the headers object because Lambda\\@edge will fail if these headers are passed in the response.\n *\n * @remarks All headers will be compared with other headers using toLowerCase, but for the RegExp, if you modify this list, you must put the flag `/gmi` at the end of the RegExp (ex: `/(X-Amz-Cf-)(.*)/gim`)\n *\n * @defaultValue To get the full list, see {@link DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS}.\n */\n disallowedHeaders?: (string | RegExp)[];\n\n /**\n * If you want to change how we check against the header if it should be stripped, you can pass a function to this property.\n *\n * @param header - The header of the response\n * @defaultValue The default method is implemented to test the header against the list {@link LambdaEdgeAdapterOptions.disallowedHeaders}.\n */\n shouldStripHeader?: (header: string) => boolean;\n\n /**\n * By default, the {@link aws-lambda#CloudFrontRequestResult} has the `headers` property, but we also have the headers sent by the framework too.\n * So this setting tells us how to handle this case, if you pass `true` to this property, we will use the framework headers.\n * Otherwise, we will forward the body back to cloudfront without modifying or trying to set the `headers` property inside {@link aws-lambda#CloudFrontRequestResult}.\n *\n * @defaultValue false\n */\n shouldUseHeadersFromFramework?: boolean;\n}\n\n/**\n * The adapter to handle requests from AWS Lambda\\@Edge.\n *\n * This adapter is not fully compatible with Lambda\\@edge supported by \\@vendia/serverless-express, the request body was modified to return {@link NewLambdaEdgeBody} instead {@link OldLambdaEdgeBody}.\n * Also, the response has been modified to return entire body sent by the framework, in this form you MUST return the body from the framework in the format of {@link aws-lambda#CloudFrontRequestResult}.\n * And when we get an error during the forwarding to the framework, we call `resolver.fail` instead of trying to return status 500 like the old implementation was.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html | Lambda edge docs}\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html | Event Reference}\n *\n * @example\n * ```typescript\n * const getPathFromEvent = () => '/lambda/edge'; // will forward all requests to the same endpoint\n * const adapter = new LambdaEdgeAdapter({ getPathFromEvent });\n * ```\n *\n * @breadcrumb Adapters / AWS / LambdaEdgeAdapter\n * @public\n */\nexport class LambdaEdgeAdapter\n implements\n AdapterContract<CloudFrontRequestEvent, Context, CloudFrontRequestResult>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link LambdaEdgeAdapter}\n */\n constructor(protected readonly options?: LambdaEdgeAdapterOptions) {\n const disallowedHeaders = getDefaultIfUndefined(\n this.options?.disallowedHeaders,\n DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS,\n );\n\n this.cachedDisallowedHeaders = disallowedHeaders.map(disallowedHeader => {\n if (disallowedHeader instanceof RegExp) return disallowedHeader;\n\n return new RegExp(`(${disallowedHeader})`, 'gim');\n });\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * This property is used to cache the disallowed headers in `RegExp` version, even if you provide a string in `disallowedHeader`, we will cache it in an instance of `RegExp`.\n */\n protected readonly cachedDisallowedHeaders: RegExp[];\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return LambdaEdgeAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is CloudFrontRequestEvent {\n const lambdaEdgeEvent = event as Partial<CloudFrontRequestEvent>;\n\n if (!Array.isArray(lambdaEdgeEvent?.Records)) return false;\n\n const eventType = lambdaEdgeEvent.Records[0]?.cf?.config?.eventType;\n const validEventTypes: CloudFrontEvent['config']['eventType'][] = [\n 'origin-response',\n 'origin-request',\n 'viewer-response',\n 'viewer-request',\n ];\n\n return validEventTypes.includes(eventType);\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: CloudFrontRequestEvent): AdapterRequest {\n const request = event.Records[0];\n const cloudFrontRequest = request.cf.request;\n\n const method = cloudFrontRequest.method;\n\n const pathFromOptions = this.options?.getPathFromEvent\n ? this.options.getPathFromEvent(request)\n : undefined;\n const defaultPath = getPathWithQueryStringParams(\n cloudFrontRequest.uri,\n cloudFrontRequest.querystring,\n );\n const path = getDefaultIfUndefined(pathFromOptions, defaultPath);\n\n const remoteAddress = cloudFrontRequest.clientIp;\n\n const headers =\n this.getFlattenedHeadersFromCloudfrontRequest(cloudFrontRequest);\n\n let body: Buffer | undefined;\n\n if (cloudFrontRequest.body) {\n const [buffer, contentLength] = getEventBodyAsBuffer(\n JSON.stringify(cloudFrontRequest.body),\n false,\n );\n\n body = buffer;\n headers['content-length'] = contentLength.toString();\n }\n\n const { host } = headers;\n\n return {\n method,\n path,\n headers,\n body,\n remoteAddress,\n host,\n hostname: host,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse(\n props: GetResponseAdapterProps<CloudFrontRequestEvent>,\n ): CloudFrontRequestResult {\n const response = this.getResponseToLambdaEdge(props);\n const responseToServiceBytes = new TextEncoder().encode(\n JSON.stringify(response),\n ).length;\n\n const isOriginRequestOrResponse = this.isEventTypeOrigin(\n props.event.Records[0].cf.config,\n );\n const maxSizeInBytes = isOriginRequestOrResponse\n ? getDefaultIfUndefined(\n this.options?.originMaxResponseSizeInBytes,\n DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES,\n )\n : getDefaultIfUndefined(\n this.options?.viewerMaxResponseSizeInBytes,\n DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES,\n );\n\n if (responseToServiceBytes <= maxSizeInBytes) return response;\n\n if (this.options?.onResponseSizeExceedLimit)\n this.options.onResponseSizeExceedLimit(response);\n else {\n props.log.error(\n `SERVERLESS_ADAPTER:LAMBDA_EDGE_ADAPTER: Max response size exceeded: ${responseToServiceBytes} of the max of ${maxSizeInBytes}.`,\n );\n }\n\n return response;\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n }: OnErrorProps<CloudFrontRequestEvent, CloudFrontRequestResult>): void {\n delegatedResolver.fail(error);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Returns the headers with the flattened (non-list) values of the cloudfront request headers\n *\n * @param cloudFrontRequest - The cloudfront request\n */\n protected getFlattenedHeadersFromCloudfrontRequest(\n cloudFrontRequest: CloudFrontRequest,\n ): SingleValueHeaders {\n return Object.keys(cloudFrontRequest.headers).reduce((acc, headerKey) => {\n const headerValue = cloudFrontRequest.headers[headerKey];\n\n acc[headerKey] = headerValue.map(header => header.value).join(',');\n\n return acc;\n }, {} as SingleValueHeaders);\n }\n\n /**\n * Returns the framework response in the format required by the Lambda\\@edge.\n *\n * @param body - The body of the response\n * @param frameworkHeaders - The headers from the framework\n */\n protected getResponseToLambdaEdge({\n body,\n headers: frameworkHeaders,\n }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontRequestResult {\n const shouldUseHeadersFromFramework = getDefaultIfUndefined(\n this.options?.shouldUseHeadersFromFramework,\n false,\n );\n\n const parsedBody: CloudFrontResultResponse | CloudFrontRequest =\n JSON.parse(body);\n\n if (parsedBody.headers) {\n parsedBody.headers = Object.keys(parsedBody.headers).reduce(\n (acc, header) => {\n if (this.shouldStripHeader(header)) return acc;\n\n acc[header] = parsedBody.headers![header];\n\n return acc;\n },\n {} as CloudFrontHeaders,\n );\n }\n\n if (!shouldUseHeadersFromFramework) return parsedBody;\n\n parsedBody.headers = this.getHeadersForCloudfrontResponse(frameworkHeaders);\n\n return parsedBody;\n }\n\n /**\n * Returns headers in Cloudfront Response format.\n *\n * @param originalHeaders - The original version of the request sent by the framework\n */\n protected getHeadersForCloudfrontResponse(\n originalHeaders: BothValueHeaders,\n ): CloudFrontHeaders {\n return Object.keys(originalHeaders).reduce((acc, headerKey) => {\n if (this.shouldStripHeader(headerKey)) return acc;\n\n if (!acc[headerKey]) acc[headerKey] = [];\n\n const headerValue = originalHeaders[headerKey];\n\n if (!Array.isArray(headerValue)) {\n acc[headerKey].push({\n key: headerKey,\n value: headerValue || '',\n });\n\n return acc;\n }\n\n const headersArray = headerValue.map(value => ({\n key: headerKey,\n value: value,\n }));\n\n acc[headerKey].push(...headersArray);\n\n return acc;\n }, {} as CloudFrontHeaders);\n }\n\n /**\n * Returns the information if we should remove the response header\n *\n * @param headerKey - The header that will be tested\n */\n protected shouldStripHeader(headerKey: string): boolean {\n if (this.options?.shouldStripHeader)\n return this.options.shouldStripHeader(headerKey);\n\n const headerKeyLowerCase = headerKey.toLowerCase();\n\n for (const stripHeaderIf of this.cachedDisallowedHeaders) {\n if (!stripHeaderIf.test(headerKeyLowerCase)) continue;\n\n return true;\n }\n\n return false;\n }\n\n /**\n * Determines whether the event is from origin or is from viewer.\n *\n * @param content - The event sent by AWS or the response sent by the framework\n */\n protected isEventTypeOrigin(content: CloudFrontEvent['config']): boolean {\n return content.eventType.includes('origin');\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { S3Event } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { AwsSimpleAdapter } from './base/index';\n\n//#endregion\n\n/**\n * The options to customize the {@link S3Adapter}\n *\n * @breadcrumb Adapters / AWS / S3Adapter\n * @public\n */\nexport interface S3AdapterOptions {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /s3\n */\n s3ForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n s3ForwardMethod?: string;\n}\n\n/**\n * The adapter to handle requests from AWS S3.\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html | Event Reference}\n *\n * @example\n * ```typescript\n * const s3ForwardPath = '/your/route/s3'; // default /s3\n * const s3ForwardMethod = 'POST'; // default POST\n * const adapter = new S3Adapter({ s3ForwardPath, s3ForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / S3Adapter\n * @public\n */\nexport class S3Adapter extends AwsSimpleAdapter<S3Event> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link SNSAdapter}\n */\n constructor(options?: S3AdapterOptions) {\n super({\n forwardPath: getDefaultIfUndefined(options?.s3ForwardPath, '/s3'),\n forwardMethod: getDefaultIfUndefined(options?.s3ForwardMethod, 'POST'),\n batch: false,\n host: 's3.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return S3Adapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is S3Event {\n const s3Event = event as Partial<S3Event>;\n\n if (!Array.isArray(s3Event?.Records)) return false;\n\n const eventSource = s3Event.Records[0]?.eventSource;\n\n return eventSource === 'aws:s3';\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { SNSEvent } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { AwsSimpleAdapter } from './base';\n\n//#endregion\n\n/**\n * The options to customize the {@link SNSAdapter}\n *\n * @breadcrumb Adapters / AWS / SNSAdapter\n * @public\n */\nexport interface SNSAdapterOptions {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /sns\n */\n snsForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n snsForwardMethod?: string;\n}\n\n/**\n * The adapter to handle requests from AWS SNS.\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html | Event Reference}\n *\n * @example\n * ```typescript\n * const snsForwardPath = '/your/route/sns'; // default /sns\n * const snsForwardMethod = 'POST'; // default POST\n * const adapter = new SNSAdapter({ snsForwardPath, snsForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / SNSAdapter\n * @public\n */\nexport class SNSAdapter extends AwsSimpleAdapter<SNSEvent> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link SNSAdapter}\n */\n constructor(options?: SNSAdapterOptions) {\n super({\n forwardPath: getDefaultIfUndefined(options?.snsForwardPath, '/sns'),\n forwardMethod: getDefaultIfUndefined(options?.snsForwardMethod, 'POST'),\n batch: false,\n host: 'sns.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return SNSAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is SNSEvent {\n const snsEvent = event as Partial<SNSEvent>;\n\n if (!Array.isArray(snsEvent?.Records)) return false;\n\n const eventSource = snsEvent.Records[0]?.EventSource;\n\n return eventSource === 'aws:sns';\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { SQSEvent } from 'aws-lambda';\nimport { getDefaultIfUndefined } from '../../core';\nimport { type AWSSimpleAdapterOptions, AwsSimpleAdapter } from './base/index';\n\n//#endregion\n\n/**\n * The options to customize the {@link SQSAdapter}\n *\n * @breadcrumb Adapters / AWS / SQSAdapter\n * @public\n */\nexport interface SQSAdapterOptions\n extends Pick<AWSSimpleAdapterOptions, 'batch'> {\n /**\n * The path that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue /sqs\n */\n sqsForwardPath?: string;\n\n /**\n * The http method that will be used to create a request to be forwarded to the framework.\n *\n * @defaultValue POST\n */\n sqsForwardMethod?: string;\n}\n\n/**\n * The adapter to handle requests from AWS SQS.\n *\n * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html | Event Reference}\n *\n * @example\n * ```typescript\n * const sqsForwardPath = '/your/route/sqs'; // default /sqs\n * const sqsForwardMethod = 'POST'; // default POST\n * const adapter = new SQSAdapter({ sqsForwardPath, sqsForwardMethod });\n * ```\n *\n * @breadcrumb Adapters / AWS / SQSAdapter\n * @public\n */\nexport class SQSAdapter extends AwsSimpleAdapter<SQSEvent> {\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link SNSAdapter}\n */\n constructor(options?: SQSAdapterOptions) {\n super({\n forwardPath: getDefaultIfUndefined(options?.sqsForwardPath, '/sqs'),\n forwardMethod: getDefaultIfUndefined(options?.sqsForwardMethod, 'POST'),\n batch: options?.batch,\n host: 'sqs.amazonaws.com',\n });\n }\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public override getAdapterName(): string {\n return SQSAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public override canHandle(event: unknown): event is SQSEvent {\n const sqsEvent = event as Partial<SQSEvent>;\n\n if (!Array.isArray(sqsEvent?.Records)) return false;\n\n const eventSource = sqsEvent.Records[0]?.eventSource;\n\n return eventSource === 'aws:sqs';\n }\n\n //#endregion\n}\n","//#region Imports\n\nimport type { CloudFrontRequest, Context } from 'aws-lambda';\nimport type {\n CloudFrontHeaders,\n CloudFrontResultResponse,\n} from 'aws-lambda/common/cloudfront';\nimport type {\n CloudFrontRequestEvent,\n CloudFrontRequestResult,\n} from 'aws-lambda/trigger/cloudfront-request';\nimport type { BothValueHeaders, SingleValueHeaders } from '../../@types';\nimport type {\n AdapterContract,\n AdapterRequest,\n GetResponseAdapterProps,\n OnErrorProps,\n} from '../../contracts';\nimport {\n type StripBasePathFn,\n buildStripBasePath,\n getDefaultIfUndefined,\n getEventBodyAsBuffer,\n getPathWithQueryStringParams,\n} from '../../core';\nimport {\n DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS,\n DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES,\n DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES,\n} from './lambda-edge.adapter';\n\n//#endregion\n\n//#endregion\n\n/**\n * The options to customize the {@link RequestLambdaEdgeAdapter}.\n *\n * @breadcrumb Adapters / AWS / RequestLambdaEdgeAdapter\n * @public\n */\nexport interface RequestLambdaEdgeAdapterOptions {\n /**\n * Strip base path for custom paths, like `/api`.\n *\n * @defaultValue ''\n */\n stripBasePath?: string;\n\n /**\n * The max response size in bytes of viewer request and viewer response.\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @defaultValue {@link DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES}\n */\n viewerMaxResponseSizeInBytes?: number;\n\n /**\n * The max response size in bytes of origin request and origin response.\n *\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference}\n *\n * @defaultValue {@link DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES}\n */\n originMaxResponseSizeInBytes?: number;\n\n /**\n * The function called when the response size exceed the max limits of the Lambda\\@edge\n *\n * @param response - The response from framework that exceed the limit of Lambda\\@edge\n * @defaultValue undefined\n */\n onResponseSizeExceedLimit?: (\n response: CloudFrontRequestResult,\n ) => CloudFrontRequestResult;\n\n /**\n * The headers that will be stripped from the headers object because Lambda\\@edge will fail if these headers are passed in the response.\n *\n * @remarks All headers will be compared with other headers using toLowerCase, but for the RegExp, if you modify this list, you must put the flag `/gmi` at the end of the RegExp (ex: `/(X-Amz-Cf-)(.*)/gim`)\n *\n * @defaultValue To get the full list, see {@link DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS}.\n */\n disallowedHeaders?: (string | RegExp)[];\n\n /**\n * If you want to change how we check against the header if it should be stripped, you can pass a function to this property.\n *\n * @param header - The header of the response\n * @defaultValue The default method is implemented to test the header against the list {@link RequestLambdaEdgeAdapterOptions.disallowedHeaders}.\n */\n shouldStripHeader?: (header: string) => boolean;\n}\n\n/**\n * The adapter to handle requests from AWS Lambda\\@Edge of the type Viewer Request.\n *\n * The idea of this Adapter is to you be able to expose your framework to the Edge, like when you build for Cloudfront.\n *\n * {@link https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html | Lambda edge docs}\n * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html | Event Reference}\n *\n * @example\n * ```typescript\n * const stripBasePath = '/api'; // in case you have configure the cloudfront to forward the path /api to your lambda\n * const adapter = new RequestLambdaEdgeAdapter({ stripBasePath });\n * ```\n *\n * @breadcrumb Adapters / AWS / RequestLambdaEdgeAdapter\n * @public\n */\nexport class RequestLambdaEdgeAdapter\n implements\n AdapterContract<CloudFrontRequestEvent, Context, CloudFrontResultResponse>\n{\n //#region Constructor\n\n /**\n * Default constructor\n *\n * @param options - The options to customize the {@link RequestLambdaEdgeAdapter}\n */\n constructor(protected readonly options?: RequestLambdaEdgeAdapterOptions) {\n this.stripPathFn = buildStripBasePath(this.options?.stripBasePath);\n\n const disallowedHeaders = getDefaultIfUndefined(\n this.options?.disallowedHeaders,\n DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS,\n );\n\n this.cachedDisallowedHeaders = disallowedHeaders.map(disallowedHeader => {\n if (disallowedHeader instanceof RegExp) return disallowedHeader;\n\n return new RegExp(`(${disallowedHeader})`, 'gim');\n });\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Strip base path function\n */\n protected readonly stripPathFn: StripBasePathFn;\n\n /**\n * This property is used to cache the disallowed headers in `RegExp` version, even if you provide a string in `disallowedHeader`, we will cache it in an instance of `RegExp`.\n */\n protected readonly cachedDisallowedHeaders: RegExp[];\n\n //#endregion\n\n //#region Public Methods\n\n /**\n * {@inheritDoc}\n */\n public getAdapterName(): string {\n return RequestLambdaEdgeAdapter.name;\n }\n\n /**\n * {@inheritDoc}\n */\n public canHandle(event: unknown): event is CloudFrontRequestEvent {\n const lambdaEdgeEvent = event as Partial<CloudFrontRequestEvent>;\n\n if (!Array.isArray(lambdaEdgeEvent?.Records)) return false;\n\n const eventType = lambdaEdgeEvent.Records[0]?.cf?.config?.eventType;\n\n return eventType === 'viewer-request' || eventType === 'origin-request';\n }\n\n /**\n * {@inheritDoc}\n */\n public getRequest(event: CloudFrontRequestEvent): AdapterRequest {\n const request = event.Records[0];\n const cloudFrontRequest = request.cf.request;\n\n const method = cloudFrontRequest.method;\n\n const path = this.stripPathFn(\n getPathWithQueryStringParams(\n cloudFrontRequest.uri,\n cloudFrontRequest.querystring,\n ),\n );\n const remoteAddress = cloudFrontRequest.clientIp;\n\n const headers =\n this.getFlattenedHeadersFromCloudfrontRequest(cloudFrontRequest);\n\n let body: Buffer | undefined;\n\n if (cloudFrontRequest.body) {\n const [buffer, contentLength] = getEventBodyAsBuffer(\n cloudFrontRequest.body.data,\n cloudFrontRequest.body.encoding === 'base64',\n );\n\n body = buffer;\n headers['content-length'] = contentLength.toString();\n }\n\n const { host } = headers;\n\n return {\n method,\n path,\n headers,\n body,\n remoteAddress,\n host,\n hostname: host,\n };\n }\n\n /**\n * {@inheritDoc}\n */\n public getResponse({\n body,\n headers: frameworkHeaders,\n isBase64Encoded,\n statusCode,\n log,\n event,\n }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontResultResponse {\n const headers = this.getHeadersForCloudfrontResponse(frameworkHeaders);\n\n const maxSizeInBytes =\n event.Records[0].cf.config.eventType === 'origin-request'\n ? getDefaultIfUndefined(\n this.options?.originMaxResponseSizeInBytes,\n DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES,\n )\n : getDefaultIfUndefined(\n this.options?.viewerMaxResponseSizeInBytes,\n DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES,\n );\n\n const response: CloudFrontResultResponse = {\n body,\n status: statusCode.toString(),\n bodyEncoding: isBase64Encoded ? 'base64' : 'text',\n headers,\n };\n\n // probably is not correctly accurate, but it's a good approximation\n const bodyLength = body.length;\n\n if (bodyLength <= maxSizeInBytes) return response;\n\n if (this.options?.onResponseSizeExceedLimit)\n this.options.onResponseSizeExceedLimit(response);\n else {\n log.error(\n `SERVERLESS_ADAPTER:LAMBDA_EDGE_ADAPTER: Max response size exceeded: ${bodyLength} of the max of ${maxSizeInBytes}.`,\n );\n }\n\n return response;\n }\n\n /**\n * {@inheritDoc}\n */\n public onErrorWhileForwarding({\n error,\n delegatedResolver,\n respondWithErrors,\n log,\n event,\n }: OnErrorProps<CloudFrontRequestEvent, CloudFrontRequestResult>): void {\n const body = respondWithErrors ? error.stack : '';\n const errorResponse = this.getResponse({\n event,\n statusCode: 500,\n body: body || '',\n headers: {},\n isBase64Encoded: false,\n log,\n });\n\n delegatedResolver.succeed(errorResponse);\n }\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Returns the headers with the flattened (non-list) values of the cloudfront request headers\n *\n * @param cloudFrontRequest - The cloudfront request\n */\n protected getFlattenedHeadersFromCloudfrontRequest(\n cloudFrontRequest: CloudFrontRequest,\n ): SingleValueHeaders {\n return Object.keys(cloudFrontRequest.headers).reduce((acc, headerKey) => {\n const headerValue = cloudFrontRequest.headers[headerKey];\n\n if (headerValue.length === 1) acc[headerKey] = headerValue[0].value;\n else acc[headerKey] = headerValue.map(header => header.value).join(',');\n\n return acc;\n }, {} as SingleValueHeaders);\n }\n\n /**\n * Returns headers in Cloudfront Response format.\n *\n * @param originalHeaders - The original version of the request sent by the framework\n */\n protected getHeadersForCloudfrontResponse(\n originalHeaders: BothValueHeaders,\n ): CloudFrontHeaders {\n return Object.keys(originalHeaders).reduce((acc, headerKey) => {\n if (this.shouldStripHeader(headerKey)) return acc;\n\n const lowercaseHeaderKey = headerKey.toLowerCase();\n\n if (!acc[lowercaseHeaderKey]) acc[lowercaseHeaderKey] = [];\n\n const headerValue = originalHeaders[headerKey];\n\n if (!Array.isArray(headerValue)) {\n acc[lowercaseHeaderKey].push({\n key: headerKey,\n value: headerValue || '',\n });\n\n return acc;\n }\n\n const headersArray = headerValue.map(value => ({\n key: headerKey,\n value: value,\n }));\n\n acc[lowercaseHeaderKey].push(...headersArray);\n\n return acc;\n }, {} as CloudFrontHeaders);\n }\n\n /**\n * Returns the information if we should remove the response header\n *\n * @param headerKey - The header that will be tested\n */\n protected shouldStripHeader(headerKey: string): boolean {\n if (this.options?.shouldStripHeader)\n return this.options.shouldStripHeader(headerKey);\n\n const headerKeyLowerCase = headerKey.toLowerCase();\n\n for (const stripHeaderIf of this.cachedDisallowedHeaders) {\n if (!stripHeaderIf.test(headerKeyLowerCase)) continue;\n\n return true;\n }\n\n return false;\n }\n\n //#endregion\n}\n"],"mappings":"4dAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,gBAAAE,EAAA,wBAAAC,EAAA,wBAAAC,EAAA,qBAAAC,EAAA,2CAAAC,EAAA,8CAAAC,EAAA,8CAAAC,EAAA,oBAAAC,EAAA,uBAAAC,EAAA,sBAAAC,EAAA,6BAAAC,EAAA,cAAAC,EAAA,eAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAhB,ICCA,IAAAiB,EAAgC,gBCAhC,IAAAC,EAAgD,gBCKzC,SAASC,EAAUC,EAAiC,CACzD,GAAI,OAAO,SAASA,CAAI,EAAG,OAAOA,EAAK,SAAS,MAAM,EACjD,GAAI,OAAOA,GAAS,SAAU,OAAOA,EACrC,GAAIA,aAAgB,WAAY,OAAO,IAAI,YAAY,EAAE,OAAOA,CAAI,EACpE,MAAM,IAAI,MAAM,wCAAwC,OAAOA,CAAI,EAAE,CAC5E,CALgBC,EAAAF,EAAA,aDAhB,IAAMG,EAAY;AAAA;AAAA,EACZC,GAAa;AAAA;AAAA,EAEbC,EAAO,OAAO,eAAe,EAC7BC,EAAU,OAAO,kBAAkB,EAEzC,SAASC,EAAQC,EAA4BC,EAA2B,CACtE,GACE,OAAO,SAASA,CAAI,GACpB,OAAOA,GAAS,UAChBA,aAAgB,WAEhBD,EAAOH,CAAI,EAAE,KAAK,OAAO,KAAKI,CAAI,CAAC,MAChC,OAAM,IAAI,MAAM,wCAAwC,OAAOA,CAAI,EAAE,CAC5E,CARSC,EAAAH,EAAA,WA8BF,IAAMI,EAAN,MAAMC,UAA2B,gBAAe,CA1CvD,MA0CuD,CAAAF,EAAA,2BACrD,YAAY,CAAE,OAAAG,CAAO,EAA4B,CAC/C,MAAM,CAAE,OAAAA,CAAO,CAAQ,EAEvB,KAAK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EAAE,EAEF,OAAAP,EAAIK,CAAkB,EAAE,KAAK,GAAGC,CAAY,EAErCN,CACT,EAAG,CAAC,CAAsB,CAC5B,CAOU,kBAAkBC,EAA4B,CACtD,GAAI,KAAK,SAAS,kBAChB,OAAO,KAAK,QAAQ,kBAAkBA,CAAS,EAEjD,IAAMO,EAAqBP,EAAU,YAAY,EAEjD,QAAWQ,KAAiB,KAAK,wBAC/B,GAAKA,EAAc,KAAKD,CAAkB,EAE1C,MAAO,GAGT,MAAO,EACT,CAGF","names":["aws_exports","__export","AlbAdapter","ApiGatewayV1Adapter","ApiGatewayV2Adapter","AwsSimpleAdapter","DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS","DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES","DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES","DynamoDBAdapter","EventBridgeAdapter","LambdaEdgeAdapter","RequestLambdaEdgeAdapter","S3Adapter","SNSAdapter","SQSAdapter","__toCommonJS","import_node_http","import_node_http","getString","data","__name","headerEnd","endChunked","BODY","HEADERS","addData","stream","data","__name","ServerlessResponse","_ServerlessResponse","method","writesToIgnore","socket","NO_OP","encoding","cb","string","getString","index","remainder","res","response","headers","key","value","statusCode","statusMessage","obj","headersObjOrArray","arrayHeaders","name","import_node_http","EmptyResponse","getEventBodyAsBuffer","body","isBase64Encoded","encoding","buffer","contentLength","__name","getFlattenedHeadersMap","headersMap","separator","lowerCaseKey","acc","headerKey","newKey","headerValue","__name","getMultiValueHeadersMap","getFlattenedHeadersMapAndCookies","lowerHeaderKey","keysToLowercase","obj","result","k","v","__name","NO_OP","__name","InternalLoggerSymbol","getDefaultIfUndefined","value","defaultValue","__name","getPathWithQueryStringParams","path","queryParams","queryParamsString","getQueryParamsStringFromRecord","__name","queryParamsRecord","searchParams","multiValueHeadersEntries","key","value","arrayValue","NOOPBasePath","buildStripBasePath","basePath","length","import_node_stream","AlbAdapter","_AlbAdapter","options","buildStripBasePath","__name","event","albEvent","method","path","headers","getFlattenedHeadersMap","body","bufferBody","contentLength","getEventBodyAsBuffer","remoteAddress","responseHeaders","isBase64Encoded","statusCode","multiValueHeaders","getMultiValueHeadersMap","error","delegatedResolver","respondWithErrors","log","errorResponse","queryParams","getPathWithQueryStringParams","ApiGatewayV1Adapter","_ApiGatewayV1Adapter","options","buildStripBasePath","__name","event","partialEventV1","method","headers","keysToLowercase","multiValueHeaderKey","headerValue","path","body","bufferBody","contentLength","getEventBodyAsBuffer","remoteAddress","responseHeaders","isBase64Encoded","statusCode","response","multiValueHeaders","getMultiValueHeadersMap","shouldThrowOnChunkedTransferEncoding","getDefaultIfUndefined","value","error","delegatedResolver","respondWithErrors","log","errorResponse","queryParams","queryStringKey","queryStringValue","getPathWithQueryStringParams","ApiGatewayV2Adapter","_ApiGatewayV2Adapter","options","buildStripBasePath","__name","event","apiGatewayEvent","method","path","headers","body","bufferBody","contentLength","getEventBodyAsBuffer","remoteAddress","responseHeaders","isBase64Encoded","statusCode","response","cookies","getFlattenedHeadersMapAndCookies","shouldThrowOnChunkedTransferEncoding","getDefaultIfUndefined","transferEncodingHeader","error","delegatedResolver","respondWithErrors","log","errorResponse","queryParams","getPathWithQueryStringParams","AwsSimpleAdapter","options","__name","_","event","path","method","body","contentLength","getEventBodyAsBuffer","headers","isBase64Encoded","statusCode","EmptyResponse","error","delegatedResolver","DynamoDBAdapter","_DynamoDBAdapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","dynamoDBevent","EventBridgeAdapter","_EventBridgeAdapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","eventBridgeEvent","DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS","DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES","DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES","LambdaEdgeAdapter","_LambdaEdgeAdapter","options","disallowedHeaders","getDefaultIfUndefined","disallowedHeader","__name","event","lambdaEdgeEvent","eventType","request","cloudFrontRequest","method","pathFromOptions","defaultPath","getPathWithQueryStringParams","path","remoteAddress","headers","body","buffer","contentLength","getEventBodyAsBuffer","host","props","response","responseToServiceBytes","maxSizeInBytes","error","delegatedResolver","acc","headerKey","headerValue","header","frameworkHeaders","shouldUseHeadersFromFramework","parsedBody","originalHeaders","headersArray","value","headerKeyLowerCase","stripHeaderIf","content","S3Adapter","_S3Adapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","s3Event","SNSAdapter","_SNSAdapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","snsEvent","SQSAdapter","_SQSAdapter","AwsSimpleAdapter","__name","options","getDefaultIfUndefined","event","sqsEvent","RequestLambdaEdgeAdapter","_RequestLambdaEdgeAdapter","options","buildStripBasePath","disallowedHeaders","getDefaultIfUndefined","DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS","disallowedHeader","__name","event","lambdaEdgeEvent","eventType","cloudFrontRequest","method","path","getPathWithQueryStringParams","remoteAddress","headers","body","buffer","contentLength","getEventBodyAsBuffer","host","frameworkHeaders","isBase64Encoded","statusCode","log","maxSizeInBytes","DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES","DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES","response","bodyLength","error","delegatedResolver","respondWithErrors","errorResponse","acc","headerKey","headerValue","header","originalHeaders","lowercaseHeaderKey","headersArray","value","headerKeyLowerCase","stripHeaderIf"]}