@celerity-sdk/serverless-aws 0.2.1 → 0.3.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @celerity-sdk/serverless-aws
2
2
 
3
- AWS Lambda adapter for the Celerity Node SDK maps API Gateway v2 events to SDK types and routes them through the handler pipeline.
3
+ AWS Lambda adapter for the Celerity Node SDK. Maps API Gateway v2 events to SDK types and routes them through the handler pipeline.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,10 +14,20 @@ The `AwsLambdaAdapter` implements the `ServerlessAdapter` interface from `@celer
14
14
 
15
15
  1. Receives an API Gateway v2 proxy event
16
16
  2. Maps it to an `HttpRequest` via `mapApiGatewayV2Event`
17
- 3. Resolves the matching handler from the registry
17
+ 3. Resolves the matching handler using the three-tier resolution chain (see below)
18
18
  4. Executes the full handler pipeline (system layers, app layers, handler layers, handler)
19
19
  5. Maps the `HttpResponse` back to an `APIGatewayProxyResultV2`
20
20
 
21
+ ### Handler Resolution
22
+
23
+ When `CELERITY_HANDLER_ID` is set (typical for serverless deployments where each Lambda maps to a single handler), the adapter resolves the handler using a three-tier chain:
24
+
25
+ 1. **Direct registry lookup** - `registry.getHandlerById(CELERITY_HANDLER_ID)` for handlers with an explicit ID
26
+ 2. **Module resolution fallback** - dynamically imports the handler module and matches the exported function against the registry by reference. Supports formats like `"handlers.hello"` (named export) and `"handlers"` (default export). Dotted module names like `"app.module"` are handled by trying the named export split first, then falling back to the full string as a module with a default export.
27
+ 3. **Path/method routing** - falls back to matching the incoming request's HTTP method and path
28
+
29
+ Resolution is cached: once a handler is matched on cold start, subsequent warm invocations use the cached handler directly without repeating the lookup.
30
+
21
31
  ### Event Mapping
22
32
 
23
33
  `mapApiGatewayV2Event` extracts from the API Gateway v2 event:
@@ -33,7 +43,7 @@ The `AwsLambdaAdapter` implements the `ServerlessAdapter` interface from `@celer
33
43
  The `./handler` export provides a pre-configured Lambda handler that bootstraps the application module, initialises system layers, and caches the handler for warm invocations. It also registers a SIGTERM handler for graceful shutdown (container close + layer disposal).
34
44
 
35
45
  ```typescript
36
- // handler.ts used as the Lambda entry point
46
+ // handler.ts - used as the Lambda entry point
37
47
  export { handler } from "@celerity-sdk/serverless-aws/handler";
38
48
  ```
39
49
 
package/dist/entry.cjs CHANGED
@@ -34,6 +34,7 @@ __export(entry_exports, {
34
34
  handler: () => handler
35
35
  });
36
36
  module.exports = __toCommonJS(entry_exports);
37
+ var import_node_path = require("path");
37
38
  var import_debug2 = __toESM(require("debug"), 1);
38
39
  var import_core = require("@celerity-sdk/core");
39
40
 
@@ -162,12 +163,14 @@ async function ensureBootstrapped() {
162
163
  debug2("entry: %d system layers created", systemLayers.length);
163
164
  const rootModule = await (0, import_core.discoverModule)();
164
165
  const result = await (0, import_core.bootstrap)(rootModule);
166
+ const modulePath = process.env.CELERITY_MODULE_PATH;
165
167
  cached = {
166
168
  registry: result.registry,
167
169
  options: {
168
170
  container: result.container,
169
171
  systemLayers
170
- }
172
+ },
173
+ moduleDir: modulePath ? (0, import_node_path.dirname)((0, import_node_path.resolve)(modulePath)) : process.cwd()
171
174
  };
172
175
  debug2("entry: bootstrap complete");
173
176
  }
@@ -175,13 +178,19 @@ async function ensureBootstrapped() {
175
178
  }
176
179
  __name(ensureBootstrapped, "ensureBootstrapped");
