@trayio/tray-client 0.5.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/base/BaseClient.d.ts +21 -0
- package/dist/base/BaseClient.d.ts.map +1 -0
- package/dist/base/BaseClient.js +63 -0
- package/dist/connector/deployment/ConnectorDeploymentHttpClient.d.ts +9 -0
- package/dist/connector/deployment/ConnectorDeploymentHttpClient.d.ts.map +1 -0
- package/dist/connector/deployment/ConnectorDeploymentHttpClient.e2e.test.d.ts +2 -0
- package/dist/connector/deployment/ConnectorDeploymentHttpClient.e2e.test.d.ts.map +1 -0
- package/dist/connector/deployment/ConnectorDeploymentHttpClient.e2e.test.js +13 -0
- package/dist/connector/deployment/ConnectorDeploymentHttpClient.js +25 -0
- package/package.json +31 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpClient } from '@trayio/tray-commons/http/HttpClient';
|
|
2
|
+
import { HttpHeaders, HttpMethod, HttpQueryString } from '@trayio/tray-commons/http/Http';
|
|
3
|
+
import { JsonSerialization } from '@trayio/tray-commons/serialization/JsonSerialization';
|
|
4
|
+
import { Result } from '@trayio/tray-commons/result/Result';
|
|
5
|
+
export type HttpConfig = {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
};
|
|
8
|
+
export declare abstract class BaseHttpApiClient {
|
|
9
|
+
httpConfig: HttpConfig;
|
|
10
|
+
httpClient: HttpClient;
|
|
11
|
+
serialization: JsonSerialization;
|
|
12
|
+
constructor(httpConfig: HttpConfig, httpClient: HttpClient);
|
|
13
|
+
execute<REQ, RES>(path: string, method: HttpMethod, headers: HttpHeaders, token: string | undefined, pathParams: Record<string, string>, queryString: HttpQueryString, body: REQ): Promise<Result<Error, RES>>;
|
|
14
|
+
executeWithoutInput<RES>(path: string, method: HttpMethod, headers: HttpHeaders, token?: string): Promise<Result<Error, RES>>;
|
|
15
|
+
executeWithBody<REQ, RES>(path: string, method: HttpMethod, headers: HttpHeaders, body: REQ, token?: string): Promise<Result<Error, RES>>;
|
|
16
|
+
executeWithBodyAndPathParams<REQ, RES>(path: string, method: HttpMethod, headers: HttpHeaders, pathParams: Record<string, string>, body: REQ, token?: string): Promise<Result<Error, RES>>;
|
|
17
|
+
executeWithPathParams<RES>(path: string, method: HttpMethod, headers: HttpHeaders, pathParams: Record<string, string>, token?: string): Promise<Result<Error, RES>>;
|
|
18
|
+
executeWithQueryString<RES>(path: string, method: HttpMethod, headers: HttpHeaders, queryString: HttpQueryString, token?: string): Promise<Result<Error, RES>>;
|
|
19
|
+
private addTokenHeader;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=BaseClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../src/base/BaseClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EACN,WAAW,EACX,UAAU,EACV,eAAe,EAEf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AACzF,OAAO,EACN,MAAM,EAGN,MAAM,oCAAoC,CAAC;AAE5C,MAAM,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,8BAAsB,iBAAiB;IACtC,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,EAAE,iBAAiB,CAAC;gBAErB,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAMpD,OAAO,CAAC,GAAG,EAAE,GAAG,EACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,GAAG,GACP,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAgC9B,mBAAmB,CAAC,GAAG,EACtB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,MAAM;IAKf,eAAe,CAAC,GAAG,EAAE,GAAG,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,GAAG,EACT,KAAK,CAAC,EAAE,MAAM;IAKf,4BAA4B,CAAC,GAAG,EAAE,GAAG,EACpC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,IAAI,EAAE,GAAG,EACT,KAAK,CAAC,EAAE,MAAM;IAaf,qBAAqB,CAAC,GAAG,EACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,KAAK,CAAC,EAAE,MAAM;IAaf,sBAAsB,CAAC,GAAG,EACzB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,eAAe,EAC5B,KAAK,CAAC,EAAE,MAAM;IAaf,OAAO,CAAC,cAAc;CAOtB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BaseHttpApiClient = void 0;
|
|
13
|
+
const JsonSerialization_1 = require("@trayio/tray-commons/serialization/JsonSerialization");
|
|
14
|
+
const Result_1 = require("@trayio/tray-commons/result/Result");
|
|
15
|
+
class BaseHttpApiClient {
|
|
16
|
+
constructor(httpConfig, httpClient) {
|
|
17
|
+
this.httpConfig = httpConfig;
|
|
18
|
+
this.httpClient = httpClient;
|
|
19
|
+
this.serialization = new JsonSerialization_1.JsonSerialization();
|
|
20
|
+
}
|
|
21
|
+
execute(path, method, headers, token, pathParams, queryString, body) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const url = this.httpConfig.baseUrl + path;
|
|
24
|
+
const JsonBody = this.serialization.serialize(body);
|
|
25
|
+
const populatedHeaders = this.addTokenHeader(headers, token);
|
|
26
|
+
const responseE = yield this.httpClient.execute(method, url, {
|
|
27
|
+
headers: populatedHeaders,
|
|
28
|
+
pathParams,
|
|
29
|
+
queryString,
|
|
30
|
+
body: JsonBody,
|
|
31
|
+
})();
|
|
32
|
+
const result = Result_1.RequestHandlerResultInternal.fromEitherWithSimpleError(responseE);
|
|
33
|
+
if (result.isFailure) {
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
const deserializedResponseE = this.serialization.deserialize(result.value.body);
|
|
37
|
+
const successResult = Result_1.RequestHandlerResultInternal.fromEitherWithSimpleErrorAndUnknown(deserializedResponseE);
|
|
38
|
+
return successResult;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
executeWithoutInput(path, method, headers, token) {
|
|
42
|
+
return this.execute(path, method, headers, token, {}, {}, {});
|
|
43
|
+
}
|
|
44
|
+
executeWithBody(path, method, headers, body, token) {
|
|
45
|
+
return this.execute(path, method, headers, token, {}, {}, body);
|
|
46
|
+
}
|
|
47
|
+
executeWithBodyAndPathParams(path, method, headers, pathParams, body, token) {
|
|
48
|
+
return this.execute(path, method, headers, token, pathParams, {}, body);
|
|
49
|
+
}
|
|
50
|
+
executeWithPathParams(path, method, headers, pathParams, token) {
|
|
51
|
+
return this.execute(path, method, headers, token, pathParams, {}, {});
|
|
52
|
+
}
|
|
53
|
+
executeWithQueryString(path, method, headers, queryString, token) {
|
|
54
|
+
return this.execute(path, method, headers, token, {}, queryString, {});
|
|
55
|
+
}
|
|
56
|
+
addTokenHeader(headers, token) {
|
|
57
|
+
if (token) {
|
|
58
|
+
headers.Authorization = `Bearer ${token}`;
|
|
59
|
+
}
|
|
60
|
+
return headers;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.BaseHttpApiClient = BaseHttpApiClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HttpClient } from '@trayio/tray-commons/http/HttpClient';
|
|
2
|
+
import { DeployConnectorFromSourceCode, GetConnectorDeployment, ConnectorDeploymentApi, ConnectorDeployment } from '@trayio/tray-api/connector/deployment/ConnectorDeploymentApi';
|
|
3
|
+
import { HttpConfig, BaseHttpApiClient } from '../../base/BaseClient';
|
|
4
|
+
export default class ConnectorDeploymentHttpClient extends BaseHttpApiClient implements ConnectorDeploymentApi {
|
|
5
|
+
constructor(httpConfig: HttpConfig, httpClient: HttpClient);
|
|
6
|
+
deployFromSourceCode({ connectorName, connectorVersion, connectorSourceCode, token, }: DeployConnectorFromSourceCode): Promise<import("@trayio/tray-commons/dist/result/Result").Result<Error, ConnectorDeployment>>;
|
|
7
|
+
get({ id, connectorName, connectorVersion, token }: GetConnectorDeployment): Promise<import("@trayio/tray-commons/dist/result/Result").Result<Error, ConnectorDeployment>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ConnectorDeploymentHttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectorDeploymentHttpClient.d.ts","sourceRoot":"","sources":["../../../src/connector/deployment/ConnectorDeploymentHttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAElE,OAAO,EACN,6BAA6B,EAC7B,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,MAAM,8DAA8D,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,MAAM,CAAC,OAAO,OAAO,6BACpB,SAAQ,iBACR,YAAW,sBAAsB;gBAErB,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAI1D,oBAAoB,CAAC,EACpB,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,GACL,EAAE,6BAA6B;IAmBhC,GAAG,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,sBAAsB;CAa1E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectorDeploymentHttpClient.e2e.test.d.ts","sourceRoot":"","sources":["../../../src/connector/deployment/ConnectorDeploymentHttpClient.e2e.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ConnectorDeploymentApi_abstract_test_1 = require("@trayio/tray-api/connector/deployment/ConnectorDeploymentApi.abstract.test");
|
|
7
|
+
const AxiosHttpClient_1 = require("@trayio/tray-axios/http/AxiosHttpClient");
|
|
8
|
+
const ConnectorDeploymentHttpClient_1 = __importDefault(require("./ConnectorDeploymentHttpClient"));
|
|
9
|
+
describe('ConnectorDeploymentHttpClient', () => {
|
|
10
|
+
(0, ConnectorDeploymentApi_abstract_test_1.connectorDeploymentApiTest)(new ConnectorDeploymentHttpClient_1.default({
|
|
11
|
+
baseUrl: process.env.TRAY_API_URL,
|
|
12
|
+
}, new AxiosHttpClient_1.AxiosHttpClient()));
|
|
13
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Http_1 = require("@trayio/tray-commons/http/Http");
|
|
4
|
+
const BaseClient_1 = require("../../base/BaseClient");
|
|
5
|
+
class ConnectorDeploymentHttpClient extends BaseClient_1.BaseHttpApiClient {
|
|
6
|
+
constructor(httpConfig, httpClient) {
|
|
7
|
+
super(httpConfig, httpClient);
|
|
8
|
+
}
|
|
9
|
+
deployFromSourceCode({ connectorName, connectorVersion, connectorSourceCode, token, }) {
|
|
10
|
+
return this.executeWithBodyAndPathParams(`/internal/v1/connectors/:connectorName/versions/:connectorVersion/deployments/deploy-connector-from-source`, Http_1.HttpMethod.Post, {}, {
|
|
11
|
+
connectorName,
|
|
12
|
+
connectorVersion,
|
|
13
|
+
}, {
|
|
14
|
+
connectorSourceCode,
|
|
15
|
+
}, token);
|
|
16
|
+
}
|
|
17
|
+
get({ id, connectorName, connectorVersion, token }) {
|
|
18
|
+
return this.executeWithPathParams(`/internal/v1/connectors/:connectorName/versions/:connectorVersion/deployments/:id`, Http_1.HttpMethod.Get, {}, {
|
|
19
|
+
connectorName,
|
|
20
|
+
connectorVersion,
|
|
21
|
+
id,
|
|
22
|
+
}, token);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.default = ConnectorDeploymentHttpClient;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trayio/tray-client",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "A client for the Tray.io API",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./*": "./dist/*.js"
|
|
7
|
+
},
|
|
8
|
+
"author": "Tray.io",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18.x"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
"*": [
|
|
19
|
+
"*",
|
|
20
|
+
"dist/*"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"/dist"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@trayio/tray-api": "0.5.0",
|
|
29
|
+
"@trayio/tray-commons": "*"
|
|
30
|
+
}
|
|
31
|
+
}
|