unnbound-events 1.0.17 → 1.0.19

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
@@ -160,7 +160,17 @@ interface QueueEnvelope {
160
160
 
161
161
  The SDK supports automatic handling of large payloads (>256KB) stored in S3, which is necessary since SQS has a 256KB message size limit.
162
162
 
163
- ### Configuration
163
+ The S3 SDK (`@aws-sdk/client-s3`) is included as a dependency, so no additional installation is required.
164
+
165
+ ### Automatic Configuration
166
+
167
+ The SDK will automatically enable S3 support when environment variables are set:
168
+
169
+ - `UNNBOUND_S3_PAYLOAD_BUCKET` or `S3_BUCKET` - S3 bucket name for payload storage
170
+
171
+ No code changes needed! Just set the environment variable and the SDK will handle S3 payloads automatically.
172
+
173
+ ### Manual Configuration
164
174
 
165
175
  Configure S3 support when starting the client:
166
176
 
@@ -191,14 +201,19 @@ await client.sqsListen({
191
201
  The SDK supports two S3 payload formats:
192
202
 
193
203
  1. **ExtendedSQSClient Pointer Format** (AWS Extended Client Library compatible):
204
+
194
205
  ```json
195
- ["software.amazon.payloadoffloading.PayloadS3Pointer", {
196
- "s3BucketName": "bucket-name",
197
- "s3Key": "key-path"
198
- }]
206
+ [
207
+ "software.amazon.payloadoffloading.PayloadS3Pointer",
208
+ {
209
+ "s3BucketName": "bucket-name",
210
+ "s3Key": "key-path"
211
+ }
212
+ ]
199
213
  ```
200
214
 
201
215
  2. **Envelope-based S3 Payloads** (Unnbound format):
216
+
202
217
  ```json
203
218
  {
204
219
  "payload": {
@@ -220,6 +235,7 @@ The SDK supports two S3 payload formats:
220
235
  ### Compression Support
221
236
 
222
237
  The SDK automatically decompresses payloads with:
238
+
223
239
  - `brotli` compression
224
240
  - `gzip` compression
225
241
 
@@ -48,17 +48,7 @@ exports.shouldIgnorePath = shouldIgnorePath;
48
48
  exports.defaultIgnoreTraceRoutes = ['/health', '/healthcheck'];
49
49
  // Helper function to create S3 client
50
50
  function createS3Client(options) {
51
- const awsS3 = (() => {
52
- try {
53
- return require('@aws-sdk/client-s3');
54
- }
55
- catch {
56
- return null;
57
- }
58
- })();
59
- if (!awsS3) {
60
- throw new Error('@aws-sdk/client-s3 is required for S3 payload support');
61
- }
51
+ const awsS3 = require('@aws-sdk/client-s3');
62
52
  const env = globalThis.process
63
53
  ?.env ?? {};
64
54
  const region = options.region || env.AWS_REGION || 'us-east-1';
@@ -76,7 +66,7 @@ async function fetchS3Payload(s3Client, bucket, key, versionId) {
76
66
  params.VersionId = versionId;
77
67
  }
78
68
  try {
79
- const response = await s3Client.send(new awsS3.GetObjectCommand(params));
69
+ const response = (await s3Client.send(new awsS3.GetObjectCommand(params)));
80
70
  const body = response.Body;
81
71
  // Convert stream to string
82
72
  const chunks = [];
@@ -353,7 +343,8 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
353
343
  try {
354
344
  const parsed = JSON.parse(recordBody);
355
345
  // Detect S3 pointer format: ["software.amazon.payloadoffloading.PayloadS3Pointer", {...}]
356
- if (Array.isArray(parsed) && parsed.length === 2 &&
346
+ if (Array.isArray(parsed) &&
347
+ parsed.length === 2 &&
357
348
  parsed[0] === 'software.amazon.payloadoffloading.PayloadS3Pointer') {
358
349
  const pointer = parsed[1];
359
350
  if (!s3Client) {
@@ -373,7 +364,8 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
373
364
  throw error;
374
365
  }
375
366
  // Check if envelope payload is stored in S3
376
- if (envelope.payload.type === 's3-single' || envelope.payload.type === 's3-multipart') {
367
+ if (envelope.payload.type === 's3-single' ||
368
+ envelope.payload.type === 's3-multipart') {
377
369
  if (!envelope.payload.location) {
378
370
  throw new Error(`Payload type is ${envelope.payload.type} but no location specified`);
379
371
  }
@@ -383,7 +375,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
383
375
  unnbound_logger_sdk_1.logger.info({
384
376
  type: envelope.payload.type,
385
377
  bucket: envelope.payload.location.bucket,
386
- key: envelope.payload.location.key
378
+ key: envelope.payload.location.key,
387
379
  }, 'Fetching S3 envelope payload');
388
380
  let payloadData = await fetchS3Payload(s3Client, envelope.payload.location.bucket, envelope.payload.location.key, envelope.payload.location.versionId);
389
381
  // Handle decompression if needed
@@ -466,18 +458,18 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
466
458
  };
467
459
  },
468
460
  sqsListen(options) {
469
- // Initialize S3 client if options provided
470
- if (options?.s3) {
471
- s3Options = options.s3;
472
- const env = globalThis
473
- .process?.env ?? {};
474
- const bucketName = options.s3.bucketName || env.UNNBOUND_S3_PAYLOAD_BUCKET || env.S3_BUCKET;
461
+ // Initialize S3 client if options provided OR if environment variables are set
462
+ const env = globalThis
463
+ .process?.env ?? {};
464
+ const bucketName = options?.s3?.bucketName || env.UNNBOUND_S3_PAYLOAD_BUCKET || env.S3_BUCKET;
465
+ if (bucketName || options?.s3) {
466
+ s3Options = options?.s3 || {};
475
467
  if (!bucketName) {
476
468
  unnbound_logger_sdk_1.logger.warn('S3 options provided but no bucket name specified. S3 payload support disabled.');
477
469
  }
478
470
  else {
479
471
  try {
480
- s3Client = createS3Client({ ...options.s3, bucketName });
472
+ s3Client = createS3Client({ ...s3Options, bucketName });
481
473
  unnbound_logger_sdk_1.logger.info({ bucket: bucketName }, 'S3 client initialized for payload offloading');
482
474
  }
483
475
  catch (error) {
@@ -498,8 +490,6 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
498
490
  if (!awsSqs) {
499
491
  throw new Error('@aws-sdk/client-sqs is required to use sqsListen');
500
492
  }
501
- const env = globalThis
502
- .process?.env ?? {};
503
493
  const queueUrl = options?.queueUrl || env.UNNBOUND_SQS_QUEUE_URL || env.SQS_QUEUE_URL || env.QUEUE_URL;
504
494
  if (!queueUrl || queueUrl === undefined) {
505
495
  throw new Error('SQS queue URL not provided. Set UNNBOUND_SQS_QUEUE_URL, SQS_QUEUE_URL env or pass options.queueUrl');
@@ -581,9 +571,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
581
571
  const httpOptions = options?.http ?? { port: 3000 };
582
572
  const sqsOptions = options?.sqs ?? {};
583
573
  // Pass S3 options through to SQS listener if provided
584
- const sqsListenOptions = options?.s3
585
- ? { ...sqsOptions, s3: options.s3 }
586
- : sqsOptions;
574
+ const sqsListenOptions = options?.s3 ? { ...sqsOptions, s3: options.s3 } : sqsOptions;
587
575
  // Start HTTP server
588
576
  let httpServer;
589
577
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unnbound-events",
3
3
  "description": "Unified events SDK to handle HTTP routes and SQS messages with a single routing API.",
4
- "version": "1.0.17",
4
+ "version": "1.0.19",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
@@ -33,18 +33,15 @@
33
33
  "dependencies": {
34
34
  "express": "^4.0.0 || ^5.0.0",
35
35
  "@aws-sdk/client-sqs": "^3.0.0",
36
+ "@aws-sdk/client-s3": "^3.0.0",
36
37
  "unnbound-logger-sdk": "^3.0.22"
37
38
  },
38
39
  "peerDependencies": {
39
- "express": "^4.0.0 || ^5.0.0",
40
- "@aws-sdk/client-s3": "^3.0.0"
40
+ "express": "^4.0.0 || ^5.0.0"
41
41
  },
42
42
  "peerDependenciesMeta": {
43
43
  "express": {
44
44
  "optional": true
45
- },
46
- "@aws-sdk/client-s3": {
47
- "optional": true
48
45
  }
49
46
  },
50
47
  "devDependencies": {