@trayio/cdk-runtime 5.6.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;
|
|
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;AAY7D,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,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.
|
|
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
|
},
|
|
@@ -453,7 +455,7 @@ describe('OperationExecutionGateway', () => {
|
|
|
453
455
|
.finallyDoNothing())
|
|
454
456
|
.nothingAfterAll());
|
|
455
457
|
});
|
|
456
|
-
describe('post multipart (with file)', () => {
|
|
458
|
+
describe.skip('post multipart (with file)', () => {
|
|
457
459
|
const multipartOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
|
|
458
460
|
.post('http://localhost:3000/multipart-upload')
|
|
459
461
|
.handleRequest((_ctx, _input, request) => request.withBodyAsMultipart({
|
|
@@ -463,7 +465,7 @@ describe('OperationExecutionGateway', () => {
|
|
|
463
465
|
files: {
|
|
464
466
|
'test-image': {
|
|
465
467
|
name: 'testImage.png',
|
|
466
|
-
url: 'https://
|
|
468
|
+
url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/Wikipedia-logo-transparent.png/526px-Wikipedia-logo-transparent.png',
|
|
467
469
|
mime_type: 'image/png',
|
|
468
470
|
expires: 0,
|
|
469
471
|
},
|
|
@@ -514,12 +516,12 @@ describe('OperationExecutionGateway', () => {
|
|
|
514
516
|
.finallyDoNothing())
|
|
515
517
|
.nothingAfterAll());
|
|
516
518
|
});
|
|
517
|
-
describe('upload an image', () => {
|
|
519
|
+
describe.skip('upload an image', () => {
|
|
518
520
|
const uploadImageOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
|
|
519
521
|
.post('http://localhost:3000/image-upload')
|
|
520
522
|
.handleRequest((ctx, input, request) => request.withBodyAsFile({
|
|
521
523
|
name: 'test-image',
|
|
522
|
-
url: 'https://
|
|
524
|
+
url: 'https://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg',
|
|
523
525
|
mime_type: 'image/svg+xml',
|
|
524
526
|
expires: 0,
|
|
525
527
|
}))
|
|
@@ -538,7 +540,7 @@ describe('OperationExecutionGateway', () => {
|
|
|
538
540
|
.finallyDoNothing())
|
|
539
541
|
.nothingAfterAll());
|
|
540
542
|
});
|
|
541
|
-
describe('download a file', () => {
|
|
543
|
+
describe.skip('download a file', () => {
|
|
542
544
|
const downloadFileOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
|
|
543
545
|
.get('https://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg')
|
|
544
546
|
.handleRequest((ctx, input, request) => request.withoutBody())
|
|
@@ -579,30 +581,62 @@ describe('OperationExecutionGateway', () => {
|
|
|
579
581
|
.finallyDoNothing())
|
|
580
582
|
.nothingAfterAll());
|
|
581
583
|
});
|
|
582
|
-
describe('
|
|
583
|
-
|
|
584
|
-
.
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
.
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
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.
|
|
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.
|
|
18
|
-
"@trayio/cdk-dsl": "5.
|
|
19
|
-
"@trayio/express": "5.
|
|
20
|
-
"@trayio/winston": "5.
|
|
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
|
},
|