attlaz-client 1.12.2 → 1.12.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 CHANGED
@@ -36,7 +36,6 @@ export declare class Client {
36
36
  private parseConfig;
37
37
  constructor(token?: string | null, config?: Record<string, unknown>);
38
38
  setClientCredentials(clientId: string, clientSecret?: string): void;
39
- private getHeaders;
40
39
  getHttpClient(): OAuthClient;
41
40
  authenticate(): Promise<boolean>;
42
41
  authenticate(username: string, password: string): Promise<boolean>;
package/dist/Client.js CHANGED
@@ -27,7 +27,6 @@ import { TriggerEndpoint } from './Service/TriggerEndpoint.js';
27
27
  import { PlatformEndpoint } from './Service/PlatformEndpoint.js';
28
28
  import { FlowRunStatsEndpoint } from './Service/FlowRunStatsEndpoint.js';
29
29
  import { FirewallEndpoint } from './Service/FirewallEndpoint.js';
30
- import { VERSION } from './version.js';
31
30
  import { CodeSourceStrategiesEndpoint } from './Service/CodeSourceStrategiesEndpoint.js';
32
31
  import { SearchEndpoint } from './Service/SearchEndpoint.js';
33
32
  export class Client {
@@ -72,7 +71,7 @@ export class Client {
72
71
  if (parsedConfig.apiEndpoint !== undefined) {
73
72
  this.apiEndpoint = parsedConfig.apiEndpoint;
74
73
  }
75
- const options = new OAuthClientOptions(this.apiEndpoint, null, null, this.getHeaders());
74
+ const options = new OAuthClientOptions(this.apiEndpoint);
76
75
  this.httpClient = new OAuthClient(options);
77
76
  if (token !== null) {
78
77
  const clientToken = new OAuthClientToken(token, 'Bearer', '', '');
@@ -81,21 +80,9 @@ export class Client {
81
80
  this.endpoints = new Map();
82
81
  }
83
82
  setClientCredentials(clientId, clientSecret = '') {
84
- const options = new OAuthClientOptions(this.apiEndpoint, clientId, clientSecret, this.getHeaders());
83
+ const options = new OAuthClientOptions(this.apiEndpoint, clientId, clientSecret);
85
84
  this.httpClient = new OAuthClient(options);
86
85
  }
87
- getHeaders() {
88
- const userAgentInfo = {
89
- version: VERSION,
90
- language: 'Javascript',
91
- language_version: '',
92
- publisher: 'Attlaz',
93
- };
94
- return {
95
- 'User-Agent': 'Attlaz Javascript Client/' + VERSION,
96
- 'X-Attlaz-Client-User-Agent': JSON.stringify(userAgentInfo),
97
- };
98
- }
99
86
  getHttpClient() {
100
87
  return this.httpClient;
101
88
  }
@@ -115,10 +102,6 @@ export class Client {
115
102
  setToken(token) {
116
103
  this.httpClient.setToken(token);
117
104
  }
118
- //
119
- // public x(accessToken: string, refreshToken: string): Promise<Token> {
120
- // return this.httpClient.refreshToken(accessToken, refreshToken);
121
- // }
122
105
  unsetAccessToken() {
123
106
  this.httpClient.unsetToken();
124
107
  }
@@ -1,4 +1,4 @@
1
- import { HttpClient } from '../../Http/HttpClient.js';
1
+ import { HttpClient } from './HttpClient.js';
2
2
  export class ClientError {
3
3
  code;
4
4
  name;
@@ -12,7 +12,6 @@ export class ClientError {
12
12
  this.code = code;
13
13
  }
14
14
  static fromError(error) {
15
- console.log(error);
16
15
  if (error.body !== undefined && error.body !== null && error.body.error !== undefined && error.body.error !== null) {
17
16
  error = error.body.error;
18
17
  }
@@ -31,17 +30,21 @@ export class ClientError {
31
30
  }
32
31
  }
33
32
  else if (error.code !== null && error.code !== undefined) {
34
- if (error.code === 'EUNAVAILABLE') {
35
- clientError.code = HttpClient.HTTP_UNAVAILABLE;
36
- }
37
- if (error.code === 'EAUTH') {
38
- clientError.code = HttpClient.HTTP_UNAUTHORIZED;
39
- }
40
- // if (error.code === 'ESTATUS' && error.message === 'HTTP status 503') {
41
- // clientError.code = HttpClient.HTTP_UNAVAILABLE;
42
- // }
43
- else {
44
- clientError.code = error.code;
33
+ switch (error.code) {
34
+ case 'EUNAVAILABLE':
35
+ clientError.code = HttpClient.HTTP_UNAVAILABLE;
36
+ break;
37
+ case 'EAUTH':
38
+ clientError.code = HttpClient.HTTP_UNAUTHORIZED;
39
+ break;
40
+ case 'ESTATUS':
41
+ if (error.message === 'HTTP status 503') {
42
+ clientError.code = HttpClient.HTTP_UNAVAILABLE;
43
+ }
44
+ break;
45
+ default:
46
+ console.warn('[Client error] Error code `' + error.code + '` not recognised');
47
+ clientError.code = error.code;
45
48
  }
46
49
  }
47
50
  clientError.name = error.name;
@@ -11,7 +11,7 @@ export declare class HttpClient {
11
11
  static HTTP_BAD_GATEWAY: number;
12
12
  static HTTP_UNAVAILABLE: number;
13
13
  static HTTP_TIMEOUT: number;
14
- static request2(request: HttpClientRequest): Promise<HttpClientResponse>;
14
+ static request(request: HttpClientRequest): Promise<HttpClientResponse>;
15
15
  private static getContentType;
16
16
  private static formatContentType;
17
17
  }
@@ -1,7 +1,6 @@
1
1
  import { fetch } from 'popsicle';
2
2
  import { HttpClientResponse } from './HttpClientResponse.js';
3
- import { ClientError } from '../Model/Error/ClientError.js';
4
- import { VERSION } from '../version.js';
3
+ import { ClientError } from './ClientError.js';
5
4
  export class HttpClient {
6
5
  static HTTP_BAD_REQUEST = 400;
7
6
  static HTTP_UNAUTHORIZED = 401;
@@ -13,26 +12,7 @@ export class HttpClient {
13
12
  static HTTP_BAD_GATEWAY = 502;
14
13
  static HTTP_UNAVAILABLE = 503;
15
14
  static HTTP_TIMEOUT = 504;
16
- // public static async get(url: string, requestData: any = {}): Promise<any> {
17
- // if (Utils.isNullOrUndefined(requestData)) {
18
- // requestData = {};
19
- // }
20
- // const response: Response = await fetch(url, requestData);
21
- //
22
- // //TODO: validate status
23
- // const error: ClientError | null = ClientError.byStatus(response.status, response.statusText);
24
- // if (!Utils.isNullOrUndefined(error)) {
25
- // throw error;
26
- // }
27
- //
28
- // // TODO: make it possible to do request without parsing the json
29
- // return await response.json();
30
- // }
31
- static async request2(request) {
32
- if (typeof window === 'undefined') {
33
- // Add user agent when running in Node
34
- request.headers['User-Agent'] = 'Attlaz Http/' + VERSION;
35
- }
15
+ static async request(request) {
36
16
  const rawRequest = {
37
17
  url: request.getFullUrl(),
38
18
  method: request.method,
@@ -1,9 +1,10 @@
1
+ import { Headers } from './Data/Header.js';
1
2
  export declare class HttpClientRequest {
2
- static readonly GET = "GET";
3
- static readonly POST = "POST";
4
- static readonly PUT = "PUT";
3
+ static readonly GET: string;
4
+ static readonly POST: string;
5
+ static readonly PUT: string;
5
6
  method: string;
6
- headers: any;
7
+ headers: Headers;
7
8
  body: any;
8
9
  private urlObj;
9
10
  constructor(url: string, method?: string);
@@ -1,16 +1,17 @@
1
1
  import { OAuthClientOptions } from './OAuthClientOptions.js';
2
2
  import { OAuthClientToken } from './OAuthClientToken.js';
3
3
  import { Parameters } from './Data/Parameters.js';
4
+ import { Headers } from './Data/Header.js';
4
5
  export declare class OAuthClient {
5
6
  private readonly options;
6
7
  private debug;
7
8
  private oauthClient;
8
9
  private oauthToken;
9
10
  private oathClientToken;
11
+ private refreshTokenPromise;
10
12
  constructor(options: OAuthClientOptions);
11
13
  authenticate(username: string, password: string): Promise<boolean>;
12
14
  authenticate(): Promise<boolean>;
13
- private refreshTokenPromise;
14
15
  refreshToken(): Promise<void>;
15
16
  isTokenExpires(): boolean;
16
17
  request(action: string, parameters?: Parameters, method?: string, signWithOauthToken?: boolean): Promise<any>;
@@ -26,6 +27,8 @@ export declare class OAuthClient {
26
27
  [key: string]: string | string[];
27
28
  };
28
29
  } | null): string;
30
+ getDefaultHeaders(): Headers;
31
+ private isNodeEnvironment;
29
32
  private tokenToOauthClientToken;
30
33
  private getUri;
31
34
  private createRequestData;
@@ -1,15 +1,17 @@
1
1
  import ClientOAuth2 from 'client-oauth2';
2
- import { ClientError } from '../Model/Error/ClientError.js';
2
+ import { ClientError } from './ClientError.js';
3
3
  import { HttpClient } from './HttpClient.js';
4
4
  import { HttpClientRequest } from './HttpClientRequest.js';
5
5
  import { OAuthClientToken } from './OAuthClientToken.js';
6
6
  import { JsonSerializable } from '../Model/JsonSerializable.js';
7
+ import { VERSION } from '../version.js';
7
8
  export class OAuthClient {
8
9
  options;
9
10
  debug = false;
10
11
  oauthClient;
11
12
  oauthToken = null;
12
13
  oathClientToken = null;
14
+ refreshTokenPromise = null;
13
15
  constructor(options) {
14
16
  this.options = options;
15
17
  this.oauthClient = new ClientOAuth2({
@@ -20,7 +22,7 @@ export class OAuthClient {
20
22
  redirectUri: options.redirectUri,
21
23
  scopes: options.scopes,
22
24
  state: options.state,
23
- headers: options.headers,
25
+ headers: this.getDefaultHeaders(),
24
26
  });
25
27
  }
26
28
  async authenticate(username = null, password = null) {
@@ -46,7 +48,6 @@ export class OAuthClient {
46
48
  throw ClientError.fromError(e);
47
49
  }
48
50
  }
49
- refreshTokenPromise = null;
50
51
  async refreshToken() {
51
52
  if (this.debug) {
52
53
  console.debug('[OAuthClient] refresh token');
@@ -98,7 +99,7 @@ export class OAuthClient {
98
99
  console.debug('[OAuthClient] Request: ' + requestData.method.toUpperCase() + ' ' + requestData.getFullUrl());
99
100
  }
100
101
  try {
101
- const response = await HttpClient.request2(requestData);
102
+ const response = await HttpClient.request(requestData);
102
103
  // if (this.debug) {
103
104
  // console.info('[Client response] ', {body: response.body});
104
105
  // }
@@ -159,6 +160,22 @@ export class OAuthClient {
159
160
  getTokenFlowUrl(options = null) {
160
161
  return this.oauthClient.token.getUri(options === null ? undefined : options);
161
162
  }
163
+ getDefaultHeaders() {
164
+ const userAgentInfo = {
165
+ version: VERSION,
166
+ language: 'Javascript',
167
+ language_version: '',
168
+ publisher: 'Attlaz',
169
+ };
170
+ const headers = { 'X-Attlaz-Client': JSON.stringify(userAgentInfo) };
171
+ if (this.isNodeEnvironment()) {
172
+ headers['User-Agent'] = 'Attlaz Http/' + VERSION;
173
+ }
174
+ return headers;
175
+ }
176
+ isNodeEnvironment() {
177
+ return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
178
+ }
162
179
  tokenToOauthClientToken(oauthToken) {
163
180
  const token = new OAuthClientToken(oauthToken.accessToken, oauthToken.tokenType, oauthToken.refreshToken, oauthToken.data.scopes);
164
181
  const rawTokenExpires = oauthToken.expires;
@@ -176,6 +193,7 @@ export class OAuthClient {
176
193
  createRequestData(action, parameters = null, method = 'GET', signWithOauthToken = true) {
177
194
  const url = this.getUri(action);
178
195
  let requestData = new HttpClientRequest(url, method);
196
+ requestData.headers = this.getDefaultHeaders();
179
197
  if ((method === 'POST' || method === 'DELETE' || method === 'PUT') && parameters !== null && parameters !== undefined) {
180
198
  if (typeof parameters === 'object') {
181
199
  requestData.body = JsonSerializable.stringify(parameters);
@@ -1,13 +1,11 @@
1
- import { Headers } from './Data/Header.js';
2
1
  export declare class OAuthClientOptions {
3
2
  apiEndpoint: string;
4
3
  readonly clientId: string | null;
5
4
  readonly clientSecret: string | null;
6
- headers: Headers;
7
5
  accessTokenUri: string;
8
6
  authorizationUri: string;
9
7
  redirectUri: string;
10
8
  scopes: string[];
11
9
  state: string;
12
- constructor(apiEndpoint: string, clientId: string | null, clientSecret: string | null, headers: Headers);
10
+ constructor(apiEndpoint: string, clientId?: string | null, clientSecret?: string | null);
13
11
  }
@@ -2,16 +2,14 @@ export class OAuthClientOptions {
2
2
  apiEndpoint;
3
3
  clientId;
4
4
  clientSecret;
5
- headers;
6
5
  accessTokenUri = 'oauth/token';
7
6
  authorizationUri = 'oauth/authorize';
8
7
  redirectUri = 'https://example.com/auth/github/callback';
9
8
  scopes = ['all'];
10
9
  state = 'xyz';
11
- constructor(apiEndpoint, clientId, clientSecret, headers) {
10
+ constructor(apiEndpoint, clientId = null, clientSecret = null) {
12
11
  this.apiEndpoint = apiEndpoint;
13
12
  this.clientId = clientId;
14
13
  this.clientSecret = clientSecret;
15
- this.headers = headers;
16
14
  }
17
15
  }
@@ -1,6 +1,4 @@
1
1
  import { Endpoint } from './Endpoint.js';
2
- import { ClientError } from '../Model/Error/ClientError.js';
3
- import { HttpClient } from '../Http/HttpClient.js';
4
2
  import { FlowRun } from '../Model/Flow/FlowRun.js';
5
3
  import { FlowRunSummary } from '../Model/Flow/FlowRunSummary.js';
6
4
  import { FlowRunHistory } from '../Model/Flow/FlowRunHistory.js';
@@ -54,9 +52,6 @@ export class FlowRunEndpoint extends Endpoint {
54
52
  return result.getData();
55
53
  }
56
54
  catch (error) {
57
- if (error instanceof ClientError && error.code === HttpClient.HTTP_NOTFOUND) {
58
- return null;
59
- }
60
55
  if (this.httpClient.isDebugEnabled()) {
61
56
  console.error('Failed to load flow runs: ' + error);
62
57
  }
package/dist/index.d.ts CHANGED
@@ -7,13 +7,13 @@ export { HttpClientResponse } from './Http/HttpClientResponse.js';
7
7
  export { OAuthClient } from './Http/OAuthClient.js';
8
8
  export { OAuthClientOptions } from './Http/OAuthClientOptions.js';
9
9
  export { OAuthClientToken } from './Http/OAuthClientToken.js';
10
+ export { ClientError } from './Http/ClientError.js';
10
11
  /**
11
12
  * Models
12
13
  */
13
14
  export { Adapter } from './Model/Adapter/Adapter.js';
14
15
  export { AdapterConfiguration } from './Model/Adapter/AdapterConfiguration.js';
15
16
  export { AdapterConnection } from './Model/Adapter/AdapterConnection.js';
16
- export { ClientError } from './Model/Error/ClientError.js';
17
17
  export { EventType } from './Model/Event/EventType.js';
18
18
  export { HealthAlert } from './Model/HealthAlert/HealthAlert.js';
19
19
  export { HealthAlertStatus } from './Model/HealthAlert/HealthAlertStatus.js';
package/dist/index.js CHANGED
@@ -7,13 +7,13 @@ export { HttpClientResponse } from './Http/HttpClientResponse.js';
7
7
  export { OAuthClient } from './Http/OAuthClient.js';
8
8
  export { OAuthClientOptions } from './Http/OAuthClientOptions.js';
9
9
  export { OAuthClientToken } from './Http/OAuthClientToken.js';
10
+ export { ClientError } from './Http/ClientError.js';
10
11
  /**
11
12
  * Models
12
13
  */
13
14
  export { Adapter } from './Model/Adapter/Adapter.js';
14
15
  export { AdapterConfiguration } from './Model/Adapter/AdapterConfiguration.js';
15
16
  export { AdapterConnection } from './Model/Adapter/AdapterConnection.js';
16
- export { ClientError } from './Model/Error/ClientError.js';
17
17
  export { EventType } from './Model/Event/EventType.js';
18
18
  export { HealthAlert } from './Model/HealthAlert/HealthAlert.js';
19
19
  export { HealthAlertStatus } from './Model/HealthAlert/HealthAlertStatus.js';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.11.14";
1
+ export declare const VERSION = "1.12.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.11.14";
1
+ export const VERSION = "1.12.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.12.2",
3
+ "version": "1.12.5",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
File without changes