attlaz-client 1.4.32 → 1.5.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.
Files changed (58) hide show
  1. package/dist/Client.d.ts +1 -1
  2. package/dist/Client.js +4 -1
  3. package/dist/Http/HttpClient.js +3 -3
  4. package/dist/Http/HttpClientRequest.spec.js +6 -6
  5. package/dist/Http/HttpClientResponse.d.ts +2 -1
  6. package/dist/Http/HttpClientResponse.js +5 -0
  7. package/dist/Http/OAuthClient.js +34 -14
  8. package/dist/Http/OAuthClientOptions.js +1 -1
  9. package/dist/Http/OAuthClientToken.d.ts +2 -1
  10. package/dist/Http/OAuthClientToken.js +20 -2
  11. package/dist/Model/Error/ClientError.js +4 -1
  12. package/dist/Model/HealthAlert/HealthAlertStatus.js +1 -1
  13. package/dist/Model/HealthAlert/HealthTestType.js +1 -1
  14. package/dist/Model/Log/LogLevel.js +1 -1
  15. package/dist/Model/Log/LogQuery.d.ts +2 -2
  16. package/dist/Model/Messaging/Channel/ChannelType.js +1 -1
  17. package/dist/Model/Messaging/Subscriber.js +2 -1
  18. package/dist/Model/PagedResult.d.ts +1 -1
  19. package/dist/Model/PagedResult.js +2 -3
  20. package/dist/Model/Project/ProjectDeployStatus.js +1 -1
  21. package/dist/Model/Project/ProjectEnvironment.d.ts +1 -1
  22. package/dist/Model/Result/DataResult.d.ts +1 -1
  23. package/dist/Model/State.js +1 -1
  24. package/dist/Model/Storage/StorageType.js +1 -1
  25. package/dist/Model/TaskExecutionStatus.js +1 -1
  26. package/dist/Model/Team/TeamMemberInviteState.js +1 -1
  27. package/dist/Model/Trigger/TriggerType.js +1 -1
  28. package/dist/Model/Worker/WorkerInstanceState.js +1 -1
  29. package/dist/Model/Worker/WorkerState.js +1 -1
  30. package/dist/Service/ChannelEndpoint.d.ts +1 -1
  31. package/dist/Service/ChannelEndpoint.js +9 -5
  32. package/dist/Service/ConfigEndpoint.d.ts +2 -2
  33. package/dist/Service/HealthAlertEndpoint.d.ts +1 -1
  34. package/dist/Service/HealthAlertEndpoint.js +5 -2
  35. package/dist/Service/LogEndpoint.d.ts +1 -1
  36. package/dist/Service/LogEndpoint.js +5 -1
  37. package/dist/Service/ProjectDeployEndpoint.d.ts +1 -1
  38. package/dist/Service/ProjectEndpoint.d.ts +1 -1
  39. package/dist/Service/ProjectEnvironmentEndpoint.d.ts +1 -1
  40. package/dist/Service/ProjectEnvironmentEndpoint.js +3 -0
  41. package/dist/Service/QueueEndpoint.js +4 -2
  42. package/dist/Service/SourcesAccountEndpoint.js +2 -1
  43. package/dist/Service/StorageEndpoint.js +6 -7
  44. package/dist/Service/SubscriberEndpoint.d.ts +1 -1
  45. package/dist/Service/TaskEndpoint.d.ts +2 -2
  46. package/dist/Service/TaskExecutionEndpoint.d.ts +3 -3
  47. package/dist/Service/TaskExecutionEndpoint.js +5 -5
  48. package/dist/Service/TeamMemberEndpoint.js +3 -3
  49. package/dist/Service/TriggerEndpoint.d.ts +1 -1
  50. package/dist/Service/UserEndpoint.js +4 -3
  51. package/dist/Service/WorkerConfigEndpoint.d.ts +1 -1
  52. package/dist/Service/WorkerConfigEndpoint.js +5 -1
  53. package/dist/Service/WorkerEndpoint.d.ts +1 -1
  54. package/dist/Utils.d.ts +1 -1
  55. package/dist/Utils.js +9 -2
  56. package/dist/auth.spec.js +25 -4
  57. package/dist/data.spec.js +3 -0
  58. package/package.json +1 -1
