@trayio/cdk-runtime 3.15.0 → 3.17.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/connector/operation/HttpOperationExecution.d.ts +1 -0
- package/dist/connector/operation/HttpOperationExecution.d.ts.map +1 -1
- package/dist/connector/operation/HttpOperationExecution.js +16 -2
- package/dist/connector/operation/OperationExecutionGateway.unit.test.d.ts.map +1 -1
- package/dist/connector/operation/OperationExecutionGateway.unit.test.js +37 -0
- package/package.json +5 -5
|
@@ -23,6 +23,7 @@ export declare class HttpOperationExecution<AUTH extends OperationHandlerAuth<un
|
|
|
23
23
|
private serializeAsFile;
|
|
24
24
|
private serializeEmptyBody;
|
|
25
25
|
private defaultErrorHandling;
|
|
26
|
+
private parseErrorResponse;
|
|
26
27
|
private parseResponse;
|
|
27
28
|
private parseBodyAsJson;
|
|
28
29
|
private parseEmptyBody;
|
|
@@ -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;AAKlC,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;AACtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAO1D,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;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;IAU5B,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"HttpOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/HttpOperationExecution.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,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;AACtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAO1D,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;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;IAU5B,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;IAuD5B,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,kBAAkB;IA8B1B,OAAO,CAAC,aAAa;IAoCrB,OAAO,CAAC,eAAe;IAmBvB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,eAAe;IA2CvB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,qBAAqB;CAwC7B"}
|
|
@@ -63,7 +63,7 @@ class HttpOperationExecution {
|
|
|
63
63
|
const resultTE = this.httpClient.execute(operationRequest.method, operationRequest.path, httpRequestE.right);
|
|
64
64
|
const operationResponseTE = (0, function_1.pipe)(resultTE,
|
|
65
65
|
// get the dsl http response object
|
|
66
|
-
TE.map((response) => this.handler.responseHandler(ctx, input, new HttpOperationHandler_1.HttpOperationResponseBuilder(response, this.defaultErrorHandling(response.statusCode)))),
|
|
66
|
+
TE.map((response) => this.handler.responseHandler(ctx, input, new HttpOperationHandler_1.HttpOperationResponseBuilder(response, this.defaultErrorHandling(response.statusCode), O.none))),
|
|
67
67
|
// interpret the dsl response object by mapping the low level http response to a connector response
|
|
68
68
|
TE.chain((operationResponse) => this.parseResponse(operationResponse)),
|
|
69
69
|
// handle errors during the execution of the http request or parsing or the http response
|
|
@@ -170,9 +170,23 @@ class HttpOperationExecution {
|
|
|
170
170
|
statusCode,
|
|
171
171
|
}));
|
|
172
172
|
}
|
|
173
|
+
parseErrorResponse(operationResponse) {
|
|
174
|
+
return (0, function_1.pipe)(operationResponse.contentType, O.fold(() => this.parseEmptyBody(operationResponse), (contentType) => {
|
|
175
|
+
switch (contentType) {
|
|
176
|
+
case Http_1.HttpContentType.Json:
|
|
177
|
+
const bufferTE = BufferExtensions_1.BufferExtensions.readableToArrayBuffer(operationResponse.response.body);
|
|
178
|
+
return (0, function_1.pipe)(bufferTE, TE.chain((buffer) => {
|
|
179
|
+
const deserializedBodyE = this.jsonSerialization.deserialize(buffer);
|
|
180
|
+
return TE.fromEither(deserializedBodyE);
|
|
181
|
+
}));
|
|
182
|
+
default:
|
|
183
|
+
return TE.right(undefined);
|
|
184
|
+
}
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
173
187
|
parseResponse(operationResponse) {
|
|
174
188
|
if (operationResponse.response.statusCode >= 300) {
|
|
175
|
-
return TE.right(operationResponse.errorHandling());
|
|
189
|
+
return (0, function_1.pipe)(this.parseErrorResponse(operationResponse), TE.chain((result) => TE.right(operationResponse.errorHandling(result))));
|
|
176
190
|
}
|
|
177
191
|
return (0, function_1.pipe)(operationResponse.contentType, O.map((contentType) => {
|
|
178
192
|
switch (contentType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationExecutionGateway.unit.test.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionGateway.unit.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OperationExecutionGateway.unit.test.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionGateway.unit.test.ts"],"names":[],"mappings":"AA0BA,OAAO,8BAA8B,CAAC"}
|
|
@@ -56,6 +56,17 @@ class TestControllerHttp {
|
|
|
56
56
|
});
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
|
+
{
|
|
60
|
+
path: `/error`,
|
|
61
|
+
method: Http_1.HttpMethod.Get,
|
|
62
|
+
execute: () => (_request) => T.of({
|
|
63
|
+
body: stream_1.Readable.from(JSON.stringify({
|
|
64
|
+
message: 'Error message',
|
|
65
|
+
})),
|
|
66
|
+
headers: {},
|
|
67
|
+
statusCode: 500,
|
|
68
|
+
}),
|
|
69
|
+
},
|
|
59
70
|
{
|
|
60
71
|
path: `/tokens`,
|
|
61
72
|
method: Http_1.HttpMethod.Get,
|
|
@@ -384,4 +395,30 @@ describe('OperationExecutionGateway', () => {
|
|
|
384
395
|
.finallyDoNothing())
|
|
385
396
|
.nothingAfterAll());
|
|
386
397
|
});
|
|
398
|
+
describe('it should an error using the body as the message', () => {
|
|
399
|
+
const getProductOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
|
|
400
|
+
.get('http://localhost:3000/error')
|
|
401
|
+
.handleRequest((ctx, input, request) => request.addPathParameter('id', input.id.toString()).withoutBody())
|
|
402
|
+
.handleResponse((ctx, input, response) => response
|
|
403
|
+
.withJsonErrorHandling((errorResponse) => OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.apiError(errorResponse.message)))
|
|
404
|
+
.parseWithBodyAsJson())));
|
|
405
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
|
|
406
|
+
.usingHandlerContext('test')
|
|
407
|
+
.nothingBeforeAll()
|
|
408
|
+
.testCase('should get a error message from the body', (testCase) => testCase
|
|
409
|
+
.usingHandlerContext('test')
|
|
410
|
+
.givenNothing()
|
|
411
|
+
.when(() => ({ id: 2 }))
|
|
412
|
+
.then(({ output }) => {
|
|
413
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.failure(output);
|
|
414
|
+
if (outputValue.isFailure && outputValue.error.isFailure) {
|
|
415
|
+
expect(outputValue.error.error.message).toEqual('Error message');
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
fail('Expected output to be a failure');
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
.finallyDoNothing())
|
|
422
|
+
.nothingAfterAll());
|
|
423
|
+
});
|
|
387
424
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/cdk-runtime",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.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": "3.
|
|
18
|
-
"@trayio/cdk-dsl": "3.
|
|
19
|
-
"@trayio/express": "3.
|
|
20
|
-
"@trayio/winston": "3.
|
|
17
|
+
"@trayio/axios": "3.17.0",
|
|
18
|
+
"@trayio/cdk-dsl": "3.17.0",
|
|
19
|
+
"@trayio/express": "3.17.0",
|
|
20
|
+
"@trayio/winston": "3.17.0",
|
|
21
21
|
"mime": "3.0.0",
|
|
22
22
|
"uuid": "9.0.0"
|
|
23
23
|
},
|