attlaz-client 1.6.10 → 1.7.1
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/Http/HttpClient.d.ts +3 -2
- package/dist/Http/HttpClient.js +56 -68
- package/dist/Http/OAuthClient.js +5 -5
- package/dist/Model/Error/ClientError.d.ts +1 -0
- package/dist/Model/Error/ClientError.js +4 -0
- package/dist/Service/AdapterEndpoint.js +4 -6
- package/dist/Service/TaskExecutionEndpoint.d.ts +1 -1
- package/dist/Service/TaskExecutionEndpoint.js +2 -2
- package/dist/test.js +1 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/package.json +2 -1
|
@@ -8,8 +8,9 @@ export declare class HttpClient {
|
|
|
8
8
|
static HTTP_NOT_ALLOWED: number;
|
|
9
9
|
static HTTP_UNPROCESSABLE_ENTITY: number;
|
|
10
10
|
static HTTP_INTERNAL_SERVER_ERROR: number;
|
|
11
|
+
static HTTP_BAD_GATEWAY: number;
|
|
11
12
|
static HTTP_UNAVAILABLE: number;
|
|
12
|
-
static get(url: string, requestData?: any): Promise<any>;
|
|
13
|
-
static request(request: HttpClientRequest): Promise<any>;
|
|
14
13
|
static request2(request: HttpClientRequest): Promise<HttpClientResponse>;
|
|
14
|
+
private static getContentType;
|
|
15
|
+
private static formatContentType;
|
|
15
16
|
}
|
package/dist/Http/HttpClient.js
CHANGED
|
@@ -2,45 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpClient = void 0;
|
|
4
4
|
const popsicle_1 = require("popsicle");
|
|
5
|
-
const Utils_1 = require("../Utils");
|
|
6
|
-
// import {ClientError} from '..';
|
|
7
5
|
const HttpClientResponse_1 = require("./HttpClientResponse");
|
|
8
6
|
const ClientError_1 = require("../Model/Error/ClientError");
|
|
9
|
-
|
|
7
|
+
const version_1 = require("../version");
|
|
10
8
|
class HttpClient {
|
|
11
|
-
static async get(url, requestData = {}) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
// console.log(response);
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
// TODO: make it possible to do request without parsing the json
|
|
31
|
-
return await response.json();
|
|
32
|
-
}
|
|
33
|
-
static async request(request) {
|
|
34
|
-
const rawRequest = {
|
|
35
|
-
url: request.getFullUrl(),
|
|
36
|
-
method: request.method,
|
|
37
|
-
headers: request.headers,
|
|
38
|
-
omitDefaultHeaders: true,
|
|
39
|
-
body: request.body
|
|
40
|
-
};
|
|
41
|
-
return HttpClient.get(request.getFullUrl(), rawRequest);
|
|
42
|
-
}
|
|
9
|
+
// public static async get(url: string, requestData: any = {}): Promise<any> {
|
|
10
|
+
// if (Utils.isNullOrUndefined(requestData)) {
|
|
11
|
+
// requestData = {};
|
|
12
|
+
// }
|
|
13
|
+
// const response: Response = await fetch(url, requestData);
|
|
14
|
+
//
|
|
15
|
+
// //TODO: validate status
|
|
16
|
+
// const error: ClientError | null = ClientError.byStatus(response.status, response.statusText);
|
|
17
|
+
// if (!Utils.isNullOrUndefined(error)) {
|
|
18
|
+
// throw error;
|
|
19
|
+
// }
|
|
20
|
+
//
|
|
21
|
+
// // TODO: make it possible to do request without parsing the json
|
|
22
|
+
// return await response.json();
|
|
23
|
+
// }
|
|
43
24
|
static async request2(request) {
|
|
25
|
+
if (typeof window === 'undefined') {
|
|
26
|
+
// Add user agent when running in Node
|
|
27
|
+
request.headers['User-Agent'] = 'Attlaz Http/' + version_1.VERSION;
|
|
28
|
+
}
|
|
44
29
|
const rawRequest = {
|
|
45
30
|
url: request.getFullUrl(),
|
|
46
31
|
method: request.method,
|
|
@@ -48,49 +33,51 @@ class HttpClient {
|
|
|
48
33
|
omitDefaultHeaders: true,
|
|
49
34
|
body: request.body
|
|
50
35
|
};
|
|
51
|
-
// TODO: set user agent
|
|
52
|
-
// rawRequest.negotiateHttpVersion = NegotiateHttpVersion.HTTP1_ONLY;
|
|
53
36
|
const response = await (0, popsicle_1.fetch)(request.getFullUrl(), rawRequest);
|
|
54
37
|
const httpResponse = new HttpClientResponse_1.HttpClientResponse(response.status, response.statusText);
|
|
55
|
-
|
|
56
|
-
// httpResponse.statusText = response.statusText;
|
|
57
|
-
// TODO: should we get JSON immediately?
|
|
58
|
-
// response.json
|
|
59
|
-
// httpResponse.body = await response.text();
|
|
38
|
+
let contentType = this.getContentType(response);
|
|
60
39
|
const rawData = await response.text();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
if (contentType.type === 'application/json') {
|
|
41
|
+
let jsonData = null;
|
|
42
|
+
try {
|
|
43
|
+
jsonData = JSON.parse(rawData);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.log(httpResponse.statusText);
|
|
47
|
+
console.error('Unable to parse response data to JSON');
|
|
48
|
+
}
|
|
49
|
+
httpResponse.body = jsonData;
|
|
64
50
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
console.error('Unable to parse response data to JSON');
|
|
51
|
+
else {
|
|
52
|
+
httpResponse.body = rawData;
|
|
68
53
|
}
|
|
69
|
-
httpResponse.body = jsonData;
|
|
70
54
|
const error = ClientError_1.ClientError.byStatus(response.status, response.statusText);
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
// console.log('Text' + body);
|
|
74
|
-
//
|
|
75
|
-
// console.log(response);
|
|
55
|
+
if (error !== null && error !== undefined) {
|
|
56
|
+
error.body = httpResponse.body;
|
|
76
57
|
throw error;
|
|
77
58
|
}
|
|
78
|
-
// //TODO: validate status
|
|
79
|
-
//
|
|
80
|
-
// const error: ClientError = ClientError.byStatus(response.status, response.statusText);
|
|
81
|
-
// if (!Utils.isNullOrUndefined(error)) {
|
|
82
|
-
//
|
|
83
|
-
// // const body: string = await response.text();
|
|
84
|
-
// // console.log('Text' + body);
|
|
85
|
-
// //
|
|
86
|
-
// // console.log(response);
|
|
87
|
-
// throw error;
|
|
88
|
-
// }
|
|
89
|
-
//
|
|
90
|
-
// // TODO: make it possible to do request without parsing the json
|
|
91
|
-
// return await response.json();
|
|
92
59
|
return httpResponse;
|
|
93
60
|
}
|
|
61
|
+
static getContentType(response) {
|
|
62
|
+
if (response.headers.has('Content-Type')) {
|
|
63
|
+
const rawContentType = response.headers.get('Content-Type');
|
|
64
|
+
if (rawContentType !== null) {
|
|
65
|
+
return this.formatContentType(rawContentType);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { type: 'application/json', options: null };
|
|
69
|
+
}
|
|
70
|
+
static formatContentType(input) {
|
|
71
|
+
const d = input.split(';');
|
|
72
|
+
if (d.length === 1) {
|
|
73
|
+
return { type: d[0], options: null };
|
|
74
|
+
}
|
|
75
|
+
else if (d.length === 2) {
|
|
76
|
+
return { type: d[0], options: d[1].trim() };
|
|
77
|
+
}
|
|
78
|
+
console.error('Unable to parse content type "' + input + '"');
|
|
79
|
+
return { type: input, options: null };
|
|
80
|
+
}
|
|
94
81
|
}
|
|
95
82
|
exports.HttpClient = HttpClient;
|
|
96
83
|
HttpClient.HTTP_BAD_REQUEST = 400;
|
|
@@ -100,4 +87,5 @@ HttpClient.HTTP_NOTFOUND = 404;
|
|
|
100
87
|
HttpClient.HTTP_NOT_ALLOWED = 405;
|
|
101
88
|
HttpClient.HTTP_UNPROCESSABLE_ENTITY = 422;
|
|
102
89
|
HttpClient.HTTP_INTERNAL_SERVER_ERROR = 500;
|
|
90
|
+
HttpClient.HTTP_BAD_GATEWAY = 502;
|
|
103
91
|
HttpClient.HTTP_UNAVAILABLE = 503;
|
package/dist/Http/OAuthClient.js
CHANGED
|
@@ -84,19 +84,19 @@ class OAuthClient {
|
|
|
84
84
|
}
|
|
85
85
|
const requestData = this.createRequestData(action, parameters, method, signWithOauthToken);
|
|
86
86
|
if (this.debug) {
|
|
87
|
-
console.
|
|
87
|
+
console.debug('[Client] REQ: ' + requestData.method.toUpperCase() + ' ' + requestData.getFullUrl());
|
|
88
88
|
}
|
|
89
89
|
try {
|
|
90
90
|
const response = await HttpClient_1.HttpClient.request2(requestData);
|
|
91
|
-
if (this.debug) {
|
|
92
|
-
|
|
93
|
-
}
|
|
91
|
+
// if (this.debug) {
|
|
92
|
+
// console.info('[Client response] ', {body: response.body});
|
|
93
|
+
// }
|
|
94
94
|
return response.body;
|
|
95
95
|
}
|
|
96
96
|
catch (error) {
|
|
97
97
|
const clientError = ClientError_1.ClientError.fromError(error);
|
|
98
98
|
if (this.debug) {
|
|
99
|
-
console.error('[Client
|
|
99
|
+
console.error('[Client] Error:', { error, clientError });
|
|
100
100
|
}
|
|
101
101
|
throw clientError;
|
|
102
102
|
}
|
|
@@ -3,6 +3,7 @@ export declare class ClientError implements Error {
|
|
|
3
3
|
name: string;
|
|
4
4
|
code: number | null;
|
|
5
5
|
stack: string;
|
|
6
|
+
body: string | null;
|
|
6
7
|
constructor(message: string, code?: number | null);
|
|
7
8
|
static fromError(error: Error | any): ClientError;
|
|
8
9
|
static byStatus(statusCode: number, statusText: string): ClientError | null;
|
|
@@ -4,6 +4,7 @@ exports.ClientError = void 0;
|
|
|
4
4
|
const HttpClient_1 = require("../../Http/HttpClient");
|
|
5
5
|
class ClientError {
|
|
6
6
|
constructor(message, code = null) {
|
|
7
|
+
this.body = null;
|
|
7
8
|
this.message = message;
|
|
8
9
|
this.code = code;
|
|
9
10
|
}
|
|
@@ -66,6 +67,9 @@ class ClientError {
|
|
|
66
67
|
case 500:
|
|
67
68
|
return new ClientError('Internal Server Error', HttpClient_1.HttpClient.HTTP_INTERNAL_SERVER_ERROR);
|
|
68
69
|
break;
|
|
70
|
+
case 502:
|
|
71
|
+
return new ClientError('Bad gateway', HttpClient_1.HttpClient.HTTP_BAD_GATEWAY);
|
|
72
|
+
break;
|
|
69
73
|
case 503:
|
|
70
74
|
return new ClientError('Service not available', HttpClient_1.HttpClient.HTTP_UNAVAILABLE);
|
|
71
75
|
break;
|
|
@@ -50,8 +50,8 @@ class AdapterEndpoint extends Endpoint_1.Endpoint {
|
|
|
50
50
|
}
|
|
51
51
|
async getConnections(projectId) {
|
|
52
52
|
try {
|
|
53
|
-
let url = '/connections';
|
|
54
|
-
const result = await this.request(url,
|
|
53
|
+
let url = '/project/' + projectId + '/connections';
|
|
54
|
+
const result = await this.request(url, null, 'GET');
|
|
55
55
|
result.setData(this.parseCollection(result, AdapterConnection_1.AdapterConnection.parse));
|
|
56
56
|
return result;
|
|
57
57
|
}
|
|
@@ -78,10 +78,8 @@ class AdapterEndpoint extends Endpoint_1.Endpoint {
|
|
|
78
78
|
}
|
|
79
79
|
async saveConnection(projectId, adapter) {
|
|
80
80
|
try {
|
|
81
|
-
let url = '/connections';
|
|
82
|
-
const
|
|
83
|
-
data.projectId = projectId;
|
|
84
|
-
const result = await this.request(url, data, 'POST');
|
|
81
|
+
let url = '/project/' + projectId + '/connections';
|
|
82
|
+
const result = await this.request(url, adapter, 'POST');
|
|
85
83
|
result.setData(AdapterConnection_1.AdapterConnection.parse(result.getData()));
|
|
86
84
|
return result;
|
|
87
85
|
}
|
|
@@ -6,7 +6,7 @@ import { TaskExecutionStatus } from '../Model/TaskExecutionStatus';
|
|
|
6
6
|
export declare class TaskExecutionEndpoint extends Endpoint {
|
|
7
7
|
getTaskExecutions(taskId: string): Promise<TaskExecution[]>;
|
|
8
8
|
getTaskExecutionSummaries(taskId: string, from?: Date | null, to?: Date | null, projectEnvironmentId?: string | null): Promise<TaskExecutionSummary[]>;
|
|
9
|
-
getTaskExecutionSummary(taskExecutionId: string): Promise<TaskExecutionSummary>;
|
|
9
|
+
getTaskExecutionSummary(taskExecutionId: string): Promise<TaskExecutionSummary | null>;
|
|
10
10
|
getTaskExecutionHistory(taskExecutionId: string): Promise<TaskExecutionHistory[]>;
|
|
11
11
|
updateTaskExecution(taskExecutionId: string, status: TaskExecutionStatus, time?: Date | null): Promise<TaskExecution>;
|
|
12
12
|
}
|
|
@@ -61,8 +61,8 @@ class TaskExecutionEndpoint extends Endpoint_1.Endpoint {
|
|
|
61
61
|
async getTaskExecutionSummary(taskExecutionId) {
|
|
62
62
|
try {
|
|
63
63
|
const rawTaskExecution = await this.httpClient.request('/taskexecutions/' + taskExecutionId + '/summaries');
|
|
64
|
-
if (
|
|
65
|
-
|
|
64
|
+
if (rawTaskExecution === null || rawTaskExecution === undefined) {
|
|
65
|
+
return null;
|
|
66
66
|
}
|
|
67
67
|
return TaskExecutionSummary_1.TaskExecutionSummary.parse(rawTaskExecution);
|
|
68
68
|
}
|
package/dist/test.js
CHANGED
|
@@ -132,7 +132,7 @@ async function testHTTPAuth() {
|
|
|
132
132
|
requestData.setJsonHeader();
|
|
133
133
|
requestData.setBasicAuth('attlaz', '4$0x51eIaF9w');
|
|
134
134
|
try {
|
|
135
|
-
const res = await HttpClient_1.HttpClient.
|
|
135
|
+
const res = await HttpClient_1.HttpClient.request2(requestData);
|
|
136
136
|
console.log(res);
|
|
137
137
|
}
|
|
138
138
|
catch (e) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "1.7.1";
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "attlaz-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Javascript Client to access Attlaz API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"author": "Stijn Duynslaeger <stijn@attlaz.com> (stijn@attlaz.com)",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"scripts": {
|
|
17
|
+
"prebuild": "node -p \"'export const VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
|
|
17
18
|
"prepare": "npm run build",
|
|
18
19
|
"build": "npm run clean && tsc",
|
|
19
20
|
"clean": "rimraf dist",
|