attlaz-client 1.11.12 → 1.12.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/Client.d.ts CHANGED
@@ -29,13 +29,13 @@ import { FirewallEndpoint } from './Service/FirewallEndpoint.js';
29
29
  import { CodeSourceStrategiesEndpoint } from './Service/CodeSourceStrategiesEndpoint.js';
30
30
  import { SearchEndpoint } from './Service/SearchEndpoint.js';
31
31
  export declare class Client {
32
- private readonly apiEndpoint;
33
- private readonly clientId;
34
- private readonly clientSecret;
35
32
  private endpoints;
36
- private readonly httpClient;
33
+ private httpClient;
37
34
  private Store;
38
- constructor(apiEndpoint: string, clientId: string, clientSecret: string);
35
+ private apiEndpoint;
36
+ private parseConfig;
37
+ constructor(token?: string | null, config?: Record<string, unknown>);
38
+ setClientCredentials(clientId: string, clientSecret?: string): void;
39
39
  private getHeaders;
40
40
  getHttpClient(): OAuthClient;
41
41
  authenticate(): Promise<boolean>;
package/dist/Client.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { OAuthClientToken } from './Http/OAuthClientToken.js';
1
2
  import { WorkerEndpoint } from './Service/WorkerEndpoint.js';
2
3
  import { AdapterEndpoint } from './Service/AdapterEndpoint.js';
3
4
  import { ProjectEnvironmentEndpoint } from './Service/ProjectEnvironmentEndpoint.js';
@@ -30,9 +31,6 @@ import { VERSION } from './version.js';
30
31
  import { CodeSourceStrategiesEndpoint } from './Service/CodeSourceStrategiesEndpoint.js';
31
32
  import { SearchEndpoint } from './Service/SearchEndpoint.js';
32
33
  export class Client {
33
- apiEndpoint;
34
- clientId;
35
- clientSecret;
36
34
  endpoints;
37
35
  httpClient;
38
36
  Store = {
@@ -65,21 +63,26 @@ export class Client {
65
63
  FirewallEndpoint,
66
64
  SearchEndpoint,
67
65
  };
68
- constructor(apiEndpoint, clientId, clientSecret) {
69
- this.apiEndpoint = apiEndpoint;
70
- this.clientId = clientId;
71
- this.clientSecret = clientSecret;
72
- const options = new OAuthClientOptions(apiEndpoint, clientId, clientSecret, this.getHeaders());
66
+ apiEndpoint = 'https://api.attlaz.com';
67
+ parseConfig(config) {
68
+ return config;
69
+ }
70
+ constructor(token = null, config = {}) {
71
+ const parsedConfig = this.parseConfig(config);
72
+ if (parsedConfig.apiEndpoint !== undefined) {
73
+ this.apiEndpoint = parsedConfig.apiEndpoint;
74
+ }
75
+ const options = new OAuthClientOptions(this.apiEndpoint, null, null, this.getHeaders());
73
76
  this.httpClient = new OAuthClient(options);
77
+ if (token !== null) {
78
+ const clientToken = new OAuthClientToken(token, 'Bearer', '', '');
79
+ this.httpClient.setToken(clientToken);
80
+ }
74
81
  this.endpoints = new Map();
75
- // this.test = new Map<string, any>();
76
- //
77
- // this.test.set('WorkerEndpoint', WorkerEndpoint);
78
- // this.socketService = socketIo(this.apiEndpoint);
79
- //
80
- // this.socketService.on('message', (data: any) => {
81
- // console.log('Incoming:', data);
82
- // });
82
+ }
83
+ setClientCredentials(clientId, clientSecret = '') {
84
+ const options = new OAuthClientOptions(this.apiEndpoint, clientId, clientSecret, this.getHeaders());
85
+ this.httpClient = new OAuthClient(options);
83
86
  }
84
87
  getHeaders() {
85
88
  const userAgentInfo = {
@@ -100,6 +103,7 @@ export class Client {
100
103
  if (username === null || password === null) {
101
104
  return this.httpClient.authenticate();
102
105
  }
106
+ // TODO: this is only possible when clientId and clientSecret are defined
103
107
  return this.httpClient.authenticate(username, password);
104
108
  }
105
109
  isAuthenticated() {
@@ -108,10 +112,6 @@ export class Client {
108
112
  getToken() {
109
113
  return this.httpClient.getToken();
110
114
  }
111
- // public getAccessToken(): string {
112
- // return this.httpClient.getAccessToken();
113
- // }
114
- //
115
115
  setToken(token) {
116
116
  this.httpClient.setToken(token);
117
117
  }
@@ -51,7 +51,9 @@ export class HttpClient {
51
51
  jsonData = JSON.parse(rawData);
52
52
  }
53
53
  catch (e) {
54
- console.error('Unable to parse response data to JSON', { statusText: httpResponse.statusText, error: e });
54
+ console.error('Unable to parse response data to JSON', {
55
+ statusText: httpResponse.statusText, error: e,
56
+ });
55
57
  }
56
58
  }
57
59
  httpResponse.body = jsonData;
@@ -61,7 +63,7 @@ export class HttpClient {
61
63
  }
62
64
  const error = ClientError.byStatus(response.status, response.statusText);
63
65
  if (error !== null && error !== undefined) {
64
- error.body = httpResponse.body;
66
+ error.message = httpResponse.body.error.message;
65
67
  throw error;
66
68
  }
67
69
  return httpResponse;
@@ -13,8 +13,8 @@ export class OAuthClient {
13
13
  constructor(options) {
14
14
  this.options = options;
15
15
  this.oauthClient = new ClientOAuth2({
16
- clientId: options.clientId,
17
- clientSecret: options.clientSecret,
16
+ clientId: options.clientId === null ? undefined : options.clientId,
17
+ clientSecret: options.clientSecret === null ? undefined : options.clientSecret,
18
18
  accessTokenUri: this.getUri(options.accessTokenUri),
19
19
  authorizationUri: this.getUri(options.authorizationUri),
20
20
  redirectUri: options.redirectUri,
@@ -105,11 +105,14 @@ export class OAuthClient {
105
105
  return response.body;
106
106
  }
107
107
  catch (error) {
108
- const clientError = ClientError.fromError(error);
109
- if (this.debug) {
110
- console.error('[Client] Error:', { error, clientError });
108
+ if (!(error instanceof ClientError)) {
109
+ const clientError = ClientError.fromError(error);
110
+ if (this.debug) {
111
+ console.error('[Client] Error:', { error, clientError });
112
+ }
113
+ throw clientError;
111
114
  }
112
- throw clientError;
115
+ throw error;
113
116
  }
114
117
  }
115
118
  }
@@ -1,13 +1,13 @@
1
1
  import { Headers } from './Data/Header.js';
2
2
  export declare class OAuthClientOptions {
3
3
  apiEndpoint: string;
4
- clientId: string;
5
- clientSecret: string;
4
+ readonly clientId: string | null;
5
+ readonly clientSecret: string | null;
6
+ headers: Headers;
6
7
  accessTokenUri: string;
7
8
  authorizationUri: string;
8
9
  redirectUri: string;
9
10
  scopes: string[];
10
11
  state: string;
11
- headers: Headers;
12
- constructor(apiEndpoint: string, clientId: string, clientSecret: string, headers: Headers);
12
+ constructor(apiEndpoint: string, clientId: string | null, clientSecret: string | null, headers: Headers);
13
13
  }
@@ -2,12 +2,12 @@ export class OAuthClientOptions {
2
2
  apiEndpoint;
3
3
  clientId;
4
4
  clientSecret;
5
+ headers;
5
6
  accessTokenUri = 'oauth/token';
6
7
  authorizationUri = 'oauth/authorize';
7
8
  redirectUri = 'https://example.com/auth/github/callback';
8
9
  scopes = ['all'];
9
10
  state = 'xyz';
10
- headers;
11
11
  constructor(apiEndpoint, clientId, clientSecret, headers) {
12
12
  this.apiEndpoint = apiEndpoint;
13
13
  this.clientId = clientId;
@@ -1,10 +1,8 @@
1
1
  export declare class ClientError implements Error {
2
- message: string;
3
- name: string;
4
2
  code: number | null;
5
- stack: string;
6
- body: string | null;
7
- constructor(message: string, code?: number | null);
3
+ name: string;
4
+ message: string;
5
+ constructor(name: string, code?: number | null);
8
6
  static fromError(error: Error | any): ClientError;
9
7
  static byStatus(statusCode: number, statusText: string): ClientError | null;
10
8
  }
@@ -1,15 +1,18 @@
1
1
  import { HttpClient } from '../../Http/HttpClient.js';
2
2
  export class ClientError {
3
- message;
4
- name;
5
3
  code;
6
- stack;
7
- body = null;
8
- constructor(message, code = null) {
9
- this.message = message;
4
+ name;
5
+ message;
6
+ // description: string | null;
7
+ // stack: string;
8
+ // body: string | null = null;
9
+ constructor(name, code = null) {
10
+ this.name = name;
11
+ this.message = name;
10
12
  this.code = code;
11
13
  }
12
14
  static fromError(error) {
15
+ console.log(error);
13
16
  if (error.body !== undefined && error.body !== null && error.body.error !== undefined && error.body.error !== null) {
14
17
  error = error.body.error;
15
18
  }
@@ -42,7 +45,7 @@ export class ClientError {
42
45
  }
43
46
  }
44
47
  clientError.name = error.name;
45
- clientError.stack = error.stack;
48
+ // clientError.stack = error.stack;
46
49
  return clientError;
47
50
  }
48
51
  static byStatus(statusCode, statusText) {
@@ -3,5 +3,6 @@ import { Workspace } from '../Model/Workspace/Workspace.js';
3
3
  import { CollectionResult } from '../Model/Result/CollectionResult.js';
4
4
  export declare class WorkspaceEndpoint extends Endpoint {
5
5
  getAll(): Promise<CollectionResult<Workspace>>;
6
+ getById(workspaceId: string): Promise<Workspace | null>;
6
7
  save(workspace: Workspace): Promise<Workspace>;
7
8
  }
@@ -13,6 +13,19 @@ export class WorkspaceEndpoint extends Endpoint {
13
13
  throw e;
14
14
  }
15
15
  }
16
+ async getById(workspaceId) {
17
+ try {
18
+ const url = '/workspaces/' + workspaceId + '';
19
+ const result = await this.requestObject(url, null, Workspace.parse);
20
+ return result.getData();
21
+ }
22
+ catch (error) {
23
+ if (this.httpClient.isDebugEnabled()) {
24
+ console.error('Failed to load workspace by id: ', error);
25
+ }
26
+ throw error;
27
+ }
28
+ }
16
29
  async save(workspace) {
17
30
  try {
18
31
  const url = '/workspaces';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.11.8";
1
+ export declare const VERSION = "1.11.14";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.11.8";
1
+ export const VERSION = "1.11.14";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.11.12",
3
+ "version": "1.12.0",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",