attlaz-client 1.8.12 → 1.8.15

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.
@@ -43,8 +43,7 @@ class HttpClient {
43
43
  jsonData = JSON.parse(rawData);
44
44
  }
45
45
  catch (e) {
46
- console.log(httpResponse.statusText);
47
- console.error('Unable to parse response data to JSON');
46
+ console.error('Unable to parse response data to JSON', { statusText: httpResponse.statusText, error: e });
48
47
  }
49
48
  httpResponse.body = jsonData;
50
49
  }
@@ -9,6 +9,7 @@ export declare class OAuthClient {
9
9
  constructor(options: OAuthClientOptions);
10
10
  authenticate(username: string, password: string): Promise<boolean>;
11
11
  authenticate(): Promise<boolean>;
12
+ private refreshTokenPromise;
12
13
  refreshToken(): Promise<void>;
13
14
  isTokenExpires(): boolean;
14
15
  request(action: string, parameters?: any, method?: string, signWithOauthToken?: boolean): Promise<any>;
@@ -15,6 +15,7 @@ class OAuthClient {
15
15
  this.debug = false;
16
16
  this.oauthToken = null;
17
17
  this.oathClientToken = null;
18
+ this.refreshTokenPromise = null;
18
19
  this.options = options;
19
20
  //
20
21
  this.oauthClient = new client_oauth2_1.default({
@@ -44,11 +45,16 @@ class OAuthClient {
44
45
  return true;
45
46
  }
46
47
  catch (e) {
47
- console.log(e);
48
+ if (this.debug) {
49
+ console.debug('[Client] Error during authentication', e);
50
+ }
48
51
  throw ClientError_1.ClientError.fromError(e);
49
52
  }
50
53
  }
51
54
  async refreshToken() {
55
+ if (this.debug) {
56
+ console.debug('[OAuthClient] refresh token');
57
+ }
52
58
  if (this.oauthToken === null) {
53
59
  throw new Error('unable to refresh token, auth token not set');
54
60
  }
@@ -58,8 +64,7 @@ class OAuthClient {
58
64
  this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
59
65
  }
60
66
  catch (e) {
61
- const error = ClientError_1.ClientError.fromError(e);
62
- throw error;
67
+ throw ClientError_1.ClientError.fromError(e);
63
68
  }
64
69
  }
65
70
  else {
@@ -82,12 +87,19 @@ class OAuthClient {
82
87
  throw new ClientError_1.ClientError('Unable to perform request, access token not provided');
83
88
  }
84
89
  if (signWithOauthToken && this.oauthToken.expired()) {
85
- await this.refreshToken();
90
+ if (this.refreshTokenPromise === null) {
91
+ this.refreshTokenPromise = this.refreshToken();
92
+ await this.refreshTokenPromise;
93
+ this.refreshTokenPromise = null;
94
+ }
95
+ else {
96
+ await this.refreshTokenPromise;
97
+ }
86
98
  }
87
99
  }
88
100
  const requestData = this.createRequestData(action, parameters, method, signWithOauthToken);
89
101
  if (this.debug) {
90
- console.debug('[Client] REQ: ' + requestData.method.toUpperCase() + ' ' + requestData.getFullUrl());
102
+ console.debug('[OAuthClient] Request: ' + requestData.method.toUpperCase() + ' ' + requestData.getFullUrl());
91
103
  }
92
104
  try {
93
105
  const response = await HttpClient_1.HttpClient.request2(requestData);
@@ -9,7 +9,14 @@ class ClientError {
9
9
  this.code = code;
10
10
  }
11
11
  static fromError(error) {
12
- let clientError = new ClientError(error.message);
12
+ if (error.body !== undefined && error.body !== null && error.body.error !== undefined && error.body.error !== null) {
13
+ error = error.body.error;
14
+ }
15
+ let message = error;
16
+ if (error.message !== undefined && error.message !== null) {
17
+ message = error.message;
18
+ }
19
+ let clientError = new ClientError(message);
13
20
  //console.error(error);
14
21
  if (error.status !== null && error.status !== undefined) {
15
22
  const statusCode = error.status;
@@ -2,4 +2,5 @@ export declare class StorageItem {
2
2
  key: string;
3
3
  value: string | number | boolean | null | any;
4
4
  expiration: Date | null;
5
+ static parse(raw: any): StorageItem;
5
6
  }
@@ -2,5 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageItem = void 0;
4
4
  class StorageItem {
5
+ static parse(raw) {
6
+ let storageItem = new StorageItem();
7
+ storageItem.key = raw.key;
8
+ storageItem.value = raw.value;
9
+ storageItem.expiration = new Date(raw.expiration);
10
+ return storageItem;
11
+ }
5
12
  }
6
13
  exports.StorageItem = StorageItem;
@@ -2,4 +2,5 @@ export declare class StorageItemInformation {
2
2
  key: string;
3
3
  bytes: number;
4
4
  expiration: Date | null;
5
+ static parse(raw: any): StorageItemInformation;
5
6
  }
@@ -2,5 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageItemInformation = void 0;
4
4
  class StorageItemInformation {
5
+ static parse(raw) {
6
+ let storageItemInformation = new StorageItemInformation();
7
+ storageItemInformation.key = raw.id;
8
+ storageItemInformation.bytes = raw.bytes;
9
+ storageItemInformation.expiration = new Date(raw.expiration);
10
+ return storageItemInformation;
11
+ }
5
12
  }
6
13
  exports.StorageItemInformation = StorageItemInformation;
@@ -6,6 +6,9 @@ export declare class WorkerConfig {
6
6
  static KEY_CPU_LIMIT: string;
7
7
  static KEY_PLATFORM: string;
8
8
  static KEY_WORKER_VERSION: string;
9
+ static KEY_API_ENDPOINT: string;
10
+ static KEY_API_CLIENT_ID: string;
11
+ static KEY_CLIENT_SECRET: string;
9
12
  projectEnvironment: string;
10
13
  key: string;
11
14
  value: DataValueValue | null;
@@ -18,3 +18,6 @@ WorkerConfig.KEY_MEMORY_LIMIT = 'memory_limit';
18
18
  WorkerConfig.KEY_CPU_LIMIT = 'cpu_limit';
19
19
  WorkerConfig.KEY_PLATFORM = 'platform';
20
20
  WorkerConfig.KEY_WORKER_VERSION = 'worker_version';
21
+ WorkerConfig.KEY_API_ENDPOINT = 'api_endpoint';
22
+ WorkerConfig.KEY_API_CLIENT_ID = 'api_client_id';
23
+ WorkerConfig.KEY_CLIENT_SECRET = 'api_client_secret';
@@ -40,7 +40,6 @@ class ProjectDeployEndpoint extends Endpoint_1.Endpoint {
40
40
  try {
41
41
  const projectDeploy = await this.httpClient.request('/projectenvironments/' + projectEnvironmentId + '/deploys', {}, 'POST');
42
42
  // TODO: parse deploy
43
- console.log('Parse deploy', projectDeploy);
44
43
  return projectDeploy;
45
44
  }
46
45
  catch (error) {
@@ -8,7 +8,7 @@ export declare class StorageEndpoint extends Endpoint {
8
8
  getInformation(projectEnvironmentId: string, storageType: StorageType): Promise<DataResult<StorageInformation>>;
9
9
  clearPool(projectEnvironmentId: string, storageType: StorageType, poolKey: string): Promise<DataResult<any>>;
10
10
  getPoolItemsInformation(projectEnvironmentId: string, storageType: StorageType, poolKey: string): Promise<DataResult<StorageItemInformation[]>>;
11
- getItem(projectEnvironmentId: string, storageType: StorageType, poolKey: string, storageItemKey: string): Promise<DataResult<StorageItem>>;
12
- setItem(projectEnvironmentId: string, storageType: StorageType, poolKey: string, storageItem: StorageItem): Promise<DataResult<StorageItem>>;
11
+ getItem(projectEnvironmentId: string, storageType: StorageType, poolKey: string, storageItemKey: string): Promise<StorageItem | null>;
12
+ setItem(projectEnvironmentId: string, storageType: StorageType, poolKey: string, storageItem: StorageItem): Promise<void>;
13
13
  deleteItem(projectEnvironmentId: string, storageType: StorageType, poolKey: string, storageItemKey: string): Promise<DataResult<StorageItem>>;
14
14
  }
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageEndpoint = void 0;
4
4
  const Endpoint_1 = require("./Endpoint");
5
+ const StorageItem_1 = require("../Model/Storage/StorageItem");
6
+ const StorageItemInformation_1 = require("../Model/Storage/StorageItemInformation");
5
7
  class StorageEndpoint extends Endpoint_1.Endpoint {
6
8
  async getInformation(projectEnvironmentId, storageType) {
7
9
  let cmd = '/projectenvironments/' + projectEnvironmentId + '/storage/' + storageType;
@@ -33,6 +35,7 @@ class StorageEndpoint extends Endpoint_1.Endpoint {
33
35
  let cmd = '/projectenvironments/' + projectEnvironmentId + '/storage/' + storageType + '/' + poolKey + '/items';
34
36
  try {
35
37
  const result = await this.request(cmd, null, 'GET');
38
+ result.setData(this.parseCollection(result, StorageItemInformation_1.StorageItemInformation.parse));
36
39
  return result;
37
40
  }
38
41
  catch (ex) {
@@ -46,11 +49,16 @@ class StorageEndpoint extends Endpoint_1.Endpoint {
46
49
  let cmd = '/projectenvironments/' + projectEnvironmentId + '/storage/' + storageType + '/' + poolKey + '/items/' + storageItemKey;
47
50
  try {
48
51
  const result = await this.request(cmd, null, 'GET');
49
- return result;
52
+ if (result.getData() === null) {
53
+ return null;
54
+ }
55
+ else {
56
+ return StorageItem_1.StorageItem.parse(result.getData());
57
+ }
50
58
  }
51
59
  catch (ex) {
52
60
  if (this.httpClient.isDebugEnabled()) {
53
- console.error('Failed to get storage information', ex);
61
+ console.error('Failed to get storage item', ex);
54
62
  }
55
63
  throw ex;
56
64
  }
@@ -59,7 +67,7 @@ class StorageEndpoint extends Endpoint_1.Endpoint {
59
67
  let cmd = '/projectenvironments/' + projectEnvironmentId + '/storage/' + storageType + '/' + poolKey + '/items/' + storageItem.key;
60
68
  try {
61
69
  const result = await this.request(cmd, { 'storage_item': storageItem }, 'POST');
62
- return result;
70
+ return;
63
71
  }
64
72
  catch (ex) {
65
73
  if (this.httpClient.isDebugEnabled()) {
@@ -11,7 +11,7 @@ class TaskExecutionRequestEndpoint extends Endpoint_1.Endpoint {
11
11
  try {
12
12
  // TODO: parse
13
13
  const result = await this.httpClient.request(url, params, 'POST');
14
- console.log('TODO: parse postTaskExecutionRequest result', result);
14
+ // console.log('TODO: parse postTaskExecutionRequest result', result);
15
15
  return result;
16
16
  }
17
17
  catch (ex) {
@@ -33,7 +33,7 @@ class WorkerConfigEndpoint extends Endpoint_1.Endpoint {
33
33
  try {
34
34
  let url = '/projectenvironments/' + workerConfig.projectEnvironment + '/workerconfiguration';
35
35
  const result = await this.request(url, workerConfig, 'POST');
36
- console.log(result);
36
+ // console.log(result);
37
37
  return WorkerConfig_1.WorkerConfig.parse(result);
38
38
  }
39
39
  catch (error) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.8.12";
1
+ export declare const VERSION = "1.8.15";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "1.8.12";
4
+ exports.VERSION = "1.8.15";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.8.12",
3
+ "version": "1.8.15",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -30,16 +30,16 @@
30
30
  "popsicle": "^12.1.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@types/jest": "^27.4.1",
34
- "@types/node": "^17.0.21",
35
- "jest": "^27.5.1",
33
+ "@types/jest": "^28.1.6",
34
+ "@types/node": "^18.7.2",
35
+ "jest": "^28.1.3",
36
36
  "rimraf": "^3.0.2",
37
37
  "rollup-plugin-commonjs": "^10.1.0",
38
38
  "rollup-plugin-node-resolve": "^5.2.0",
39
39
  "rollup-plugin-typescript": "^1.0.1",
40
- "ts-jest": "^27.1.3",
41
- "typescript": "^4.6.2",
42
- "dotenv": "^16.0.0"
40
+ "ts-jest": "^28.0.7",
41
+ "typescript": "^4.7.4",
42
+ "dotenv": "^16.0.1"
43
43
  },
44
44
  "directories": {
45
45
  "test": "test"