attlaz-client 1.18.3 → 1.18.5
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/Client.d.ts +5 -3
- package/dist/Client.js +7 -7
- package/dist/Http/ClientError.d.ts +8 -4
- package/dist/Http/ClientError.js +44 -23
- package/dist/Http/HttpClient.js +21 -21
- package/dist/Http/OAuthClient.js +12 -3
- package/dist/Service/Endpoint.js +4 -0
- package/dist/Service/FirewallEndpoint.d.ts +3 -0
- package/dist/Service/FirewallEndpoint.js +3 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/Client.d.ts
CHANGED
|
@@ -31,12 +31,14 @@ import { SearchEndpoint } from './Service/SearchEndpoint.js';
|
|
|
31
31
|
import { UserActionEndpoint } from './Service/UserActionEndpoint.js';
|
|
32
32
|
import { AccessTokenEndpoint } from './Service/AccessTokenEndpoint.js';
|
|
33
33
|
export declare class Client {
|
|
34
|
-
private endpoints;
|
|
34
|
+
private readonly endpoints;
|
|
35
35
|
private httpClient;
|
|
36
|
-
private Store;
|
|
36
|
+
private readonly Store;
|
|
37
37
|
private apiEndpoint;
|
|
38
38
|
private parseConfig;
|
|
39
|
-
constructor(token?: string | null, config?:
|
|
39
|
+
constructor(token?: string | null, config?: {
|
|
40
|
+
apiEndpoint: string | undefined;
|
|
41
|
+
});
|
|
40
42
|
setClientCredentials(clientId: string, clientSecret?: string): void;
|
|
41
43
|
getHttpClient(): OAuthClient;
|
|
42
44
|
authenticate(): Promise<boolean>;
|
package/dist/Client.js
CHANGED
|
@@ -71,7 +71,7 @@ export class Client {
|
|
|
71
71
|
// TODO: go over other records in config and warn if any unknown ones
|
|
72
72
|
return config;
|
|
73
73
|
}
|
|
74
|
-
constructor(token = null, config = {}) {
|
|
74
|
+
constructor(token = null, config = { apiEndpoint: undefined }) {
|
|
75
75
|
const parsedConfig = this.parseConfig(config);
|
|
76
76
|
if (parsedConfig.apiEndpoint !== undefined) {
|
|
77
77
|
this.apiEndpoint = parsedConfig.apiEndpoint;
|
|
@@ -95,10 +95,10 @@ export class Client {
|
|
|
95
95
|
}
|
|
96
96
|
async authenticate(username = null, password = null) {
|
|
97
97
|
if (username === null || password === null) {
|
|
98
|
-
return this.httpClient.authenticate();
|
|
98
|
+
return await this.httpClient.authenticate();
|
|
99
99
|
}
|
|
100
100
|
// TODO: this is only possible when clientId and clientSecret are defined
|
|
101
|
-
return this.httpClient.authenticate(username, password);
|
|
101
|
+
return await this.httpClient.authenticate(username, password);
|
|
102
102
|
}
|
|
103
103
|
isAuthenticated() {
|
|
104
104
|
return this.httpClient.isAuthenticated();
|
|
@@ -208,18 +208,18 @@ export class Client {
|
|
|
208
208
|
getFirewallEndpoint() {
|
|
209
209
|
return this.getEndpoint('firewall', this.Store.FirewallEndpoint);
|
|
210
210
|
}
|
|
211
|
-
getEndpoint(key,
|
|
211
|
+
getEndpoint(key, ClassName) {
|
|
212
212
|
// const classNameString: string = className.name;
|
|
213
213
|
if (!this.endpoints.has(key)) {
|
|
214
214
|
// if (this.Store[classNameString] === undefined || this.Store[classNameString] === null) {
|
|
215
215
|
// throw new Error(`Class type of \'${classNameString}\' is not in the store`);
|
|
216
216
|
// }
|
|
217
217
|
try {
|
|
218
|
-
const endpoint = new
|
|
218
|
+
const endpoint = new ClassName(this.httpClient);
|
|
219
219
|
this.endpoints.set(key, endpoint);
|
|
220
220
|
}
|
|
221
|
-
catch (
|
|
222
|
-
throw new Error('Unable to initialize ' + key + ' endpoint (' +
|
|
221
|
+
catch (error) {
|
|
222
|
+
throw new Error('Unable to initialize ' + key + ' endpoint (' + error.message + ')');
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
return this.endpoints.get(key);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
1
2
|
export declare class ClientError extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
httpErrorCode: number | null;
|
|
4
|
+
type: string;
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
param?: string;
|
|
4
8
|
stack?: string;
|
|
5
|
-
constructor(
|
|
6
|
-
static fromError(error: Error |
|
|
9
|
+
constructor(code: string, httpErrorCode?: number | null);
|
|
10
|
+
static fromError(error: Error | AxiosError): ClientError;
|
|
7
11
|
static byStatus(statusCode: number, statusText: string): ClientError | null;
|
|
8
12
|
}
|
package/dist/Http/ClientError.js
CHANGED
|
@@ -1,51 +1,73 @@
|
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
1
2
|
import { HttpClient } from './HttpClient.js';
|
|
2
3
|
export class ClientError extends Error {
|
|
4
|
+
httpErrorCode = null;
|
|
5
|
+
type;
|
|
3
6
|
code;
|
|
4
|
-
|
|
7
|
+
message;
|
|
8
|
+
param = undefined;
|
|
5
9
|
stack = undefined;
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
-
this.name = name;
|
|
10
|
+
constructor(code, httpErrorCode = null) {
|
|
11
|
+
super(code);
|
|
9
12
|
this.code = code;
|
|
13
|
+
this.httpErrorCode = httpErrorCode;
|
|
10
14
|
}
|
|
11
15
|
static fromError(error) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
let clientError = new ClientError('Unknown error', HttpClient.HTTP_INTERNAL_SERVER_ERROR);
|
|
17
|
+
if (error instanceof AxiosError) {
|
|
18
|
+
if (error.status !== undefined) {
|
|
19
|
+
clientError.httpErrorCode = error.status;
|
|
20
|
+
}
|
|
21
|
+
if (error.response !== undefined) {
|
|
22
|
+
const errorData = error.response.data;
|
|
23
|
+
clientError.type = errorData.type;
|
|
24
|
+
clientError.code = errorData.code;
|
|
25
|
+
clientError.message = errorData.message;
|
|
26
|
+
clientError.param = errorData.param;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.error('Unable to parse AxiosError response', { error });
|
|
30
|
+
}
|
|
31
|
+
return clientError;
|
|
18
32
|
}
|
|
19
|
-
|
|
33
|
+
// if (error.body !== undefined && error.body !== null && error.body.error !== undefined && error.body.error !== null) {
|
|
34
|
+
// error = error.body.error;
|
|
35
|
+
// }
|
|
36
|
+
// let message: string = error;
|
|
37
|
+
// if (error.message !== undefined && error.message !== null) {
|
|
38
|
+
// message = error.message;
|
|
39
|
+
// }
|
|
40
|
+
//
|
|
20
41
|
// console.error(error);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
42
|
+
const xError = error;
|
|
43
|
+
if (xError.status !== null && xError.status !== undefined) {
|
|
44
|
+
const statusCode = xError.status;
|
|
45
|
+
const { body } = xError;
|
|
24
46
|
const clientErrorByStatus = this.byStatus(statusCode, body);
|
|
25
47
|
if (clientErrorByStatus !== null) {
|
|
26
48
|
clientError = clientErrorByStatus;
|
|
27
49
|
}
|
|
28
50
|
}
|
|
29
|
-
else if (
|
|
30
|
-
switch (
|
|
51
|
+
else if (xError.code !== null && xError.code !== undefined) {
|
|
52
|
+
switch (xError.code) {
|
|
31
53
|
case 'EUNAVAILABLE':
|
|
32
|
-
clientError.
|
|
54
|
+
clientError.httpErrorCode = HttpClient.HTTP_UNAVAILABLE;
|
|
33
55
|
break;
|
|
34
56
|
case 'EAUTH':
|
|
35
57
|
case 401:
|
|
36
|
-
clientError.
|
|
58
|
+
clientError.httpErrorCode = HttpClient.HTTP_UNAUTHORIZED;
|
|
37
59
|
break;
|
|
38
60
|
case 'ESTATUS':
|
|
39
61
|
if (error.message === 'HTTP status 503') {
|
|
40
|
-
clientError.
|
|
62
|
+
clientError.httpErrorCode = HttpClient.HTTP_UNAVAILABLE;
|
|
41
63
|
}
|
|
42
64
|
break;
|
|
43
65
|
case 500:
|
|
44
|
-
clientError.
|
|
66
|
+
clientError.httpErrorCode = HttpClient.HTTP_INTERNAL_SERVER_ERROR;
|
|
45
67
|
break;
|
|
46
68
|
default:
|
|
47
|
-
console.warn('[Client error] Error code `' +
|
|
48
|
-
clientError.
|
|
69
|
+
console.warn('[Client error] Error code `' + xError.code + '` not recognised');
|
|
70
|
+
clientError.httpErrorCode = HttpClient.HTTP_INTERNAL_SERVER_ERROR;
|
|
49
71
|
}
|
|
50
72
|
}
|
|
51
73
|
clientError.name = error.name;
|
|
@@ -83,6 +105,5 @@ export class ClientError extends Error {
|
|
|
83
105
|
console.error('Unknown status code "' + statusCode + '"', { code: statusCode, text: statusText });
|
|
84
106
|
return new ClientError('Status code ' + statusCode + ': ' + statusText, statusCode);
|
|
85
107
|
}
|
|
86
|
-
return null;
|
|
87
108
|
}
|
|
88
109
|
}
|
package/dist/Http/HttpClient.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import axios
|
|
1
|
+
import axios from 'axios';
|
|
2
2
|
import { HttpClientResponse } from './HttpClientResponse.js';
|
|
3
3
|
import { ClientError } from './ClientError.js';
|
|
4
4
|
export class HttpClient {
|
|
@@ -14,13 +14,15 @@ export class HttpClient {
|
|
|
14
14
|
static HTTP_TIMEOUT = 504;
|
|
15
15
|
static async request(request) {
|
|
16
16
|
const response = await HttpClient.axiosRequest(request);
|
|
17
|
-
const error = ClientError.byStatus(response.status, response.statusText);
|
|
18
|
-
if (error !== null && error !== undefined) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
// const error: ClientError | null = ClientError.byStatus(response.status, response.statusText);
|
|
18
|
+
// if (error !== null && error !== undefined) {
|
|
19
|
+
// if (response.body !== null && response.body !== undefined && response.body.error !== null && response.body.error !== undefined && response.body.error.message !== null && response.body.error.message !== undefined
|
|
20
|
+
// ) {
|
|
21
|
+
// error.message = response.body.error.message;
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
24
|
+
// throw error;
|
|
25
|
+
// }
|
|
24
26
|
return response;
|
|
25
27
|
}
|
|
26
28
|
static async axiosRequest(request) {
|
|
@@ -45,19 +47,17 @@ export class HttpClient {
|
|
|
45
47
|
httpResponse.body = await rawResponse.data;
|
|
46
48
|
return httpResponse;
|
|
47
49
|
}
|
|
48
|
-
catch (
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const response = new HttpClientResponse(500, '');
|
|
60
|
-
return response;
|
|
50
|
+
catch (requestError) {
|
|
51
|
+
// if (requestError instanceof AxiosError) {
|
|
52
|
+
// const status: number = requestError.status === undefined ? 500 : requestError.status;
|
|
53
|
+
// const statusCode: string = requestError.code === undefined ? 'Error' : requestError.code;
|
|
54
|
+
//
|
|
55
|
+
// const response: HttpClientResponse = new HttpClientResponse(status, statusCode);
|
|
56
|
+
//
|
|
57
|
+
//
|
|
58
|
+
// throw ClientError.fromError(requestError);
|
|
59
|
+
// }
|
|
60
|
+
throw ClientError.fromError(requestError);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
static isJson(response) {
|
package/dist/Http/OAuthClient.js
CHANGED
|
@@ -28,14 +28,23 @@ export class OAuthClient {
|
|
|
28
28
|
// Client credentials flow
|
|
29
29
|
const getClientCredentials = clientCredentials(this.getAxiosInstance(), this.getApiEndpointUrl(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
|
|
30
30
|
const rawAuthToken = await getClientCredentials(this.options.scopes.join(' '));
|
|
31
|
+
console.log('Faw token', rawAuthToken);
|
|
31
32
|
this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
|
|
33
|
+
// const getRefreshToken = refreshToken(
|
|
34
|
+
// this.getAxiosInstance(),
|
|
35
|
+
// this.getApiEndpointUrl(this.options.accessTokenUri),
|
|
36
|
+
// this.options.clientId === null ? undefined : this.options.clientId,
|
|
37
|
+
// this.options.clientSecret === null ? undefined : this.options.clientSecret,
|
|
38
|
+
// );
|
|
39
|
+
// const auth = await getRefreshToken(this.oathClientToken.access_token, this.options.scopes.join(' '))
|
|
40
|
+
// console.log('Refresh token', auth);
|
|
32
41
|
return true;
|
|
33
42
|
}
|
|
34
|
-
catch (
|
|
43
|
+
catch (requestError) {
|
|
35
44
|
if (this.debug) {
|
|
36
|
-
console.debug('[Client] Error during authentication',
|
|
45
|
+
console.debug('[Client] Error during authentication', requestError);
|
|
37
46
|
}
|
|
38
|
-
throw ClientError.fromError(
|
|
47
|
+
throw ClientError.fromError(requestError);
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
async refreshToken() {
|
package/dist/Service/Endpoint.js
CHANGED
|
@@ -74,6 +74,10 @@ export class Endpoint {
|
|
|
74
74
|
if (action instanceof QueryString) {
|
|
75
75
|
action = action.build();
|
|
76
76
|
}
|
|
77
|
+
try {
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
}
|
|
77
81
|
const requestResponse = await this.httpClient.request(action, parameters, method, signWithOauthToken);
|
|
78
82
|
const result = new CollectionResult();
|
|
79
83
|
/**
|
|
@@ -2,17 +2,20 @@ import { Endpoint } from './Endpoint.js';
|
|
|
2
2
|
import { CollectionResult } from '../Model/Result/CollectionResult.js';
|
|
3
3
|
import { CursorPagination } from '../Model/Pagination/CursorPagination.js';
|
|
4
4
|
export type BlockedIp = {
|
|
5
|
+
id: string;
|
|
5
6
|
ip: string;
|
|
6
7
|
from: Date;
|
|
7
8
|
to: Date;
|
|
8
9
|
reason: string;
|
|
9
10
|
};
|
|
10
11
|
export type FlaggedIp = {
|
|
12
|
+
id: string;
|
|
11
13
|
ip: string;
|
|
12
14
|
date: Date;
|
|
13
15
|
reason: string;
|
|
14
16
|
};
|
|
15
17
|
export type IpRule = {
|
|
18
|
+
id: string;
|
|
16
19
|
ip: string;
|
|
17
20
|
action: string;
|
|
18
21
|
description: string;
|
|
@@ -5,6 +5,7 @@ export class FirewallEndpoint extends Endpoint {
|
|
|
5
5
|
async getBlockedIps(pagination) {
|
|
6
6
|
const parser = (raw) => {
|
|
7
7
|
return {
|
|
8
|
+
id: raw.id,
|
|
8
9
|
ip: raw.ip,
|
|
9
10
|
from: Utils.parseRawDate(raw.from),
|
|
10
11
|
to: Utils.parseRawDate(raw.to),
|
|
@@ -19,6 +20,7 @@ export class FirewallEndpoint extends Endpoint {
|
|
|
19
20
|
async getFlaggedIps(pagination) {
|
|
20
21
|
const parser = (raw) => {
|
|
21
22
|
return {
|
|
23
|
+
id: raw.id,
|
|
22
24
|
ip: raw.ip,
|
|
23
25
|
date: Utils.parseRawDate(raw.date),
|
|
24
26
|
reason: raw.reason,
|
|
@@ -32,6 +34,7 @@ export class FirewallEndpoint extends Endpoint {
|
|
|
32
34
|
async getIpRules(pagination) {
|
|
33
35
|
const parser = (raw) => {
|
|
34
36
|
return {
|
|
37
|
+
id: raw.id,
|
|
35
38
|
ip: raw.ip,
|
|
36
39
|
action: raw.action,
|
|
37
40
|
description: raw.description,
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.18.4";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "1.
|
|
1
|
+
export const VERSION = "1.18.4";
|