@trayio/cdk-runtime 5.7.0 → 5.8.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;AAMlC,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EAItB,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;AAEtG,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,u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C,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;IAWvB,OAAO,CAAC,oBAAoB;IA4E5B,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,kBAAkB;IAyC1B,OAAO,CAAC,aAAa;IAoDrB,OAAO,CAAC,eAAe;IAmBvB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,eAAe;IA8CvB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,qBAAqB;CAwC7B"}
@@ -192,7 +192,7 @@ class HttpOperationExecution extends AbstractOperationExecution_1.default {
192
192
  }));
193
193
  }
194
194
  parseErrorResponse(operationResponse) {
195
- return (0, function_1.pipe)(operationResponse.contentType, O.fold(() => this.parseEmptyBody(operationResponse), (contentType) => {
195
+ return (0, function_1.pipe)(operationResponse.errorContentType, O.fold(() => TE.right(undefined), (contentType) => {
196
196
  switch (contentType) {
197
197
  case Http_1.HttpContentType.Json:
198
198
  const bufferTE = BufferExtensions_1.BufferExtensions.readableToArrayBuffer(operationResponse.response.body);
@@ -200,6 +200,12 @@ class HttpOperationExecution extends AbstractOperationExecution_1.default {
200
200
  const deserializedBodyE = this.jsonSerialization.deserialize(buffer);
201
201
  return TE.fromEither(deserializedBodyE);
202
202
  }));
203
+ case Http_1.HttpContentType.Text:
204
+ const textBufferTE = BufferExtensions_1.BufferExtensions.readableToArrayBuffer(operationResponse.response.body);
205
+ return (0, function_1.pipe)(textBufferTE, TE.map((arrayBuffer) => {
206
+ const text = new TextDecoder().decode(arrayBuffer);
207
+ return text || undefined;
208
+ }));
203
209
  default:
204
210
  return TE.right(undefined);
205
211
  }
@@ -82,7 +82,9 @@ class TestControllerHttp {
82
82
  body: stream_1.Readable.from(JSON.stringify({
83
83
  message: 'Error message',
84
84
  })),
85
- headers: {},
85
+ headers: {
86
+ 'content-type': 'application/json',
87
+ },
86
88
  statusCode: 500,
87
89
  }),
88
90
  },
@@ -579,30 +581,62 @@ describe('OperationExecutionGateway', () => {
579
581
  .finallyDoNothing())
580
582
  .nothingAfterAll());
581
583
  });
582
- describe('it should an error using the body as the message', () => {
583
- const getProductOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
584
- .get('http://localhost:3000/error')
585
- .handleRequest((ctx, input, request) => request.addPathParameter('id', input.id.toString()).withoutBody())
586
- .handleResponse((ctx, input, response) => response
587
- .withJsonErrorHandling((errorResponse) => OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.apiError(errorResponse.message)))
588
- .parseWithBodyAsJson())));
589
- OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
590
- .usingHandlerContext('test')
591
- .nothingBeforeAll()
592
- .testCase('should get a error message from the body', (testCase) => testCase
593
- .usingHandlerContext('test')
594
- .givenNothing()
595
- .when(() => ({ id: 2 }))
596
- .then(({ output }) => {
597
- if (output.isFailure) {
598
- expect(output.error.message).toEqual('Error message');
599
- }
600
- else {
601
- fail('Expected output to be a failure');
602
- }
603
- })
604
- .finallyDoNothing())
605
- .nothingAfterAll());
584
+ describe('error handling with error body exposure', () => {
585
+ describe('withJsonErrorHandling should parse JSON error body', () => {
586
+ const getProductOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
587
+ .get('http://localhost:3000/error')
588
+ .handleRequest((ctx, input, request) => request.addPathParameter('id', input.id.toString()).withoutBody())
589
+ .handleResponse((ctx, input, response) => response
590
+ .withJsonErrorHandling((errorResponse) => OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.apiError(errorResponse.message)))
591
+ .parseWithBodyAsJson())));
592
+ OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
593
+ .usingHandlerContext('test')
594
+ .nothingBeforeAll()
595
+ .testCase('should get a error message from the body', (testCase) => testCase
596
+ .usingHandlerContext('test')
597
+ .givenNothing()
598
+ .when(() => ({ id: 2 }))
599
+ .then(({ output }) => {
600
+ if (output.isFailure) {
601
+ expect(output.error.message).toEqual('Error message');
602
+ }
603
+ else {
604
+ fail('Expected output to be a failure');
605
+ }
606
+ })
607
+ .finallyDoNothing())
608
+ .nothingAfterAll());
609
+ });
610
+ describe('withErrorHandling should auto-detect and expose error body', () => {
611
+ const getProductOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
612
+ .get('http://localhost:3000/error')
613
+ .handleRequest((ctx, input, request) => request.addPathParameter('id', input.id.toString()).withoutBody())
614
+ .handleResponse((ctx, input, response) => response
615
+ .withErrorHandling((errorBody) => OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.apiError(`API error with body: ${JSON.stringify(errorBody)}`, { body: errorBody })))
616
+ .parseWithBodyAsJson())));
617
+ OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
618
+ .usingHandlerContext('test')
619
+ .nothingBeforeAll()
620
+ .testCase('should auto-detect JSON content type and parse error body', (testCase) => testCase
621
+ .usingHandlerContext('test')
622
+ .givenNothing()
623
+ .when(() => ({ id: 2 }))
624
+ .then(({ output }) => {
625
+ if (output.isFailure) {
626
+ // Should have the error body in the response
627
+ expect(output.error.response?.body).toEqual({
628
+ message: 'Error message',
629
+ });
630
+ // Should have the error body in the message
631
+ expect(output.error.message).toContain('Error message');
632
+ }
633
+ else {
634
+ fail('Expected output to be a failure');
635
+ }
636
+ })
637
+ .finallyDoNothing())
638
+ .nothingAfterAll());
639
+ });
606
640
  });
607
641
  describe('should error for invalid operation response (i.e. not object)', () => {
608
642
  describe('http handler', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-runtime",
3
- "version": "5.7.0",
3
+ "version": "5.8.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": "5.7.0",
18
- "@trayio/cdk-dsl": "5.7.0",
19
- "@trayio/express": "5.7.0",
20
- "@trayio/winston": "5.7.0",
17
+ "@trayio/axios": "5.8.0",
18
+ "@trayio/cdk-dsl": "5.8.0",
19
+ "@trayio/express": "5.8.0",
20
+ "@trayio/winston": "5.8.0",
21
21
  "mime": "3.0.0",
22
22
  "uuid": "9.0.0"
23
23
  },