@vyriy/handler 0.6.0 → 0.6.6

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
@@ -168,6 +168,16 @@ export const handler = schedule(async (event) => {
168
168
  });
169
169
  ```
170
170
 
171
+ Use a prebuilt EventBridge custom event handler chain:
172
+
173
+ ```ts
174
+ import { eventBridge } from '@vyriy/handler';
175
+
176
+ export const handler = eventBridge(async (event) => {
177
+ console.info('EventBridge event:', event.source, event['detail-type'], event.detail);
178
+ });
179
+ ```
180
+
171
181
  Compose a custom handler pipeline from individual helpers:
172
182
 
173
183
  ```ts
@@ -232,6 +242,9 @@ export const handler = compose(
232
242
  - `dynamodb`
233
243
  DynamoDB Streams chain with logging, timeout handling, context setup, smoke checks, and rethrown errors.
234
244
 
245
+ - `eventBridge`
246
+ EventBridge custom event chain with logging, timeout handling, context setup, smoke checks, and rethrown errors.
247
+
235
248
  - `s3`
236
249
  S3 event chain with logging, timeout handling, context setup, smoke checks, and rethrown errors.
237
250
 
package/api.js CHANGED
@@ -9,16 +9,16 @@ import { streamWithHeaders, withHeaders } from './wrapper/headers.js';
9
9
  import { streamWithCors, withCors } from './wrapper/cors.js';
10
10
  import { streamWithChaos, withChaos } from './wrapper/chaos.js';
11
11
  export const api = compose(withApiError(), withLogger(), withTimeout(), withContext(), withSmoke(), withHealthcheck(), withHeaders({
12
- 'Access-Control-Allow-Origin': '*',
13
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
14
- 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-Api-Key, Accept, User-Agent, X-CSRF-Token',
15
- 'Content-Type': 'application/json',
16
- 'X-Robots-Tag': 'noindex, nofollow',
12
+ 'access-control-allow-origin': '*',
13
+ 'access-control-allow-methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
14
+ 'access-control-allow-headers': 'Content-Type, Authorization, X-Requested-With, X-Api-Key, Accept, User-Agent, X-CSRF-Token',
15
+ 'content-type': 'application/json',
16
+ 'x-robots-tag': 'noindex, nofollow',
17
17
  }), withCors(), withChaos());
18
18
  export const streamApi = streamCompose(streamWithApiError(), streamWithLogger(), streamWithTimeout(), streamWithContext(), streamWithSmoke(), streamWithHealthcheck(), streamWithHeaders({
19
- 'Access-Control-Allow-Origin': '*',
20
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
21
- 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-Api-Key, Accept, User-Agent, X-CSRF-Token',
22
- 'Content-Type': 'application/json',
23
- 'X-Robots-Tag': 'noindex, nofollow',
19
+ 'access-control-allow-origin': '*',
20
+ 'access-control-allow-methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
21
+ 'access-control-allow-headers': 'Content-Type, Authorization, X-Requested-With, X-Api-Key, Accept, User-Agent, X-CSRF-Token',
22
+ 'content-type': 'application/json',
23
+ 'x-robots-tag': 'noindex, nofollow',
24
24
  }), streamWithCors(), streamWithChaos());
@@ -0,0 +1,2 @@
1
+ import type { EventBridgeEvent } from 'aws-lambda';
2
+ export declare const eventBridge: import("./types.js").Decorator<EventBridgeEvent<string, unknown>, void>;
package/eventBridge.js ADDED
@@ -0,0 +1,7 @@
1
+ import { compose } from './compose.js';
2
+ import { withError } from './wrapper/error.js';
3
+ import { withLogger } from './wrapper/logger.js';
4
+ import { withTimeout } from './wrapper/timeout.js';
5
+ import { withContext } from './wrapper/context.js';
6
+ import { withSmoke } from './wrapper/smoke.js';
7
+ export const eventBridge = compose(withError(), withLogger(), withTimeout(), withContext(), withSmoke());
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './api.js';
2
2
  export * from './compose.js';
3
3
  export * from './dynamodb.js';
4
+ export * from './eventBridge.js';
4
5
  export * from './factory.js';
5
6
  export * from './s3.js';
6
7
  export * from './schedule.js';
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './api.js';
2
2
  export * from './compose.js';
3
3
  export * from './dynamodb.js';
4
+ export * from './eventBridge.js';
4
5
  export * from './factory.js';
5
6
  export * from './s3.js';
6
7
  export * from './schedule.js';
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@vyriy/handler",
3
- "version": "0.6.0",
3
+ "version": "0.6.6",
4
4
  "description": "Composable AWS Lambda handler chains and wrappers for Vyriy projects",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@types/aws-lambda": "^8.10.161",
8
- "@vyriy/chaos": "0.6.0",
9
- "@vyriy/config": "0.6.0",
10
- "@vyriy/logger": "0.6.0",
11
- "@vyriy/smoke": "0.6.0",
12
- "@vyriy/timeout": "0.6.0"
7
+ "@types/aws-lambda": "^8.10.162",
8
+ "@vyriy/chaos": "0.6.6",
9
+ "@vyriy/config": "0.6.6",
10
+ "@vyriy/logger": "0.6.6",
11
+ "@vyriy/smoke": "0.6.6",
12
+ "@vyriy/timeout": "0.6.6"
13
13
  },
