attlaz-client 1.5.3 → 1.5.6

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.
@@ -5,6 +5,7 @@ export declare class OAuthClient {
5
5
  private debug;
6
6
  private oauthClient;
7
7
  private oauthToken;
8
+ private oathClientToken;
8
9
  constructor(options: OAuthClientOptions);
9
10
  authenticate(username: string, password: string): Promise<boolean>;
10
11
  authenticate(): Promise<boolean>;
@@ -23,6 +24,7 @@ export declare class OAuthClient {
23
24
  [key: string]: string | string[];
24
25
  };
25
26
  } | null): string;
27
+ private tokenToOauthClientToken;
26
28
  private getUri;
27
29
  private createRequestData;
28
30
  private signRequest;
@@ -11,6 +11,7 @@ class OAuthClient {
11
11
  constructor(options) {
12
12
  this.debug = false;
13
13
  this.oauthToken = null;
14
+ this.oathClientToken = null;
14
15
  this.options = options;
15
16
  //
16
17
  this.oauthClient = new ClientOAuth2({
@@ -50,6 +51,7 @@ class OAuthClient {
50
51
  if (this.oauthToken.refreshToken !== undefined && this.oauthToken.refreshToken !== null && this.oauthToken.refreshToken !== '') {
51
52
  try {
52
53
  this.oauthToken = await this.oauthToken.refresh();
54
+ this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
53
55
  }
54
56
  catch (e) {
55
57
  const error = ClientError_1.ClientError.fromError(e);
@@ -94,26 +96,16 @@ class OAuthClient {
94
96
  }
95
97
  isAuthenticated() {
96
98
  //TODO: other ways to determine if the client is authenticated?
97
- return this.oauthToken !== null && this.oauthToken !== undefined;
99
+ return this.oathClientToken !== null && this.oathClientToken !== undefined;
98
100
  }
99
101
  getToken() {
100
102
  if (this.oauthToken === null) {
101
103
  return null;
102
104
  }
103
- console.log('Oauth token', this.oauthToken);
104
- const token = new OAuthClientToken_1.OAuthClientToken(this.oauthToken.accessToken, this.oauthToken.tokenType, this.oauthToken.refreshToken, this.oauthToken.data.scopes);
105
- const rawTokenExpires = this.oauthToken.expires;
106
- if (rawTokenExpires !== null && rawTokenExpires !== undefined) {
107
- token.expires = rawTokenExpires;
105
+ if (this.oathClientToken === null) {
106
+ this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
108
107
  }
109
- // return {
110
- // access_token: this.oauthToken.accessToken,
111
- // token_type: this.oauthToken.tokenType,
112
- // refresh_token: this.oauthToken.refreshToken,
113
- // expires: (this.oauthToken as any as { expires: Date }).expires,
114
- // scope: this.oauthToken.data.scope
115
- // };
116
- return token;
108
+ return this.oathClientToken;
117
109
  }
118
110
  setToken(token) {
119
111
  const data = {
@@ -127,9 +119,11 @@ class OAuthClient {
127
119
  oauthToken.expiresIn(token.expires);
128
120
  }
129
121
  this.oauthToken = oauthToken;
122
+ this.oathClientToken = token;
130
123
  }
131
124
  unsetToken() {
132
125
  this.oauthToken = null;
126
+ this.oathClientToken = null;
133
127
  }
134
128
  enableDebug() {
135
129
  this.debug = true;
@@ -143,6 +137,14 @@ class OAuthClient {
143
137
  getTokenFlowUrl(options = null) {
144
138
  return this.oauthClient.token.getUri(options === null ? undefined : options);
145
139
  }
140
+ tokenToOauthClientToken(oauthToken) {
141
+ const token = new OAuthClientToken_1.OAuthClientToken(oauthToken.accessToken, oauthToken.tokenType, oauthToken.refreshToken, oauthToken.data.scopes);
142
+ const rawTokenExpires = oauthToken.expires;
143
+ if (rawTokenExpires !== null && rawTokenExpires !== undefined) {
144
+ token.expires = rawTokenExpires;
145
+ }
146
+ return token;
147
+ }
146
148
  getUri(uri) {
147
149
  if (uri.indexOf("http://") == 0 || uri.indexOf("https://") == 0) {
148
150
  return uri;
@@ -184,11 +186,11 @@ class OAuthClient {
184
186
  return requestData;
185
187
  }
186
188
  signRequest(requestObject) {
187
- if (this.oauthToken === null) {
189
+ if (this.oathClientToken === null) {
188
190
  throw new ClientError_1.ClientError('Unable to sign request, access token not provided');
189
191
  }
190
- const tokenType = this.oauthToken.tokenType;
191
- const accessToken = this.oauthToken.accessToken;
192
+ const tokenType = this.oathClientToken.token_type;
193
+ const accessToken = this.oathClientToken.access_token;
192
194
  if (tokenType !== undefined && tokenType.toLowerCase() === 'bearer') {
193
195
  requestObject.setHeader('Authorization', 'Bearer ' + accessToken);
194
196
  }
@@ -1,7 +1,7 @@
1
1
  import { TaskExecutionStatus } from "./TaskExecutionStatus";
2
2
  import { TaskExecution } from './TaskExecution';
3
3
  export declare class TaskExecutionSummary extends TaskExecution {
4
- time: Date | null;
4
+ time: Date;
5
5
  duration: number;
6
6
  status: TaskExecutionStatus;
7
7
  static parse(rawTaskExecutionSummary: any): TaskExecutionSummary;
@@ -7,14 +7,14 @@ const Utils_1 = require("../Utils");
7
7
  class TaskExecutionSummary extends TaskExecution_1.TaskExecution {
8
8
  constructor() {
9
9
  super(...arguments);
10
- this.time = null;
11
10
  this.status = TaskExecutionStatus_1.TaskExecutionStatus.Unknown;
12
11
  }
13
12
  static parse(rawTaskExecutionSummary) {
14
13
  let taskExecutionSummary = TaskExecution_1.TaskExecution.parse(rawTaskExecutionSummary);
15
14
  if (rawTaskExecutionSummary.time !== null && rawTaskExecutionSummary.time !== undefined) {
16
- taskExecutionSummary.time = Utils_1.Utils.parseRawDate(rawTaskExecutionSummary.time);
15
+ throw new Error('Task execution time cannot be empty');
17
16
  }
17
+ taskExecutionSummary.time = Utils_1.Utils.parseRawDate(rawTaskExecutionSummary.time);
18
18
  taskExecutionSummary.duration = rawTaskExecutionSummary.duration;
19
19
  taskExecutionSummary.status = rawTaskExecutionSummary.status;
20
20
  return taskExecutionSummary;
@@ -3,7 +3,7 @@ import { Task } from './Task';
3
3
  export declare class TaskSummary extends Task {
4
4
  status: TaskExecutionStatus;
5
5
  lastExecution: Date | null;
6
- averageExecutionDuration: number;
6
+ averageExecutionDuration: number | null;
7
7
  executionCount: number;
8
8
  static parse(rawTask: any): TaskSummary;
9
9
  }
@@ -9,6 +9,8 @@ class TaskSummary extends Task_1.Task {
9
9
  super(...arguments);
10
10
  this.status = TaskExecutionStatus_1.TaskExecutionStatus.Unknown;
11
11
  this.lastExecution = null;
12
+ this.averageExecutionDuration = null;
13
+ this.executionCount = 0;
12
14
  }
13
15
  static parse(rawTask) {
14
16
  let task = Task_1.Task.parse(rawTask);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.5.3",
3
+ "version": "1.5.6",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",