177
180
  async function handler(event, _context) {
178
- const { registry, options } = await ensureBootstrapped();
181
+ const { registry, options, moduleDir } = await ensureBootstrapped();
179
182
  registerShutdownHandler(options);
180
183
  const apiEvent = event;
181
184
  const httpRequest = mapApiGatewayV2Event(apiEvent);
182
185
  debug2("entry: %s %s", httpRequest.method, httpRequest.path);
183
186
  const handlerId = process.env.CELERITY_HANDLER_ID;
184
- const resolved = (handlerId ? registry.getHandlerById(handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method);
187
+ let resolved = handlerId ? registry.getHandlerById(handlerId) : void 0;
188
+ if (!resolved && handlerId) {
189
+ resolved = await (0, import_core.resolveHandlerByModuleRef)(handlerId, registry, moduleDir) ?? void 0;
190
+ }
191
+ if (!resolved) {
192
+ resolved = registry.getHandler(httpRequest.path, httpRequest.method);
193
+ }
185
194
  if (!resolved) {
186
195
  return {
187
196
  statusCode: 404,
@@ -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 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;A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kBAAkBhB,YAAYE,MAAM,IAAIF,YAAYG,IAAI;MACnE,CAAA;IACF;EACF;AAEA,QAAMc,eAAe,UAAMC,oCAAuBX,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","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"]}
1
+ {"version":3,"sources":["../src/entry.ts","../src/event-mapper.ts"],"sourcesContent":["import { dirname, resolve } from \"node:path\";\nimport 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 resolveHandlerByModuleRef,\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: {\n registry: HandlerRegistry;\n options: PipelineOptions;\n moduleDir: string;\n} | 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 moduleDir: string;\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 const modulePath = process.env.CELERITY_MODULE_PATH;\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n moduleDir: modulePath ? dirname(resolve(modulePath)) : process.cwd(),\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, moduleDir } = 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\n let resolved = handlerId ? registry.getHandlerById(handlerId) : undefined;\n\n if (!resolved && handlerId) {\n resolved = (await resolveHandlerByModuleRef(handlerId, registry, moduleDir)) ?? undefined;\n }\n\n if (!resolved) {\n resolved = registry.getHandler(httpRequest.path, httpRequest.method);\n }\n\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;;;;;uBAAiC;AACjC,IAAAA,gBAAwB;AAGxB,kBAOO;;;ACXP,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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AMC,oCAAuBZ,UAAUN,aAAa5B,OAAAA;AACzE,SAAO+C,wBAAwBF,YAAAA;AACjC;AAhCsBrB;","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","modulePath","env","CELERITY_MODULE_PATH","registry","moduleDir","dirname","resolve","cwd","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","CELERITY_HANDLER_ID","resolved","getHandlerById","undefined","resolveHandlerByModuleRef","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
package/dist/entry.js CHANGED
@@ -2,8 +2,9 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/entry.ts
5
+ import { dirname, resolve } from "path";
5
6
  import createDebug2 from "debug";
6
- import { discoverModule, bootstrap, executeHandlerPipeline, createDefaultSystemLayers, disposeLayers } from "@celerity-sdk/core";
7
+ import { discoverModule, bootstrap, executeHandlerPipeline, createDefaultSystemLayers, disposeLayers, resolveHandlerByModuleRef } from "@celerity-sdk/core";
7
8
 
8
9
  // src/event-mapper.ts
9
10
  import createDebug from "debug";
@@ -130,12 +131,14 @@ async function ensureBootstrapped() {
130
131
  debug2("entry: %d system layers created", systemLayers.length);
131
132
  const rootModule = await discoverModule();
132
133
  const result = await bootstrap(rootModule);
134
+ const modulePath = process.env.CELERITY_MODULE_PATH;
133
135
  cached = {
134
136
  registry: result.registry,
135
137
  options: {
136
138
  container: result.container,
137
139
  systemLayers
138
- }
140
+ },
141
+ moduleDir: modulePath ? dirname(resolve(modulePath)) : process.cwd()
139
142
  };
140
143
  debug2("entry: bootstrap complete");
141
144
  }
@@ -143,13 +146,19 @@ async function ensureBootstrapped() {
143
146
  }
144
147
  __name(ensureBootstrapped, "ensureBootstrapped");
145
148
  async function handler(event, _context) {
146
- const { registry, options } = await ensureBootstrapped();
149
+ const { registry, options, moduleDir } = await ensureBootstrapped();
147
150
  registerShutdownHandler(options);
148
151
  const apiEvent = event;
149
152
  const httpRequest = mapApiGatewayV2Event(apiEvent);
150
153
  debug2("entry: %s %s", httpRequest.method, httpRequest.path);
151
154
  const handlerId = process.env.CELERITY_HANDLER_ID;
152
- const resolved = (handlerId ? registry.getHandlerById(handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method);
155
+ let resolved = handlerId ? registry.getHandlerById(handlerId) : void 0;
156
+ if (!resolved && handlerId) {
157
+ resolved = await resolveHandlerByModuleRef(handlerId, registry, moduleDir) ?? void 0;
158
+ }
159
+ if (!resolved) {
160
+ resolved = registry.getHandler(httpRequest.path, httpRequest.method);
161
+ }
153
162
  if (!resolved) {
154
163
  return {
155
164
  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 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;;;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,IAAIK,YAAW,CAAA,IAAMJ;IAC/B;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AAA;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,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,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"]}
1
+ {"version":3,"sources":["../src/entry.ts","../src/event-mapper.ts"],"sourcesContent":["import { dirname, resolve } from \"node:path\";\nimport 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 resolveHandlerByModuleRef,\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: {\n registry: HandlerRegistry;\n options: PipelineOptions;\n moduleDir: string;\n} | 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 moduleDir: string;\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 const modulePath = process.env.CELERITY_MODULE_PATH;\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n moduleDir: modulePath ? dirname(resolve(modulePath)) : process.cwd(),\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, moduleDir } = 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\n let resolved = handlerId ? registry.getHandlerById(handlerId) : undefined;\n\n if (!resolved && handlerId) {\n resolved = (await resolveHandlerByModuleRef(handlerId, registry, moduleDir)) ?? undefined;\n }\n\n if (!resolved) {\n resolved = registry.getHandler(httpRequest.path, httpRequest.method);\n }\n\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,SAASA,SAASC,eAAe;AACjC,OAAOC,kBAAiB;AAGxB,SACEC,gBACAC,WACAC,wBACAC,2BACAC,eACAC,iCACK;;;ACXP,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,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ACT;AAvBeY;AAyBf,eAAsBe,QAAQC,OAAgBC,UAAiB;AAC7D,QAAM,EAAEP,UAAUnB,SAASoB,UAAS,IAAK,MAAMX,mBAAAA;AAC/CV,0BAAwBC,OAAAA;AACxB,QAAM2B,WAAWF;AACjB,QAAMG,cAAcC,qBAAqBF,QAAAA;AACzChC,EAAAA,OAAM,gBAAgBiC,YAAYE,QAAQF,YAAYG,IAAI;AAE1D,QAAMC,YAAY/B,QAAQgB,IAAIgB;AAE9B,MAAIC,WAAWF,YAAYb,SAASgB,eAAeH,SAAAA,IAAaI;AAEhE,MAAI,CAACF,YAAYF,WAAW;AAC1BE,eAAY,MAAMG,0BAA0BL,WAAWb,UAAUC,SAAAA,KAAegB;EAClF;AAEA,MAAI,CAACF,UAAU;AACbA,eAAWf,SAASmB,WAAWV,YAAYG,MAAMH,YAAYE,MAAM;EACrE;AAEA,MAAI,CAACI,UAAU;AACb,WAAO;MACLK,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,uBAAuBZ,UAAUN,aAAa5B,OAAAA;AACzE,SAAO+C,wBAAwBF,YAAAA;AACjC;AAhCsBrB;","names":["dirname","resolve","createDebug","discoverModule","bootstrap","executeHandlerPipeline","createDefaultSystemLayers","disposeLayers","resolveHandlerByModuleRef","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","modulePath","env","CELERITY_MODULE_PATH","registry","moduleDir","dirname","resolve","cwd","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","CELERITY_HANDLER_ID","resolved","getHandlerById","undefined","resolveHandlerByModuleRef","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
package/dist/index.cjs CHANGED
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  module.exports = __toCommonJS(index_exports);
40
40
 
41
41
  // src/adapter.ts
42
+ var import_node_path = require("path");
42
43
  var import_debug2 = __toESM(require("debug"), 1);
43
44
  var import_core = require("@celerity-sdk/core");
44
45
 
@@ -159,7 +160,13 @@ var AwsLambdaAdapter = class {
159
160
  const httpRequest = mapApiGatewayV2Event(apiEvent);
160
161
  if (!cachedHandler) {
161
162
  debug2("adapter: cache miss, looking up handler for %s %s", httpRequest.method, httpRequest.path);
162
- cachedHandler = (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method) ?? null;
163
+ cachedHandler = (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : void 0) ?? null;
164
+ if (!cachedHandler && this.config.handlerId) {
165
+ cachedHandler = await (0, import_core.resolveHandlerByModuleRef)(this.config.handlerId, registry, this.config.moduleDir);
166
+ }
167
+ if (!cachedHandler) {
168
+ cachedHandler = registry.getHandler(httpRequest.path, httpRequest.method) ?? null;
169
+ }
163
170
  } else {
164
171
  debug2("adapter: using cached handler for %s %s", httpRequest.method, httpRequest.path);
165
172
  }
@@ -181,13 +188,16 @@ var AwsLambdaAdapter = class {
181
188
  }
182
189
  };
183
190
  function captureAwsLambdaConfig() {
191
+ const modulePath = process.env.CELERITY_MODULE_PATH;
184
192
  return {
185
- handlerId: process.env.CELERITY_HANDLER_ID
193
+ handlerId: process.env.CELERITY_HANDLER_ID,
194
+ moduleDir: modulePath ? (0, import_node_path.dirname)((0, import_node_path.resolve)(modulePath)) : process.cwd()
186
195
  };
187
196
  }
188
197
  __name(captureAwsLambdaConfig, "captureAwsLambdaConfig");
189
198
 
190
199
  // src/entry.ts
200
+ var import_node_path2 = require("path");
191
201
  var import_debug3 = __toESM(require("debug"), 1);
192
202
  var import_core2 = require("@celerity-sdk/core");
193
203
  var debug3 = (0, import_debug3.default)("celerity:serverless-aws");
@@ -214,12 +224,14 @@ async function ensureBootstrapped() {
214
224
  debug3("entry: %d system layers created", systemLayers.length);
215
225
  const rootModule = await (0, import_core2.discoverModule)();
216
226
  const result = await (0, import_core2.bootstrap)(rootModule);
227
+ const modulePath = process.env.CELERITY_MODULE_PATH;
217
228
  cached = {
218
229
  registry: result.registry,
219
230
  options: {
220
231
  container: result.container,
221
232
  systemLayers
222
- }
233
+ },
234
+ moduleDir: modulePath ? (0, import_node_path2.dirname)((0, import_node_path2.resolve)(modulePath)) : process.cwd()
223
235
  };
224
236
  debug3("entry: bootstrap complete");
225
237
  }
@@ -227,13 +239,19 @@ async function ensureBootstrapped() {
227
239
  }
228
240
  __name(ensureBootstrapped, "ensureBootstrapped");
229
241
  async function handler(event, _context) {
230
- const { registry, options } = await ensureBootstrapped();
242
+ const { registry, options, moduleDir } = await ensureBootstrapped();
231
243
  registerShutdownHandler(options);
232
244
  const apiEvent = event;
233
245
  const httpRequest = mapApiGatewayV2Event(apiEvent);
234
246
  debug3("entry: %s %s", httpRequest.method, httpRequest.path);
235
247
  const handlerId = process.env.CELERITY_HANDLER_ID;
236
- const resolved = (handlerId ? registry.getHandlerById(handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method);
248
+ let resolved = handlerId ? registry.getHandlerById(handlerId) : void 0;
249
+ if (!resolved && handlerId) {
250
+ resolved = await (0, import_core2.resolveHandlerByModuleRef)(handlerId, registry, moduleDir) ?? void 0;
251
+ }
252
+ if (!resolved) {
253
+ resolved = registry.getHandler(httpRequest.path, httpRequest.method);
254
+ }
237
255
  if (!resolved) {
238
256
  return {
239
257
  statusCode: 404,
@@ -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\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":";;;;;;;;;;;;;;;;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e,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"]}
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 { dirname, resolve } from \"node:path\";\nimport 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, resolveHandlerByModuleRef } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\ntype AwsLambdaAdapterConfig = {\n handlerId?: string;\n moduleDir: 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\n cachedHandler =\n (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : undefined) ??\n null;\n\n if (!cachedHandler && this.config.handlerId) {\n cachedHandler = await resolveHandlerByModuleRef(\n this.config.handlerId,\n registry,\n this.config.moduleDir,\n );\n }\n\n if (!cachedHandler) {\n cachedHandler = registry.getHandler(httpRequest.path, httpRequest.method) ?? null;\n }\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 const modulePath = process.env.CELERITY_MODULE_PATH;\n return {\n handlerId: process.env.CELERITY_HANDLER_ID,\n moduleDir: modulePath ? dirname(resolve(modulePath)) : process.cwd(),\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 { dirname, resolve } from \"node:path\";\nimport 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 resolveHandlerByModuleRef,\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: {\n registry: HandlerRegistry;\n options: PipelineOptions;\n moduleDir: string;\n} | 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 moduleDir: string;\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 const modulePath = process.env.CELERITY_MODULE_PATH;\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n moduleDir: modulePath ? dirname(resolve(modulePath)) : process.cwd(),\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, moduleDir } = 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\n let resolved = handlerId ? registry.getHandlerById(handlerId) : undefined;\n\n if (!resolved && handlerId) {\n resolved = (await resolveHandlerByModuleRef(handlerId, registry, moduleDir)) ?? undefined;\n }\n\n if (!resolved) {\n resolved = registry.getHandler(httpRequest.path, httpRequest.method);\n }\n\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 mapH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,0BAAwBC,OAAAA;AACxB,QAAM2B,WAAWF;AACjB,QAAMG,cAAcC,qBAAqBF,QAAAA;AACzChC,EAAAA,OAAM,gBAAgBiC,YAAYE,QAAQF,YAAYG,IAAI;AAE1D,QAAMC,YAAY/B,QAAQgB,IAAIgB;AAE9B,MAAIC,WAAWF,YAAYb,SAASgB,eAAeH,SAAAA,IAAaI;AAEhE,MAAI,CAACF,YAAYF,WAAW;AAC1BE,eAAY,UAAMG,wCAA0BL,WAAWb,UAAUC,SAAAA,KAAegB;EAClF;AAEA,MAAI,CAACF,UAAU;AACbA,eAAWf,SAASmB,WAAWV,YAAYG,MAAMH,YAAYE,MAAM;EACrE;AAEA,MAAI,CAACI,UAAU;AACb,WAAO;MACLK,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,qCAAuBZ,UAAUN,aAAa5B,OAAAA;AACzE,SAAO+C,wBAAwBF,YAAAA;AACjC;AAhCsBrB;","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","resolveHandlerByModuleRef","moduleDir","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult","modulePath","process","env","CELERITY_MODULE_PATH","CELERITY_HANDLER_ID","dirname","resolve","cwd","import_node_path","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","modulePath","env","CELERITY_MODULE_PATH","registry","moduleDir","dirname","resolve","cwd","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","CELERITY_HANDLER_ID","resolved","getHandlerById","undefined","resolveHandlerByModuleRef","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult"]}
package/dist/index.d.cts CHANGED
@@ -5,6 +5,7 @@ export { handler } from './entry.cjs';
5
5
 
6
6
  type AwsLambdaAdapterConfig = {
7
7
  handlerId?: string;
8
+ moduleDir: string;
8
9
  };
9
10
  declare class AwsLambdaAdapter implements ServerlessAdapter {
10
11
  config: AwsLambdaAdapterConfig;
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { handler } from './entry.js';
5
5
 
6
6
  type AwsLambdaAdapterConfig = {
7
7
  handlerId?: string;
8
+ moduleDir: string;
8
9
  };
9
10
  declare class AwsLambdaAdapter implements ServerlessAdapter {
10
11
  config: AwsLambdaAdapterConfig;
package/dist/index.js CHANGED
@@ -2,8 +2,9 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/adapter.ts
5
+ import { dirname, resolve } from "path";
5
6
  import createDebug2 from "debug";
6
- import { executeHandlerPipeline } from "@celerity-sdk/core";
7
+ import { executeHandlerPipeline, resolveHandlerByModuleRef } from "@celerity-sdk/core";
7
8
 
8
9
  // src/event-mapper.ts
9
10
  import createDebug from "debug";
@@ -122,7 +123,13 @@ var AwsLambdaAdapter = class {
122
123
  const httpRequest = mapApiGatewayV2Event(apiEvent);
123
124
  if (!cachedHandler) {
124
125
  debug2("adapter: cache miss, looking up handler for %s %s", httpRequest.method, httpRequest.path);
125
- cachedHandler = (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method) ?? null;
126
+ cachedHandler = (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : void 0) ?? null;
127
+ if (!cachedHandler && this.config.handlerId) {
128
+ cachedHandler = await resolveHandlerByModuleRef(this.config.handlerId, registry, this.config.moduleDir);
129
+ }
130
+ if (!cachedHandler) {
131
+ cachedHandler = registry.getHandler(httpRequest.path, httpRequest.method) ?? null;
132
+ }
126
133
  } else {
127
134
  debug2("adapter: using cached handler for %s %s", httpRequest.method, httpRequest.path);
128
135
  }
@@ -144,15 +151,18 @@ var AwsLambdaAdapter = class {
144
151
  }
145
152
  };
146
153
  function captureAwsLambdaConfig() {
154
+ const modulePath = process.env.CELERITY_MODULE_PATH;
147
155
  return {
148
- handlerId: process.env.CELERITY_HANDLER_ID
156
+ handlerId: process.env.CELERITY_HANDLER_ID,
157
+ moduleDir: modulePath ? dirname(resolve(modulePath)) : process.cwd()
149
158
  };
150
159
  }
151
160
  __name(captureAwsLambdaConfig, "captureAwsLambdaConfig");
152
161
 
153
162
  // src/entry.ts
163
+ import { dirname as dirname2, resolve as resolve2 } from "path";
154
164
  import createDebug3 from "debug";
155
- import { discoverModule, bootstrap, executeHandlerPipeline as executeHandlerPipeline2, createDefaultSystemLayers, disposeLayers } from "@celerity-sdk/core";
165
+ import { discoverModule, bootstrap, executeHandlerPipeline as executeHandlerPipeline2, createDefaultSystemLayers, disposeLayers, resolveHandlerByModuleRef as resolveHandlerByModuleRef2 } from "@celerity-sdk/core";
156
166
  var debug3 = createDebug3("celerity:serverless-aws");
157
167
  var cached = null;
158
168
  var shutdownRegistered = false;
@@ -177,12 +187,14 @@ async function ensureBootstrapped() {
177
187
  debug3("entry: %d system layers created", systemLayers.length);
178
188
  const rootModule = await discoverModule();
179
189
  const result = await bootstrap(rootModule);
190
+ const modulePath = process.env.CELERITY_MODULE_PATH;
180
191
  cached = {
181
192
  registry: result.registry,
182
193
  options: {
183
194
  container: result.container,
184
195
  systemLayers
185
- }
196
+ },
197
+ moduleDir: modulePath ? dirname2(resolve2(modulePath)) : process.cwd()
186
198
  };
187
199
  debug3("entry: bootstrap complete");
188
200
  }
@@ -190,13 +202,19 @@ async function ensureBootstrapped() {
190
202
  }
191
203
  __name(ensureBootstrapped, "ensureBootstrapped");
192
204
  async function handler(event, _context) {
193
- const { registry, options } = await ensureBootstrapped();
205
+ const { registry, options, moduleDir } = await ensureBootstrapped();
194
206
  registerShutdownHandler(options);
195
207
  const apiEvent = event;
196
208
  const httpRequest = mapApiGatewayV2Event(apiEvent);
197
209
  debug3("entry: %s %s", httpRequest.method, httpRequest.path);
198
210
  const handlerId = process.env.CELERITY_HANDLER_ID;
199
- const resolved = (handlerId ? registry.getHandlerById(handlerId) : void 0) ?? registry.getHandler(httpRequest.path, httpRequest.method);
211
+ let resolved = handlerId ? registry.getHandlerById(handlerId) : void 0;
212
+ if (!resolved && handlerId) {
213
+ resolved = await resolveHandlerByModuleRef2(handlerId, registry, moduleDir) ?? void 0;
214
+ }
215
+ if (!resolved) {
216
+ resolved = registry.getHandler(httpRequest.path, httpRequest.method);
217
+ }
200
218
  if (!resolved) {
201
219
  return {
202
220
  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\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;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;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,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"]}
1
+ {"version":3,"sources":["../src/adapter.ts","../src/event-mapper.ts","../src/entry.ts"],"sourcesContent":["import { dirname, resolve } from \"node:path\";\nimport 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, resolveHandlerByModuleRef } from \"@celerity-sdk/core\";\nimport { mapApiGatewayV2Event, mapHttpResponseToResult } from \"./event-mapper\";\n\nconst debug = createDebug(\"celerity:serverless-aws\");\n\ntype AwsLambdaAdapterConfig = {\n handlerId?: string;\n moduleDir: 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\n cachedHandler =\n (this.config.handlerId ? registry.getHandlerById(this.config.handlerId) : undefined) ??\n null;\n\n if (!cachedHandler && this.config.handlerId) {\n cachedHandler = await resolveHandlerByModuleRef(\n this.config.handlerId,\n registry,\n this.config.moduleDir,\n );\n }\n\n if (!cachedHandler) {\n cachedHandler = registry.getHandler(httpRequest.path, httpRequest.method) ?? null;\n }\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 const modulePath = process.env.CELERITY_MODULE_PATH;\n return {\n handlerId: process.env.CELERITY_HANDLER_ID,\n moduleDir: modulePath ? dirname(resolve(modulePath)) : process.cwd(),\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 { dirname, resolve } from \"node:path\";\nimport 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 resolveHandlerByModuleRef,\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: {\n registry: HandlerRegistry;\n options: PipelineOptions;\n moduleDir: string;\n} | 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 moduleDir: string;\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 const modulePath = process.env.CELERITY_MODULE_PATH;\n cached = {\n registry: result.registry,\n options: {\n container: result.container,\n systemLayers,\n },\n moduleDir: modulePath ? dirname(resolve(modulePath)) : process.cwd(),\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, moduleDir } = 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\n let resolved = handlerId ? registry.getHandlerById(handlerId) : undefined;\n\n if (!resolved && handlerId) {\n resolved = (await resolveHandlerByModuleRef(handlerId, registry, moduleDir)) ?? undefined;\n }\n\n if (!resolved) {\n resolved = registry.getHandler(httpRequest.path, httpRequest.method);\n }\n\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,SAASA,SAASC,eAAe;AACjC,OAAOC,kBAAiB;AAQxB,SAASC,wBAAwBC,iCAAiC;;;ACTlE,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,I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,UAAUN,aAAa5B,OAAAA;AACzE,SAAO+C,wBAAwBF,YAAAA;AACjC;AAhCsBrB;","names":["dirname","resolve","createDebug","executeHandlerPipeline","resolveHandlerByModuleRef","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","resolveHandlerByModuleRef","moduleDir","getHandler","statusCode","headers","body","JSON","stringify","message","httpResponse","executeHandlerPipeline","mapHttpResponseToResult","modulePath","process","env","CELERITY_MODULE_PATH","CELERITY_HANDLER_ID","dirname","resolve","cwd","dirname","resolve","createDebug","discoverModule","bootstrap","executeHandlerPipeline","createDefaultSystemLayers","disposeLayers","resolveHandlerByModuleRef","debug","createDebug","cached","shutdownRegistered","registerShutdownHandler","options","process","on","container","closeAll","disposeLayers","systemLayers","appLayers","exit","ensureBootstrapped","createDefaultSystemLayers","length","rootModule","discoverModule","result","bootstrap","modulePath","env","CELERITY_MODULE_PATH","registry","moduleDir","dirname","resolve","cwd","handler","event","_context","apiEvent","httpRequest","mapApiGatewayV2Event","method","path","handlerId","CELERITY_HANDLER_ID","resolved","getHandlerById","undefined","resolveHandlerByModuleRef","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.1",
3
+ "version": "0.3.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/core": "^0.2.1",
46
- "@celerity-sdk/types": "^0.2.1"
45
+ "@celerity-sdk/core": "^0.3.1",
46
+ "@celerity-sdk/types": "^0.3.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/aws-lambda": "^8.10.160"