package/dist/Client.d.ts CHANGED
@@ -35,7 +35,7 @@ export declare class Client {
35
35
  authenticate(): Promise<boolean>;
36
36
  authenticate(username: string, password: string): Promise<boolean>;
37
37
  isAuthenticated(): boolean;
38
- getToken(): OAuthClientToken;
38
+ getToken(): OAuthClientToken | null;
39
39
  setToken(token: OAuthClientToken): void;
40
40
  unsetAccessToken(): void;
41
41
  getApiInformation(): Promise<{
package/dist/Client.js CHANGED
@@ -73,7 +73,10 @@ class Client {
73
73
  getHttpClient() {
74
74
  return this.httpClient;
75
75
  }
76
- async authenticate(username, password) {
76
+ async authenticate(username = null, password = null) {
77
+ if (username === null || password === null) {
78
+ return this.httpClient.authenticate();
79
+ }
77
80
  return this.httpClient.authenticate(username, password);
78
81
  }
79
82
  isAuthenticated() {
@@ -51,9 +51,9 @@ class HttpClient {
51
51
  // TODO: set user agent
52
52
  // rawRequest.negotiateHttpVersion = NegotiateHttpVersion.HTTP1_ONLY;
53
53
  const response = await (0, popsicle_1.fetch)(request.getFullUrl(), rawRequest);
54
- const httpResponse = new HttpClientResponse_1.HttpClientResponse();
55
- httpResponse.status = response.status;
56
- httpResponse.statusText = response.statusText;
54
+ const httpResponse = new HttpClientResponse_1.HttpClientResponse(response.status, response.statusText);
55
+ // httpResponse.status = response.status;
56
+ // httpResponse.statusText = response.statusText;
57
57
  // TODO: should we get JSON immediately?
58
58
  // response.json
59
59
  // httpResponse.body = await response.text();
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const HttpClientRequest_1 = require("./HttpClientRequest");
4
4
  test('Test query string', async () => {
5
- const request = new HttpClientRequest_1.HttpClientRequest('http://example.com');
6
- expect(request.getFullUrl()).toBe('http://example.com');
5
+ const request = new HttpClientRequest_1.HttpClientRequest('https://example.com');
6
+ expect(request.getFullUrl()).toBe('https://example.com');
7
7
  request.addQueryParam('queryparam1', 'queryparam1value');
8
- expect(request.getFullUrl()).toBe('http://example.com?queryparam1=queryparam1value');
8
+ expect(request.getFullUrl()).toBe('https://example.com?queryparam1=queryparam1value');
9
9
  });
10
10
  test('Test query string - add to existing query string', async () => {
11
- const request = new HttpClientRequest_1.HttpClientRequest('http://example.com?queryparam0=queryparam0value');
12
- expect(request.getFullUrl()).toBe('http://example.com?queryparam0=queryparam0value');
11
+ const request = new HttpClientRequest_1.HttpClientRequest('https://example.com?queryparam0=queryparam0value');
12
+ expect(request.getFullUrl()).toBe('https://example.com?queryparam0=queryparam0value');
13
13
  request.addQueryParam('queryparam1', 'queryparam1value');
14
- expect(request.getFullUrl()).toBe('http://example.com?queryparam0=queryparam0value&queryparam1=queryparam1value');
14
+ expect(request.getFullUrl()).toBe('https://example.com?queryparam0=queryparam0value&queryparam1=queryparam1value');
15
15
  });
@@ -1,5 +1,6 @@
1
1
  export declare class HttpClientResponse {
2
2
  status: number;
3
3
  statusText: string;
4
- body: any;
4
+ body: any | null;
5
+ constructor(status: number, statusText: string);
5
6
  }
@@ -2,5 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpClientResponse = void 0;
4
4
  class HttpClientResponse {
5
+ constructor(status, statusText) {
6
+ this.body = null;
7
+ this.status = status;
8
+ this.statusText = statusText;
9
+ }
5
10
  }
6
11
  exports.HttpClientResponse = HttpClientResponse;
@@ -4,7 +4,7 @@ exports.OAuthClient = void 0;
4
4
  const ClientError_1 = require("../Model/Error/ClientError");
5
5
  const HttpClient_1 = require("./HttpClient");
6
6
  const HttpClientRequest_1 = require("./HttpClientRequest");
7
- const Utils_1 = require("../Utils");
7
+ const OAuthClientToken_1 = require("./OAuthClientToken");
8
8
  const ClientOAuth2 = require("client-oauth2");
9
9
  const JsonSerializable_1 = require("../Model/JsonSerializable");
10
10
  class OAuthClient {
@@ -23,11 +23,11 @@ class OAuthClient {
23
23
  state: this.options.state
24
24
  });
25
25
  }
26
- async authenticate(username, password) {
26
+ async authenticate(username = null, password = null) {
27
27
  //TODO: should we encrypt the password in the client (or is https save enough)?
28
28
  try {
29
29
  let accessToken;
30
- if (!Utils_1.Utils.isNullOrUndefined(username) && !Utils_1.Utils.isNullOrUndefined(password)) {
30
+ if (username !== null && username !== undefined && password !== null && password !== undefined) {
31
31
  // Password flow
32
32
  accessToken = await this.oauthClient.owner.getToken(username, password);
33
33
  }
@@ -44,6 +44,9 @@ class OAuthClient {
44
44
  }
45
45
  }
46
46
  async refreshToken() {
47
+ if (this.oauthToken === null) {
48
+ throw new Error('unable to refresh token, auth token not set');
49
+ }
47
50
  if (this.oauthToken.refreshToken !== undefined && this.oauthToken.refreshToken !== null && this.oauthToken.refreshToken !== '') {
48
51
  try {
49
52
  this.oauthToken = await this.oauthToken.refresh();
@@ -68,8 +71,13 @@ class OAuthClient {
68
71
  throw new ClientError_1.ClientError('Unable to perform request, access token not provided');
69
72
  }
70
73
  else {
71
- if (signWithOauthToken && this.oauthToken.expired()) {
72
- await this.refreshToken();
74
+ if (signWithOauthToken) {
75
+ if (this.oauthToken === null) {
76
+ throw new ClientError_1.ClientError('Unable to perform request, access token not provided');
77
+ }
78
+ if (signWithOauthToken && this.oauthToken.expired()) {
79
+ await this.refreshToken();
80
+ }
73
81
  }
74
82
  const requestData = this.createRequestData(action, parameters, method, signWithOauthToken);
75
83
  if (this.debug) {
@@ -92,14 +100,20 @@ class OAuthClient {
92
100
  if (this.oauthToken === null) {
93
101
  return null;
94
102
  }
95
- console.log(this.oauthToken.data);
96
- return {
97
- access_token: this.oauthToken.accessToken,
98
- token_type: this.oauthToken.tokenType,
99
- refresh_token: this.oauthToken.refreshToken,
100
- expires: this.oauthToken.expires,
101
- scope: this.oauthToken.data.scope
102
- };
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;
108
+ }
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;
103
117
  }
104
118
  setToken(token) {
105
119
  const data = {
@@ -127,7 +141,7 @@ class OAuthClient {
127
141
  return this.debug;
128
142
  }
129
143
  getTokenFlowUrl(options = null) {
130
- return this.oauthClient.token.getUri(options);
144
+ return this.oauthClient.token.getUri(options === null ? undefined : options);
131
145
  }
132
146
  getUri(uri) {
133
147
  if (uri.indexOf("http://") == 0 || uri.indexOf("https://") == 0) {
@@ -157,6 +171,9 @@ class OAuthClient {
157
171
  });
158
172
  }
159
173
  if (signWithOauthToken) {
174
+ if (this.oauthToken === null) {
175
+ throw new ClientError_1.ClientError('Unable to perform request, access token not provided');
176
+ }
160
177
  if (this.oauthToken.expired()) {
161
178
  throw new Error('Unable to sign request, token is expired');
162
179
  }
@@ -167,6 +184,9 @@ class OAuthClient {
167
184
  return requestData;
168
185
  }
169
186
  signRequest(requestObject) {
187
+ if (this.oauthToken === null) {
188
+ throw new ClientError_1.ClientError('Unable to sign request, access token not provided');
189
+ }
170
190
  const tokenType = this.oauthToken.tokenType;
171
191
  const accessToken = this.oauthToken.accessToken;
172
192
  if (tokenType !== undefined && tokenType.toLowerCase() === 'bearer') {
@@ -5,7 +5,7 @@ class OAuthClientOptions {
5
5
  constructor(apiEndpoint, clientId, clientSecret) {
6
6
  this.accessTokenUri = 'oauth/token';
7
7
  this.authorizationUri = 'oauth/authorize';
8
- this.redirectUri = 'http://example.com/auth/github/callback';
8
+ this.redirectUri = 'https://example.com/auth/github/callback';
9
9
  this.scopes = ['all'];
10
10
  this.state = 'xyz';
11
11
  this.apiEndpoint = apiEndpoint;
@@ -2,8 +2,9 @@ export declare class OAuthClientToken {
2
2
  access_token: string;
3
3
  token_type: string;
4
4
  refresh_token: string | null;
5
- expires: Date;
5
+ expires: Date | null;
6
6
  scope: string;
7
+ constructor(access_token: string, token_type: string, refresh_token: string, scope: string);
7
8
  static isExpired(token: OAuthClientToken): boolean;
8
9
  static serialize(token: OAuthClientToken): string;
9
10
  static deserialize(serializedToken: string): OAuthClientToken;
@@ -2,8 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OAuthClientToken = void 0;
4
4
  class OAuthClientToken {
5
+ constructor(access_token, token_type, refresh_token, scope) {
6
+ this.access_token = '';
7
+ this.token_type = '';
8
+ this.refresh_token = null;
9
+ this.expires = null;
10
+ this.scope = '';
11
+ this.access_token = access_token;
12
+ this.token_type = token_type;
13
+ this.refresh_token = refresh_token;
14
+ this.scope = scope;
15
+ }
5
16
  static isExpired(token) {
6
- console.log(token);
17
+ if (token.expires === null) {
18
+ return false;
19
+ }
7
20
  return token.expires <= new Date();
8
21
  }
9
22
  static serialize(token) {
@@ -11,7 +24,12 @@ class OAuthClientToken {
11
24
  }
12
25
  static deserialize(serializedToken) {
13
26
  const token = JSON.parse(serializedToken);
14
- token.expires = new Date(token.expires);
27
+ if (token.expires !== null && token.expires !== undefined) {
28
+ token.expires = new Date(token.expires);
29
+ }
30
+ else {
31
+ token.expires = null;
32
+ }
15
33
  return token;
16
34
  }
17
35
  }
@@ -13,7 +13,10 @@ class ClientError {
13
13
  if (error.status !== null && error.status !== undefined) {
14
14
  const statusCode = error.status;
15
15
  const body = error.body;
16
- clientError = this.byStatus(statusCode, body);
16
+ const clientErrorByStatus = this.byStatus(statusCode, body);
17
+ if (clientErrorByStatus !== null) {
18
+ clientError = clientErrorByStatus;
19
+ }
17
20
  }
18
21
  else {
19
22
  if (error.code !== null && error.code !== undefined) {
@@ -11,7 +11,7 @@ var HealthAlertStatus;
11
11
  (function (HealthAlertStatus) {
12
12
  function fromString(input) {
13
13
  const result = Utils_1.Utils.parseEnum(input, HealthAlertStatus);
14
- if (Utils_1.Utils.isNullOrUndefined(result)) {
14
+ if (result === null) {
15
15
  throw new Error('Unable to parse HealthAlertStatus from string: Unknown HealthAlertStatus "' + input + '"');
16
16
  }
17
17
  return result;
@@ -12,7 +12,7 @@ var HealthTestType;
12
12
  (function (HealthTestType) {
13
13
  function fromString(input) {
14
14
  const result = Utils_1.Utils.parseEnum(input, HealthTestType);
15
- if (Utils_1.Utils.isNullOrUndefined(result)) {
15
+ if (result === null) {
16
16
  throw new Error('Unable to parse HealthTestType from string: Unknown HealthTestType "' + input + '"');
17
17
  }
18
18
  return result;
@@ -51,7 +51,7 @@ var LogLevel;
51
51
  LogLevel.toNumeric = toNumeric;
52
52
  function fromString(input) {
53
53
  const result = Utils_1.Utils.parseEnum(input, LogLevel);
54
- if (Utils_1.Utils.isNullOrUndefined(result)) {
54
+ if (result === null) {
55
55
  throw new Error('Unable to parse LogLevel from string: Unknown LogLevel "' + input + '"');
56
56
  }
57
57
  return result;
@@ -3,8 +3,8 @@ import { LogStreamId } from './LogStreamId';
3
3
  import { DataValueValue } from '../DataValue';
4
4
  export declare class LogQuery {
5
5
  readonly logStreamId: LogStreamId;
6
- message: string;
7
- hidden: boolean;
6
+ message: string | null;
7
+ hidden: boolean | null;
8
8
  logLevels: LogLevel[];
9
9
  tags: Array<{
10
10
  key: string;
@@ -13,7 +13,7 @@ var ChannelType;
13
13
  (function (ChannelType) {
14
14
  function fromString(input) {
15
15
  const result = Utils_1.Utils.parseEnum(input, ChannelType);
16
- if (Utils_1.Utils.isNullOrUndefined(result)) {
16
+ if (result === null) {
17
17
  throw new Error('Unable to parse ChannelType from string: Unknown ChannelType "' + input + '"');
18
18
  }
19
19
  return result;
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Subscriber = void 0;
4
4
  const State_1 = require("../State");
5
+ const LogLevel_1 = require("../Log/LogLevel");
5
6
  class Subscriber {
6
- constructor(id, eventTypes, projectEnvironment, task, taskExecution, channels, logLevelThreshold = null) {
7
+ constructor(id, eventTypes, projectEnvironment, task, taskExecution, channels, logLevelThreshold = LogLevel_1.LogLevel.Debug) {
7
8
  this.state = State_1.State.Active;
8
9
  this.id = id;
9
10
  this.eventTypes = eventTypes;
@@ -2,5 +2,5 @@ export declare class PagedResult<T> {
2
2
  pageSize: number;
3
3
  totalCount: number;
4
4
  data: Array<T>;
5
- constructor(data: Array<T>, pageSize?: number, totalCount?: number);
5
+ constructor(data: Array<T>, pageSize?: number | null, totalCount?: number | null);
6
6
  }
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PagedResult = void 0;
4
- const Utils_1 = require("../Utils");
5
4
  class PagedResult {
6
5
  constructor(data, pageSize = null, totalCount = null) {
7
6
  this.data = data;
8
- if (Utils_1.Utils.isNullOrUndefined(pageSize)) {
7
+ if (pageSize === null) {
9
8
  pageSize = data.length;
10
9
  }
11
10
  this.pageSize = pageSize;
12
- if (Utils_1.Utils.isNullOrUndefined(totalCount)) {
11
+ if (totalCount === null) {
13
12
  totalCount = data.length;
14
13
  }
15
14
  this.totalCount = totalCount;
@@ -15,7 +15,7 @@ var ProjectDeployStatus;
15
15
  (function (ProjectDeployStatus) {
16
16
  function fromString(input) {
17
17
  const result = Utils_1.Utils.parseEnum(input, ProjectDeployStatus);
18
- if (Utils_1.Utils.isNullOrUndefined(result)) {
18
+ if (result === null) {
19
19
  throw new Error('Unable to parse ProjectDeployStatus from string: Unknown ProjectDeployStatus "' + input + '"');
20
20
  }
21
21
  return result;
@@ -6,7 +6,7 @@ export declare class ProjectEnvironment implements StateAware {
6
6
  projectId: string;
7
7
  name: string;
8
8
  sourceBranch: string;
9
- parent?: string;
9
+ parent: string | null;
10
10
  isLocal: boolean;
11
11
  state: State;
12
12
  static parse(rawProjectEnvironment: any): ProjectEnvironment;
@@ -5,7 +5,7 @@ export declare class DataResult<T> {
5
5
  constructor();
6
6
  static parse<T>(raw: any): DataResult<T>;
7
7
  setData(data: T): void;
8
- getData(): T;
8
+ getData(): T | null;
9
9
  addError(error: ResultError): void;
10
10
  getErrors(): ResultError[];
11
11
  hasErrors(): boolean;
@@ -11,7 +11,7 @@ var State;
11
11
  (function (State) {
12
12
  function fromString(input) {
13
13
  const result = Utils_1.Utils.parseEnum(input, State);
14
- if (Utils_1.Utils.isNullOrUndefined(result)) {
14
+ if (result === null) {
15
15
  throw new Error('Unable to parse State from string: Unknown State "' + input + '"');
16
16
  }
17
17
  return result;
@@ -12,7 +12,7 @@ var StorageType;
12
12
  (function (StorageType) {
13
13
  function fromString(input) {
14
14
  const result = Utils_1.Utils.parseEnum(input, StorageType);
15
- if (Utils_1.Utils.isNullOrUndefined(result)) {
15
+ if (result === null) {
16
16
  throw new Error('Unable to parse StorageType from string: Unknown StorageType "' + input + '"');
17
17
  }
18
18
  return result;
@@ -15,7 +15,7 @@ var TaskExecutionStatus;
15
15
  (function (TaskExecutionStatus) {
16
16
  function fromString(input) {
17
17
  const result = Utils_1.Utils.parseEnum(input, TaskExecutionStatus);
18
- if (Utils_1.Utils.isNullOrUndefined(result)) {
18
+ if (result === null) {
19
19
  throw new Error('Unable to parse TaskExecutionStatus from string: Unknown TaskExecutionStatus "' + input + '"');
20
20
  }
21
21
  return result;
@@ -14,7 +14,7 @@ var TeamMemberInviteState;
14
14
  (function (TeamMemberInviteState) {
15
15
  function fromString(input) {
16
16
  const result = Utils_1.Utils.parseEnum(input, TeamMemberInviteState);
17
- if (Utils_1.Utils.isNullOrUndefined(result)) {
17
+ if (result === null) {
18
18
  throw new Error('Unable to parse TeamMemberInviteState from string: Unknown TeamMemberInviteState "' + input + '"');
19
19
  }
20
20
  return result;
@@ -11,7 +11,7 @@ var TriggerType;
11
11
  (function (TriggerType) {
12
12
  function fromString(input) {
13
13
  const result = Utils_1.Utils.parseEnum(input, TriggerType);
14
- if (Utils_1.Utils.isNullOrUndefined(result)) {
14
+ if (result === null) {
15
15
  throw new Error('Unable to parse TriggerType from string: Unknown TriggerType "' + input + '"');
16
16
  }
17
17
  return result;
@@ -11,7 +11,7 @@ var WorkerInstanceState;
11
11
  (function (WorkerInstanceState) {
12
12
  function fromString(input) {
13
13
  const result = Utils_1.Utils.parseEnum(input, WorkerInstanceState);
14
- if (Utils_1.Utils.isNullOrUndefined(result)) {
14
+ if (result === null) {
15
15
  throw new Error('Unable to parse WorkerInstanceState from string: Unknown WorkerInstanceState "' + input + '"');
16
16
  }
17
17
  return result;
@@ -13,7 +13,7 @@ var WorkerState;
13
13
  (function (WorkerState) {
14
14
  function fromString(input) {
15
15
  const result = Utils_1.Utils.parseEnum(input, WorkerState);
16
- if (Utils_1.Utils.isNullOrUndefined(result)) {
16
+ if (result === null) {
17
17
  throw new Error('Unable to parse WorkerState from string: Unknown WorkerState "' + input + '"');
18
18
  }
19
19
  return result;
@@ -3,7 +3,7 @@ import { DataResult } from '../Model/Result/DataResult';
3
3
  import { Channel } from '../Model/Messaging/Channel/Channel';
4
4
  import { ChannelHistory } from '../Model/Messaging/ChannelHistory';
5
5
  export declare class ChannelEndpoint extends Endpoint {
6
- getById(channelId: string): Promise<DataResult<Channel>>;
6
+ getById(channelId: string): Promise<DataResult<Channel | null>>;
7
7
  getByTeam(teamId: string): Promise<Channel[]>;
8
8
  getByOwner(): Promise<Channel[]>;
9
9
  getMessages(channelId: string): Promise<DataResult<ChannelHistory[]>>;
@@ -10,9 +10,10 @@ class ChannelEndpoint extends Endpoint_1.Endpoint {
10
10
  try {
11
11
  const result = await this.request('/channels/' + channelId + '');
12
12
  if (Utils_1.Utils.isNullOrUndefined(result)) {
13
- return null;
14
13
  }
15
- result.setData(Channel_1.Channel.parse(result.getData()));
14
+ else {
15
+ result.setData(Channel_1.Channel.parse(result.getData()));
16
+ }
16
17
  return result;
17
18
  }
18
19
  catch (ex) {
@@ -58,9 +59,12 @@ class ChannelEndpoint extends Endpoint_1.Endpoint {
58
59
  try {
59
60
  const rawChannelHistory = await this.request('/channels/' + channelId + '/messages');
60
61
  const data = [];
61
- const orig = rawChannelHistory.getData();
62
- for (const rawChannelMessage of orig) {
63
- data.push(ChannelHistory_1.ChannelHistory.parse(rawChannelMessage));
62
+ const resultData = rawChannelHistory.getData();
63
+ if (resultData !== null) {
64
+ const orig = resultData;
65
+ for (const rawChannelMessage of orig) {
66
+ data.push(ChannelHistory_1.ChannelHistory.parse(rawChannelMessage));
67
+ }
64
68
  }
65
69
  rawChannelHistory.setData(data);
66
70
  return rawChannelHistory;
@@ -1,7 +1,7 @@
1
1
  import { Endpoint } from './Endpoint';
2
2
  import { Config } from '../Model/Config';
3
3
  export declare class ConfigEndpoint extends Endpoint {
4
- getConfigByTask(taskId: string, projectEnvironmentId?: string): Promise<Config[]>;
5
- getByProject(projectId: string, projectEnvironmentId?: string): Promise<Config[]>;
4
+ getConfigByTask(taskId: string, projectEnvironmentId?: string | null): Promise<Config[]>;
5
+ getByProject(projectId: string, projectEnvironmentId?: string | null): Promise<Config[]>;
6
6
  saveByProject(projectId: string, configs: Config[]): Promise<any>;
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import { Endpoint } from './Endpoint';
2
2
  import { HealthAlert } from '../Model/HealthAlert/HealthAlert';
3
3
  export declare class HealthAlertEndpoint extends Endpoint {
4
- getLatestByProjectEnvironment(projectEnvironmentId: string): Promise<HealthAlert[]>;
4
+ getLatestByProjectEnvironment(projectEnvironmentId: string): Promise<HealthAlert[] | null>;
5
5
  }
@@ -13,8 +13,11 @@ class HealthAlertEndpoint extends Endpoint_1.Endpoint {
13
13
  return null;
14
14
  }
15
15
  let alerts = [];
16
- for (let raw of result.getData()) {
17
- alerts.push(HealthAlert_1.HealthAlert.parse(raw));
16
+ const resultData = result.getData();
17
+ if (resultData !== null) {
18
+ for (let raw of resultData) {
19
+ alerts.push(HealthAlert_1.HealthAlert.parse(raw));
20
+ }
18
21
  }
19
22
  return alerts;
20
23
  }
@@ -13,5 +13,5 @@ export declare class LogEndpoint extends Endpoint {
13
13
  getInformation(logStreamId: LogStreamId): Promise<{
14
14
  logLevels: Map<LogLevel, number>;
15
15
  tags: Map<string, (DataValueValue)[]>;
16
- }>;
16
+ } | null>;
17
17
  }
@@ -97,7 +97,11 @@ class LogEndpoint extends Endpoint_1.Endpoint {
97
97
  if (Utils_1.Utils.isNullOrUndefined(dataResult)) {
98
98
  return null;
99
99
  }
100
- const rawData = dataResult.getData();
100
+ const data = dataResult.getData();
101
+ if (data === null) {
102
+ return null;
103
+ }
104
+ const rawData = data;
101
105
  const logLevels = new Map();
102
106
  Object.keys(rawData.level_count).forEach((logLevelKey, index) => {
103
107
  const logLevel = LogLevel_1.LogLevel.fromString(logLevelKey);
@@ -1,7 +1,7 @@
1
1
  import { Endpoint } from './Endpoint';
2
2
  import { ProjectDeploy } from '../Model/Project/ProjectDeploy';
3
3
  export declare class ProjectDeployEndpoint extends Endpoint {
4
- getById(deployId: number): Promise<ProjectDeploy>;
4
+ getById(deployId: number): Promise<ProjectDeploy | null>;
5
5
  getByProjectEnvironment(projectEnvironmentId: string): Promise<ProjectDeploy[]>;
6
6
  requestDeploy(projectEnvironmentId: string): Promise<any>;
7
7
  }
@@ -3,6 +3,6 @@ import { Project } from '../Model/Project/Project';
3
3
  export declare class ProjectEndpoint extends Endpoint {
4
4
  getAll(): Promise<Project[]>;
5
5
  getByTeam(teamId: string): Promise<Project[]>;
6
- getById(projectId: string): Promise<Project>;
6
+ getById(projectId: string): Promise<Project | null>;
7
7
  save(project: Project): Promise<Project>;
8
8
  }
@@ -2,6 +2,6 @@ import { Endpoint } from './Endpoint';
2
2
  import { ProjectEnvironment } from '../Model/Project/ProjectEnvironment';
3
3
  export declare class ProjectEnvironmentEndpoint extends Endpoint {
4
4
  getByProject(id: string): Promise<ProjectEnvironment[]>;
5
- getById(id: string): Promise<ProjectEnvironment>;
5
+ getById(id: string): Promise<ProjectEnvironment | null>;
6
6
  save(projectEnvironment: ProjectEnvironment): Promise<ProjectEnvironment>;
7
7
  }
@@ -23,6 +23,9 @@ class ProjectEnvironmentEndpoint extends Endpoint_1.Endpoint {
23
23
  async getById(id) {
24
24
  try {
25
25
  const rawProjectEnvironment = await this.httpClient.request('/projectenvironments/' + id + '');
26
+ if (rawProjectEnvironment === null) {
27
+ return null;
28
+ }
26
29
  const projectEnvironment = rawProjectEnvironment;
27
30
  return projectEnvironment;
28
31
  }
@@ -10,9 +10,11 @@ class QueueEndpoint extends Endpoint_1.Endpoint {
10
10
  let url = '/projectenvironments/' + projectEnvironmentId + '/queues';
11
11
  const result = await this.request(url);
12
12
  if (Utils_1.Utils.isNullOrUndefined(result)) {
13
- return null;
13
+ // return null;
14
+ }
15
+ else {
16
+ result.setData(QueueStatus_1.QueueStatus.parse(result.getData()));
14
17
  }
15
- result.setData(QueueStatus_1.QueueStatus.parse(result.getData()));
16
18
  return result;
17
19
  }
18
20
  catch (error) {
@@ -4,6 +4,7 @@ exports.SourcesAccountEndpoint = void 0;
4
4
  const Endpoint_1 = require("./Endpoint");
5
5
  const SourcesAccount_1 = require("../Model/SourcesAccount");
6
6
  const SourcesAccountRepository_1 = require("../Model/SourcesAccountRepository");
7
+ const Utils_1 = require("../Utils");
7
8
  class SourcesAccountEndpoint extends Endpoint_1.Endpoint {
8
9
  async getAll() {
9
10
  const rawSourcesAccounts = await this.httpClient.request('sourcesaccounts');
@@ -22,7 +23,7 @@ class SourcesAccountEndpoint extends Endpoint_1.Endpoint {
22
23
  return sourcesAccountRepositories;
23
24
  }
24
25
  async getRepositoryBranches(sourcesAccountId, repositoryKey) {
25
- repositoryKey = btoa(repositoryKey);
26
+ repositoryKey = Utils_1.Utils.base64encode(repositoryKey);
26
27
  const rawBranches = await this.httpClient.request('sourcesaccounts/' + sourcesAccountId + '/repositories/' + repositoryKey + '/branches');
27
28
  return rawBranches;
28
29
  }
@@ -2,15 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageEndpoint = void 0;
4
4
  const Endpoint_1 = require("./Endpoint");
5
- const Utils_1 = require("../Utils");
6
5
  class StorageEndpoint extends Endpoint_1.Endpoint {
7
6
  async getInformation(projectEnvironmentId, storageType) {
8
7
  let cmd = '/projectenvironments/' + projectEnvironmentId + '/storage/' + storageType;
9
8
  try {
10
9
  const result = await this.request(cmd, null, 'GET');
11
- if (Utils_1.Utils.isNullOrUndefined(result)) {
12
- return null;
13
- }
10
+ // if (Utils.isNullOrUndefined(result)) {
11
+ // return null;
12
+ // }
14
13
  return result;
15
14
  }
16
15
  catch (ex) {
@@ -24,9 +23,9 @@ class StorageEndpoint extends Endpoint_1.Endpoint {
24
23
  let cmd = '/projectenvironments/' + projectEnvironmentId + '/storage/' + storageType + '/' + poolKey;
25
24
  try {
26
25
  const result = await this.request(cmd, null, 'DELETE');
27
- if (Utils_1.Utils.isNullOrUndefined(result)) {
28
- return null;
29
- }
26
+ // if (Utils.isNullOrUndefined(result)) {
27
+ // return null;
28
+ // }
30
29
  return result;
31
30
  }
32
31
  catch (ex) {
@@ -1,7 +1,7 @@
1
1
  import { Endpoint } from './Endpoint';
2
2
  import { Subscriber } from '../Model/Messaging/Subscriber';
3
3
  export declare class SubscriberEndpoint extends Endpoint {
4
- getSubscribersByTask(taskId: string, projectEnvironmentId?: string): Promise<Subscriber[]>;
4
+ getSubscribersByTask(taskId: string, projectEnvironmentId?: string | null): Promise<Subscriber[]>;
5
5
  getSubscribersByChannel(channelId: string): Promise<Subscriber[]>;
6
6
  save(subscriber: Subscriber): Promise<any>;
7
7
  }
@@ -3,8 +3,8 @@ import { Task } from '../Model/Task';
3
3
  import { TaskSummary } from '../Model/TaskSummary';
4
4
  export declare class TaskEndpoint extends Endpoint {
5
5
  getTasks(projectId: string): Promise<Task[]>;
6
- getTask(taskId: string): Promise<Task>;
6
+ getTask(taskId: string): Promise<Task | null>;
7
7
  getTaskSummaries(projectId: string, projectEnvironmentId?: string | null): Promise<TaskSummary[]>;
8
- getTaskSummary(taskId: string, projectEnvironmentId?: string | null): Promise<TaskSummary>;
8
+ getTaskSummary(taskId: string, projectEnvironmentId?: string | null): Promise<TaskSummary | null>;
9
9
  save(task: Task): Promise<Task>;
10
10
  }
@@ -5,8 +5,8 @@ import { TaskExecutionHistory } from '../Model/TaskExecutionHistory';
5
5
  import { TaskExecutionStatus } from '../Model/TaskExecutionStatus';
6
6
  export declare class TaskExecutionEndpoint extends Endpoint {
7
7
  getTaskExecutions(taskId: string): Promise<TaskExecution[]>;
8
- getTaskExecutionSummaries(taskId: string, from?: Date, to?: Date, projectEnvironmentId?: string): Promise<TaskExecutionSummary[]>;
9
- getTaskExecutionSummary(taskExecutionId: string): Promise<TaskExecutionSummary>;
8
+ getTaskExecutionSummaries(taskId: string, from?: Date | null, to?: Date | null, projectEnvironmentId?: string | null): Promise<TaskExecutionSummary[]>;
9
+ getTaskExecutionSummary(taskExecutionId: string): Promise<TaskExecutionSummary | null>;
10
10
  getTaskExecutionHistory(taskExecutionId: string): Promise<TaskExecutionHistory[]>;
11
- updateTaskExecution(taskExecutionId: string, status: TaskExecutionStatus, time?: Date): Promise<TaskExecution>;
11
+ updateTaskExecution(taskExecutionId: string, status: TaskExecutionStatus, time?: Date | null): Promise<TaskExecution>;
12
12
  }
@@ -26,20 +26,20 @@ class TaskExecutionEndpoint extends Endpoint_1.Endpoint {
26
26
  async getTaskExecutionSummaries(taskId, from = null, to = null, projectEnvironmentId = null) {
27
27
  try {
28
28
  let params = null;
29
- if (!Utils_1.Utils.isNullOrUndefined(from)) {
30
- if (Utils_1.Utils.isNullOrUndefined(params)) {
29
+ if (from !== null && from !== undefined) {
30
+ if (params === null || params === undefined) {
31
31
  params = {};
32
32
  }
33
33
  params.from = from.toISOString();
34
34
  }
35
- if (!Utils_1.Utils.isNullOrUndefined(to)) {
36
- if (Utils_1.Utils.isNullOrUndefined(params)) {
35
+ if (to !== null && to !== undefined) {
36
+ if (params === null || params === undefined) {
37
37
  params = {};
38
38
  }
39
39
  params.to = to.toISOString();
40
40
  }
41
41
  if (!Utils_1.Utils.isNullOrUndefined(projectEnvironmentId)) {
42
- if (Utils_1.Utils.isNullOrUndefined(params)) {
42
+ if (params === null || params === undefined) {
43
43
  params = {};
44
44
  }
45
45
  params.environment = projectEnvironmentId;
@@ -38,9 +38,9 @@ class TeamMemberEndpoint extends Endpoint_1.Endpoint {
38
38
  }
39
39
  try {
40
40
  const result = await this.request(cmd, { invites: rawInvites }, 'POST');
41
- if (Utils_1.Utils.isNullOrUndefined(result)) {
42
- return null;
43
- }
41
+ // if (Utils.isNullOrUndefined(result)) {
42
+ // return null;
43
+ // }
44
44
  return result;
45
45
  }
46
46
  catch (ex) {
@@ -1,7 +1,7 @@
1
1
  import { Endpoint } from './Endpoint';
2
2
  import { Trigger } from '../Model/Trigger/Trigger';
3
3
  export declare class TriggerEndpoint extends Endpoint {
4
- getByTask(taskId: string, projectEnvironmentId?: string): Promise<Trigger[]>;
4
+ getByTask(taskId: string, projectEnvironmentId?: string | null): Promise<Trigger[]>;
5
5
  getById(id: string): Promise<Trigger | null>;
6
6
  save(trigger: Trigger): Promise<Trigger>;
7
7
  }
@@ -10,7 +10,7 @@ class UserEndpoint extends Endpoint_1.Endpoint {
10
10
  let cmd = '/user';
11
11
  const rawUser = await this.httpClient.request(cmd);
12
12
  if (Utils_1.Utils.isNullOrUndefined(rawUser)) {
13
- return null;
13
+ throw new Error('User not found');
14
14
  }
15
15
  return User_1.User.parse(rawUser);
16
16
  }
@@ -77,8 +77,9 @@ class UserEndpoint extends Endpoint_1.Endpoint {
77
77
  let url = '/user/';
78
78
  const data = { user, invitation_code: invitationCode };
79
79
  const result = await this.request(url, data, 'PUT', false);
80
- if (!Utils_1.Utils.isNullOrUndefined(result.getData().createdUser)) {
81
- result.setData({ createdUser: User_1.User.parse(result.getData().createdUser) });
80
+ const resultData = result.getData();
81
+ if (resultData !== null && resultData.createdUser !== null) {
82
+ result.setData({ createdUser: User_1.User.parse(resultData.createdUser) });
82
83
  }
83
84
  return result;
84
85
  }
@@ -1,6 +1,6 @@
1
1
  import { Endpoint } from './Endpoint';
2
2
  import { WorkerConfig } from '../Model/Worker/WorkerConfig';
3
3
  export declare class WorkerConfigEndpoint extends Endpoint {
4
- getByProjectEnvironment(projectEnvironmentId: string): Promise<WorkerConfig[]>;
4
+ getByProjectEnvironment(projectEnvironmentId: string): Promise<WorkerConfig[] | null>;
5
5
  save(workerConfig: WorkerConfig): Promise<WorkerConfig>;
6
6
  }
@@ -12,8 +12,12 @@ class WorkerConfigEndpoint extends Endpoint_1.Endpoint {
12
12
  if (Utils_1.Utils.isNullOrUndefined(result)) {
13
13
  return null;
14
14
  }
15
+ const resultData = result.getData();
16
+ if (resultData === null) {
17
+ return null;
18
+ }
15
19
  let workerConfigValues = [];
16
- for (let rawConfig of result.getData()) {
20
+ for (let rawConfig of resultData) {
17
21
  workerConfigValues.push(WorkerConfig_1.WorkerConfig.parse(rawConfig));
18
22
  }
19
23
  return workerConfigValues;
@@ -3,7 +3,7 @@ import { Worker } from '../Model/Worker/Worker';
3
3
  import { DataResult } from '../Model/Result/DataResult';
4
4
  import { Platform } from '../Model/Worker/Platform';
5
5
  export declare class WorkerEndpoint extends Endpoint {
6
- getByProjectEnvironment(projectEnvironmentId: string): Promise<Worker>;
6
+ getByProjectEnvironment(projectEnvironmentId: string): Promise<Worker | null>;
7
7
  update(projectEnvironmentId: string): Promise<DataResult<boolean>>;
8
8
  getPlatforms(): Promise<Platform[]>;
9
9
  }
package/dist/Utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export declare class Utils {
2
2
  static isNullOrUndefined(variable: any): boolean;
3
3
  static isTrue(input: string | number | boolean | null | undefined): boolean;
4
- static parseRawDate(input: Date): Date | null;
4
+ static parseRawDate(input: Date): Date;
5
5
  static parseEnum<T>(input: string, Enum: any): T | null;
6
6
  static base64encode(input: string): string;
7
7
  static base64decode(encodedString: string): string;
package/dist/Utils.js CHANGED
@@ -12,24 +12,31 @@ class Utils {
12
12
  if (input !== null && input !== undefined) {
13
13
  return new Date(input);
14
14
  }
15
- return null;
15
+ throw new Error('Unable to parse date, null/undefined');
16
16
  }
17
17
  static parseEnum(input, Enum) {
18
18
  if (this.isNullOrUndefined(input)) {
19
19
  return null;
20
20
  }
21
+ // tslint:disable-next-line:forin
21
22
  for (const property in Enum) {
23
+ // noinspection JSUnfilteredForInLoop
22
24
  const enumMember = Enum[property];
23
25
  if (typeof enumMember === 'string' || typeof enumMember === 'number') {
24
26
  if (enumMember.toString().toUpperCase() === input.toString().toUpperCase()) {
25
27
  // const key = enumMember as string as keyof typeof Enum;
26
- return Enum[property];
28
+ const res = Enum[property];
29
+ if (res === undefined) {
30
+ return null;
31
+ }
32
+ return res;
27
33
  }
28
34
  }
29
35
  else if (typeof enumMember === 'string') {
30
36
  console.error('Unable to parse enum type: ' + typeof enumMember + ' for enum ', Enum);
31
37
  }
32
38
  }
39
+ return null;
33
40
  }
34
41
  static base64encode(input) {
35
42
  if (input === null || input === undefined || input === '') {
package/dist/auth.spec.js CHANGED
@@ -20,16 +20,30 @@ test('Test client credentials flow', async () => {
20
20
  client.getHttpClient().enableDebug();
21
21
  await client.authenticate();
22
22
  const user = await client.getUserEndpoint().getUser();
23
+ if (user === null) {
24
+ throw new Error('User is null');
25
+ }
23
26
  // console.log('User', user);
24
27
  expect(user.email).toBe('demo@attlaz.com');
25
28
  // TODO: how to get the seconds to wait for the token to expire?
26
- const expiresIn = client.getToken().expires.getTime() - (new Date()).getTime();
29
+ const token = client.getToken();
30
+ if (token === null) {
31
+ throw new Error('Token is null');
32
+ }
33
+ if (token.expires === null) {
34
+ throw new Error('Token expires not set');
35
+ }
36
+ const expiresIn = token.expires.getTime() - (new Date()).getTime();
27
37
  if (expiresIn < 30) {
28
38
  const waitSecondsForTokenToExpire = expiresIn + 5;
29
39
  // console.log(client.getToken().expires);
30
40
  await new Promise((r) => setTimeout(r, waitSecondsForTokenToExpire * 1000));
31
41
  // TODO: make sure we are not authenticated anymore
32
- expect(OAuthClientToken_1.OAuthClientToken.isExpired(client.getToken())).toBeTruthy();
42
+ const token = client.getToken();
43
+ if (token === null) {
44
+ throw new Error('Token is null');
45
+ }
46
+ expect(OAuthClientToken_1.OAuthClientToken.isExpired(token)).toBeTruthy();
33
47
  }
34
48
  // const user2: User = await client.getUserEndpoint().getUser()
35
49
  // expect(user.email).toBe('demo@attlaz.com');
@@ -46,9 +60,13 @@ test('Test password authentication - valid', async () => {
46
60
  const waitSecondsForTokenToExpire = tokenExpirationInSeconds + 5;
47
61
  // console.log(client.getToken().expires);
48
62
  await new Promise((r) => setTimeout(r, waitSecondsForTokenToExpire * 1000));
49
- expect(OAuthClientToken_1.OAuthClientToken.isExpired(client.getToken())).toBeTruthy();
63
+ const token = client.getToken();
64
+ if (token === null) {
65
+ throw new Error('Token is null');
66
+ }
67
+ expect(OAuthClientToken_1.OAuthClientToken.isExpired(token)).toBeTruthy();
50
68
  const user2 = await client.getUserEndpoint().getUser();
51
- expect(user.email).toBe(passwordFlowUsername);
69
+ expect(user2.email).toBe(passwordFlowUsername);
52
70
  });
53
71
  test('Test password authentication - invalid', async () => {
54
72
  expect.assertions(3);
@@ -70,6 +88,9 @@ test('Test set access token + JSON encode', async () => {
70
88
  client.getHttpClient().enableDebug();
71
89
  await client.authenticate(passwordFlowUsername, passwordFlowPassword);
72
90
  const token = client.getToken();
91
+ if (token === null) {
92
+ throw new Error('Token is null');
93
+ }
73
94
  expect(OAuthClientToken_1.OAuthClientToken.isExpired(token)).toBeFalsy();
74
95
  const encoded = OAuthClientToken_1.OAuthClientToken.serialize(token);
75
96
  console.log(encoded);
package/dist/data.spec.js CHANGED
@@ -26,6 +26,9 @@ test('Test get project', async () => {
26
26
  client.getHttpClient().enableDebug();
27
27
  await client.authenticate();
28
28
  const project = await client.getProjectEndpoint().getById('8B5C14EBB');
29
+ if (project === null) {
30
+ throw new Error('Project is null');
31
+ }
29
32
  // console.log('User', user);
30
33
  expect(project.id).toBe('8B5C14EBB');
31
34
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.4.32",
3
+ "version": "1.5.0",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",