@trayio/cdk-runtime 2.8.0 → 2.10.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.
@@ -21,6 +21,7 @@ export declare class HttpOperationExecution<AUTH extends OperationHandlerAuth<un
21
21
  private parseBodyAsJson;
22
22
  private parseEmptyBody;
23
23
  private parseBodyAsFile;
24
- private parseeBodyAsText;
24
+ private parseBodyAsText;
25
+ private generateUploadOptions;
25
26
  }
26
27
  //# sourceMappingURL=HttpOperationExecution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HttpOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/HttpOperationExecution.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EAGtB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAEN,oBAAoB,EAKpB,MAAM,0DAA0D,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAe7D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,qBAAa,sBAAsB,CAClC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EACnD,EAAE,EACF,GAAG,CACF,YAAW,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAE7C,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,WAAW,CAAc;gBAGhC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,oBAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAQvC,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GAC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,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAiDvC,OAAO,CAAC,6BAA6B;IA2BrC,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,aAAa;IAiCrB,OAAO,CAAC,eAAe;IAmBvB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,eAAe;IA2CvB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,qBAAqB;CAwC7B"}
@@ -44,6 +44,7 @@ const O = __importStar(require("fp-ts/Option"));
44
44
  const function_1 = require("fp-ts/function");
45
45
  const BufferExtensions_1 = require("@trayio/commons/buffer/BufferExtensions");
46
46
  const mime = require('mime');
47
+ const { AWS_LAMBDA_FUNCTION_MEMORY_SIZE, CONNECTOR_MAX_ALLOCATED_RAM_MB } = process.env;
47
48
  class HttpOperationExecution {
48
49
  constructor(httpClient, fileStorage, handler) {
49
50
  this.jsonSerialization = new JsonSerialization_1.JsonSerialization();
@@ -131,7 +132,7 @@ class HttpOperationExecution {
131
132
  case Http_1.HttpContentType.MultipartRequestBody:
132
133
  return TE.right(OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(`Invalid Response Type ${contentType}`)));
133
134
  case Http_1.HttpContentType.Text:
134
- return this.parseeBodyAsText(operationResponse);
135
+ return this.parseBodyAsText(operationResponse);
135
136
  default:
136
137
  return this.parseBodyAsJson(operationResponse);
137
138
  }
@@ -148,18 +149,19 @@ class HttpOperationExecution {
148
149
  return TE.right(operationResponse.responseParser(undefined));
149
150
  }
150
151
  parseBodyAsFile(operationResponse) {
151
- var _a;
152
152
  const contentType = (operationResponse.response.headers[Http_1.HttpHeader.ContentType.toLowerCase()]);
153
153
  const fileExtension = mime.getExtension(contentType);
154
+ const contentLength = (operationResponse.response.headers[Http_1.HttpHeader.ContentLength.toLowerCase()]);
155
+ const uploadOptions = this.generateUploadOptions(contentLength);
154
156
  return (0, function_1.pipe)(this.fileStorage.write({
155
157
  content: operationResponse.response.body,
156
158
  key: fileExtension ? `${(0, uuid_1.v4)()}.${fileExtension}` : (0, uuid_1.v4)(),
157
159
  metadata: {
158
160
  name: (0, uuid_1.v4)(),
159
- size: parseFloat((_a = (operationResponse.response.headers[Http_1.HttpHeader.ContentLength.toLowerCase()])) !== null && _a !== void 0 ? _a : undefined),
161
+ size: parseFloat(contentLength !== null && contentLength !== void 0 ? contentLength : undefined),
160
162
  contentType,
161
163
  },
162
- }), TE.chain((file) => (0, function_1.pipe)(this.fileStorage.getSharedUrl(file.key), TE.map((sharedUrl) => {
164
+ }, O.some(uploadOptions)), TE.chain((file) => (0, function_1.pipe)(this.fileStorage.getSharedUrl(file.key), TE.map((sharedUrl) => {
163
165
  var _a, _b;
164
166
  return operationResponse.responseParser({
165
167
  name: file.metadata.name,
@@ -169,12 +171,43 @@ class HttpOperationExecution {
169
171
  });
170
172
  }))));
171
173
  }
172
- parseeBodyAsText(operationResponse) {
174
+ parseBodyAsText(operationResponse) {
173
175
  const arrayBufferTE = BufferExtensions_1.BufferExtensions.readableToArrayBuffer(operationResponse.response.body);
174
176
  return (0, function_1.pipe)(arrayBufferTE, TE.chain((arrayBuffer) => {
175
177
  const deserializeBody = new TextDecoder().decode(arrayBuffer);
176
178
  return TE.right(operationResponse.responseParser(deserializeBody));
177
179
  }));
178
180
  }
181
+ // This method is used to respect lambda memory limits as per the old falfel implementation
182
+ generateUploadOptions(contentLength) {
183
+ const allocatedRam = AWS_LAMBDA_FUNCTION_MEMORY_SIZE || CONNECTOR_MAX_ALLOCATED_RAM_MB;
184
+ const availableRAM = allocatedRam ? parseInt(allocatedRam, 10) : 128; // 128MB default
185
+ const uploadMinSize = 1024 * 1024 * 8, // 8MB
186
+ maxRam = 1024 * 1024 * availableRAM;
187
+ /*
188
+ 128 / 16 = 8 (which is UPLOAD_MIN_SIZE)
189
+ TARGET_SIZE should either be 8MB (since default assumed RAM is 128MB) or
190
+ 1/16 of of the availableRAM, which ever is greater. The TARGET_SIZE, set
191
+ as `partSize`, will always be used in conjuction with `queueSize`.
192
+ */
193
+ const sixteenthOfRAM = Math.floor(maxRam / 16);
194
+ const targetSize = sixteenthOfRAM < uploadMinSize ? uploadMinSize : sixteenthOfRAM;
195
+ const uploadOptions = {
196
+ // 8MB (minimum) * 4 parallel = upto 32MB/s RAM usage
197
+ partSize: targetSize,
198
+ queueSize: 4,
199
+ acl: 'bucket-owner-full-control',
200
+ };
201
+ if (!contentLength) {
202
+ if (CONNECTOR_MAX_ALLOCATED_RAM_MB) {
203
+ uploadOptions.queueSize = 12;
204
+ }
205
+ }
206
+ else if (parseInt(contentLength, 10) > targetSize &&
207
+ parseInt(contentLength, 10) > targetSize * 8) {
208
+ uploadOptions.queueSize = 12;
209
+ }
210
+ return uploadOptions;
211
+ }
179
212
  }
180
213
  exports.HttpOperationExecution = HttpOperationExecution;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-runtime",
3
- "version": "2.8.0",
3
+ "version": "2.10.0",
4
4
  "description": "A Runtime that executes connector operations defined using the CDK DSL",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -14,10 +14,10 @@
14
14
  "node": ">=18.x"
15
15
  },
16
16
  "dependencies": {
17
- "@trayio/axios": "2.8.0",
18
- "@trayio/cdk-dsl": "2.8.0",
19
- "@trayio/express": "2.8.0",
20
- "@trayio/winston": "2.8.0",
17
+ "@trayio/axios": "2.10.0",
18
+ "@trayio/cdk-dsl": "2.10.0",
19
+ "@trayio/express": "2.10.0",
20
+ "@trayio/winston": "2.10.0",
21
21
  "mime": "3.0.0",
22
22
  "uuid": "9.0.0"
23
23
  },