@trayio/cdk-runtime 4.56.0 → 4.58.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.
@@ -1 +1 @@
1
- {"version":3,"file":"HttpOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/HttpOperationExecution.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAOlC,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EAGtB,oBAAoB,EACpB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAGN,oBAAoB,EAMpB,MAAM,0DAA0D,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAW7D,OAAO,EAAQ,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2DAA2D,CAAC;AAGtG,OAAO,0BAA0B,MAAM,8BAA8B,CAAC;AAOtE,qBAAa,sBAAsB,CAClC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EACnD,EAAE,EACF,GAAG,CACF,SAAQ,0BAA0B,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAClD,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,mBAAmB,CAA4C;IACvE,WAAW,EAAE,oBAAoB,CAAC;gBAGjC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,oBAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAC5C,mBAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,EAC9D,WAAW,EAAE,oBAAoB;IAW5B,OAAO,CACZ,GAAG,EAAE,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7C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,mBAAmB,CAA4C;IACvE,WAAW,EAAE,oBAAoB,CAAC;gBAGjC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,oBAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAC5C,mBAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,EAC9D,WAAW,EAAE,oBAAoB;IAW5B,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAuDvC,OAAO,CAAC,eAAe;IAkCvB,OAAO,CAAC,6BAA6B;IAiCrC,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,yBAAyB;IAajC,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,oBAAoB;IA4E5B,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,kBAAkB;IA8B1B,OAAO,CAAC,aAAa;IAoDrB,OAAO,CAAC,eAAe;IAmBvB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,eAAe;IA8CvB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,qBAAqB;CAwC7B"}
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.HttpOperationExecution = void 0;
30
+ const stream_1 = require("stream");
30
31
  const TE = __importStar(require("fp-ts/TaskEither"));
31
32
  const E = __importStar(require("fp-ts/Either"));
32
33
  const O = __importStar(require("fp-ts/Option"));
