idea-aws 4.5.1 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/s3.d.ts CHANGED
@@ -40,6 +40,7 @@ export declare class S3 {
40
40
  getObjectAsJSON(options: GetObjectOptions): Promise<any>;
41
41
  /**
42
42
  * Get an object from a S3 bucket and convert the content to string.
43
+ * If the object was stored with `Content-Encoding: gzip`, it is decompressed transparently.
43
44
  */
44
45
  getObjectAsText(options: GetObjectOptions): Promise<string>;
45
46
  /**
@@ -83,6 +84,17 @@ export interface CreateDownloadURLFromDataOptions {
83
84
  * Content type, e.g. application/json; default: _guessed_.
84
85
  */
85
86
  contentType?: string;
87
+ /**
88
+ * If true, the body is gzipped with `Content-Encoding: gzip`. Browsers and `fetch` decompress transparently.
89
+ * Recommended for text/JSON payloads over ~50 KB; for already-compressed binaries (images, zip, etc.) leave it off.
90
+ * Only applied when `data` is a `string`, `Buffer`, or `Uint8Array`; silently ignored for other body types.
91
+ */
92
+ compress?: boolean;
93
+ /**
94
+ * Explicit `Content-Encoding` to store on the object (e.g., `'gzip'`, `'br'`).
95
+ * Use this when the body is already compressed. Ignored when `compress: true` (in that case `'gzip'` is forced).
96
+ */
97
+ contentEncoding?: string;
86
98
  /**
87
99
  * Seconds to URL expiration; default: `180`.
88
100
  */
@@ -179,6 +191,11 @@ export interface PutObjectOptions {
179
191
  * Content type (e.g. image/png).
180
192
  */
181
193
  contentType?: string;
194
+ /**
195
+ * `Content-Encoding` header to store on the object (e.g., `'gzip'`).
196
+ * The body is uploaded as-is; the caller is responsible for pre-compressing it.
197
+ */
198
+ contentEncoding?: string;
182
199
  /**
183
200
  * Access-control list (e.g. public-read).
184
201
  */
package/dist/src/s3.js CHANGED
@@ -34,8 +34,9 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.cleanFilename = exports.S3 = void 0;
37
+ const node_zlib_1 = require("node:zlib");
38
+ const node_util_1 = require("node:util");
37
39
  const AWSS3 = __importStar(require("@aws-sdk/client-s3"));
38
- const lib_storage_1 = require("@aws-sdk/lib-storage");
39
40
  const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
40
41
  const idea_toolbox_1 = require("idea-toolbox");
41
42
  const lambdaLogger_1 = require("./lambdaLogger");
@@ -62,9 +63,22 @@ class S3 {
62
63
  options.key = `${options.prefix ?? this.DEFAULT_DOWNLOAD_BUCKET_PREFIX}/${options.key}`;
63
64
  options.bucket = options.bucket ?? this.DEFAULT_DOWNLOAD_BUCKET;
64
65
  options.secToExp = options.secToExp ?? this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP;
65
- const params = { Bucket: options.bucket, Key: options.key, Body: data, ContentType: options.contentType };
66
- const upload = new lib_storage_1.Upload({ client: this.client, params });
67
- await upload.done();
66
+ let body = data;
67
+ let contentEncoding = options.contentEncoding;
68
+ if (options.compress && (typeof data === 'string' || data instanceof Uint8Array)) {
69
+ const gzip = (0, node_util_1.promisify)(node_zlib_1.gzip);
70
+ body = await gzip(data);
71
+ contentEncoding = 'gzip';
72
+ }
73
+ const params = {
74
+ Bucket: options.bucket,
75
+ Key: options.key,
76
+ Body: body,
77
+ ContentType: options.contentType
78
+ };
79
+ if (contentEncoding)
80
+ params.ContentEncoding = contentEncoding;
81
+ await this.client.send(new AWSS3.PutObjectCommand(params));
68
82
  return this.signedURLGet(options.bucket, options.key, { secToExp: options.secToExp, filename: options.filename });
69
83
  }
70
84
  /**
@@ -121,9 +135,15 @@ class S3 {
121
135
  }
122
136
  /**
123
137
  * Get an object from a S3 bucket and convert the content to string.
138
+ * If the object was stored with `Content-Encoding: gzip`, it is decompressed transparently.
124
139
  */
125
140
  async getObjectAsText(options) {
126
141
  const result = await this.getObject(options);
142
+ if (result.ContentEncoding === 'gzip') {
143
+ const gunzip = (0, node_util_1.promisify)(node_zlib_1.gunzip);
144
+ const compressed = await result.Body.transformToByteArray();
145
+ return (await gunzip(Buffer.from(compressed))).toString('utf-8');
146
+ }
127
147
  return await result.Body.transformToString('utf-8');
128
148
  }
129
149
  /**
@@ -133,6 +153,8 @@ class S3 {
133
153
  const params = { Bucket: options.bucket, Key: options.key, Body: options.body };
134
154
  if (options.contentType)
135
155
  params.ContentType = options.contentType;
156
+ if (options.contentEncoding)
157
+ params.ContentEncoding = options.contentEncoding;
136
158
  if (options.acl)
137
159
  params.ACL = options.acl;
138
160
  if (options.metadata)
@@ -1 +1 @@
1
- {"root":["../index.ts","../src/attachments.ts","../src/cognito.ts","../src/comprehend.ts","../src/dynamodb.ts","../src/genericcontroller.ts","../src/lambdalogger.ts","../src/metrics.ts","../src/resourcecontroller.ts","../src/s3.ts","../src/secretsmanager.ts","../src/ses.ts","../src/sns.ts","../src/ssm.ts","../src/streamcontroller.ts","../src/translate.ts"],"version":"5.8.3"}
1
+ {"root":["../index.ts","../src/attachments.ts","../src/cognito.ts","../src/comprehend.ts","../src/dynamodb.ts","../src/genericcontroller.ts","../src/lambdalogger.ts","../src/metrics.ts","../src/resourcecontroller.ts","../src/s3.ts","../src/secretsmanager.ts","../src/ses.ts","../src/sns.ts","../src/ssm.ts","../src/streamcontroller.ts","../src/translate.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "4.5.1",
3
+ "version": "4.6.0",
4
+ "engines": {
5
+ "node": ">=24.0.0"
6
+ },
4
7
  "description": "AWS wrappers to use in IDEA's back-ends",
5
8
  "license": "MPL-2.0",
6
9
  "main": "dist/index.js",
@@ -39,9 +42,9 @@
39
42
  "dependencies": {
40
43
  "@aws-lambda-powertools/metrics": "^2.24.0",
41
44
  "@aws-lambda-powertools/tracer": "^2.24.0",
42
- "idea-toolbox": "^7.1.10",
45
+ "idea-toolbox": "^7.3.0",
43
46
  "nanoid": "^3.3.7",
44
- "nodemailer": "^7.0.5",
47
+ "nodemailer": "^8.0.11",
45
48
  "source-map-support": "^0.5.21"
46
49
  },
47
50
  "peerDependencies": {
@@ -62,14 +65,14 @@
62
65
  "@aws-sdk/util-dynamodb": "^3.848.0"
63
66
  },
64
67
  "devDependencies": {
65
- "@tsconfig/node22": "^22.0.2",
68
+ "@tsconfig/node24": "^24.0.4",
66
69
  "@types/aws-lambda": "^8.10.152",
67
- "@types/node": "^22.16.5",
70
+ "@types/node": "^24.13.2",
68
71
  "@types/nodemailer": "^6.4.17",
69
- "@typescript-eslint/eslint-plugin": "^8.38.0",
70
- "@typescript-eslint/parser": "^8.38.0",
72
+ "@typescript-eslint/eslint-plugin": "^8.39.0",
73
+ "@typescript-eslint/parser": "^8.39.0",
71
74
  "eslint": "^9.32.0",
72
- "typedoc": "^0.28.8",
73
- "typescript": "^5.8.3"
75
+ "typedoc": "^0.28.19",
76
+ "typescript": "^5.9.3"
74
77
  }
75
78
  }