attlaz-client 1.11.14 → 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
  }
@@ -63,7 +63,6 @@ export class HttpClient {
63
63
  }
64
64
  const error = ClientError.byStatus(response.status, response.statusText);
65
65
  if (error !== null && error !== undefined) {
66
- console.log(httpResponse.body);
67
66
  error.message = httpResponse.body.error.message;
68
67
  throw error;
69
68
  }
@@ -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,
@@ -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;
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.14",
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",