@@ -122,29 +123,42 @@ class HttpOperationExecution extends AbstractOperationExecution_1.default {
122
123
  serializeAsMultipart(body) {
123
124
  const fileStreamsFromReferencesTasks = Object.keys(body.files).map((fileKey) => {
124
125
  const fileRef = body.files[fileKey];
125
- return (0, function_1.pipe)(this.httpClient.execute(Http_1.HttpMethod.Get, fileRef.url, Http_1.HttpRequest.create({
126
- headers: {},
127
- pathParams: {},
128
- queryString: {},
129
- body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
130
- })), TE.chain((response) => {
131
- if (response.statusCode >= 300) {
132
- return TE.left(Error('error downloading file from source'));
133
- }
134
- const parsedSized = Number.parseInt(response.headers.ContentLength ||
135
- response.headers['content-length'], 10);
136
- return TE.right({
137
- reference: {
138
- _tag: 'FileDescriptor',
139
- key: fileKey,
140
- metadata: {
141
- size: Number.isNaN(parsedSized) ? undefined : parsedSized,
142
- contentType: fileRef.mime_type,
126
+ if (fileRef.url) {
127
+ return (0, function_1.pipe)(this.httpClient.execute(Http_1.HttpMethod.Get, fileRef.url, Http_1.HttpRequest.create({
128
+ headers: {},
129
+ pathParams: {},
130
+ queryString: {},
131
+ body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
132
+ })), TE.chain((response) => {
133
+ if (response.statusCode >= 300) {
134
+ return TE.left(Error('error downloading file from source'));
135
+ }
136
+ const parsedSized = Number.parseInt(response.headers.ContentLength ||
137
+ response.headers['content-length'], 10);
138
+ return TE.right({
139
+ reference: {
140
+ _tag: 'FileDescriptor',
141
+ key: fileKey,
142
+ metadata: {
143
+ size: Number.isNaN(parsedSized) ? undefined : parsedSized,
144
+ contentType: fileRef.mime_type,
145
+ },
143
146
  },
147
+ content: response.body,
148
+ });
149
+ }));
150
+ }
151
+ return TE.right({
152
+ reference: {
153
+ _tag: 'FileDescriptor',
154
+ key: fileKey,
155
+ metadata: {
156
+ size: fileRef.content.length,
157
+ contentType: Http_1.HttpContentType.Text,
144
158
  },
145
- content: response.body,
146
- });
147
- }));
159
+ },
160
+ content: stream_1.Readable.from(fileRef.content),
161
+ });
148
162
  });
149
163
  const filesTask = (0, Array_1.sequence)(TE.MonadTask)(fileStreamsFromReferencesTasks);
150
164
  return (0, function_1.pipe)(filesTask, TE.map((files) => files.reduce((acc, file) => {
@@ -164,6 +164,26 @@ class TestControllerHttp {
164
164
  });
165
165
  },
166
166
  },
167
+ {
168
+ path: `/multipart-upload-plain-text`,
169
+ method: Http_1.HttpMethod.Post,
170
+ execute: () => (request) => {
171
+ const { body } = request;
172
+ expect(body).toEqual(expect.objectContaining({
173
+ fields: expect.objectContaining({ test: 'Hello world!' }),
174
+ files: expect.objectContaining({
175
+ 'test-text': expect.any(Object),
176
+ }),
177
+ }));
178
+ return T.of({
179
+ body: stream_1.Readable.from(JSON.stringify({
180
+ success: true,
181
+ })),
182
+ headers: {},
183
+ statusCode: 200,
184
+ });
185
+ },
186
+ },
167
187
  ];
168
188
  }
169
189
  const testHttpController = new ExpressHttpController_1.ExpressHttpController(new TestControllerHttp(), '/tmp', O.none);
@@ -455,6 +475,36 @@ describe('OperationExecutionGateway', () => {
455
475
  .finallyDoNothing())
456
476
  .nothingAfterAll());
457
477
  });
478
+ describe('post multipart (with plain text)', () => {
479
+ const multipartOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
480
+ .post('http://localhost:3000/multipart-upload-plain-text')
481
+ .handleRequest((_ctx, _input, request) => request.withBodyAsMultipart({
482
+ fields: {
483
+ test: 'Hello world!',
484
+ },
485
+ files: {
486
+ 'test-text': {
487
+ name: 'text.txt',
488
+ content: 'This is content to test the plain text upload with exactly 67 bytes',
489
+ expires: 0,
490
+ },
491
+ },
492
+ }))
493
+ .handleResponse((_ctx, _input, response) => response.parseWithBodyAsJson())));
494
+ OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(multipartOperation, (handlerTest) => handlerTest
495
+ .usingHandlerContext('test')
496
+ .nothingBeforeAll()
497
+ .testCase('should send a multipart body (both data and plain text)', (testCase) => testCase
498
+ .usingHandlerContext('test')
499
+ .givenNothing()
500
+ .when(() => ({}))
501
+ .then(({ output }) => {
502
+ const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
503
+ expect(outputValue.success).toEqual(true);
504
+ })
505
+ .finallyDoNothing())
506
+ .nothingAfterAll());
507
+ });
458
508
  describe('upload an image', () => {
459
509
  const uploadImageOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
460
510
  .post('http://localhost:3000/image-upload')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-runtime",
3
- "version": "4.56.0",
3
+ "version": "4.58.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": "4.56.0",
18
- "@trayio/cdk-dsl": "4.56.0",
19
- "@trayio/express": "4.56.0",
20
- "@trayio/winston": "4.56.0",
17
+ "@trayio/axios": "4.58.0",
18
+ "@trayio/cdk-dsl": "4.58.0",
19
+ "@trayio/express": "4.58.0",
20
+ "@trayio/winston": "4.58.0",
21
21
  "mime": "3.0.0",
22
22
  "uuid": "9.0.0"
23
23
  },