@trayio/cdk-runtime 3.5.0 → 3.6.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 +4 -1
- package/dist/connector/operation/OperationExecutionGateway.unit.test.js +39 -0
- package/package.json +5 -5
|
@@ -13,6 +13,7 @@ export declare class HttpOperationExecution<AUTH extends OperationHandlerAuth<un
|
|
|
13
13
|
private globalConfiguration;
|
|
14
14
|
constructor(httpClient: HttpClient, fileStorage: FileStorage, handler: HttpOperationHandler<AUTH, IN, OUT>, globalConfiguration: O.Option<OperationGlobalConfigHttp>);
|
|
15
15
|
execute(ctx: OperationHandlerContext<AUTH>, input: IN): Promise<OperationHandlerResult<OUT>>;
|
|
16
|
+
private decorateRequest;
|
|
16
17
|
private operationRequestToHttpRequest;
|
|
17
18
|
private serializeAsJson;
|
|
18
19
|
private serializeAsFormUrlEncoded;
|
|
@@ -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,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAGN,oBAAoB,
|
|
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,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAGN,oBAAoB,EAMpB,MAAM,0DAA0D,CAAC;AAClE,OA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qBAAqB;CAwC7B"}
|
|
@@ -57,7 +57,7 @@ class HttpOperationExecution {
|
|
|
57
57
|
}
|
|
58
58
|
execute(ctx, input) {
|
|
59
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const request = (0, function_1.pipe)(this.globalConfiguration, O.match(() => this.handler.request, (globalConfig) =>
|
|
60
|
+
const request = (0, function_1.pipe)(this.globalConfiguration, O.match(() => this.handler.request, (globalConfig) => this.decorateRequest(globalConfig, this.handler.request, ctx)));
|
|
61
61
|
const operationRequest = this.handler.requestHandler(ctx, input, request);
|
|
62
62
|
const httpRequestE = yield this.operationRequestToHttpRequest(operationRequest)();
|
|
63
63
|
if (E.isLeft(httpRequestE)) {
|
|
@@ -74,6 +74,9 @@ class HttpOperationExecution {
|
|
|
74
74
|
return TE.toUnion(operationResponseTE)();
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
+
decorateRequest(globalConfig, operationRequest, ctx) {
|
|
78
|
+
return (0, function_1.pipe)(globalConfig.getBaseUrl(), O.fold(() => operationRequest, (baseUrl) => operationRequest.withPath(`${baseUrl(ctx)}${operationRequest.path}`)), (request) => (0, function_1.pipe)(globalConfig.getBearerToken(), O.fold(() => request, (bearerToken) => request.withBearerToken(bearerToken(ctx)))));
|
|
79
|
+
}
|
|
77
80
|
operationRequestToHttpRequest(operationRequest) {
|
|
78
81
|
return (0, function_1.pipe)(operationRequest.contentType, O.map((contentType) => {
|
|
79
82
|
switch (contentType) {
|
|
@@ -56,6 +56,23 @@ class TestControllerHttp {
|
|
|
56
56
|
});
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
|
+
{
|
|
60
|
+
path: `/tokens`,
|
|
61
|
+
method: Http_1.HttpMethod.Get,
|
|
62
|
+
execute: (request) => {
|
|
63
|
+
const token = request.headers.authorization;
|
|
64
|
+
if (token === 'Bearer valid') {
|
|
65
|
+
return T.of({
|
|
66
|
+
body: stream_1.Readable.from(JSON.stringify({
|
|
67
|
+
success: true,
|
|
68
|
+
})),
|
|
69
|
+
headers: {},
|
|
70
|
+
statusCode: 200,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
throw new Error('Unauthorized');
|
|
74
|
+
},
|
|
75
|
+
},
|
|
59
76
|
{
|
|
60
77
|
path: `/posts/create`,
|
|
61
78
|
method: Http_1.HttpMethod.Post,
|
|
@@ -188,6 +205,28 @@ describe('OperationExecutionGateway', () => {
|
|
|
188
205
|
.finallyDoNothing())
|
|
189
206
|
.nothingAfterAll());
|
|
190
207
|
});
|
|
208
|
+
describe('set a bearer token via globalConfig', () => {
|
|
209
|
+
const globalConfig = OperationGlobalConfig_1.OperationGlobalConfigHttp.create()
|
|
210
|
+
.withBaseUrl(() => 'http://localhost:3000')
|
|
211
|
+
.withBearerToken(() => 'valid');
|
|
212
|
+
const getProductOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.withGlobalConfiguration(globalConfig).usingHttp((http) => http
|
|
213
|
+
.get('/tokens')
|
|
214
|
+
.handleRequest((ctx, input, request) => request.withoutBody())
|
|
215
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())));
|
|
216
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
|
|
217
|
+
.usingHandlerContext('test')
|
|
218
|
+
.nothingBeforeAll()
|
|
219
|
+
.testCase('should return successfully', (testCase) => testCase
|
|
220
|
+
.usingHandlerContext('test')
|
|
221
|
+
.givenNothing()
|
|
222
|
+
.when(() => ({}))
|
|
223
|
+
.then(({ output }) => {
|
|
224
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
225
|
+
expect(outputValue.success).toEqual(true);
|
|
226
|
+
})
|
|
227
|
+
.finallyDoNothing())
|
|
228
|
+
.nothingAfterAll());
|
|
229
|
+
});
|
|
191
230
|
describe('get a product as text', () => {
|
|
192
231
|
const getProductOperationAsText = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler
|
|
193
232
|
.addInputValidation((inputValidation) => inputValidation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/cdk-runtime",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.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.6.0",
|
|
18
|
+
"@trayio/cdk-dsl": "3.6.0",
|
|
19
|
+
"@trayio/express": "3.6.0",
|
|
20
|
+
"@trayio/winston": "3.6.0",
|
|
21
21
|
"mime": "3.0.0",
|
|
22
22
|
"uuid": "9.0.0"
|
|
23
23
|
},
|