@trayio/tray-client 0.0.1-beta
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/LICENSE.txt +22 -0
- package/dist/base/BaseClient.d.ts +21 -0
- package/dist/base/BaseClient.d.ts.map +1 -0
- package/dist/base/BaseClient.js +100 -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 +10 -0
- package/dist/connector/deployment/ConnectorDeploymentHttpClient.js +26 -0
- package/package.json +31 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Tray.io, Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpClient } from '@trayio/commons/http/HttpClient';
|
|
2
|
+
import { HttpHeaders, HttpMethod, HttpQueryString } from '@trayio/commons/http/Http';
|
|
3
|
+
import { JsonSerialization } from '@trayio/commons/serialization/JsonSerialization';
|
|
4
|
+
import { Result } from '@trayio/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,iCAAiC,CAAC;AAE7D,OAAO,EACN,WAAW,EACX,UAAU,EACV,eAAe,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACpF,OAAO,EAAE,MAAM,EAA2B,MAAM,+BAA+B,CAAC;AAIhF,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;IAqD9B,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,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.BaseHttpApiClient = void 0;
|
|
36
|
+
const E = __importStar(require("fp-ts/lib/Either"));
|
|
37
|
+
const JsonSerialization_1 = require("@trayio/commons/serialization/JsonSerialization");
|
|
38
|
+
const Result_1 = require("@trayio/commons/result/Result");
|
|
39
|
+
const util_1 = require("util");
|
|
40
|
+
const BufferExtensions_1 = require("@trayio/commons/buffer/BufferExtensions");
|
|
41
|
+
class BaseHttpApiClient {
|
|
42
|
+
constructor(httpConfig, httpClient) {
|
|
43
|
+
this.httpConfig = httpConfig;
|
|
44
|
+
this.httpClient = httpClient;
|
|
45
|
+
this.serialization = new JsonSerialization_1.JsonSerialization();
|
|
46
|
+
}
|
|
47
|
+
execute(path, method, headers, token, pathParams, queryString, body) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const url = this.httpConfig.baseUrl + path;
|
|
50
|
+
const JsonBody = this.serialization.serialize(body);
|
|
51
|
+
const populatedHeaders = this.addTokenHeader(headers, token);
|
|
52
|
+
const responseE = yield this.httpClient.execute(method, url, {
|
|
53
|
+
headers: populatedHeaders,
|
|
54
|
+
pathParams,
|
|
55
|
+
queryString,
|
|
56
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(JsonBody),
|
|
57
|
+
})();
|
|
58
|
+
const result = Result_1.ResultInternal.fromEitherWithSimpleError(responseE);
|
|
59
|
+
switch (result.isSuccess) {
|
|
60
|
+
case false:
|
|
61
|
+
return result;
|
|
62
|
+
case true:
|
|
63
|
+
const { statusCode } = result.value;
|
|
64
|
+
const responseArrayBufferE = yield BufferExtensions_1.BufferExtensions.readableToArrayBuffer(result.value.body)();
|
|
65
|
+
if (E.isLeft(responseArrayBufferE)) {
|
|
66
|
+
return Result_1.Result.failure(new Error(`Error deploying connector (${statusCode}): ${responseArrayBufferE.left}`));
|
|
67
|
+
}
|
|
68
|
+
if (result.value.statusCode >= 300) {
|
|
69
|
+
const errorBody = new util_1.TextDecoder().decode(responseArrayBufferE.right);
|
|
70
|
+
return Result_1.Result.failure(new Error(`Error deploying connector (${statusCode}): ${errorBody}`));
|
|
71
|
+
}
|
|
72
|
+
const deserializedResponseE = this.serialization.deserialize(responseArrayBufferE.right);
|
|
73
|
+
const successResult = Result_1.ResultInternal.fromEitherWithSimpleErrorAndUnknown(deserializedResponseE);
|
|
74
|
+
return successResult;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
executeWithoutInput(path, method, headers, token) {
|
|
79
|
+
return this.execute(path, method, headers, token, {}, {}, {});
|
|
80
|
+
}
|
|
81
|
+
executeWithBody(path, method, headers, body, token) {
|
|
82
|
+
return this.execute(path, method, headers, token, {}, {}, body);
|
|
83
|
+
}
|
|
84
|
+
executeWithBodyAndPathParams(path, method, headers, pathParams, body, token) {
|
|
85
|
+
return this.execute(path, method, headers, token, pathParams, {}, body);
|
|
86
|
+
}
|
|
87
|
+
executeWithPathParams(path, method, headers, pathParams, token) {
|
|
88
|
+
return this.execute(path, method, headers, token, pathParams, {}, {});
|
|
89
|
+
}
|
|
90
|
+
executeWithQueryString(path, method, headers, queryString, token) {
|
|
91
|
+
return this.execute(path, method, headers, token, {}, queryString, {});
|
|
92
|
+
}
|
|
93
|
+
addTokenHeader(headers, token) {
|
|
94
|
+
if (token) {
|
|
95
|
+
headers.Authorization = `Bearer ${token}`;
|
|
96
|
+
}
|
|
97
|
+
return headers;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.BaseHttpApiClient = BaseHttpApiClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HttpClient } from '@trayio/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 declare class ConnectorDeploymentHttpClient extends BaseHttpApiClient implements ConnectorDeploymentApi {
|
|
5
|
+
constructor(httpConfig: HttpConfig, httpClient: HttpClient);
|
|
6
|
+
deployFromSourceCode({ connectorName, connectorVersion, connectorSourceCode, token, }: DeployConnectorFromSourceCode): Promise<import("commons/dist/result/Result").Result<Error, ConnectorDeployment>>;
|
|
7
|
+
get({ id, connectorName, connectorVersion, token }: GetConnectorDeployment): Promise<import("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,iCAAiC,CAAC;AAE7D,OAAO,EACN,6BAA6B,EAC7B,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,MAAM,8DAA8D,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,qBAAa,6BACZ,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,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ConnectorDeploymentApi_abstract_test_1 = require("@trayio/tray-api/connector/deployment/ConnectorDeploymentApi.abstract.test");
|
|
4
|
+
const AxiosHttpClient_1 = require("@trayio/axios/http/AxiosHttpClient");
|
|
5
|
+
const ConnectorDeploymentHttpClient_1 = require("./ConnectorDeploymentHttpClient");
|
|
6
|
+
describe('ConnectorDeploymentHttpClient', () => {
|
|
7
|
+
(0, ConnectorDeploymentApi_abstract_test_1.connectorDeploymentApiTest)(new ConnectorDeploymentHttpClient_1.ConnectorDeploymentHttpClient({
|
|
8
|
+
baseUrl: process.env.TRAY_API_URL,
|
|
9
|
+
}, new AxiosHttpClient_1.AxiosHttpClient()));
|
|
10
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectorDeploymentHttpClient = void 0;
|
|
4
|
+
const Http_1 = require("@trayio/commons/http/Http");
|
|
5
|
+
const BaseClient_1 = require("../../base/BaseClient");
|
|
6
|
+
class ConnectorDeploymentHttpClient extends BaseClient_1.BaseHttpApiClient {
|
|
7
|
+
constructor(httpConfig, httpClient) {
|
|
8
|
+
super(httpConfig, httpClient);
|
|
9
|
+
}
|
|
10
|
+
deployFromSourceCode({ connectorName, connectorVersion, connectorSourceCode, token, }) {
|
|
11
|
+
return this.executeWithBodyAndPathParams(`/internal/v1/connectors/:connectorName/versions/:connectorVersion/deployments/deploy-connector-from-source`, Http_1.HttpMethod.Post, {}, {
|
|
12
|
+
connectorName,
|
|
13
|
+
connectorVersion,
|
|
14
|
+
}, {
|
|
15
|
+
connectorSourceCode,
|
|
16
|
+
}, token);
|
|
17
|
+
}
|
|
18
|
+
get({ id, connectorName, connectorVersion, token }) {
|
|
19
|
+
return this.executeWithPathParams(`/internal/v1/connectors/:connectorName/versions/:connectorVersion/deployments/:id`, Http_1.HttpMethod.Get, {}, {
|
|
20
|
+
connectorName,
|
|
21
|
+
connectorVersion,
|
|
22
|
+
id,
|
|
23
|
+
}, token);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ConnectorDeploymentHttpClient = ConnectorDeploymentHttpClient;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trayio/tray-client",
|
|
3
|
+
"version": "0.0.1-beta",
|
|
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/commons": "0.0.1-beta",
|
|
29
|
+
"@trayio/tray-api": "0.0.1-beta"
|
|
30
|
+
}
|
|
31
|
+
}
|