attlaz-client 1.18.5 → 1.18.7

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.
@@ -1,10 +1,10 @@
1
1
  import { AxiosError } from 'axios';
2
2
  export declare class ClientError extends Error {
3
- httpErrorCode: number | null;
3
+ httpStatus: number | null;
4
4
  type: string;
5
5
  code: string;
6
6
  message: string;
7
- param?: string;
7
+ param?: string | undefined;
8
8
  stack?: string;
9
9
  constructor(code: string, httpErrorCode?: number | null);
10
10
  static fromError(error: Error | AxiosError): ClientError;
@@ -1,33 +1,48 @@
1
1
  import { AxiosError } from 'axios';
2
- import { HttpClient } from './HttpClient.js';
2
+ import { HttpStatus } from './HttpStatus.js';
3
3
  export class ClientError extends Error {
4
- httpErrorCode = null;
4
+ httpStatus = null;
5
5
  type;
6
6
  code;
7
7
  message;
8
8
  param = undefined;
9
- stack = undefined;
9
+ stack;
10
10
  constructor(code, httpErrorCode = null) {
11
11
  super(code);
12
12
  this.code = code;
13
- this.httpErrorCode = httpErrorCode;
13
+ this.httpStatus = httpErrorCode;
14
14
  }
15
15
  static fromError(error) {
16
- let clientError = new ClientError('Unknown error', HttpClient.HTTP_INTERNAL_SERVER_ERROR);
16
+ let clientError = new ClientError('Unknown error', HttpStatus.HTTP_INTERNAL_SERVER_ERROR);
17
17
  if (error instanceof AxiosError) {
18
18
  if (error.status !== undefined) {
19
- clientError.httpErrorCode = error.status;
19
+ clientError.httpStatus = error.status;
20
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;
21
+ // console.log('Status', clientError.httpStatus);
22
+ // if(clientError.httpStatus === HttpStatusCode.Ref)
23
+ clientError.message = error.message;
24
+ if (error.code !== undefined) {
25
+ clientError.code = error.code;
27
26
  }
28
- else {
27
+ if (error.response === undefined) {
29
28
  console.error('Unable to parse AxiosError response', { error });
30
29
  }
30
+ else {
31
+ // console.debug('Parse response', {error: error, data: error.response.data});
32
+ const errorData = error.response.data;
33
+ if (errorData.type !== undefined) {
34
+ clientError.type = errorData.type;
35
+ }
36
+ if (errorData.code !== undefined) {
37
+ clientError.code = errorData.code;
38
+ }
39
+ if (errorData.message !== undefined) {
40
+ clientError.message = errorData.message;
41
+ }
42
+ if (errorData.param !== undefined) {
43
+ clientError.param = errorData.param;
44
+ }
45
+ }
31
46
  return clientError;
32
47
  }
33
48
  // if (error.body !== undefined && error.body !== null && error.body.error !== undefined && error.body.error !== null) {
@@ -51,23 +66,23 @@ export class ClientError extends Error {
51
66
  else if (xError.code !== null && xError.code !== undefined) {
52
67
  switch (xError.code) {
53
68
  case 'EUNAVAILABLE':
54
- clientError.httpErrorCode = HttpClient.HTTP_UNAVAILABLE;
69
+ clientError.httpStatus = HttpStatus.HTTP_UNAVAILABLE;
55
70
  break;
56
71
  case 'EAUTH':
57
72
  case 401:
58
- clientError.httpErrorCode = HttpClient.HTTP_UNAUTHORIZED;
73
+ clientError.httpStatus = HttpStatus.HTTP_UNAUTHORIZED;
59
74
  break;
60
75
  case 'ESTATUS':
61
76
  if (error.message === 'HTTP status 503') {
62
- clientError.httpErrorCode = HttpClient.HTTP_UNAVAILABLE;
77
+ clientError.httpStatus = HttpStatus.HTTP_UNAVAILABLE;
63
78
  }
64
79
  break;
65
80
  case 500:
66
- clientError.httpErrorCode = HttpClient.HTTP_INTERNAL_SERVER_ERROR;
81
+ clientError.httpStatus = HttpStatus.HTTP_INTERNAL_SERVER_ERROR;
67
82
  break;
68
83
  default:
69
84
  console.warn('[Client error] Error code `' + xError.code + '` not recognised');
70
- clientError.httpErrorCode = HttpClient.HTTP_INTERNAL_SERVER_ERROR;
85
+ clientError.httpStatus = HttpStatus.HTTP_INTERNAL_SERVER_ERROR;
71
86
  }
72
87
  }
73
88
  clientError.name = error.name;
@@ -82,25 +97,25 @@ export class ClientError extends Error {
82
97
  case 202:
83
98
  return null;
84
99
  case 400:
85
- return new ClientError('Bad Request', HttpClient.HTTP_BAD_REQUEST);
100
+ return new ClientError('Bad Request', HttpStatus.HTTP_BAD_REQUEST);
86
101
  case 401:
87
- return new ClientError('Unauthorized', HttpClient.HTTP_UNAUTHORIZED);
102
+ return new ClientError('Unauthorized', HttpStatus.HTTP_UNAUTHORIZED);
88
103
  case 403:
89
- return new ClientError('Forbidden', HttpClient.HTTP_FORBIDDEN);
104
+ return new ClientError('Forbidden', HttpStatus.HTTP_FORBIDDEN);
90
105
  case 404:
91
- return new ClientError('Not Found', HttpClient.HTTP_NOTFOUND);
106
+ return new ClientError('Not Found', HttpStatus.HTTP_NOTFOUND);
92
107
  case 405:
93
- return new ClientError('Not allowed', HttpClient.HTTP_NOT_ALLOWED);
108
+ return new ClientError('Not allowed', HttpStatus.HTTP_NOT_ALLOWED);
94
109
  case 422:
95
- return new ClientError('Unprocessable Entity', HttpClient.HTTP_UNPROCESSABLE_ENTITY);
110
+ return new ClientError('Unprocessable Entity', HttpStatus.HTTP_UNPROCESSABLE_ENTITY);
96
111
  case 500:
97
- return new ClientError('Internal Server Error', HttpClient.HTTP_INTERNAL_SERVER_ERROR);
112
+ return new ClientError('Internal Server Error', HttpStatus.HTTP_INTERNAL_SERVER_ERROR);
98
113
  case 502:
99
- return new ClientError('Bad gateway', HttpClient.HTTP_BAD_GATEWAY);
114
+ return new ClientError('Bad gateway', HttpStatus.HTTP_BAD_GATEWAY);
100
115
  case 503:
101
- return new ClientError('Service not available', HttpClient.HTTP_UNAVAILABLE);
116
+ return new ClientError('Service not available', HttpStatus.HTTP_UNAVAILABLE);
102
117
  case 504:
103
- return new ClientError('Gateway Time-out', HttpClient.HTTP_TIMEOUT);
118
+ return new ClientError('Gateway Time-out', HttpStatus.HTTP_TIMEOUT);
104
119
  default:
105
120
  console.error('Unknown status code "' + statusCode + '"', { code: statusCode, text: statusText });
106
121
  return new ClientError('Status code ' + statusCode + ': ' + statusText, statusCode);
@@ -0,0 +1,6 @@
1
+ export declare class ContentTypeHelper {
2
+ static formatContentType(input: string): {
3
+ type: string;
4
+ options: string | null;
5
+ };
6
+ }
@@ -0,0 +1,13 @@
1
+ export class ContentTypeHelper {
2
+ static formatContentType(input) {
3
+ const arrInput = input.split(';');
4
+ if (arrInput.length === 1) {
5
+ return { type: arrInput[0], options: null };
6
+ }
7
+ if (arrInput.length === 2) {
8
+ return { type: arrInput[0], options: arrInput[1].trim() };
9
+ }
10
+ console.error('Unable to parse content type "' + input + '"');
11
+ return { type: input, options: null };
12
+ }
13
+ }
@@ -1,21 +1,6 @@
1
1
  import { HttpClientRequest } from './HttpClientRequest.js';
2
2
  import { HttpClientResponse } from './HttpClientResponse.js';
3
3
  export declare class HttpClient {
4
- static HTTP_BAD_REQUEST: number;
5
- static HTTP_UNAUTHORIZED: number;
6
- static HTTP_FORBIDDEN: number;
7
- static HTTP_NOTFOUND: number;
8
- static HTTP_NOT_ALLOWED: number;
9
- static HTTP_UNPROCESSABLE_ENTITY: number;
10
- static HTTP_INTERNAL_SERVER_ERROR: number;
11
- static HTTP_BAD_GATEWAY: number;
12
- static HTTP_UNAVAILABLE: number;
13
- static HTTP_TIMEOUT: number;
14
4
  static request(request: HttpClientRequest): Promise<HttpClientResponse>;
15
5
  private static axiosRequest;
16
- private static isJson;
17
- static formatContentType(input: string): {
18
- type: string;
19
- options: string | null;
20
- };
21
6
  }
@@ -2,16 +2,6 @@ import axios from 'axios';
2
2
  import { HttpClientResponse } from './HttpClientResponse.js';
3
3
  import { ClientError } from './ClientError.js';
4
4
  export class HttpClient {
5
- static HTTP_BAD_REQUEST = 400;
6
- static HTTP_UNAUTHORIZED = 401;
7
- static HTTP_FORBIDDEN = 403;
8
- static HTTP_NOTFOUND = 404;
9
- static HTTP_NOT_ALLOWED = 405;
10
- static HTTP_UNPROCESSABLE_ENTITY = 422;
11
- static HTTP_INTERNAL_SERVER_ERROR = 500;
12
- static HTTP_BAD_GATEWAY = 502;
13
- static HTTP_UNAVAILABLE = 503;
14
- static HTTP_TIMEOUT = 504;
15
5
  static async request(request) {
16
6
  const response = await HttpClient.axiosRequest(request);
17
7
  // const error: ClientError | null = ClientError.byStatus(response.status, response.statusText);
@@ -60,18 +50,4 @@ export class HttpClient {
60
50
  throw ClientError.fromError(requestError);
61
51
  }
62
52
  }
63
- static isJson(response) {
64
- return response.getContentType() === 'application/json';
65
- }
66
- static formatContentType(input) {
67
- const d = input.split(';');
68
- if (d.length === 1) {
69
- return { type: d[0], options: null };
70
- }
71
- if (d.length === 2) {
72
- return { type: d[0], options: d[1].trim() };
73
- }
74
- console.error('Unable to parse content type "' + input + '"');
75
- return { type: input, options: null };
76
- }
77
53
  }
@@ -6,4 +6,5 @@ export declare class HttpClientResponse {
6
6
  headers: Headers;
7
7
  constructor(status: number, statusText: string);
8
8
  getContentType(): string | null;
9
+ isJson(): boolean;
9
10
  }
@@ -1,4 +1,4 @@
1
- import { HttpClient } from './HttpClient.js';
1
+ import { ContentTypeHelper } from './ContentTypeHelper.js';
2
2
  export class HttpClientResponse {
3
3
  status;
4
4
  statusText;
@@ -20,7 +20,10 @@ export class HttpClientResponse {
20
20
  if (contentType === null || contentType === undefined) {
21
21
  return null;
22
22
  }
23
- const parsedContentType = HttpClient.formatContentType(contentType);
23
+ const parsedContentType = ContentTypeHelper.formatContentType(contentType);
24
24
  return parsedContentType.type;
25
25
  }
26
+ isJson() {
27
+ return this.getContentType() === 'application/json';
28
+ }
26
29
  }
@@ -0,0 +1,12 @@
1
+ export declare class HttpStatus {
2
+ static HTTP_BAD_REQUEST: number;
3
+ static HTTP_UNAUTHORIZED: number;
4
+ static HTTP_FORBIDDEN: number;
5
+ static HTTP_NOTFOUND: number;
6
+ static HTTP_NOT_ALLOWED: number;
7
+ static HTTP_UNPROCESSABLE_ENTITY: number;
8
+ static HTTP_INTERNAL_SERVER_ERROR: number;
9
+ static HTTP_BAD_GATEWAY: number;
10
+ static HTTP_UNAVAILABLE: number;
11
+ static HTTP_TIMEOUT: number;
12
+ }
@@ -0,0 +1,12 @@
1
+ export class HttpStatus {
2
+ static HTTP_BAD_REQUEST = 400;
3
+ static HTTP_UNAUTHORIZED = 401;
4
+ static HTTP_FORBIDDEN = 403;
5
+ static HTTP_NOTFOUND = 404;
6
+ static HTTP_NOT_ALLOWED = 405;
7
+ static HTTP_UNPROCESSABLE_ENTITY = 422;
8
+ static HTTP_INTERNAL_SERVER_ERROR = 500;
9
+ static HTTP_BAD_GATEWAY = 502;
10
+ static HTTP_UNAVAILABLE = 503;
11
+ static HTTP_TIMEOUT = 504;
12
+ }
@@ -28,7 +28,7 @@ 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
+ // console.log('Raw token', rawAuthToken);
32
32
  this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
33
33
  // const getRefreshToken = refreshToken(
34
34
  // this.getAxiosInstance(),
@@ -121,6 +121,9 @@ export class OAuthClient {
121
121
  }
122
122
  throw clientError;
123
123
  }
124
+ if (this.debug) {
125
+ console.error('[Client] Error:', { error });
126
+ }
124
127
  throw error;
125
128
  }
126
129
  }
@@ -1,12 +1,12 @@
1
1
  import { CollectionResult } from '../Model/Result/CollectionResult.js';
2
2
  import { ObjectResult } from '../Model/Result/ObjectResult.js';
3
- import { HttpClient } from '../Http/HttpClient.js';
4
3
  import { Utils } from '../Utils.js';
5
4
  import { ObjectWrapper } from '../Model/Result/ObjectWrapper.js';
6
5
  import { DataValueCollection } from '../Model/DataValueCollection.js';
7
6
  import { JsonSerializable } from '../Model/JsonSerializable.js';
8
7
  import { LogStreamId } from '../Model/Log/LogStreamId.js';
9
8
  import { QueryString } from '../Http/Data/QueryString.js';
9
+ import { HttpStatus } from '../Http/HttpStatus.js';
10
10
  export class Endpoint {
11
11
  httpClient;
12
12
  constructor(httpClient) {
@@ -123,7 +123,7 @@ export class Endpoint {
123
123
  result.setData(this.parseObject(requestResponse, parser));
124
124
  }
125
125
  catch (error) {
126
- if (error.code === HttpClient.HTTP_NOTFOUND) {
126
+ if (error.httpStatus === HttpStatus.HTTP_NOTFOUND) {
127
127
  result.setData(null);
128
128
  }
129
129
  else {
@@ -1,8 +1,8 @@
1
1
  import { Endpoint } from './Endpoint.js';
2
2
  import { Utils } from '../Utils.js';
3
- import { HttpClient } from '../Http/HttpClient.js';
4
3
  import { Flow } from '../Model/Flow/Flow.js';
5
4
  import { FlowSummary } from '../Model/Flow/FlowSummary.js';
5
+ import { HttpStatus } from '../Http/HttpStatus.js';
6
6
  export class FlowEndpoint extends Endpoint {
7
7
  async getByProject(projectId) {
8
8
  try {
@@ -23,7 +23,7 @@ export class FlowEndpoint extends Endpoint {
23
23
  return result.getData();
24
24
  }
25
25
  catch (error) {
26
- if (error.code === HttpClient.HTTP_NOTFOUND) {
26
+ if (error.httpStatus === HttpStatus.HTTP_NOTFOUND) {
27
27
  return null;
28
28
  }
29
29
  if (this.httpClient.isDebugEnabled()) {
@@ -1,7 +1,7 @@
1
1
  import { Endpoint } from './Endpoint.js';
2
2
  import { ProjectEnvironment } from '../Model/Project/ProjectEnvironment.js';
3
- import { HttpClient } from '../Http/HttpClient.js';
4
3
  import { ProjectEnvironmentConfiguration } from '../Model/Project/ProjectEnvironmentConfiguration.js';
4
+ import { HttpStatus } from '../Http/HttpStatus.js';
5
5
  export class ProjectEnvironmentEndpoint extends Endpoint {
6
6
  async getByProject(id) {
7
7
  try {
@@ -21,7 +21,7 @@ export class ProjectEnvironmentEndpoint extends Endpoint {
21
21
  return rawProjectEnvironment.getData();
22
22
  }
23
23
  catch (error) {
24
- if (error.code === HttpClient.HTTP_NOTFOUND) {
24
+ if (error.httpStatus === HttpStatus.HTTP_NOTFOUND) {
25
25
  return null;
26
26
  }
27
27
  if (this.httpClient.isDebugEnabled()) {
@@ -60,7 +60,7 @@ export class ProjectEnvironmentEndpoint extends Endpoint {
60
60
  return rawProjectEnvironment.getData();
61
61
  }
62
62
  catch (error) {
63
- if (error.code === HttpClient.HTTP_NOTFOUND) {
63
+ if (error.httpStatus === HttpStatus.HTTP_NOTFOUND) {
64
64
  return null;
65
65
  }
66
66
  if (this.httpClient.isDebugEnabled()) {
@@ -1,10 +1,10 @@
1
1
  import { Endpoint } from './Endpoint.js';
2
2
  import { CodeSourceAccount } from '../Model/Deployment/CodeSourceAccount.js';
3
3
  import { CodeSource } from '../Model/Deployment/CodeSource.js';
4
- import { HttpClient } from '../Http/HttpClient.js';
5
4
  import { SourcesAccountRepository } from '../Model/Deployment/SourcesAccountRepository.js';
6
5
  import { SourcesAccountRepositoryBranch } from '../Model/Deployment/SourcesAccountRepositoryBranch.js';
7
6
  import { QueryString } from '../Http/Data/QueryString.js';
7
+ import { HttpStatus } from '../Http/HttpStatus.js';
8
8
  export class SourcesAccountEndpoint extends Endpoint {
9
9
  async getAllCodeSources(workspaceId, pagination = null) {
10
10
  const queryString = new QueryString('workspaces/' + workspaceId + '/codesources');
@@ -24,7 +24,7 @@ export class SourcesAccountEndpoint extends Endpoint {
24
24
  return rawSourcesAccounts.getData();
25
25
  }
26
26
  catch (error) {
27
- if (error.code === HttpClient.HTTP_NOTFOUND) {
27
+ if (error.httpStatus === HttpStatus.HTTP_NOTFOUND) {
28
28
  return null;
29
29
  }
30
30
  if (this.httpClient.isDebugEnabled()) {
@@ -44,7 +44,7 @@ export class SourcesAccountEndpoint extends Endpoint {
44
44
  return result.getData();
45
45
  }
46
46
  catch (error) {
47
- if (error.code === HttpClient.HTTP_NOTFOUND) {
47
+ if (error.httpStatus === HttpStatus.HTTP_NOTFOUND) {
48
48
  return null;
49
49
  }
50
50
  if (this.httpClient.isDebugEnabled()) {
package/dist/index.d.ts CHANGED
@@ -11,6 +11,8 @@ export { OAuthClient } from './Http/OAuthClient.js';
11
11
  export { OAuthClientOptions } from './Http/OAuthClientOptions.js';
12
12
  export { OAuthClientToken } from './Http/OAuthClientToken.js';
13
13
  export { ClientError } from './Http/ClientError.js';
14
+ export { HttpStatus } from './Http/HttpStatus.js';
15
+ export { ContentTypeHelper } from './Http/ContentTypeHelper.js';
14
16
  /**
15
17
  * Models
16
18
  */
package/dist/index.js CHANGED
@@ -6,6 +6,8 @@ export { OAuthClient } from './Http/OAuthClient.js';
6
6
  export { OAuthClientOptions } from './Http/OAuthClientOptions.js';
7
7
  export { OAuthClientToken } from './Http/OAuthClientToken.js';
8
8
  export { ClientError } from './Http/ClientError.js';
9
+ export { HttpStatus } from './Http/HttpStatus.js';
10
+ export { ContentTypeHelper } from './Http/ContentTypeHelper.js';
9
11
  /**
10
12
  * Models
11
13
  */
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.18.4";
1
+ export declare const VERSION = "1.18.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.18.4";
1
+ export const VERSION = "1.18.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.18.5",
3
+ "version": "1.18.7",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",