14
14
  "agents": "./AGENTS.md",
15
15
  "license": "MIT",
@@ -56,6 +56,16 @@
56
56
  "import": "./dynamodb.js",
57
57
  "default": "./dynamodb.js"
58
58
  },
59
+ "./eventBridge": {
60
+ "types": "./eventBridge.d.ts",
61
+ "import": "./eventBridge.js",
62
+ "default": "./eventBridge.js"
63
+ },
64
+ "./eventBridge.js": {
65
+ "types": "./eventBridge.d.ts",
66
+ "import": "./eventBridge.js",
67
+ "default": "./eventBridge.js"
68
+ },
59
69
  "./factory": {
60
70
  "types": "./factory.d.ts",
61
71
  "import": "./factory.js",
@@ -1,9 +1,10 @@
1
1
  import { factory, streamFactory } from '../factory.js';
2
2
  import { responseStream } from './stream.js';
3
+ const normalizeHeaders = (headers) => Object.fromEntries(Object.entries(headers ?? {}).map(([key, value]) => [key.toLowerCase(), value]));
3
4
  const mergeHeaders = (result, options) => {
4
5
  result.headers = {
5
- ...options,
6
- ...result.headers,
6
+ ...normalizeHeaders(options),
7
+ ...normalizeHeaders(result.headers),
7
8
  };
8
9
  return result;
9
10
  };
@@ -13,5 +14,5 @@ export const withHeaders = factory(async (handler, args, options = {}) => {
13
14
  });
14
15
  export const streamWithHeaders = streamFactory(async (handler, args, options = {}) => {
15
16
  const [event, stream, context] = args;
16
- await handler(event, responseStream(stream, { headers: options }), context);
17
+ await handler(event, responseStream(stream, { headers: normalizeHeaders(options) }), context);
17
18
  });
package/wrapper/stream.js CHANGED
@@ -1,4 +1,7 @@
1
- const getContentType = (headers) => headers?.['content-type'] ?? headers?.['Content-Type'];
1
+ const getContentType = (headers) => {
2
+ const contentType = Object.entries(headers ?? {}).find(([key]) => key.toLowerCase() === 'content-type')?.[1];
3
+ return typeof contentType === 'string' ? contentType : undefined;
4
+ };
2
5
  export const responseStream = (stream, metadata = {}) => {
3
6
  const runtimeStream = globalThis.awslambda?.HttpResponseStream?.from?.(stream, {
4
7
  headers: metadata.headers,
@@ -9,7 +12,7 @@ export const responseStream = (stream, metadata = {}) => {
9
12
  }
10
13
  const contentType = getContentType(metadata.headers);
11
14
  if (contentType) {
12
- stream.setContentType?.(String(contentType));
15
+ stream.setContentType?.(contentType);
13
16
  }
14
17
  return stream;
15
18
  };