lambda-reactor 1.0.4 → 1.0.5

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/middleware.d.ts CHANGED
@@ -6,6 +6,11 @@ import { RouteHandler } from "./route-handler";
6
6
  * by {@link dispatch}.
7
7
  */
8
8
  export type Middleware = (result: APIGatewayProxyResult) => APIGatewayProxyResult;
9
+ /**
10
+ * Unprefixed CORS header names accepted by {@link cors}.
11
+ * Each key is prefixed with `"Access-Control-"` in the response.
12
+ */
13
+ export type CorsHeaders = Partial<Record<"Allow-Origin" | "Allow-Methods" | "Allow-Headers" | "Allow-Credentials" | "Expose-Headers" | "Max-Age" | "Request-Headers" | "Request-Method", string>>;
9
14
  /**
10
15
  * Creates a middleware that injects CORS response headers.
11
16
  *
@@ -16,7 +21,7 @@ export type Middleware = (result: APIGatewayProxyResult) => APIGatewayProxyResul
16
21
  * @param headers - Map of unprefixed CORS header names to their values.
17
22
  * Defaults to an empty object (no CORS headers added).
18
23
  */
19
- export declare function cors(headers?: Record<string, string>): Middleware;
24
+ export declare function cors(headers?: CorsHeaders): Middleware;
20
25
  /**
21
26
  * Folds all middlewares registered on `route` over `result`, applying them
22
27
  * left-to-right, and returns the final {@link APIGatewayProxyResult}.
package/middleware.js.map CHANGED
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/middleware.ts"],
4
4
  "sourcesContent": [
5
- "import type {APIGatewayProxyResult} from \"aws-lambda\"\n\nimport {RouteHandler} from \"./route-handler\"\n\n/**\n * A pure function that receives an {@link APIGatewayProxyResult} and returns\n * a (possibly modified) copy of it. Middlewares are composed left-to-right\n * by {@link dispatch}.\n */\nexport type Middleware = (result: APIGatewayProxyResult) => APIGatewayProxyResult\n\n/**\n * Creates a middleware that injects CORS response headers.\n *\n * Each key in `headers` is prefixed with `\"Access-Control-\"` before being\n * merged into the response, so passing `{\"Allow-Origin\": \"*\"}` produces the\n * `Access-Control-Allow-Origin: *` header.\n *\n * @param headers - Map of unprefixed CORS header names to their values.\n * Defaults to an empty object (no CORS headers added).\n */\nexport function cors(headers: Record<string, string> = {}): Middleware {\n return (result) => {\n const corsHeaders: Record<string, string> = {}\n for (const [key, value] of Object.entries(headers)) {\n corsHeaders[`Access-Control-${key}`] = value\n }\n return {...result, headers: {...result.headers, ...corsHeaders}}\n }\n}\n\n/**\n * Folds all middlewares registered on `route` over `result`, applying them\n * left-to-right, and returns the final {@link APIGatewayProxyResult}.\n */\nexport function applyMiddlewares(\n result: APIGatewayProxyResult,\n route: RouteHandler,\n): APIGatewayProxyResult {\n return route.middlewares.reduce((r, middleware) => middleware(r), result)\n}\n"
5
+ "import type {APIGatewayProxyResult} from \"aws-lambda\"\n\nimport {RouteHandler} from \"./route-handler\"\n\n/**\n * A pure function that receives an {@link APIGatewayProxyResult} and returns\n * a (possibly modified) copy of it. Middlewares are composed left-to-right\n * by {@link dispatch}.\n */\nexport type Middleware = (result: APIGatewayProxyResult) => APIGatewayProxyResult\n\n/**\n * Unprefixed CORS header names accepted by {@link cors}.\n * Each key is prefixed with `\"Access-Control-\"` in the response.\n */\nexport type CorsHeaders = Partial<\n Record<\n | \"Allow-Origin\"\n | \"Allow-Methods\"\n | \"Allow-Headers\"\n | \"Allow-Credentials\"\n | \"Expose-Headers\"\n | \"Max-Age\"\n | \"Request-Headers\"\n | \"Request-Method\",\n string\n >\n>\n\n/**\n * Creates a middleware that injects CORS response headers.\n *\n * Each key in `headers` is prefixed with `\"Access-Control-\"` before being\n * merged into the response, so passing `{\"Allow-Origin\": \"*\"}` produces the\n * `Access-Control-Allow-Origin: *` header.\n *\n * @param headers - Map of unprefixed CORS header names to their values.\n * Defaults to an empty object (no CORS headers added).\n */\nexport function cors(headers: CorsHeaders = {}): Middleware {\n return (result) => {\n const corsHeaders: Record<string, string> = {}\n for (const [key, value] of Object.entries(headers)) {\n corsHeaders[`Access-Control-${key}`] = value\n }\n return {...result, headers: {...result.headers, ...corsHeaders}}\n }\n}\n\n/**\n * Folds all middlewares registered on `route` over `result`, applying them\n * left-to-right, and returns the final {@link APIGatewayProxyResult}.\n */\nexport function applyMiddlewares(\n result: APIGatewayProxyResult,\n route: RouteHandler,\n): APIGatewayProxyResult {\n return route.middlewares.reduce((r, middleware) => middleware(r), result)\n}\n"
6
6
  ],
7
- "mappings": ";AAqBO,SAAS,IAAI,CAAC,UAAkC,CAAC,GAAe;AAAA,EACnE,OAAO,CAAC,WAAW;AAAA,IACf,MAAM,cAAsC,CAAC;AAAA,IAC7C,YAAY,KAAK,UAAU,OAAO,QAAQ,OAAO,GAAG;AAAA,MAChD,YAAY,kBAAkB,SAAS;AAAA,IAC3C;AAAA,IACA,OAAO,KAAI,QAAQ,SAAS,KAAI,OAAO,YAAY,YAAW,EAAC;AAAA;AAAA;AAQhE,SAAS,gBAAgB,CAC5B,QACA,OACqB;AAAA,EACrB,OAAO,MAAM,YAAY,OAAO,CAAC,GAAG,eAAe,WAAW,CAAC,GAAG,MAAM;AAAA;",
7
+ "mappings": ";AAuCO,SAAS,IAAI,CAAC,UAAuB,CAAC,GAAe;AAAA,EACxD,OAAO,CAAC,WAAW;AAAA,IACf,MAAM,cAAsC,CAAC;AAAA,IAC7C,YAAY,KAAK,UAAU,OAAO,QAAQ,OAAO,GAAG;AAAA,MAChD,YAAY,kBAAkB,SAAS;AAAA,IAC3C;AAAA,IACA,OAAO,KAAI,QAAQ,SAAS,KAAI,OAAO,YAAY,YAAW,EAAC;AAAA;AAAA;AAQhE,SAAS,gBAAgB,CAC5B,QACA,OACqB;AAAA,EACrB,OAAO,MAAM,YAAY,OAAO,CAAC,GAAG,eAAe,WAAW,CAAC,GAAG,MAAM;AAAA;",
8
8
  "debugId": "235C7399F968D7AF64756E2164756E21",
9
9
  "names": []
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-reactor",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "scripts": {
5
5
  "prepare": "lefthook install",
6
6
  "check": "tsgo",