@celerity-sdk/serverless-aws 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entry.cjs +2 -1
- package/dist/entry.cjs.map +1 -1
- package/dist/entry.js +2 -1
- package/dist/entry.js.map +1 -1
- package/dist/index.cjs +13 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/entry.cjs
CHANGED
|
@@ -180,7 +180,8 @@ async function handler(event, _context) {
|
|
|
180
180
|
const apiEvent = event;
|
|
181
181
|
const httpRequest = mapApiGatewayV2Event(apiEvent);
|
|
182
182
|
debug2("entry: %s %s", httpRequest.method, httpRequest.path);
|
|
183
|
-
const
|
|
183
|
+
const handlerId = process.env.CELERITY_HANDLER_ID;
|
|
184
|
+
const resolved = (handlerId ? registry.getHandlerById(handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method);
|
|
184
185
|
if (!resolved) {
|
|
185
186
|
return {
|
|
186
187
|
statusCode: 404,
|
package/dist/entry.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entry.ts","../src/event-mapper.ts"],"sourcesContent":["import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type { PipelineOptions } from \"@celerity-sdk/core\";\nimport {\n discoverModule,\n bootstrap,\n executeHandlerPipeline,\n createDefaultSystemLayers,\n disposeLayers,\n} from \"@celerity-sdk/core\";\nimport type { HandlerRegistry } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nlet cached: { registry: HandlerRegistry; options: PipelineOptions } | null = null;\nlet shutdownRegistered = false;\n\nfunction registerShutdownHandler(options: PipelineOptions): void {\n if (shutdownRegistered) return;\n shutdownRegistered = true;\n debug(\"entry: SIGTERM shutdown handler registered\");\n\n process.on(\"SIGTERM\", async () => {\n await options.container.closeAll();\n await disposeLayers([...(options.systemLayers ?? []), ...(options.appLayers ?? [])]);\n process.exit(0);\n });\n}\n\nasync function ensureBootstrapped(): Promise<{\n registry: HandlerRegistry;\n options: PipelineOptions;\n}> {\n if (!cached) {\n debug(\"entry: cold start, bootstrapping\");\n const systemLayers = await createDefaultSystemLayers();\n debug(\"entry: %d system layers created\", systemLayers.length);\n const rootModule = await discoverModule();\n const result = await bootstrap(rootModule);\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n };\n debug(\"entry: bootstrap complete\");\n }\n return cached;\n}\n\nexport async function handler(event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> {\n const { registry, options } = await ensureBootstrapped();\n registerShutdownHandler(options);\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n debug(\"entry: %s %s\", httpRequest.method, httpRequest.path);\n\n const resolved = registry.getHandler(httpRequest.path, httpRequest.method);\n if (!resolved) {\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n statusCode: 404,\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(resolved, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n}\n","import createDebug from \"debug\";\nimport type { HttpMethod, HttpRequest, HttpResponse } from \"@celerity-sdk/types\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from \"aws-lambda\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nfunction parseBody(event: APIGatewayProxyEventV2): {\n textBody: string | null;\n binaryBody: Buffer | null;\n} {\n if (!event.body) return { textBody: null, binaryBody: null };\n if (event.isBase64Encoded)\n return { textBody: null, binaryBody: Buffer.from(event.body, \"base64\") };\n return { textBody: event.body, binaryBody: null };\n}\n\nfunction parseHeaders(event: APIGatewayProxyEventV2): Record<string, string | string[]> {\n const headers: Record<string, string | string[]> = {};\n if (!event.headers) return headers;\n\n for (const [key, value] of Object.entries(event.headers)) {\n if (value !== undefined) {\n headers[key.toLowerCase()] = value;\n }\n }\n return headers;\n}\n\nfunction parseCookies(event: APIGatewayProxyEventV2): Record<string, string> {\n const cookies: Record<string, string> = {};\n if (!event.cookies) return cookies;\n\n for (const cookie of event.cookies) {\n const eqIndex = cookie.indexOf(\"=\");\n if (eqIndex > 0) {\n cookies[cookie.slice(0, eqIndex).trim()] = cookie.slice(eqIndex + 1).trim();\n }\n }\n return cookies;\n}\n\nfunction parsePathParams(event: APIGatewayProxyEventV2): Record<string, string> {\n const params: Record<string, string> = {};\n if (!event.pathParameters) return params;\n\n for (const [key, value] of Object.entries(event.pathParameters)) {\n if (value !== undefined) {\n params[key] = value;\n }\n }\n return params;\n}\n\nexport function mapApiGatewayV2Event(event: APIGatewayProxyEventV2): HttpRequest {\n const method = event.requestContext.http.method.toUpperCase() as HttpMethod;\n const headers = parseHeaders(event);\n const { textBody, binaryBody } = parseBody(event);\n\n const authorizer = (\n event.requestContext as unknown as {\n authorizer?: { jwt?: { claims?: Record<string, unknown> } };\n }\n ).authorizer;\n\n const contentType = (headers[\"content-type\"] as string | undefined) ?? null;\n const xrayHeader = (headers[\"x-amzn-trace-id\"] as string | undefined) ?? null;\n\n const request: HttpRequest = {\n method,\n path: event.rawPath,\n pathParams: parsePathParams(event),\n query: (event.queryStringParameters ?? {}) as Record<string, string | string[]>,\n headers,\n cookies: parseCookies(event),\n textBody,\n binaryBody,\n contentType,\n requestId: event.requestContext.requestId,\n requestTime: event.requestContext.time ?? new Date().toISOString(),\n auth: authorizer?.jwt?.claims ?? null,\n clientIp: event.requestContext.http.sourceIp,\n traceContext: xrayHeader ? { \"x-amzn-trace-id\": xrayHeader } : null,\n userAgent: event.requestContext.http.userAgent ?? null,\n matchedRoute: event.routeKey ?? null,\n };\n\n debug(\n \"mapEvent: %s %s (auth=%s, traceContext=%s)\",\n method,\n event.rawPath,\n !!authorizer?.jwt?.claims,\n !!xrayHeader,\n );\n\n return request;\n}\n\nexport function mapHttpResponseToResult(response: HttpResponse): APIGatewayProxyStructuredResultV2 {\n const result: APIGatewayProxyStructuredResultV2 = {\n statusCode: response.status,\n };\n\n if (response.headers) {\n result.headers = response.headers;\n }\n\n if (response.binaryBody) {\n result.body = response.binaryBody.toString(\"base64\");\n result.isBase64Encoded = true;\n } else if (response.body) {\n result.body = response.body;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;IAAAA,gBAAwB;AAGxB,kBAMO;;;ACTP,mBAAwB;AAIxB,IAAMC,YAAQC,aAAAA,SAAY,yBAAA;AAE1B,SAASC,UAAUC,OAA6B;AAI9C,MAAI,CAACA,MAAMC,KAAM,QAAO;IAAEC,UAAU;IAAMC,YAAY;EAAK;AAC3D,MAAIH,MAAMI,gBACR,QAAO;IAAEF,UAAU;IAAMC,YAAYE,OAAOC,KAAKN,MAAMC,MAAM,QAAA;EAAU;AACzE,SAAO;IAAEC,UAAUF,MAAMC;IAAME,YAAY;EAAK;AAClD;AARSJ;AAUT,SAASQ,aAAaP,OAA6B;AACjD,QAAMQ,UAA6C,CAAC;AACpD,MAAI,CAACR,MAAMQ,QAAS,QAAOA;AAE3B,aAAW,CAACC,KAAKC,KAAAA,KAAUC,OAAOC,QAAQZ,MAAMQ,OAAO,GAAG;AACxD,QAAIE,UAAUG,QAAW;AACvBL,cAAQC,IAAIK,YAAW,CAAA,IAAMJ;IAC/B;EACF;AACA,SAAOF;AACT;AAVSD;AAYT,SAASQ,aAAaf,OAA6B;AACjD,QAAMgB,UAAkC,CAAC;AACzC,MAAI,CAAChB,MAAMgB,QAAS,QAAOA;AAE3B,aAAWC,UAAUjB,MAAMgB,SAAS;AAClC,UAAME,UAAUD,OAAOE,QAAQ,GAAA;AAC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f,eAAsBQ,QAAQC,OAAgBC,UAAiB;AAC7D,QAAM,EAAEH,UAAUhB,QAAO,IAAK,MAAMS,mBAAAA;AACpCV,0BAAwBC,OAAAA;AACxB,QAAMoB,WAAWF;AACjB,QAAMG,cAAcC,qBAAqBF,QAAAA;AACzCzB,EAAAA,OAAM,gBAAgB0B,YAAYE,QAAQF,YAAYG,IAAI;AAE1D,QAAMC,WAAWT,SAASU,WAAWL,YAAYG,MAAMH,YAAYE,MAAM;AACzE,MAAI,CAACE,UAAU;AACb,WAAO;MACLE,YAAY;MACZC,SAAS;QAAE,gBAAgB;MAAmB;MAC9CC,MAAMC,KAAKC,UAAU;QACnBJ,YAAY;QACZK,SAAS,kBAAkBX,YAAYE,MAAM,IAAIF,YAAYG,IAAI;MACnE,CAAA;IACF;EACF;AAEA,QAAMS,eAAe,UAAMC,oCAAuBT,UAAUJ,aAAarB,OAAAA;AACzE,SAAOmC,wBAAwBF,YAAAA;AACjC;AArBsBhB;","names":["import_debug","debug","createDebug","parseBody","event","body","textBody","binaryBody","isBase64Encoded","Buffer","from","parseHeaders","headers","key","value","Object","entries","undefined","toLowerCase","parseCookies","cookies","cookie","eqIndex","indexOf","slice","trim","parsePathParams","params","pathParameters","mapApiGatewayV2Event","method","requestContext","http","toUpperCase","authorizer","contentType","xrayHeader","request","path","rawPath","pathParams","query","queryStringParameters","requestId","requestTime","time","Date","toISOString","auth","jwt","claims","clientIp","sourceIp","traceContext","userAgent","matchedRoute","routeKey","mapHttpResponseToResult","response","result","statusCode","status","toString","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","registry","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","resolved","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
|
|
1
|
+
{"version":3,"sources":["../src/entry.ts","../src/event-mapper.ts"],"sourcesContent":["import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type { PipelineOptions } from \"@celerity-sdk/core\";\nimport {\n discoverModule,\n bootstrap,\n executeHandlerPipeline,\n createDefaultSystemLayers,\n disposeLayers,\n} from \"@celerity-sdk/core\";\nimport type { HandlerRegistry } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nlet cached: { registry: HandlerRegistry; options: PipelineOptions } | null = null;\nlet shutdownRegistered = false;\n\nfunction registerShutdownHandler(options: PipelineOptions): void {\n if (shutdownRegistered) return;\n shutdownRegistered = true;\n debug(\"entry: SIGTERM shutdown handler registered\");\n\n process.on(\"SIGTERM\", async () => {\n await options.container.closeAll();\n await disposeLayers([...(options.systemLayers ?? []), ...(options.appLayers ?? [])]);\n process.exit(0);\n });\n}\n\nasync function ensureBootstrapped(): Promise<{\n registry: HandlerRegistry;\n options: PipelineOptions;\n}> {\n if (!cached) {\n debug(\"entry: cold start, bootstrapping\");\n const systemLayers = await createDefaultSystemLayers();\n debug(\"entry: %d system layers created\", systemLayers.length);\n const rootModule = await discoverModule();\n const result = await bootstrap(rootModule);\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n };\n debug(\"entry: bootstrap complete\");\n }\n return cached;\n}\n\nexport async function handler(event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> {\n const { registry, options } = await ensureBootstrapped();\n registerShutdownHandler(options);\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n debug(\"entry: %s %s\", httpRequest.method, httpRequest.path);\n\n const handlerId = process.env.CELERITY_HANDLER_ID;\n const resolved =\n (handlerId ? registry.getHandlerById(handlerId) : undefined) ??\n registry.getHandler(httpRequest.path, httpRequest.method);\n if (!resolved) {\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n statusCode: 404,\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(resolved, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n}\n","import createDebug from \"debug\";\nimport type { HttpMethod, HttpRequest, HttpResponse } from \"@celerity-sdk/types\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from \"aws-lambda\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nfunction parseBody(event: APIGatewayProxyEventV2): {\n textBody: string | null;\n binaryBody: Buffer | null;\n} {\n if (!event.body) return { textBody: null, binaryBody: null };\n if (event.isBase64Encoded)\n return { textBody: null, binaryBody: Buffer.from(event.body, \"base64\") };\n return { textBody: event.body, binaryBody: null };\n}\n\nfunction parseHeaders(event: APIGatewayProxyEventV2): Record<string, string | string[]> {\n const headers: Record<string, string | string[]> = {};\n if (!event.headers) return headers;\n\n for (const [key, value] of Object.entries(event.headers)) {\n if (value !== undefined) {\n headers[key.toLowerCase()] = value;\n }\n }\n return headers;\n}\n\nfunction parseCookies(event: APIGatewayProxyEventV2): Record<string, string> {\n const cookies: Record<string, string> = {};\n if (!event.cookies) return cookies;\n\n for (const cookie of event.cookies) {\n const eqIndex = cookie.indexOf(\"=\");\n if (eqIndex > 0) {\n cookies[cookie.slice(0, eqIndex).trim()] = cookie.slice(eqIndex + 1).trim();\n }\n }\n return cookies;\n}\n\nfunction parsePathParams(event: APIGatewayProxyEventV2): Record<string, string> {\n const params: Record<string, string> = {};\n if (!event.pathParameters) return params;\n\n for (const [key, value] of Object.entries(event.pathParameters)) {\n if (value !== undefined) {\n params[key] = value;\n }\n }\n return params;\n}\n\nexport function mapApiGatewayV2Event(event: APIGatewayProxyEventV2): HttpRequest {\n const method = event.requestContext.http.method.toUpperCase() as HttpMethod;\n const headers = parseHeaders(event);\n const { textBody, binaryBody } = parseBody(event);\n\n const authorizer = (\n event.requestContext as unknown as {\n authorizer?: { jwt?: { claims?: Record<string, unknown> } };\n }\n ).authorizer;\n\n const contentType = (headers[\"content-type\"] as string | undefined) ?? null;\n const xrayHeader = (headers[\"x-amzn-trace-id\"] as string | undefined) ?? null;\n\n const request: HttpRequest = {\n method,\n path: event.rawPath,\n pathParams: parsePathParams(event),\n query: (event.queryStringParameters ?? {}) as Record<string, string | string[]>,\n headers,\n cookies: parseCookies(event),\n textBody,\n binaryBody,\n contentType,\n requestId: event.requestContext.requestId,\n requestTime: event.requestContext.time ?? new Date().toISOString(),\n auth: authorizer?.jwt?.claims ?? null,\n clientIp: event.requestContext.http.sourceIp,\n traceContext: xrayHeader ? { \"x-amzn-trace-id\": xrayHeader } : null,\n userAgent: event.requestContext.http.userAgent ?? null,\n matchedRoute: event.routeKey ?? null,\n };\n\n debug(\n \"mapEvent: %s %s (auth=%s, traceContext=%s)\",\n method,\n event.rawPath,\n !!authorizer?.jwt?.claims,\n !!xrayHeader,\n );\n\n return request;\n}\n\nexport function mapHttpResponseToResult(response: HttpResponse): APIGatewayProxyStructuredResultV2 {\n const result: APIGatewayProxyStructuredResultV2 = {\n statusCode: response.status,\n };\n\n if (response.headers) {\n result.headers = response.headers;\n }\n\n if (response.binaryBody) {\n result.body = response.binaryBody.toString(\"base64\");\n result.isBase64Encoded = true;\n } else if (response.body) {\n result.body = response.body;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;IAAAA,gBAAwB;AAGxB,kBAMO;;;ACTP,mBAAwB;AAIxB,IAAMC,YAAQC,aAAAA,SAAY,yBAAA;AAE1B,SAASC,UAAUC,OAA6B;AAI9C,MAAI,CAACA,MAAMC,KAAM,QAAO;IAAEC,UAAU;IAAMC,YAAY;EAAK;AAC3D,MAAIH,MAAMI,gBACR,QAAO;IAAEF,UAAU;IAAMC,YAAYE,OAAOC,KAAKN,MAAMC,MAAM,QAAA;EAAU;AACzE,SAAO;IAAEC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Base64Encoded","Buffer","from","parseHeaders","headers","key","value","Object","entries","undefined","toLowerCase","parseCookies","cookies","cookie","eqIndex","indexOf","slice","trim","parsePathParams","params","pathParameters","mapApiGatewayV2Event","method","requestContext","http","toUpperCase","authorizer","contentType","xrayHeader","request","path","rawPath","pathParams","query","queryStringParameters","requestId","requestTime","time","Date","toISOString","auth","jwt","claims","clientIp","sourceIp","traceContext","userAgent","matchedRoute","routeKey","mapHttpResponseToResult","response","result","statusCode","status","toString","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","registry","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","env","CELERITY_HANDLER_ID","resolved","getHandlerById","undefined","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
|
package/dist/entry.js
CHANGED
|
@@ -148,7 +148,8 @@ async function handler(event, _context) {
|
|
|
148
148
|
const apiEvent = event;
|
|
149
149
|
const httpRequest = mapApiGatewayV2Event(apiEvent);
|
|
150
150
|
debug2("entry: %s %s", httpRequest.method, httpRequest.path);
|
|
151
|
-
const
|
|
151
|
+
const handlerId = process.env.CELERITY_HANDLER_ID;
|
|
152
|
+
const resolved = (handlerId ? registry.getHandlerById(handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method);
|
|
152
153
|
if (!resolved) {
|
|
153
154
|
return {
|
|
154
155
|
statusCode: 404,
|
package/dist/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entry.ts","../src/event-mapper.ts"],"sourcesContent":["import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type { PipelineOptions } from \"@celerity-sdk/core\";\nimport {\n discoverModule,\n bootstrap,\n executeHandlerPipeline,\n createDefaultSystemLayers,\n disposeLayers,\n} from \"@celerity-sdk/core\";\nimport type { HandlerRegistry } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nlet cached: { registry: HandlerRegistry; options: PipelineOptions } | null = null;\nlet shutdownRegistered = false;\n\nfunction registerShutdownHandler(options: PipelineOptions): void {\n if (shutdownRegistered) return;\n shutdownRegistered = true;\n debug(\"entry: SIGTERM shutdown handler registered\");\n\n process.on(\"SIGTERM\", async () => {\n await options.container.closeAll();\n await disposeLayers([...(options.systemLayers ?? []), ...(options.appLayers ?? [])]);\n process.exit(0);\n });\n}\n\nasync function ensureBootstrapped(): Promise<{\n registry: HandlerRegistry;\n options: PipelineOptions;\n}> {\n if (!cached) {\n debug(\"entry: cold start, bootstrapping\");\n const systemLayers = await createDefaultSystemLayers();\n debug(\"entry: %d system layers created\", systemLayers.length);\n const rootModule = await discoverModule();\n const result = await bootstrap(rootModule);\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n };\n debug(\"entry: bootstrap complete\");\n }\n return cached;\n}\n\nexport async function handler(event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> {\n const { registry, options } = await ensureBootstrapped();\n registerShutdownHandler(options);\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n debug(\"entry: %s %s\", httpRequest.method, httpRequest.path);\n\n const resolved = registry.getHandler(httpRequest.path, httpRequest.method);\n if (!resolved) {\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n statusCode: 404,\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(resolved, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n}\n","import createDebug from \"debug\";\nimport type { HttpMethod, HttpRequest, HttpResponse } from \"@celerity-sdk/types\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from \"aws-lambda\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nfunction parseBody(event: APIGatewayProxyEventV2): {\n textBody: string | null;\n binaryBody: Buffer | null;\n} {\n if (!event.body) return { textBody: null, binaryBody: null };\n if (event.isBase64Encoded)\n return { textBody: null, binaryBody: Buffer.from(event.body, \"base64\") };\n return { textBody: event.body, binaryBody: null };\n}\n\nfunction parseHeaders(event: APIGatewayProxyEventV2): Record<string, string | string[]> {\n const headers: Record<string, string | string[]> = {};\n if (!event.headers) return headers;\n\n for (const [key, value] of Object.entries(event.headers)) {\n if (value !== undefined) {\n headers[key.toLowerCase()] = value;\n }\n }\n return headers;\n}\n\nfunction parseCookies(event: APIGatewayProxyEventV2): Record<string, string> {\n const cookies: Record<string, string> = {};\n if (!event.cookies) return cookies;\n\n for (const cookie of event.cookies) {\n const eqIndex = cookie.indexOf(\"=\");\n if (eqIndex > 0) {\n cookies[cookie.slice(0, eqIndex).trim()] = cookie.slice(eqIndex + 1).trim();\n }\n }\n return cookies;\n}\n\nfunction parsePathParams(event: APIGatewayProxyEventV2): Record<string, string> {\n const params: Record<string, string> = {};\n if (!event.pathParameters) return params;\n\n for (const [key, value] of Object.entries(event.pathParameters)) {\n if (value !== undefined) {\n params[key] = value;\n }\n }\n return params;\n}\n\nexport function mapApiGatewayV2Event(event: APIGatewayProxyEventV2): HttpRequest {\n const method = event.requestContext.http.method.toUpperCase() as HttpMethod;\n const headers = parseHeaders(event);\n const { textBody, binaryBody } = parseBody(event);\n\n const authorizer = (\n event.requestContext as unknown as {\n authorizer?: { jwt?: { claims?: Record<string, unknown> } };\n }\n ).authorizer;\n\n const contentType = (headers[\"content-type\"] as string | undefined) ?? null;\n const xrayHeader = (headers[\"x-amzn-trace-id\"] as string | undefined) ?? null;\n\n const request: HttpRequest = {\n method,\n path: event.rawPath,\n pathParams: parsePathParams(event),\n query: (event.queryStringParameters ?? {}) as Record<string, string | string[]>,\n headers,\n cookies: parseCookies(event),\n textBody,\n binaryBody,\n contentType,\n requestId: event.requestContext.requestId,\n requestTime: event.requestContext.time ?? new Date().toISOString(),\n auth: authorizer?.jwt?.claims ?? null,\n clientIp: event.requestContext.http.sourceIp,\n traceContext: xrayHeader ? { \"x-amzn-trace-id\": xrayHeader } : null,\n userAgent: event.requestContext.http.userAgent ?? null,\n matchedRoute: event.routeKey ?? null,\n };\n\n debug(\n \"mapEvent: %s %s (auth=%s, traceContext=%s)\",\n method,\n event.rawPath,\n !!authorizer?.jwt?.claims,\n !!xrayHeader,\n );\n\n return request;\n}\n\nexport function mapHttpResponseToResult(response: HttpResponse): APIGatewayProxyStructuredResultV2 {\n const result: APIGatewayProxyStructuredResultV2 = {\n statusCode: response.status,\n };\n\n if (response.headers) {\n result.headers = response.headers;\n }\n\n if (response.binaryBody) {\n result.body = response.binaryBody.toString(\"base64\");\n result.isBase64Encoded = true;\n } else if (response.body) {\n result.body = response.body;\n }\n\n return result;\n}\n"],"mappings":";;;;AAAA,OAAOA,kBAAiB;AAGxB,SACEC,gBACAC,WACAC,wBACAC,2BACAC,qBACK;;;ACTP,OAAOC,iBAAiB;AAIxB,IAAMC,QAAQC,YAAY,yBAAA;AAE1B,SAASC,UAAUC,OAA6B;AAI9C,MAAI,CAACA,MAAMC,KAAM,QAAO;IAAEC,UAAU;IAAMC,YAAY;EAAK;AAC3D,MAAIH,MAAMI,gBACR,QAAO;IAAEF,UAAU;IAAMC,YAAYE,OAAOC,KAAKN,MAAMC,MAAM,QAAA;EAAU;AACzE,SAAO;IAAEC,UAAUF,MAAMC;IAAME,YAAY;EAAK;AAClD;AARSJ;AAUT,SAASQ,aAAaP,OAA6B;AACjD,QAAMQ,UAA6C,CAAC;AACpD,MAAI,CAACR,MAAMQ,QAAS,QAAOA;AAE3B,aAAW,CAACC,KAAKC,KAAAA,KAAUC,OAAOC,QAAQZ,MAAMQ,OAAO,GAAG;AACxD,QAAIE,UAAUG,QAAW;AACvBL,cAAQC,IAA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;AAC5D,UAAMC,aAAa,MAAMC,eAAAA;AACzB,UAAMC,SAAS,MAAMC,UAAUH,UAAAA;AAC/Bf,aAAS;MACPmB,UAAUF,OAAOE;MACjBhB,SAAS;QACPG,WAAWW,OAAOX;QAClBG;MACF;IACF;AACAX,IAAAA,OAAM,2BAAA;EACR;AACA,SAAOE;AACT;AApBeY;AAsBf,eAAsBQ,QAAQC,OAAgBC,UAAiB;AAC7D,QAAM,EAAEH,UAAUhB,QAAO,IAAK,MAAMS,mBAAAA;AACpCV,0BAAwBC,OAAAA;AACxB,QAAMoB,WAAWF;AACjB,QAAMG,cAAcC,qBAAqBF,QAAAA;AACzCzB,EAAAA,OAAM,gBAAgB0B,YAAYE,QAAQF,YAAYG,IAAI;AAE1D,QAAMC,WAAWT,SAASU,WAAWL,YAAYG,MAAMH,YAAYE,MAAM;AACzE,MAAI,CAACE,UAAU;AACb,WAAO;MACLE,YAAY;MACZC,SAAS;QAAE,gBAAgB;MAAmB;MAC9CC,MAAMC,KAAKC,UAAU;QACnBJ,YAAY;QACZK,SAAS,kBAAkBX,YAAYE,MAAM,IAAIF,YAAYG,IAAI;MACnE,CAAA;IACF;EACF;AAEA,QAAMS,eAAe,MAAMC,uBAAuBT,UAAUJ,aAAarB,OAAAA;AACzE,SAAOmC,wBAAwBF,YAAAA;AACjC;AArBsBhB;","names":["createDebug","discoverModule","bootstrap","executeHandlerPipeline","createDefaultSystemLayers","disposeLayers","createDebug","debug","createDebug","parseBody","event","body","textBody","binaryBody","isBase64Encoded","Buffer","from","parseHeaders","headers","key","value","Object","entries","undefined","toLowerCase","parseCookies","cookies","cookie","eqIndex","indexOf","slice","trim","parsePathParams","params","pathParameters","mapApiGatewayV2Event","method","requestContext","http","toUpperCase","authorizer","contentType","xrayHeader","request","path","rawPath","pathParams","query","queryStringParameters","requestId","requestTime","time","Date","toISOString","auth","jwt","claims","clientIp","sourceIp","traceContext","userAgent","matchedRoute","routeKey","mapHttpResponseToResult","response","result","statusCode","status","toString","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","registry","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","resolved","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
|
|
1
|
+
{"version":3,"sources":["../src/entry.ts","../src/event-mapper.ts"],"sourcesContent":["import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type { PipelineOptions } from \"@celerity-sdk/core\";\nimport {\n discoverModule,\n bootstrap,\n executeHandlerPipeline,\n createDefaultSystemLayers,\n disposeLayers,\n} from \"@celerity-sdk/core\";\nimport type { HandlerRegistry } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nlet cached: { registry: HandlerRegistry; options: PipelineOptions } | null = null;\nlet shutdownRegistered = false;\n\nfunction registerShutdownHandler(options: PipelineOptions): void {\n if (shutdownRegistered) return;\n shutdownRegistered = true;\n debug(\"entry: SIGTERM shutdown handler registered\");\n\n process.on(\"SIGTERM\", async () => {\n await options.container.closeAll();\n await disposeLayers([...(options.systemLayers ?? []), ...(options.appLayers ?? [])]);\n process.exit(0);\n });\n}\n\nasync function ensureBootstrapped(): Promise<{\n registry: HandlerRegistry;\n options: PipelineOptions;\n}> {\n if (!cached) {\n debug(\"entry: cold start, bootstrapping\");\n const systemLayers = await createDefaultSystemLayers();\n debug(\"entry: %d system layers created\", systemLayers.length);\n const rootModule = await discoverModule();\n const result = await bootstrap(rootModule);\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n };\n debug(\"entry: bootstrap complete\");\n }\n return cached;\n}\n\nexport async function handler(event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> {\n const { registry, options } = await ensureBootstrapped();\n registerShutdownHandler(options);\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n debug(\"entry: %s %s\", httpRequest.method, httpRequest.path);\n\n const handlerId = process.env.CELERITY_HANDLER_ID;\n const resolved =\n (handlerId ? registry.getHandlerById(handlerId) : undefined) ??\n registry.getHandler(httpRequest.path, httpRequest.method);\n if (!resolved) {\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n statusCode: 404,\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(resolved, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n}\n","import createDebug from \"debug\";\nimport type { HttpMethod, HttpRequest, HttpResponse } from \"@celerity-sdk/types\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from \"aws-lambda\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nfunction parseBody(event: APIGatewayProxyEventV2): {\n textBody: string | null;\n binaryBody: Buffer | null;\n} {\n if (!event.body) return { textBody: null, binaryBody: null };\n if (event.isBase64Encoded)\n return { textBody: null, binaryBody: Buffer.from(event.body, \"base64\") };\n return { textBody: event.body, binaryBody: null };\n}\n\nfunction parseHeaders(event: APIGatewayProxyEventV2): Record<string, string | string[]> {\n const headers: Record<string, string | string[]> = {};\n if (!event.headers) return headers;\n\n for (const [key, value] of Object.entries(event.headers)) {\n if (value !== undefined) {\n headers[key.toLowerCase()] = value;\n }\n }\n return headers;\n}\n\nfunction parseCookies(event: APIGatewayProxyEventV2): Record<string, string> {\n const cookies: Record<string, string> = {};\n if (!event.cookies) return cookies;\n\n for (const cookie of event.cookies) {\n const eqIndex = cookie.indexOf(\"=\");\n if (eqIndex > 0) {\n cookies[cookie.slice(0, eqIndex).trim()] = cookie.slice(eqIndex + 1).trim();\n }\n }\n return cookies;\n}\n\nfunction parsePathParams(event: APIGatewayProxyEventV2): Record<string, string> {\n const params: Record<string, string> = {};\n if (!event.pathParameters) return params;\n\n for (const [key, value] of Object.entries(event.pathParameters)) {\n if (value !== undefined) {\n params[key] = value;\n }\n }\n return params;\n}\n\nexport function mapApiGatewayV2Event(event: APIGatewayProxyEventV2): HttpRequest {\n const method = event.requestContext.http.method.toUpperCase() as HttpMethod;\n const headers = parseHeaders(event);\n const { textBody, binaryBody } = parseBody(event);\n\n const authorizer = (\n event.requestContext as unknown as {\n authorizer?: { jwt?: { claims?: Record<string, unknown> } };\n }\n ).authorizer;\n\n const contentType = (headers[\"content-type\"] as string | undefined) ?? null;\n const xrayHeader = (headers[\"x-amzn-trace-id\"] as string | undefined) ?? null;\n\n const request: HttpRequest = {\n method,\n path: event.rawPath,\n pathParams: parsePathParams(event),\n query: (event.queryStringParameters ?? {}) as Record<string, string | string[]>,\n headers,\n cookies: parseCookies(event),\n textBody,\n binaryBody,\n contentType,\n requestId: event.requestContext.requestId,\n requestTime: event.requestContext.time ?? new Date().toISOString(),\n auth: authorizer?.jwt?.claims ?? null,\n clientIp: event.requestContext.http.sourceIp,\n traceContext: xrayHeader ? { \"x-amzn-trace-id\": xrayHeader } : null,\n userAgent: event.requestContext.http.userAgent ?? null,\n matchedRoute: event.routeKey ?? null,\n };\n\n debug(\n \"mapEvent: %s %s (auth=%s, traceContext=%s)\",\n method,\n event.rawPath,\n !!authorizer?.jwt?.claims,\n !!xrayHeader,\n );\n\n return request;\n}\n\nexport function mapHttpResponseToResult(response: HttpResponse): APIGatewayProxyStructuredResultV2 {\n const result: APIGatewayProxyStructuredResultV2 = {\n statusCode: response.status,\n };\n\n if (response.headers) {\n result.headers = response.headers;\n }\n\n if (response.binaryBody) {\n result.body = response.binaryBody.toString(\"base64\");\n result.isBase64Encoded = true;\n } else if (response.body) {\n result.body = response.body;\n }\n\n return result;\n}\n"],"mappings":";;;;AAAA,OAAOA,kBAAiB;AAGxB,SACEC,gBACAC,WACAC,wBACAC,2BACAC,qBACK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CC,MAAMC,KAAKC,UAAU;QACnBJ,YAAY;QACZK,SAAS,kBAAkBhB,YAAYE,MAAM,IAAIF,YAAYG,IAAI;MACnE,CAAA;IACF;EACF;AAEA,QAAMc,eAAe,MAAMC,uBAAuBX,UAAUP,aAAarB,OAAAA;AACzE,SAAOwC,wBAAwBF,YAAAA;AACjC;AAxBsBrB;","names":["createDebug","discoverModule","bootstrap","executeHandlerPipeline","createDefaultSystemLayers","disposeLayers","createDebug","debug","createDebug","parseBody","event","body","textBody","binaryBody","isBase64Encoded","Buffer","from","parseHeaders","headers","key","value","Object","entries","undefined","toLowerCase","parseCookies","cookies","cookie","eqIndex","indexOf","slice","trim","parsePathParams","params","pathParameters","mapApiGatewayV2Event","method","requestContext","http","toUpperCase","authorizer","contentType","xrayHeader","request","path","rawPath","pathParams","query","queryStringParameters","requestId","requestTime","time","Date","toISOString","auth","jwt","claims","clientIp","sourceIp","traceContext","userAgent","matchedRoute","routeKey","mapHttpResponseToResult","response","result","statusCode","status","toString","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","registry","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","env","CELERITY_HANDLER_ID","resolved","getHandlerById","undefined","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
|
package/dist/index.cjs
CHANGED
|
@@ -148,6 +148,10 @@ var AwsLambdaAdapter = class {
|
|
|
148
148
|
static {
|
|
149
149
|
__name(this, "AwsLambdaAdapter");
|
|
150
150
|
}
|
|
151
|
+
config;
|
|
152
|
+
constructor() {
|
|
153
|
+
this.config = captureAwsLambdaConfig();
|
|
154
|
+
}
|
|
151
155
|
createHandler(registry, options) {
|
|
152
156
|
let cachedHandler = null;
|
|
153
157
|
return async (event, _context) => {
|
|
@@ -155,7 +159,7 @@ var AwsLambdaAdapter = class {
|
|
|
155
159
|
const httpRequest = mapApiGatewayV2Event(apiEvent);
|
|
156
160
|
if (!cachedHandler) {
|
|
157
161
|
debug2("adapter: cache miss, looking up handler for %s %s", httpRequest.method, httpRequest.path);
|
|
158
|
-
cachedHandler = registry.getHandler(httpRequest.path, httpRequest.method) ?? null;
|
|
162
|
+
cachedHandler = (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method) ?? null;
|
|
159
163
|
} else {
|
|
160
164
|
debug2("adapter: using cached handler for %s %s", httpRequest.method, httpRequest.path);
|
|
161
165
|
}
|
|
@@ -176,6 +180,12 @@ var AwsLambdaAdapter = class {
|
|
|
176
180
|
};
|
|
177
181
|
}
|
|
178
182
|
};
|
|
183
|
+
function captureAwsLambdaConfig() {
|
|
184
|
+
return {
|
|
185
|
+
handlerId: process.env.CELERITY_HANDLER_ID
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
__name(captureAwsLambdaConfig, "captureAwsLambdaConfig");
|
|
179
189
|
|
|
180
190
|
// src/entry.ts
|
|
181
191
|
var import_debug3 = __toESM(require("debug"), 1);
|
|
@@ -222,7 +232,8 @@ async function handler(event, _context) {
|
|
|
222
232
|
const apiEvent = event;
|
|
223
233
|
const httpRequest = mapApiGatewayV2Event(apiEvent);
|
|
224
234
|
debug3("entry: %s %s", httpRequest.method, httpRequest.path);
|
|
225
|
-
const
|
|
235
|
+
const handlerId = process.env.CELERITY_HANDLER_ID;
|
|
236
|
+
const resolved = (handlerId ? registry.getHandlerById(handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method);
|
|
226
237
|
if (!resolved) {
|
|
227
238
|
return {
|
|
228
239
|
statusCode: 404,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/event-mapper.ts","../src/entry.ts"],"sourcesContent":["export { AwsLambdaAdapter } from \"./adapter\";\nexport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\nexport { handler } from \"./entry\";\n","import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type {\n HandlerRegistry,\n ServerlessAdapter,\n ResolvedHandler,\n PipelineOptions,\n} from \"@celerity-sdk/core\";\nimport { executeHandlerPipeline } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nexport class AwsLambdaAdapter implements ServerlessAdapter {\n createHandler(\n registry: HandlerRegistry,\n options: PipelineOptions,\n ): (event: unknown, context: unknown) => Promise<unknown> {\n let cachedHandler: ResolvedHandler | null = null;\n\n return async (event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> => {\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n\n if (!cachedHandler) {\n debug(\n \"adapter: cache miss, looking up handler for %s %s\",\n httpRequest.method,\n httpRequest.path,\n );\n cachedHandler = registry.getHandler(httpRequest.path, httpRequest.method) ?? null;\n } else {\n debug(\"adapter: using cached handler for %s %s\", httpRequest.method, httpRequest.path);\n }\n\n if (!cachedHandler) {\n debug(\"adapter: no handler found → 404\");\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(cachedHandler, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n };\n }\n}\n","import createDebug from \"debug\";\nimport type { HttpMethod, HttpRequest, HttpResponse } from \"@celerity-sdk/types\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from \"aws-lambda\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nfunction parseBody(event: APIGatewayProxyEventV2): {\n textBody: string | null;\n binaryBody: Buffer | null;\n} {\n if (!event.body) return { textBody: null, binaryBody: null };\n if (event.isBase64Encoded)\n return { textBody: null, binaryBody: Buffer.from(event.body, \"base64\") };\n return { textBody: event.body, binaryBody: null };\n}\n\nfunction parseHeaders(event: APIGatewayProxyEventV2): Record<string, string | string[]> {\n const headers: Record<string, string | string[]> = {};\n if (!event.headers) return headers;\n\n for (const [key, value] of Object.entries(event.headers)) {\n if (value !== undefined) {\n headers[key.toLowerCase()] = value;\n }\n }\n return headers;\n}\n\nfunction parseCookies(event: APIGatewayProxyEventV2): Record<string, string> {\n const cookies: Record<string, string> = {};\n if (!event.cookies) return cookies;\n\n for (const cookie of event.cookies) {\n const eqIndex = cookie.indexOf(\"=\");\n if (eqIndex > 0) {\n cookies[cookie.slice(0, eqIndex).trim()] = cookie.slice(eqIndex + 1).trim();\n }\n }\n return cookies;\n}\n\nfunction parsePathParams(event: APIGatewayProxyEventV2): Record<string, string> {\n const params: Record<string, string> = {};\n if (!event.pathParameters) return params;\n\n for (const [key, value] of Object.entries(event.pathParameters)) {\n if (value !== undefined) {\n params[key] = value;\n }\n }\n return params;\n}\n\nexport function mapApiGatewayV2Event(event: APIGatewayProxyEventV2): HttpRequest {\n const method = event.requestContext.http.method.toUpperCase() as HttpMethod;\n const headers = parseHeaders(event);\n const { textBody, binaryBody } = parseBody(event);\n\n const authorizer = (\n event.requestContext as unknown as {\n authorizer?: { jwt?: { claims?: Record<string, unknown> } };\n }\n ).authorizer;\n\n const contentType = (headers[\"content-type\"] as string | undefined) ?? null;\n const xrayHeader = (headers[\"x-amzn-trace-id\"] as string | undefined) ?? null;\n\n const request: HttpRequest = {\n method,\n path: event.rawPath,\n pathParams: parsePathParams(event),\n query: (event.queryStringParameters ?? {}) as Record<string, string | string[]>,\n headers,\n cookies: parseCookies(event),\n textBody,\n binaryBody,\n contentType,\n requestId: event.requestContext.requestId,\n requestTime: event.requestContext.time ?? new Date().toISOString(),\n auth: authorizer?.jwt?.claims ?? null,\n clientIp: event.requestContext.http.sourceIp,\n traceContext: xrayHeader ? { \"x-amzn-trace-id\": xrayHeader } : null,\n userAgent: event.requestContext.http.userAgent ?? null,\n matchedRoute: event.routeKey ?? null,\n };\n\n debug(\n \"mapEvent: %s %s (auth=%s, traceContext=%s)\",\n method,\n event.rawPath,\n !!authorizer?.jwt?.claims,\n !!xrayHeader,\n );\n\n return request;\n}\n\nexport function mapHttpResponseToResult(response: HttpResponse): APIGatewayProxyStructuredResultV2 {\n const result: APIGatewayProxyStructuredResultV2 = {\n statusCode: response.status,\n };\n\n if (response.headers) {\n result.headers = response.headers;\n }\n\n if (response.binaryBody) {\n result.body = response.binaryBody.toString(\"base64\");\n result.isBase64Encoded = true;\n } else if (response.body) {\n result.body = response.body;\n }\n\n return result;\n}\n","import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type { PipelineOptions } from \"@celerity-sdk/core\";\nimport {\n discoverModule,\n bootstrap,\n executeHandlerPipeline,\n createDefaultSystemLayers,\n disposeLayers,\n} from \"@celerity-sdk/core\";\nimport type { HandlerRegistry } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nlet cached: { registry: HandlerRegistry; options: PipelineOptions } | null = null;\nlet shutdownRegistered = false;\n\nfunction registerShutdownHandler(options: PipelineOptions): void {\n if (shutdownRegistered) return;\n shutdownRegistered = true;\n debug(\"entry: SIGTERM shutdown handler registered\");\n\n process.on(\"SIGTERM\", async () => {\n await options.container.closeAll();\n await disposeLayers([...(options.systemLayers ?? []), ...(options.appLayers ?? [])]);\n process.exit(0);\n });\n}\n\nasync function ensureBootstrapped(): Promise<{\n registry: HandlerRegistry;\n options: PipelineOptions;\n}> {\n if (!cached) {\n debug(\"entry: cold start, bootstrapping\");\n const systemLayers = await createDefaultSystemLayers();\n debug(\"entry: %d system layers created\", systemLayers.length);\n const rootModule = await discoverModule();\n const result = await bootstrap(rootModule);\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n };\n debug(\"entry: bootstrap complete\");\n }\n return cached;\n}\n\nexport async function handler(event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> {\n const { registry, options } = await ensureBootstrapped();\n registerShutdownHandler(options);\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n debug(\"entry: %s %s\", httpRequest.method, httpRequest.path);\n\n const resolved = registry.getHandler(httpRequest.path, httpRequest.method);\n if (!resolved) {\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n statusCode: 404,\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(resolved, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,IAAAA,gBAAwB;AAQxB,kBAAuC;;;ACRvC,mBAAwB;AAIxB,IAAMC,YAAQC,aAAAA,SAAY,yBAAA;AAE1B,SAASC,UAAUC,OAA6B;AAI9C,MAAI,CAACA,MAAMC,KAAM,QAAO;IAAEC,UAAU;IAAMC,YAAY;EAAK;AAC3D,MAAIH,MAAMI,gBACR,QAAO;IAAEF,UAAU;IAAMC,YAAYE,OAAOC,KAAKN,MAAMC,MAAM,QAAA;EAAU;AACzE,SAAO;IAAEC,UAAUF,MAAMC;IAAME,YAAY;EAAK;AAClD;AARSJ;AAUT,SAASQ,aAAaP,OAA6B;AACjD,QAAMQ,UAA6C,CAAC;AACpD,MAAI,CAACR,MAAMQ,QAAS,QAAOA;AAE3B,aAAW,CAACC,KAAKC,KAAAA,KAAUC,OAAOC,QAAQZ,MAAMQ,OAAO,GAAG;AACxD,QAAIE,UAAUG,QAAW;AACvBL,cAAQC,IAAIK,YAAW,CAAA,IAAMJ;IAC/B;EACF;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AQF,YAAYG,IAAI;AAE1D,QAAMC,WAAWT,SAASU,WAAWL,YAAYG,MAAMH,YAAYE,MAAM;AACzE,MAAI,CAACE,UAAU;AACb,WAAO;MACLE,YAAY;MACZC,SAAS;QAAE,gBAAgB;MAAmB;MAC9CC,MAAMC,KAAKC,UAAU;QACnBJ,YAAY;QACZK,SAAS,kBAAkBX,YAAYE,MAAM,IAAIF,YAAYG,IAAI;MACnE,CAAA;IACF;EACF;AAEA,QAAMS,eAAe,UAAMC,qCAAuBT,UAAUJ,aAAarB,OAAAA;AACzE,SAAOmC,wBAAwBF,YAAAA;AACjC;AArBsBhB;","names":["import_debug","debug","createDebug","parseBody","event","body","textBody","binaryBody","isBase64Encoded","Buffer","from","parseHeaders","headers","key","value","Object","entries","undefined","toLowerCase","parseCookies","cookies","cookie","eqIndex","indexOf","slice","trim","parsePathParams","params","pathParameters","mapApiGatewayV2Event","method","requestContext","http","toUpperCase","authorizer","contentType","xrayHeader","request","path","rawPath","pathParams","query","queryStringParameters","requestId","requestTime","time","Date","toISOString","auth","jwt","claims","clientIp","sourceIp","traceContext","userAgent","matchedRoute","routeKey","mapHttpResponseToResult","response","result","statusCode","status","toString","debug","createDebug","AwsLambdaAdapter","createHandler","registry","options","cachedHandler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult","import_debug","import_core","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","registry","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","resolved","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/event-mapper.ts","../src/entry.ts"],"sourcesContent":["export { AwsLambdaAdapter } from \"./adapter\";\nexport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\nexport { handler } from \"./entry\";\n","import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type {\n HandlerRegistry,\n ServerlessAdapter,\n ResolvedHandler,\n PipelineOptions,\n} from \"@celerity-sdk/core\";\nimport { executeHandlerPipeline } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\ntype AwsLambdaAdapterConfig = {\n handlerId?: string;\n};\n\nexport class AwsLambdaAdapter implements ServerlessAdapter {\n config: AwsLambdaAdapterConfig;\n\n constructor() {\n // Capture config from environment variables on construction\n // to take a snapshot at the initialisation phase similarly to\n // how layers capture config.\n this.config = captureAwsLambdaConfig();\n }\n\n createHandler(\n registry: HandlerRegistry,\n options: PipelineOptions,\n ): (event: unknown, context: unknown) => Promise<unknown> {\n let cachedHandler: ResolvedHandler | null = null;\n\n return async (event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> => {\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n\n if (!cachedHandler) {\n debug(\n \"adapter: cache miss, looking up handler for %s %s\",\n httpRequest.method,\n httpRequest.path,\n );\n cachedHandler =\n (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : undefined) ??\n registry.getHandler(httpRequest.path, httpRequest.method) ??\n null;\n } else {\n debug(\"adapter: using cached handler for %s %s\", httpRequest.method, httpRequest.path);\n }\n\n if (!cachedHandler) {\n debug(\"adapter: no handler found → 404\");\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(cachedHandler, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n };\n }\n}\n\nfunction captureAwsLambdaConfig(): AwsLambdaAdapterConfig {\n return {\n handlerId: process.env.CELERITY_HANDLER_ID,\n };\n}\n","import createDebug from \"debug\";\nimport type { HttpMethod, HttpRequest, HttpResponse } from \"@celerity-sdk/types\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from \"aws-lambda\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nfunction parseBody(event: APIGatewayProxyEventV2): {\n textBody: string | null;\n binaryBody: Buffer | null;\n} {\n if (!event.body) return { textBody: null, binaryBody: null };\n if (event.isBase64Encoded)\n return { textBody: null, binaryBody: Buffer.from(event.body, \"base64\") };\n return { textBody: event.body, binaryBody: null };\n}\n\nfunction parseHeaders(event: APIGatewayProxyEventV2): Record<string, string | string[]> {\n const headers: Record<string, string | string[]> = {};\n if (!event.headers) return headers;\n\n for (const [key, value] of Object.entries(event.headers)) {\n if (value !== undefined) {\n headers[key.toLowerCase()] = value;\n }\n }\n return headers;\n}\n\nfunction parseCookies(event: APIGatewayProxyEventV2): Record<string, string> {\n const cookies: Record<string, string> = {};\n if (!event.cookies) return cookies;\n\n for (const cookie of event.cookies) {\n const eqIndex = cookie.indexOf(\"=\");\n if (eqIndex > 0) {\n cookies[cookie.slice(0, eqIndex).trim()] = cookie.slice(eqIndex + 1).trim();\n }\n }\n return cookies;\n}\n\nfunction parsePathParams(event: APIGatewayProxyEventV2): Record<string, string> {\n const params: Record<string, string> = {};\n if (!event.pathParameters) return params;\n\n for (const [key, value] of Object.entries(event.pathParameters)) {\n if (value !== undefined) {\n params[key] = value;\n }\n }\n return params;\n}\n\nexport function mapApiGatewayV2Event(event: APIGatewayProxyEventV2): HttpRequest {\n const method = event.requestContext.http.method.toUpperCase() as HttpMethod;\n const headers = parseHeaders(event);\n const { textBody, binaryBody } = parseBody(event);\n\n const authorizer = (\n event.requestContext as unknown as {\n authorizer?: { jwt?: { claims?: Record<string, unknown> } };\n }\n ).authorizer;\n\n const contentType = (headers[\"content-type\"] as string | undefined) ?? null;\n const xrayHeader = (headers[\"x-amzn-trace-id\"] as string | undefined) ?? null;\n\n const request: HttpRequest = {\n method,\n path: event.rawPath,\n pathParams: parsePathParams(event),\n query: (event.queryStringParameters ?? {}) as Record<string, string | string[]>,\n headers,\n cookies: parseCookies(event),\n textBody,\n binaryBody,\n contentType,\n requestId: event.requestContext.requestId,\n requestTime: event.requestContext.time ?? new Date().toISOString(),\n auth: authorizer?.jwt?.claims ?? null,\n clientIp: event.requestContext.http.sourceIp,\n traceContext: xrayHeader ? { \"x-amzn-trace-id\": xrayHeader } : null,\n userAgent: event.requestContext.http.userAgent ?? null,\n matchedRoute: event.routeKey ?? null,\n };\n\n debug(\n \"mapEvent: %s %s (auth=%s, traceContext=%s)\",\n method,\n event.rawPath,\n !!authorizer?.jwt?.claims,\n !!xrayHeader,\n );\n\n return request;\n}\n\nexport function mapHttpResponseToResult(response: HttpResponse): APIGatewayProxyStructuredResultV2 {\n const result: APIGatewayProxyStructuredResultV2 = {\n statusCode: response.status,\n };\n\n if (response.headers) {\n result.headers = response.headers;\n }\n\n if (response.binaryBody) {\n result.body = response.binaryBody.toString(\"base64\");\n result.isBase64Encoded = true;\n } else if (response.body) {\n result.body = response.body;\n }\n\n return result;\n}\n","import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type { PipelineOptions } from \"@celerity-sdk/core\";\nimport {\n discoverModule,\n bootstrap,\n executeHandlerPipeline,\n createDefaultSystemLayers,\n disposeLayers,\n} from \"@celerity-sdk/core\";\nimport type { HandlerRegistry } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nlet cached: { registry: HandlerRegistry; options: PipelineOptions } | null = null;\nlet shutdownRegistered = false;\n\nfunction registerShutdownHandler(options: PipelineOptions): void {\n if (shutdownRegistered) return;\n shutdownRegistered = true;\n debug(\"entry: SIGTERM shutdown handler registered\");\n\n process.on(\"SIGTERM\", async () => {\n await options.container.closeAll();\n await disposeLayers([...(options.systemLayers ?? []), ...(options.appLayers ?? [])]);\n process.exit(0);\n });\n}\n\nasync function ensureBootstrapped(): Promise<{\n registry: HandlerRegistry;\n options: PipelineOptions;\n}> {\n if (!cached) {\n debug(\"entry: cold start, bootstrapping\");\n const systemLayers = await createDefaultSystemLayers();\n debug(\"entry: %d system layers created\", systemLayers.length);\n const rootModule = await discoverModule();\n const result = await bootstrap(rootModule);\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n };\n debug(\"entry: bootstrap complete\");\n }\n return cached;\n}\n\nexport async function handler(event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> {\n const { registry, options } = await ensureBootstrapped();\n registerShutdownHandler(options);\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n debug(\"entry: %s %s\", httpRequest.method, httpRequest.path);\n\n const handlerId = process.env.CELERITY_HANDLER_ID;\n const resolved =\n (handlerId ? registry.getHandlerById(handlerId) : undefined) ??\n registry.getHandler(httpRequest.path, httpRequest.method);\n if (!resolved) {\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n statusCode: 404,\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(resolved, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,IAAAA,gBAAwB;AAQxB,kBAAuC;;;ACRvC,mBAAwB;AAIxB,IAAMC,YAAQC,aAAAA,SAAY,yBAAA;AAE1B,SAASC,UAAUC,OAA6B;AAI9C,MAAI,CAACA,MAAMC,KAAM,QAAO;IAAEC,UAAU;IAAMC,YAAY;EAAK;AAC3D,MAAIH,MAAMI,gBACR,QAAO;I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qBAAAA;AAIb,MAAI,CAACZ,QAAQ;AACXF,IAAAA,OAAM,kCAAA;AACN,UAAMW,eAAe,UAAMI,wCAAAA;AAC3Bf,IAAAA,OAAM,mCAAmCW,aAAaK,MAAM;AAC5D,UAAMC,aAAa,UAAMC,6BAAAA;AACzB,UAAMC,SAAS,UAAMC,wBAAUH,UAAAA;AAC/Bf,aAAS;MACPmB,UAAUF,OAAOE;MACjBhB,SAAS;QACPG,WAAWW,OAAOX;QAClBG;MACF;IACF;AACAX,IAAAA,OAAM,2BAAA;EACR;AACA,SAAOE;AACT;AApBeY;AAsBf,eAAsBQ,QAAQC,OAAgBC,UAAiB;AAC7D,QAAM,EAAEH,UAAUhB,QAAO,IAAK,MAAMS,mBAAAA;AACpCV,0BAAwBC,OAAAA;AACxB,QAAMoB,WAAWF;AACjB,QAAMG,cAAcC,qBAAqBF,QAAAA;AACzCzB,EAAAA,OAAM,gBAAgB0B,YAAYE,QAAQF,YAAYG,IAAI;AAE1D,QAAMC,YAAYxB,QAAQyB,IAAIC;AAC9B,QAAMC,YACHH,YAAYT,SAASa,eAAeJ,SAAAA,IAAaK,WAClDd,SAASe,WAAWV,YAAYG,MAAMH,YAAYE,MAAM;AAC1D,MAAI,CAACK,UAAU;AACb,WAAO;MACLI,YAAY;MACZC,SAAS;QAAE,gBAAgB;MAAmB;MAC9CC,MAAMC,KAAKC,UAAU;QACnBJ,YAAY;QACZK,SAAS,kBAAkBhB,YAAYE,MAAM,IAAIF,YAAYG,IAAI;MACnE,CAAA;IACF;EACF;AAEA,QAAMc,eAAe,UAAMC,qCAAuBX,UAAUP,aAAarB,OAAAA;AACzE,SAAOwC,wBAAwBF,YAAAA;AACjC;AAxBsBrB;","names":["import_debug","debug","createDebug","parseBody","event","body","textBody","binaryBody","isBase64Encoded","Buffer","from","parseHeaders","headers","key","value","Object","entries","undefined","toLowerCase","parseCookies","cookies","cookie","eqIndex","indexOf","slice","trim","parsePathParams","params","pathParameters","mapApiGatewayV2Event","method","requestContext","http","toUpperCase","authorizer","contentType","xrayHeader","request","path","rawPath","pathParams","query","queryStringParameters","requestId","requestTime","time","Date","toISOString","auth","jwt","claims","clientIp","sourceIp","traceContext","userAgent","matchedRoute","routeKey","mapHttpResponseToResult","response","result","statusCode","status","toString","debug","createDebug","AwsLambdaAdapter","config","captureAwsLambdaConfig","createHandler","registry","options","cachedHandler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","getHandlerById","undefined","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult","process","env","CELERITY_HANDLER_ID","import_debug","import_core","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","registry","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","env","CELERITY_HANDLER_ID","resolved","getHandlerById","undefined","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,12 @@ import { HttpRequest, HttpResponse } from '@celerity-sdk/types';
|
|
|
3
3
|
import { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from 'aws-lambda';
|
|
4
4
|
export { handler } from './entry.cjs';
|
|
5
5
|
|
|
6
|
+
type AwsLambdaAdapterConfig = {
|
|
7
|
+
handlerId?: string;
|
|
8
|
+
};
|
|
6
9
|
declare class AwsLambdaAdapter implements ServerlessAdapter {
|
|
10
|
+
config: AwsLambdaAdapterConfig;
|
|
11
|
+
constructor();
|
|
7
12
|
createHandler(registry: HandlerRegistry, options: PipelineOptions): (event: unknown, context: unknown) => Promise<unknown>;
|
|
8
13
|
}
|
|
9
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,12 @@ import { HttpRequest, HttpResponse } from '@celerity-sdk/types';
|
|
|
3
3
|
import { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from 'aws-lambda';
|
|
4
4
|
export { handler } from './entry.js';
|
|
5
5
|
|
|
6
|
+
type AwsLambdaAdapterConfig = {
|
|
7
|
+
handlerId?: string;
|
|
8
|
+
};
|
|
6
9
|
declare class AwsLambdaAdapter implements ServerlessAdapter {
|
|
10
|
+
config: AwsLambdaAdapterConfig;
|
|
11
|
+
constructor();
|
|
7
12
|
createHandler(registry: HandlerRegistry, options: PipelineOptions): (event: unknown, context: unknown) => Promise<unknown>;
|
|
8
13
|
}
|
|
9
14
|
|
package/dist/index.js
CHANGED
|
@@ -111,6 +111,10 @@ var AwsLambdaAdapter = class {
|
|
|
111
111
|
static {
|
|
112
112
|
__name(this, "AwsLambdaAdapter");
|
|
113
113
|
}
|
|
114
|
+
config;
|
|
115
|
+
constructor() {
|
|
116
|
+
this.config = captureAwsLambdaConfig();
|
|
117
|
+
}
|
|
114
118
|
createHandler(registry, options) {
|
|
115
119
|
let cachedHandler = null;
|
|
116
120
|
return async (event, _context) => {
|
|
@@ -118,7 +122,7 @@ var AwsLambdaAdapter = class {
|
|
|
118
122
|
const httpRequest = mapApiGatewayV2Event(apiEvent);
|
|
119
123
|
if (!cachedHandler) {
|
|
120
124
|
debug2("adapter: cache miss, looking up handler for %s %s", httpRequest.method, httpRequest.path);
|
|
121
|
-
cachedHandler = registry.getHandler(httpRequest.path, httpRequest.method) ?? null;
|
|
125
|
+
cachedHandler = (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method) ?? null;
|
|
122
126
|
} else {
|
|
123
127
|
debug2("adapter: using cached handler for %s %s", httpRequest.method, httpRequest.path);
|
|
124
128
|
}
|
|
@@ -139,6 +143,12 @@ var AwsLambdaAdapter = class {
|
|
|
139
143
|
};
|
|
140
144
|
}
|
|
141
145
|
};
|
|
146
|
+
function captureAwsLambdaConfig() {
|
|
147
|
+
return {
|
|
148
|
+
handlerId: process.env.CELERITY_HANDLER_ID
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
__name(captureAwsLambdaConfig, "captureAwsLambdaConfig");
|
|
142
152
|
|
|
143
153
|
// src/entry.ts
|
|
144
154
|
import createDebug3 from "debug";
|
|
@@ -185,7 +195,8 @@ async function handler(event, _context) {
|
|
|
185
195
|
const apiEvent = event;
|
|
186
196
|
const httpRequest = mapApiGatewayV2Event(apiEvent);
|
|
187
197
|
debug3("entry: %s %s", httpRequest.method, httpRequest.path);
|
|
188
|
-
const
|
|
198
|
+
const handlerId = process.env.CELERITY_HANDLER_ID;
|
|
199
|
+
const resolved = (handlerId ? registry.getHandlerById(handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method);
|
|
189
200
|
if (!resolved) {
|
|
190
201
|
return {
|
|
191
202
|
statusCode: 404,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts","../src/event-mapper.ts","../src/entry.ts"],"sourcesContent":["import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type {\n HandlerRegistry,\n ServerlessAdapter,\n ResolvedHandler,\n PipelineOptions,\n} from \"@celerity-sdk/core\";\nimport { executeHandlerPipeline } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nexport class AwsLambdaAdapter implements ServerlessAdapter {\n createHandler(\n registry: HandlerRegistry,\n options: PipelineOptions,\n ): (event: unknown, context: unknown) => Promise<unknown> {\n let cachedHandler: ResolvedHandler | null = null;\n\n return async (event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> => {\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n\n if (!cachedHandler) {\n debug(\n \"adapter: cache miss, looking up handler for %s %s\",\n httpRequest.method,\n httpRequest.path,\n );\n cachedHandler = registry.getHandler(httpRequest.path, httpRequest.method) ?? null;\n } else {\n debug(\"adapter: using cached handler for %s %s\", httpRequest.method, httpRequest.path);\n }\n\n if (!cachedHandler) {\n debug(\"adapter: no handler found → 404\");\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(cachedHandler, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n };\n }\n}\n","import createDebug from \"debug\";\nimport type { HttpMethod, HttpRequest, HttpResponse } from \"@celerity-sdk/types\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from \"aws-lambda\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nfunction parseBody(event: APIGatewayProxyEventV2): {\n textBody: string | null;\n binaryBody: Buffer | null;\n} {\n if (!event.body) return { textBody: null, binaryBody: null };\n if (event.isBase64Encoded)\n return { textBody: null, binaryBody: Buffer.from(event.body, \"base64\") };\n return { textBody: event.body, binaryBody: null };\n}\n\nfunction parseHeaders(event: APIGatewayProxyEventV2): Record<string, string | string[]> {\n const headers: Record<string, string | string[]> = {};\n if (!event.headers) return headers;\n\n for (const [key, value] of Object.entries(event.headers)) {\n if (value !== undefined) {\n headers[key.toLowerCase()] = value;\n }\n }\n return headers;\n}\n\nfunction parseCookies(event: APIGatewayProxyEventV2): Record<string, string> {\n const cookies: Record<string, string> = {};\n if (!event.cookies) return cookies;\n\n for (const cookie of event.cookies) {\n const eqIndex = cookie.indexOf(\"=\");\n if (eqIndex > 0) {\n cookies[cookie.slice(0, eqIndex).trim()] = cookie.slice(eqIndex + 1).trim();\n }\n }\n return cookies;\n}\n\nfunction parsePathParams(event: APIGatewayProxyEventV2): Record<string, string> {\n const params: Record<string, string> = {};\n if (!event.pathParameters) return params;\n\n for (const [key, value] of Object.entries(event.pathParameters)) {\n if (value !== undefined) {\n params[key] = value;\n }\n }\n return params;\n}\n\nexport function mapApiGatewayV2Event(event: APIGatewayProxyEventV2): HttpRequest {\n const method = event.requestContext.http.method.toUpperCase() as HttpMethod;\n const headers = parseHeaders(event);\n const { textBody, binaryBody } = parseBody(event);\n\n const authorizer = (\n event.requestContext as unknown as {\n authorizer?: { jwt?: { claims?: Record<string, unknown> } };\n }\n ).authorizer;\n\n const contentType = (headers[\"content-type\"] as string | undefined) ?? null;\n const xrayHeader = (headers[\"x-amzn-trace-id\"] as string | undefined) ?? null;\n\n const request: HttpRequest = {\n method,\n path: event.rawPath,\n pathParams: parsePathParams(event),\n query: (event.queryStringParameters ?? {}) as Record<string, string | string[]>,\n headers,\n cookies: parseCookies(event),\n textBody,\n binaryBody,\n contentType,\n requestId: event.requestContext.requestId,\n requestTime: event.requestContext.time ?? new Date().toISOString(),\n auth: authorizer?.jwt?.claims ?? null,\n clientIp: event.requestContext.http.sourceIp,\n traceContext: xrayHeader ? { \"x-amzn-trace-id\": xrayHeader } : null,\n userAgent: event.requestContext.http.userAgent ?? null,\n matchedRoute: event.routeKey ?? null,\n };\n\n debug(\n \"mapEvent: %s %s (auth=%s, traceContext=%s)\",\n method,\n event.rawPath,\n !!authorizer?.jwt?.claims,\n !!xrayHeader,\n );\n\n return request;\n}\n\nexport function mapHttpResponseToResult(response: HttpResponse): APIGatewayProxyStructuredResultV2 {\n const result: APIGatewayProxyStructuredResultV2 = {\n statusCode: response.status,\n };\n\n if (response.headers) {\n result.headers = response.headers;\n }\n\n if (response.binaryBody) {\n result.body = response.binaryBody.toString(\"base64\");\n result.isBase64Encoded = true;\n } else if (response.body) {\n result.body = response.body;\n }\n\n return result;\n}\n","import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type { PipelineOptions } from \"@celerity-sdk/core\";\nimport {\n discoverModule,\n bootstrap,\n executeHandlerPipeline,\n createDefaultSystemLayers,\n disposeLayers,\n} from \"@celerity-sdk/core\";\nimport type { HandlerRegistry } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nlet cached: { registry: HandlerRegistry; options: PipelineOptions } | null = null;\nlet shutdownRegistered = false;\n\nfunction registerShutdownHandler(options: PipelineOptions): void {\n if (shutdownRegistered) return;\n shutdownRegistered = true;\n debug(\"entry: SIGTERM shutdown handler registered\");\n\n process.on(\"SIGTERM\", async () => {\n await options.container.closeAll();\n await disposeLayers([...(options.systemLayers ?? []), ...(options.appLayers ?? [])]);\n process.exit(0);\n });\n}\n\nasync function ensureBootstrapped(): Promise<{\n registry: HandlerRegistry;\n options: PipelineOptions;\n}> {\n if (!cached) {\n debug(\"entry: cold start, bootstrapping\");\n const systemLayers = await createDefaultSystemLayers();\n debug(\"entry: %d system layers created\", systemLayers.length);\n const rootModule = await discoverModule();\n const result = await bootstrap(rootModule);\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n };\n debug(\"entry: bootstrap complete\");\n }\n return cached;\n}\n\nexport async function handler(event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> {\n const { registry, options } = await ensureBootstrapped();\n registerShutdownHandler(options);\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n debug(\"entry: %s %s\", httpRequest.method, httpRequest.path);\n\n const resolved = registry.getHandler(httpRequest.path, httpRequest.method);\n if (!resolved) {\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n statusCode: 404,\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(resolved, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n}\n"],"mappings":";;;;AAAA,OAAOA,kBAAiB;AAQxB,SAASC,8BAA8B;;;ACRvC,OAAOC,iBAAiB;AAIxB,IAAMC,QAAQC,YAAY,yBAAA;AA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AM,kCAAA;AACN,UAAMW,eAAe,MAAMI,0BAAAA;AAC3Bf,IAAAA,OAAM,mCAAmCW,aAAaK,MAAM;AAC5D,UAAMC,aAAa,MAAMC,eAAAA;AACzB,UAAMC,SAAS,MAAMC,UAAUH,UAAAA;AAC/Bf,aAAS;MACPmB,UAAUF,OAAOE;MACjBhB,SAAS;QACPG,WAAWW,OAAOX;QAClBG;MACF;IACF;AACAX,IAAAA,OAAM,2BAAA;EACR;AACA,SAAOE;AACT;AApBeY;AAsBf,eAAsBQ,QAAQC,OAAgBC,UAAiB;AAC7D,QAAM,EAAEH,UAAUhB,QAAO,IAAK,MAAMS,mBAAAA;AACpCV,0BAAwBC,OAAAA;AACxB,QAAMoB,WAAWF;AACjB,QAAMG,cAAcC,qBAAqBF,QAAAA;AACzCzB,EAAAA,OAAM,gBAAgB0B,YAAYE,QAAQF,YAAYG,IAAI;AAE1D,QAAMC,WAAWT,SAASU,WAAWL,YAAYG,MAAMH,YAAYE,MAAM;AACzE,MAAI,CAACE,UAAU;AACb,WAAO;MACLE,YAAY;MACZC,SAAS;QAAE,gBAAgB;MAAmB;MAC9CC,MAAMC,KAAKC,UAAU;QACnBJ,YAAY;QACZK,SAAS,kBAAkBX,YAAYE,MAAM,IAAIF,YAAYG,IAAI;MACnE,CAAA;IACF;EACF;AAEA,QAAMS,eAAe,MAAMC,wBAAuBT,UAAUJ,aAAarB,OAAAA;AACzE,SAAOmC,wBAAwBF,YAAAA;AACjC;AArBsBhB;","names":["createDebug","executeHandlerPipeline","createDebug","debug","createDebug","parseBody","event","body","textBody","binaryBody","isBase64Encoded","Buffer","from","parseHeaders","headers","key","value","Object","entries","undefined","toLowerCase","parseCookies","cookies","cookie","eqIndex","indexOf","slice","trim","parsePathParams","params","pathParameters","mapApiGatewayV2Event","method","requestContext","http","toUpperCase","authorizer","contentType","xrayHeader","request","path","rawPath","pathParams","query","queryStringParameters","requestId","requestTime","time","Date","toISOString","auth","jwt","claims","clientIp","sourceIp","traceContext","userAgent","matchedRoute","routeKey","mapHttpResponseToResult","response","result","statusCode","status","toString","debug","createDebug","AwsLambdaAdapter","createHandler","registry","options","cachedHandler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult","createDebug","discoverModule","bootstrap","executeHandlerPipeline","createDefaultSystemLayers","disposeLayers","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","registry","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","resolved","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts","../src/event-mapper.ts","../src/entry.ts"],"sourcesContent":["import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type {\n HandlerRegistry,\n ServerlessAdapter,\n ResolvedHandler,\n PipelineOptions,\n} from \"@celerity-sdk/core\";\nimport { executeHandlerPipeline } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\ntype AwsLambdaAdapterConfig = {\n handlerId?: string;\n};\n\nexport class AwsLambdaAdapter implements ServerlessAdapter {\n config: AwsLambdaAdapterConfig;\n\n constructor() {\n // Capture config from environment variables on construction\n // to take a snapshot at the initialisation phase similarly to\n // how layers capture config.\n this.config = captureAwsLambdaConfig();\n }\n\n createHandler(\n registry: HandlerRegistry,\n options: PipelineOptions,\n ): (event: unknown, context: unknown) => Promise<unknown> {\n let cachedHandler: ResolvedHandler | null = null;\n\n return async (event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> => {\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n\n if (!cachedHandler) {\n debug(\n \"adapter: cache miss, looking up handler for %s %s\",\n httpRequest.method,\n httpRequest.path,\n );\n cachedHandler =\n (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : undefined) ??\n registry.getHandler(httpRequest.path, httpRequest.method) ??\n null;\n } else {\n debug(\"adapter: using cached handler for %s %s\", httpRequest.method, httpRequest.path);\n }\n\n if (!cachedHandler) {\n debug(\"adapter: no handler found → 404\");\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(cachedHandler, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n };\n }\n}\n\nfunction captureAwsLambdaConfig(): AwsLambdaAdapterConfig {\n return {\n handlerId: process.env.CELERITY_HANDLER_ID,\n };\n}\n","import createDebug from \"debug\";\nimport type { HttpMethod, HttpRequest, HttpResponse } from \"@celerity-sdk/types\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from \"aws-lambda\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nfunction parseBody(event: APIGatewayProxyEventV2): {\n textBody: string | null;\n binaryBody: Buffer | null;\n} {\n if (!event.body) return { textBody: null, binaryBody: null };\n if (event.isBase64Encoded)\n return { textBody: null, binaryBody: Buffer.from(event.body, \"base64\") };\n return { textBody: event.body, binaryBody: null };\n}\n\nfunction parseHeaders(event: APIGatewayProxyEventV2): Record<string, string | string[]> {\n const headers: Record<string, string | string[]> = {};\n if (!event.headers) return headers;\n\n for (const [key, value] of Object.entries(event.headers)) {\n if (value !== undefined) {\n headers[key.toLowerCase()] = value;\n }\n }\n return headers;\n}\n\nfunction parseCookies(event: APIGatewayProxyEventV2): Record<string, string> {\n const cookies: Record<string, string> = {};\n if (!event.cookies) return cookies;\n\n for (const cookie of event.cookies) {\n const eqIndex = cookie.indexOf(\"=\");\n if (eqIndex > 0) {\n cookies[cookie.slice(0, eqIndex).trim()] = cookie.slice(eqIndex + 1).trim();\n }\n }\n return cookies;\n}\n\nfunction parsePathParams(event: APIGatewayProxyEventV2): Record<string, string> {\n const params: Record<string, string> = {};\n if (!event.pathParameters) return params;\n\n for (const [key, value] of Object.entries(event.pathParameters)) {\n if (value !== undefined) {\n params[key] = value;\n }\n }\n return params;\n}\n\nexport function mapApiGatewayV2Event(event: APIGatewayProxyEventV2): HttpRequest {\n const method = event.requestContext.http.method.toUpperCase() as HttpMethod;\n const headers = parseHeaders(event);\n const { textBody, binaryBody } = parseBody(event);\n\n const authorizer = (\n event.requestContext as unknown as {\n authorizer?: { jwt?: { claims?: Record<string, unknown> } };\n }\n ).authorizer;\n\n const contentType = (headers[\"content-type\"] as string | undefined) ?? null;\n const xrayHeader = (headers[\"x-amzn-trace-id\"] as string | undefined) ?? null;\n\n const request: HttpRequest = {\n method,\n path: event.rawPath,\n pathParams: parsePathParams(event),\n query: (event.queryStringParameters ?? {}) as Record<string, string | string[]>,\n headers,\n cookies: parseCookies(event),\n textBody,\n binaryBody,\n contentType,\n requestId: event.requestContext.requestId,\n requestTime: event.requestContext.time ?? new Date().toISOString(),\n auth: authorizer?.jwt?.claims ?? null,\n clientIp: event.requestContext.http.sourceIp,\n traceContext: xrayHeader ? { \"x-amzn-trace-id\": xrayHeader } : null,\n userAgent: event.requestContext.http.userAgent ?? null,\n matchedRoute: event.routeKey ?? null,\n };\n\n debug(\n \"mapEvent: %s %s (auth=%s, traceContext=%s)\",\n method,\n event.rawPath,\n !!authorizer?.jwt?.claims,\n !!xrayHeader,\n );\n\n return request;\n}\n\nexport function mapHttpResponseToResult(response: HttpResponse): APIGatewayProxyStructuredResultV2 {\n const result: APIGatewayProxyStructuredResultV2 = {\n statusCode: response.status,\n };\n\n if (response.headers) {\n result.headers = response.headers;\n }\n\n if (response.binaryBody) {\n result.body = response.binaryBody.toString(\"base64\");\n result.isBase64Encoded = true;\n } else if (response.body) {\n result.body = response.body;\n }\n\n return result;\n}\n","import createDebug from \"debug\";\nimport type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from \"aws-lambda\";\nimport type { PipelineOptions } from \"@celerity-sdk/core\";\nimport {\n discoverModule,\n bootstrap,\n executeHandlerPipeline,\n createDefaultSystemLayers,\n disposeLayers,\n} from \"@celerity-sdk/core\";\nimport type { HandlerRegistry } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\nlet cached: { registry: HandlerRegistry; options: PipelineOptions } | null = null;\nlet shutdownRegistered = false;\n\nfunction registerShutdownHandler(options: PipelineOptions): void {\n if (shutdownRegistered) return;\n shutdownRegistered = true;\n debug(\"entry: SIGTERM shutdown handler registered\");\n\n process.on(\"SIGTERM\", async () => {\n await options.container.closeAll();\n await disposeLayers([...(options.systemLayers ?? []), ...(options.appLayers ?? [])]);\n process.exit(0);\n });\n}\n\nasync function ensureBootstrapped(): Promise<{\n registry: HandlerRegistry;\n options: PipelineOptions;\n}> {\n if (!cached) {\n debug(\"entry: cold start, bootstrapping\");\n const systemLayers = await createDefaultSystemLayers();\n debug(\"entry: %d system layers created\", systemLayers.length);\n const rootModule = await discoverModule();\n const result = await bootstrap(rootModule);\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n };\n debug(\"entry: bootstrap complete\");\n }\n return cached;\n}\n\nexport async function handler(event: unknown, _context: unknown): Promise<APIGatewayProxyResultV2> {\n const { registry, options } = await ensureBootstrapped();\n registerShutdownHandler(options);\n const apiEvent = event as APIGatewayProxyEventV2;\n const httpRequest = mapApiGatewayV2Event(apiEvent);\n debug(\"entry: %s %s\", httpRequest.method, httpRequest.path);\n\n const handlerId = process.env.CELERITY_HANDLER_ID;\n const resolved =\n (handlerId ? registry.getHandlerById(handlerId) : undefined) ??\n registry.getHandler(httpRequest.path, httpRequest.method);\n if (!resolved) {\n return {\n statusCode: 404,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n statusCode: 404,\n message: `No handler for ${httpRequest.method} ${httpRequest.path}`,\n }),\n };\n }\n\n const httpResponse = await executeHandlerPipeline(resolved, httpRequest, options);\n return mapHttpResponseToResult(httpResponse);\n}\n"],"mappings":";;;;AAAA,OAAOA,kBAAiB;AAQxB,SAASC,8BAA8B;;;ACRvC,OAAOC,iBAAiB;AAIxB,IAAMC,QAAQC,YAAY,yBAAA;AAE1B,SAASC,UAAUC,OAA6B;AAI9C,MAAI,CAACA,MAAMC,KAAM,QAAO;IAAEC,UAAU;IAAMC,YAAY;EAAK;AAC3D,MAAIH,MAAMI,gBACR,QAAO;IAAEF,UAAU;IAAMC,YAAYE,OAAOC,KAAKN,MAAMC,MAAM,QAAA;EAAU;AACzE,SAAO;IAAEC,UAAUF,MAAMC;IAAME,YAAY;EAAK;AAClD;AARSJ;AAUT,SAASQ,aAAaP,OAA6B;AACjD,QAAMQ,UAA6C,CAAC;AACpD,MAAI,CAACR,MAAMQ,QAAS,QAAOA;AAE3B,aAAW,CAACC,KAAKC,KAAAA,KAAUC,OAAOC,QAAQZ,MAAMQ,OAAO,GAAG;AACxD,QAAIE,UAAUG,QAAW;AACvBL,cAAQC,IAAIK,YAAW,CAAA,IAAMJ;IAC/B;EACF;AACA,SAAOF;AACT;AAVSD;AAYT,SAASQ,aAAaf,OAA6B;AACjD,QAAMgB,UAAkC,CAAC;AACzC,MAAI,CAAChB,MAAMgB,QAAS,QAAOA;AAE3B,aAAWC,UAAUjB,MAAMgB,SAAS;AAClC,UAAME,UAAUD,OAAOE,QAAQ,GAAA;AAC/B,QAAID,UAAU,GAAG;AACfF,cAAQC,OAAOG,MAAM,GAAGF,OAAAA,EAASG,KAAI,CAAA,IAAMJ,OAAOG,MAAMF,UAAU,CAAA,EAAGG,KAAI;IAC3E;EACF;AACA,SAAOL;AACT;AAXSD;AAaT,SAASO,gBAAgBtB,OAA6B;AACpD,QA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AACb,WAAO;MACLI,YAAY;MACZC,SAAS;QAAE,gBAAgB;MAAmB;MAC9CC,MAAMC,KAAKC,UAAU;QACnBJ,YAAY;QACZK,SAAS,kBAAkBhB,YAAYE,MAAM,IAAIF,YAAYG,IAAI;MACnE,CAAA;IACF;EACF;AAEA,QAAMc,eAAe,MAAMC,wBAAuBX,UAAUP,aAAarB,OAAAA;AACzE,SAAOwC,wBAAwBF,YAAAA;AACjC;AAxBsBrB;","names":["createDebug","executeHandlerPipeline","createDebug","debug","createDebug","parseBody","event","body","textBody","binaryBody","isBase64Encoded","Buffer","from","parseHeaders","headers","key","value","Object","entries","undefined","toLowerCase","parseCookies","cookies","cookie","eqIndex","indexOf","slice","trim","parsePathParams","params","pathParameters","mapApiGatewayV2Event","method","requestContext","http","toUpperCase","authorizer","contentType","xrayHeader","request","path","rawPath","pathParams","query","queryStringParameters","requestId","requestTime","time","Date","toISOString","auth","jwt","claims","clientIp","sourceIp","traceContext","userAgent","matchedRoute","routeKey","mapHttpResponseToResult","response","result","statusCode","status","toString","debug","createDebug","AwsLambdaAdapter","config","captureAwsLambdaConfig","createHandler","registry","options","cachedHandler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","getHandlerById","undefined","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult","process","env","CELERITY_HANDLER_ID","createDebug","discoverModule","bootstrap","executeHandlerPipeline","createDefaultSystemLayers","disposeLayers","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","registry","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","env","CELERITY_HANDLER_ID","resolved","getHandlerById","undefined","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celerity-sdk/serverless-aws",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "AWS Lambda adapter for the Celerity Node SDK — converts API Gateway events to SDK types",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"debug": "^4.4.0",
|
|
45
|
-
"@celerity-sdk/
|
|
46
|
-
"@celerity-sdk/
|
|
45
|
+
"@celerity-sdk/core": "^0.2.1",
|
|
46
|
+
"@celerity-sdk/types": "^0.2.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/aws-lambda": "^8.10.160"
|