attlaz-client 1.7.3 → 1.7.7

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 (122) hide show
  1. package/dist/Client.js +59 -55
  2. package/dist/Http/HttpClient.js +13 -9
  3. package/dist/Http/HttpClientRequest.js +9 -5
  4. package/dist/Http/HttpClientRequest.spec.js +5 -3
  5. package/dist/Http/HttpClientResponse.js +5 -1
  6. package/dist/Http/OAuthClient.js +26 -19
  7. package/dist/Http/OAuthClient.spec.js +6 -4
  8. package/dist/Http/OAuthClientOptions.js +5 -1
  9. package/dist/Http/OAuthClientToken.js +5 -1
  10. package/dist/Model/Adapter/Adapter.js +5 -1
  11. package/dist/Model/Adapter/AdapterConfiguration.js +5 -1
  12. package/dist/Model/Adapter/AdapterConnection.js +8 -4
  13. package/dist/Model/Config.js +11 -7
  14. package/dist/Model/DataValue.js +5 -1
  15. package/dist/Model/DataValueCollection.js +10 -6
  16. package/dist/Model/Error/ClientError.js +17 -13
  17. package/dist/Model/Event/EventType.js +5 -2
  18. package/dist/Model/HealthAlert/HealthAlert.js +8 -4
  19. package/dist/Model/HealthAlert/HealthAlertStatus.js +8 -5
  20. package/dist/Model/HealthAlert/HealthTestType.js +8 -5
  21. package/dist/Model/JsonSerializable.js +5 -1
  22. package/dist/Model/Log/Log.js +15 -11
  23. package/dist/Model/Log/LogLevel.js +8 -5
  24. package/dist/Model/Log/LogQuery.js +5 -1
  25. package/dist/Model/Log/LogStatus.js +8 -5
  26. package/dist/Model/Log/LogStreamId.js +5 -1
  27. package/dist/Model/Messaging/Channel/Channel.js +12 -8
  28. package/dist/Model/Messaging/Channel/ChannelData.js +5 -1
  29. package/dist/Model/Messaging/Channel/ChannelType.js +8 -5
  30. package/dist/Model/Messaging/Channel/EmailChannelData.js +8 -4
  31. package/dist/Model/Messaging/Channel/PushChannelData.js +8 -4
  32. package/dist/Model/Messaging/Channel/SlackChannelData.js +8 -4
  33. package/dist/Model/Messaging/Channel/SmsChannelData.js +8 -4
  34. package/dist/Model/Messaging/Channel/WebhookChannelData.js +8 -4
  35. package/dist/Model/Messaging/ChannelHistory.js +7 -3
  36. package/dist/Model/Messaging/Subscriber.js +10 -6
  37. package/dist/Model/Notification.js +5 -1
  38. package/dist/Model/PagedResult.js +5 -1
  39. package/dist/Model/Project/PlatformLanguage.js +8 -4
  40. package/dist/Model/Project/Project.js +8 -4
  41. package/dist/Model/Project/ProjectDeploy.js +12 -8
  42. package/dist/Model/Project/ProjectDeployCommit.js +5 -1
  43. package/dist/Model/Project/ProjectDeployStatus.js +8 -5
  44. package/dist/Model/Project/ProjectEnvironment.js +10 -6
  45. package/dist/Model/Queue/QueueStatus.js +5 -1
  46. package/dist/Model/Result/DataResult.js +5 -1
  47. package/dist/Model/Result/DataResult.spec.js +4 -2
  48. package/dist/Model/Result/DataResultCollection.js +5 -1
  49. package/dist/Model/Result/ResultError.js +5 -1
  50. package/dist/Model/SourcesAccount.js +5 -1
  51. package/dist/Model/SourcesAccountRepository.js +5 -1
  52. package/dist/Model/State.js +8 -5
  53. package/dist/Model/StateAware.js +2 -1
  54. package/dist/Model/Storage/StorageInformation.js +5 -1
  55. package/dist/Model/Storage/StorageType.js +8 -5
  56. package/dist/Model/Task.js +8 -4
  57. package/dist/Model/TaskExecution/TaskExecutionStats.js +5 -1
  58. package/dist/Model/TaskExecution.js +5 -1
  59. package/dist/Model/TaskExecutionHistory.js +7 -3
  60. package/dist/Model/TaskExecutionResponse.js +5 -1
  61. package/dist/Model/TaskExecutionStatus.js +8 -5
  62. package/dist/Model/TaskExecutionSummary.js +11 -7
  63. package/dist/Model/TaskSummary.js +12 -8
  64. package/dist/Model/Team/Team.js +5 -1
  65. package/dist/Model/Team/TeamMember.js +5 -1
  66. package/dist/Model/Team/TeamMemberInvite.js +7 -3
  67. package/dist/Model/Team/TeamMemberInvite2.js +5 -1
  68. package/dist/Model/Team/TeamMemberInviteState.js +8 -5
  69. package/dist/Model/Team/TeamMemberRole.js +8 -5
  70. package/dist/Model/Trigger/ApiTrigger.js +8 -4
  71. package/dist/Model/Trigger/ApiTriggerData.js +6 -2
  72. package/dist/Model/Trigger/ScheduleTrigger.js +8 -4
  73. package/dist/Model/Trigger/ScheduleTriggerData.js +6 -2
  74. package/dist/Model/Trigger/Trigger.js +19 -15
  75. package/dist/Model/Trigger/TriggerData.js +5 -1
  76. package/dist/Model/Trigger/TriggerType.js +8 -5
  77. package/dist/Model/Trigger/WebhookTrigger.js +8 -4
  78. package/dist/Model/Trigger/WebhookTriggerData.js +6 -2
  79. package/dist/Model/User/UserAuthProvider.js +10 -6
  80. package/dist/Model/User.js +10 -6
  81. package/dist/Model/Worker/Platform.js +12 -8
  82. package/dist/Model/Worker/PlatformImage.js +10 -6
  83. package/dist/Model/Worker/Worker.js +11 -7
  84. package/dist/Model/Worker/WorkerConfig.js +5 -1
  85. package/dist/Model/Worker/WorkerInstance.js +7 -3
  86. package/dist/Model/Worker/WorkerInstanceState.js +8 -5
  87. package/dist/Model/Worker/WorkerState.js +8 -5
  88. package/dist/Service/AdapterEndpoint.js +15 -11
  89. package/dist/Service/ChannelEndpoint.js +15 -11
  90. package/dist/Service/ConfigEndpoint.js +12 -8
  91. package/dist/Service/Endpoint.js +7 -3
  92. package/dist/Service/HealthAlertEndpoint.js +8 -4
  93. package/dist/Service/LogEndpoint.js +19 -15
  94. package/dist/Service/NotificationsEndpoint.js +8 -4
  95. package/dist/Service/PlatformEndpoint.js +10 -6
  96. package/dist/Service/PlatformLanguageEndpoint.js +8 -4
  97. package/dist/Service/ProjectDeployEndpoint.js +11 -7
  98. package/dist/Service/ProjectEndpoint.js +13 -9
  99. package/dist/Service/ProjectEnvironmentEndpoint.js +6 -2
  100. package/dist/Service/QueueEndpoint.js +10 -6
  101. package/dist/Service/SourcesAccountEndpoint.js +12 -8
  102. package/dist/Service/StorageEndpoint.js +6 -2
  103. package/dist/Service/SubscriberEndpoint.js +11 -7
  104. package/dist/Service/TaskEndpoint.js +18 -14
  105. package/dist/Service/TaskExecutionEndpoint.js +18 -14
  106. package/dist/Service/TaskExecutionRequestEndpoint.js +6 -2
  107. package/dist/Service/TaskExecutionStatsEndpoint.js +8 -4
  108. package/dist/Service/TeamMemberEndpoint.js +18 -14
  109. package/dist/Service/TeamsEndpoint.js +10 -6
  110. package/dist/Service/TriggerEndpoint.js +13 -9
  111. package/dist/Service/UserEndpoint.js +14 -10
  112. package/dist/Service/WorkerConfigEndpoint.js +11 -7
  113. package/dist/Service/WorkerEndpoint.js +11 -7
  114. package/dist/Utils.js +5 -1
  115. package/dist/Utils.spec.js +34 -32
  116. package/dist/auth.spec.js +27 -25
  117. package/dist/data.spec.js +5 -3
  118. package/dist/index.js +217 -106
  119. package/dist/test.js +13 -11
  120. package/dist/version.d.ts +1 -1
  121. package/dist/version.js +4 -1
  122. package/package.json +2 -2
package/dist/Client.js CHANGED
@@ -1,31 +1,34 @@
1
- import { WorkerEndpoint } from './Service/WorkerEndpoint';
2
- import { AdapterEndpoint } from './Service/AdapterEndpoint';
3
- import { ProjectEnvironmentEndpoint } from './Service/ProjectEnvironmentEndpoint';
4
- import { ProjectEndpoint } from './Service/ProjectEndpoint';
5
- import { TaskExecutionRequestEndpoint } from './Service/TaskExecutionRequestEndpoint';
6
- import { OAuthClient } from './Http/OAuthClient';
7
- import { WorkerConfigEndpoint } from './Service/WorkerConfigEndpoint';
8
- import { TeamsEndpoint } from './Service/TeamsEndpoint';
9
- import { UserEndpoint } from './Service/UserEndpoint';
10
- import { ConfigEndpoint } from './Service/ConfigEndpoint';
11
- import { SubscriberEndpoint } from './Service/SubscriberEndpoint';
12
- import { TaskEndpoint } from './Service/TaskEndpoint';
13
- import { TeamMemberEndpoint } from './Service/TeamMemberEndpoint';
14
- import { StorageEndpoint } from './Service/StorageEndpoint';
15
- import { QueueEndpoint } from './Service/QueueEndpoint';
16
- import { NotificationsEndpoint } from './Service/NotificationsEndpoint';
17
- import { ProjectDeployEndpoint } from './Service/ProjectDeployEndpoint';
18
- import { SourcesAccountEndpoint } from './Service/SourcesAccountEndpoint';
19
- import { OAuthClientOptions } from './Http/OAuthClientOptions';
20
- import { PlatformLanguageEndpoint } from './Service/PlatformLanguageEndpoint';
21
- import { ChannelEndpoint } from './Service/ChannelEndpoint';
22
- import { HealthAlertEndpoint } from './Service/HealthAlertEndpoint';
23
- import { TaskExecutionEndpoint } from './Service/TaskExecutionEndpoint';
24
- import { LogEndpoint } from './Service/LogEndpoint';
25
- import { TriggerEndpoint } from './Service/TriggerEndpoint';
26
- import { PlatformEndpoint } from './Service/PlatformEndpoint';
27
- import { TaskExecutionStatsEndpoint } from './Service/TaskExecutionStatsEndpoint';
28
- export class Client {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = void 0;
4
+ const WorkerEndpoint_1 = require("./Service/WorkerEndpoint");
5
+ const AdapterEndpoint_1 = require("./Service/AdapterEndpoint");
6
+ const ProjectEnvironmentEndpoint_1 = require("./Service/ProjectEnvironmentEndpoint");
7
+ const ProjectEndpoint_1 = require("./Service/ProjectEndpoint");
8
+ const TaskExecutionRequestEndpoint_1 = require("./Service/TaskExecutionRequestEndpoint");
9
+ const OAuthClient_1 = require("./Http/OAuthClient");
10
+ const WorkerConfigEndpoint_1 = require("./Service/WorkerConfigEndpoint");
11
+ const TeamsEndpoint_1 = require("./Service/TeamsEndpoint");
12
+ const UserEndpoint_1 = require("./Service/UserEndpoint");
13
+ const ConfigEndpoint_1 = require("./Service/ConfigEndpoint");
14
+ const SubscriberEndpoint_1 = require("./Service/SubscriberEndpoint");
15
+ const TaskEndpoint_1 = require("./Service/TaskEndpoint");
16
+ const TeamMemberEndpoint_1 = require("./Service/TeamMemberEndpoint");
17
+ const StorageEndpoint_1 = require("./Service/StorageEndpoint");
18
+ const QueueEndpoint_1 = require("./Service/QueueEndpoint");
19
+ const NotificationsEndpoint_1 = require("./Service/NotificationsEndpoint");
20
+ const ProjectDeployEndpoint_1 = require("./Service/ProjectDeployEndpoint");
21
+ const SourcesAccountEndpoint_1 = require("./Service/SourcesAccountEndpoint");
22
+ const OAuthClientOptions_1 = require("./Http/OAuthClientOptions");
23
+ const PlatformLanguageEndpoint_1 = require("./Service/PlatformLanguageEndpoint");
24
+ const ChannelEndpoint_1 = require("./Service/ChannelEndpoint");
25
+ const HealthAlertEndpoint_1 = require("./Service/HealthAlertEndpoint");
26
+ const TaskExecutionEndpoint_1 = require("./Service/TaskExecutionEndpoint");
27
+ const LogEndpoint_1 = require("./Service/LogEndpoint");
28
+ const TriggerEndpoint_1 = require("./Service/TriggerEndpoint");
29
+ const PlatformEndpoint_1 = require("./Service/PlatformEndpoint");
30
+ const TaskExecutionStatsEndpoint_1 = require("./Service/TaskExecutionStatsEndpoint");
31
+ class Client {
29
32
  // private test: Map<string, any>;
30
33
  // private socketService;
31
34
  constructor(apiEndpoint, clientId, clientSecret) {
@@ -33,34 +36,34 @@ export class Client {
33
36
  this.clientId = clientId;
34
37
  this.clientSecret = clientSecret;
35
38
  this.Store = {
36
- WorkerEndpoint,
37
- AdapterEndpoint,
38
- ProjectEndpoint,
39
- ProjectEnvironmentEndpoint,
40
- ProjectDeployEndpoint,
41
- QueueEndpoint,
42
- ChannelEndpoint,
43
- ConfigEndpoint,
44
- NotificationsEndpoint,
45
- SubscriberEndpoint,
46
- LogEndpoint,
47
- TaskEndpoint,
48
- TaskExecutionEndpoint,
49
- TaskExecutionRequestEndpoint,
50
- TeamsEndpoint,
51
- TriggerEndpoint,
52
- UserEndpoint,
53
- MemberEndpoint: TeamMemberEndpoint,
54
- SourcesAccountEndpoint,
55
- LanguageEndpoint: PlatformLanguageEndpoint,
56
- StorageEndpoint,
57
- WorkerConfigEndpoint,
58
- HealthAlertEndpoint,
59
- PlatformEndpoint,
60
- TaskExecutionStatsEndpoint
39
+ WorkerEndpoint: WorkerEndpoint_1.WorkerEndpoint,
40
+ AdapterEndpoint: AdapterEndpoint_1.AdapterEndpoint,
41
+ ProjectEndpoint: ProjectEndpoint_1.ProjectEndpoint,
42
+ ProjectEnvironmentEndpoint: ProjectEnvironmentEndpoint_1.ProjectEnvironmentEndpoint,
43
+ ProjectDeployEndpoint: ProjectDeployEndpoint_1.ProjectDeployEndpoint,
44
+ QueueEndpoint: QueueEndpoint_1.QueueEndpoint,
45
+ ChannelEndpoint: ChannelEndpoint_1.ChannelEndpoint,
46
+ ConfigEndpoint: ConfigEndpoint_1.ConfigEndpoint,
47
+ NotificationsEndpoint: NotificationsEndpoint_1.NotificationsEndpoint,
48
+ SubscriberEndpoint: SubscriberEndpoint_1.SubscriberEndpoint,
49
+ LogEndpoint: LogEndpoint_1.LogEndpoint,
50
+ TaskEndpoint: TaskEndpoint_1.TaskEndpoint,
51
+ TaskExecutionEndpoint: TaskExecutionEndpoint_1.TaskExecutionEndpoint,
52
+ TaskExecutionRequestEndpoint: TaskExecutionRequestEndpoint_1.TaskExecutionRequestEndpoint,
53
+ TeamsEndpoint: TeamsEndpoint_1.TeamsEndpoint,
54
+ TriggerEndpoint: TriggerEndpoint_1.TriggerEndpoint,
55
+ UserEndpoint: UserEndpoint_1.UserEndpoint,
56
+ MemberEndpoint: TeamMemberEndpoint_1.TeamMemberEndpoint,
57
+ SourcesAccountEndpoint: SourcesAccountEndpoint_1.SourcesAccountEndpoint,
58
+ LanguageEndpoint: PlatformLanguageEndpoint_1.PlatformLanguageEndpoint,
59
+ StorageEndpoint: StorageEndpoint_1.StorageEndpoint,
60
+ WorkerConfigEndpoint: WorkerConfigEndpoint_1.WorkerConfigEndpoint,
61
+ HealthAlertEndpoint: HealthAlertEndpoint_1.HealthAlertEndpoint,
62
+ PlatformEndpoint: PlatformEndpoint_1.PlatformEndpoint,
63
+ TaskExecutionStatsEndpoint: TaskExecutionStatsEndpoint_1.TaskExecutionStatsEndpoint
61
64
  };
62
- const options = new OAuthClientOptions(apiEndpoint, clientId, clientSecret);
63
- this.httpClient = new OAuthClient(options);
65
+ const options = new OAuthClientOptions_1.OAuthClientOptions(apiEndpoint, clientId, clientSecret);
66
+ this.httpClient = new OAuthClient_1.OAuthClient(options);
64
67
  this.endpoints = new Map();
65
68
  // this.test = new Map<string, any>();
66
69
  //
@@ -197,3 +200,4 @@ export class Client {
197
200
  return this.endpoints.get(key);
198
201
  }
199
202
  }
203
+ exports.Client = Client;
@@ -1,8 +1,11 @@
1
- import { fetch } from 'popsicle';
2
- import { HttpClientResponse } from './HttpClientResponse';
3
- import { ClientError } from '../Model/Error/ClientError';
4
- import { VERSION } from '../version';
5
- export class HttpClient {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpClient = void 0;
4
+ const popsicle_1 = require("popsicle");
5
+ const HttpClientResponse_1 = require("./HttpClientResponse");
6
+ const ClientError_1 = require("../Model/Error/ClientError");
7
+ const version_1 = require("../version");
8
+ class HttpClient {
6
9
  // public static async get(url: string, requestData: any = {}): Promise<any> {
7
10
  // if (Utils.isNullOrUndefined(requestData)) {
8
11
  // requestData = {};
@@ -21,7 +24,7 @@ export class HttpClient {
21
24
  static async request2(request) {
22
25
  if (typeof window === 'undefined') {
23
26
  // Add user agent when running in Node
24
- request.headers['User-Agent'] = 'Attlaz Http/' + VERSION;
27
+ request.headers['User-Agent'] = 'Attlaz Http/' + version_1.VERSION;
25
28
  }
26
29
  const rawRequest = {
27
30
  url: request.getFullUrl(),
@@ -30,8 +33,8 @@ export class HttpClient {
30
33
  omitDefaultHeaders: true,
31
34
  body: request.body
32
35
  };
33
- const response = await fetch(request.getFullUrl(), rawRequest);
34
- const httpResponse = new HttpClientResponse(response.status, response.statusText);
36
+ const response = await (0, popsicle_1.fetch)(request.getFullUrl(), rawRequest);
37
+ const httpResponse = new HttpClientResponse_1.HttpClientResponse(response.status, response.statusText);
35
38
  let contentType = this.getContentType(response);
36
39
  const rawData = await response.text();
37
40
  if (contentType.type === 'application/json') {
@@ -48,7 +51,7 @@ export class HttpClient {
48
51
  else {
49
52
  httpResponse.body = rawData;
50
53
  }
51
- const error = ClientError.byStatus(response.status, response.statusText);
54
+ const error = ClientError_1.ClientError.byStatus(response.status, response.statusText);
52
55
  if (error !== null && error !== undefined) {
53
56
  error.body = httpResponse.body;
54
57
  throw error;
@@ -76,6 +79,7 @@ export class HttpClient {
76
79
  return { type: input, options: null };
77
80
  }
78
81
  }
82
+ exports.HttpClient = HttpClient;
79
83
  HttpClient.HTTP_BAD_REQUEST = 400;
80
84
  HttpClient.HTTP_UNAUTHORIZED = 401;
81
85
  HttpClient.HTTP_FORBIDDEN = 403;
@@ -1,6 +1,9 @@
1
- import { Utils } from '../Utils';
2
- import { JsonSerializable } from '../Model/JsonSerializable';
3
- export class HttpClientRequest {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpClientRequest = void 0;
4
+ const Utils_1 = require("../Utils");
5
+ const JsonSerializable_1 = require("../Model/JsonSerializable");
6
+ class HttpClientRequest {
4
7
  constructor(url, method = HttpClientRequest.GET) {
5
8
  this.headers = {};
6
9
  this.body = null;
@@ -11,7 +14,7 @@ export class HttpClientRequest {
11
14
  this.setHeader('Content-Type', 'application/json');
12
15
  }
13
16
  setBasicAuth(user, password) {
14
- this.setHeader('Authorization', 'Basic ' + Utils.base64encode(user + ':' + password));
17
+ this.setHeader('Authorization', 'Basic ' + Utils_1.Utils.base64encode(user + ':' + password));
15
18
  }
16
19
  setHeader(key, value) {
17
20
  this.headers[key] = value;
@@ -21,7 +24,7 @@ export class HttpClientRequest {
21
24
  }
22
25
  setJsonBody(data) {
23
26
  this.setJsonHeader();
24
- this.body = JsonSerializable.stringify(data);
27
+ this.body = JsonSerializable_1.JsonSerializable.stringify(data);
25
28
  }
26
29
  getFullUrl() {
27
30
  let result = this.urlObj.href;
@@ -32,6 +35,7 @@ export class HttpClientRequest {
32
35
  return result;
33
36
  }
34
37
  }
38
+ exports.HttpClientRequest = HttpClientRequest;
35
39
  HttpClientRequest.GET = 'GET';
36
40
  HttpClientRequest.POST = 'POST';
37
41
  HttpClientRequest.PUT = 'PUT';
@@ -1,12 +1,14 @@
1
- import { HttpClientRequest } from './HttpClientRequest';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const HttpClientRequest_1 = require("./HttpClientRequest");
2
4
  test('Test query string', async () => {
3
- const request = new HttpClientRequest('https://example.com');
5
+ const request = new HttpClientRequest_1.HttpClientRequest('https://example.com');
4
6
  expect(request.getFullUrl()).toBe('https://example.com');
5
7
  request.addQueryParam('queryparam1', 'queryparam1value');
6
8
  expect(request.getFullUrl()).toBe('https://example.com?queryparam1=queryparam1value');
7
9
  });
8
10
  test('Test query string - add to existing query string', async () => {
9
- const request = new HttpClientRequest('https://example.com?queryparam0=queryparam0value');
11
+ const request = new HttpClientRequest_1.HttpClientRequest('https://example.com?queryparam0=queryparam0value');
10
12
  expect(request.getFullUrl()).toBe('https://example.com?queryparam0=queryparam0value');
11
13
  request.addQueryParam('queryparam1', 'queryparam1value');
12
14
  expect(request.getFullUrl()).toBe('https://example.com?queryparam0=queryparam0value&queryparam1=queryparam1value');
@@ -1,7 +1,11 @@
1
- export class HttpClientResponse {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpClientResponse = void 0;
4
+ class HttpClientResponse {
2
5
  constructor(status, statusText) {
3
6
  this.body = null;
4
7
  this.status = status;
5
8
  this.statusText = statusText;
6
9
  }
7
10
  }
11
+ exports.HttpClientResponse = HttpClientResponse;
@@ -1,17 +1,23 @@
1
- import { ClientError } from '../Model/Error/ClientError';
2
- import { HttpClient } from './HttpClient';
3
- import { HttpClientRequest } from './HttpClientRequest';
4
- import { OAuthClientToken } from './OAuthClientToken';
5
- import * as ClientOAuth2 from 'client-oauth2';
6
- import { JsonSerializable } from '../Model/JsonSerializable';
7
- export class OAuthClient {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OAuthClient = void 0;
7
+ const ClientError_1 = require("../Model/Error/ClientError");
8
+ const HttpClient_1 = require("./HttpClient");
9
+ const HttpClientRequest_1 = require("./HttpClientRequest");
10
+ const OAuthClientToken_1 = require("./OAuthClientToken");
11
+ const client_oauth2_1 = __importDefault(require("client-oauth2"));
12
+ const JsonSerializable_1 = require("../Model/JsonSerializable");
13
+ class OAuthClient {
8
14
  constructor(options) {
9
15
  this.debug = false;
10
16
  this.oauthToken = null;
11
17
  this.oathClientToken = null;
12
18
  this.options = options;
13
19
  //
14
- this.oauthClient = new ClientOAuth2({
20
+ this.oauthClient = new client_oauth2_1.default({
15
21
  clientId: this.options.clientId,
16
22
  clientSecret: this.options.clientSecret,
17
23
  accessTokenUri: this.getUri(this.options.accessTokenUri),
@@ -39,7 +45,7 @@ export class OAuthClient {
39
45
  }
40
46
  catch (e) {
41
47
  console.log(e);
42
- throw ClientError.fromError(e);
48
+ throw ClientError_1.ClientError.fromError(e);
43
49
  }
44
50
  }
45
51
  async refreshToken() {
@@ -52,7 +58,7 @@ export class OAuthClient {
52
58
  this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
53
59
  }
54
60
  catch (e) {
55
- const error = ClientError.fromError(e);
61
+ const error = ClientError_1.ClientError.fromError(e);
56
62
  throw error;
57
63
  }
58
64
  }
@@ -68,12 +74,12 @@ export class OAuthClient {
68
74
  }
69
75
  async request(action, parameters = null, method = 'GET', signWithOauthToken = true) {
70
76
  if (signWithOauthToken && !this.isAuthenticated()) {
71
- throw new ClientError('Unable to perform request, access token not provided');
77
+ throw new ClientError_1.ClientError('Unable to perform request, access token not provided');
72
78
  }
73
79
  else {
74
80
  if (signWithOauthToken) {
75
81
  if (this.oauthToken === null) {
76
- throw new ClientError('Unable to perform request, access token not provided');
82
+ throw new ClientError_1.ClientError('Unable to perform request, access token not provided');
77
83
  }
78
84
  if (signWithOauthToken && this.oauthToken.expired()) {
79
85
  await this.refreshToken();
@@ -84,14 +90,14 @@ export class OAuthClient {
84
90
  console.debug('[Client] REQ: ' + requestData.method.toUpperCase() + ' ' + requestData.getFullUrl());
85
91
  }
86
92
  try {
87
- const response = await HttpClient.request2(requestData);
93
+ const response = await HttpClient_1.HttpClient.request2(requestData);
88
94
  // if (this.debug) {
89
95
  // console.info('[Client response] ', {body: response.body});
90
96
  // }
91
97
  return response.body;
92
98
  }
93
99
  catch (error) {
94
- const clientError = ClientError.fromError(error);
100
+ const clientError = ClientError_1.ClientError.fromError(error);
95
101
  if (this.debug) {
96
102
  console.error('[Client] Error:', { error, clientError });
97
103
  }
@@ -143,7 +149,7 @@ export class OAuthClient {
143
149
  return this.oauthClient.token.getUri(options === null ? undefined : options);
144
150
  }
145
151
  tokenToOauthClientToken(oauthToken) {
146
- const token = new OAuthClientToken(oauthToken.accessToken, oauthToken.tokenType, oauthToken.refreshToken, oauthToken.data.scopes);
152
+ const token = new OAuthClientToken_1.OAuthClientToken(oauthToken.accessToken, oauthToken.tokenType, oauthToken.refreshToken, oauthToken.data.scopes);
147
153
  const rawTokenExpires = oauthToken.expires;
148
154
  if (rawTokenExpires !== null && rawTokenExpires !== undefined) {
149
155
  token.expires = rawTokenExpires;
@@ -158,10 +164,10 @@ export class OAuthClient {
158
164
  }
159
165
  createRequestData(action, parameters = null, method = 'GET', signWithOauthToken = true) {
160
166
  const url = this.getUri(action);
161
- let requestData = new HttpClientRequest(url, method);
167
+ let requestData = new HttpClientRequest_1.HttpClientRequest(url, method);
162
168
  if ((method === 'POST' || method === 'DELETE' || method === 'PUT') && parameters !== null && parameters !== undefined) {
163
169
  if (typeof parameters === 'object') {
164
- parameters = JsonSerializable.stringify(parameters);
170
+ parameters = JsonSerializable_1.JsonSerializable.stringify(parameters);
165
171
  }
166
172
  else if (typeof parameters === 'string') {
167
173
  }
@@ -179,7 +185,7 @@ export class OAuthClient {
179
185
  }
180
186
  if (signWithOauthToken) {
181
187
  if (this.oauthToken === null) {
182
- throw new ClientError('Unable to perform request, access token not provided');
188
+ throw new ClientError_1.ClientError('Unable to perform request, access token not provided');
183
189
  }
184
190
  if (this.oauthToken.expired()) {
185
191
  throw new Error('Unable to sign request, token is expired');
@@ -192,7 +198,7 @@ export class OAuthClient {
192
198
  }
193
199
  signRequest(requestObject) {
194
200
  if (this.oathClientToken === null) {
195
- throw new ClientError('Unable to sign request, access token not provided');
201
+ throw new ClientError_1.ClientError('Unable to sign request, access token not provided');
196
202
  }
197
203
  const tokenType = this.oathClientToken.token_type;
198
204
  const accessToken = this.oathClientToken.access_token;
@@ -209,3 +215,4 @@ export class OAuthClient {
209
215
  return requestObject;
210
216
  }
211
217
  }
218
+ exports.OAuthClient = OAuthClient;
@@ -1,8 +1,10 @@
1
- import { OAuthClient } from './OAuthClient';
2
- import { OAuthClientOptions } from './OAuthClientOptions';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const OAuthClient_1 = require("./OAuthClient");
4
+ const OAuthClientOptions_1 = require("./OAuthClientOptions");
3
5
  test('Test enum parsing', async () => {
4
- const options = new OAuthClientOptions('https://github.com/login', '3b938da6f58d6bef7d59', 'da05698a6bd449de9437e11ff0b99003f511e40f');
5
- const client = new OAuthClient(options);
6
+ const options = new OAuthClientOptions_1.OAuthClientOptions('https://github.com/login', '3b938da6f58d6bef7d59', 'da05698a6bd449de9437e11ff0b99003f511e40f');
7
+ const client = new OAuthClient_1.OAuthClient(options);
6
8
  // client.getClient().cod.getToken()
7
9
  // const x: any = await client.authenticate();
8
10
  // console.log(x);
@@ -1,4 +1,7 @@
1
- export class OAuthClientOptions {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuthClientOptions = void 0;
4
+ class OAuthClientOptions {
2
5
  constructor(apiEndpoint, clientId, clientSecret) {
3
6
  this.accessTokenUri = 'oauth/token';
4
7
  this.authorizationUri = 'oauth/authorize';
@@ -10,3 +13,4 @@ export class OAuthClientOptions {
10
13
  this.clientSecret = clientSecret;
11
14
  }
12
15
  }
16
+ exports.OAuthClientOptions = OAuthClientOptions;
@@ -1,4 +1,7 @@
1
- export class OAuthClientToken {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuthClientToken = void 0;
4
+ class OAuthClientToken {
2
5
  constructor(access_token, token_type, refresh_token, scope) {
3
6
  this.access_token = '';
4
7
  this.token_type = '';
@@ -30,3 +33,4 @@ export class OAuthClientToken {
30
33
  return token;
31
34
  }
32
35
  }
36
+ exports.OAuthClientToken = OAuthClientToken;
@@ -1,4 +1,7 @@
1
- export class Adapter {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Adapter = void 0;
4
+ class Adapter {
2
5
  static parse(rawAdapter) {
3
6
  let adapter = new Adapter();
4
7
  adapter.id = rawAdapter.id;
@@ -14,3 +17,4 @@ export class Adapter {
14
17
  return adapter;
15
18
  }
16
19
  }
20
+ exports.Adapter = Adapter;
@@ -1,4 +1,7 @@
1
- export class AdapterConfiguration {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdapterConfiguration = void 0;
4
+ class AdapterConfiguration {
2
5
  static parse(rawAdapter) {
3
6
  let configuration = new AdapterConfiguration();
4
7
  configuration.id = rawAdapter.id;
@@ -10,3 +13,4 @@ export class AdapterConfiguration {
10
13
  return configuration;
11
14
  }
12
15
  }
16
+ exports.AdapterConfiguration = AdapterConfiguration;
@@ -1,7 +1,10 @@
1
- import { DataValueCollection } from '../DataValueCollection';
2
- export class AdapterConnection {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdapterConnection = void 0;
4
+ const DataValueCollection_1 = require("../DataValueCollection");
5
+ class AdapterConnection {
3
6
  constructor() {
4
- this.configuration = new DataValueCollection();
7
+ this.configuration = new DataValueCollection_1.DataValueCollection();
5
8
  }
6
9
  static parse(rawAdapterConnection) {
7
10
  let adapterConnection = new AdapterConnection();
@@ -9,7 +12,7 @@ export class AdapterConnection {
9
12
  adapterConnection.key = rawAdapterConnection.key;
10
13
  adapterConnection.adapter = rawAdapterConnection.adapter;
11
14
  adapterConnection.name = rawAdapterConnection.name;
12
- adapterConnection.configuration = DataValueCollection.fromObject(rawAdapterConnection.configuration);
15
+ adapterConnection.configuration = DataValueCollection_1.DataValueCollection.fromObject(rawAdapterConnection.configuration);
13
16
  return adapterConnection;
14
17
  // adapter.id = rawAdapter.id;
15
18
  // adapter.name = rawAdapter.name;
@@ -20,3 +23,4 @@ export class AdapterConnection {
20
23
  // return adapter;
21
24
  }
22
25
  }
26
+ exports.AdapterConnection = AdapterConnection;
@@ -1,10 +1,13 @@
1
- import { State } from './State';
2
- import { Utils } from '../Utils';
3
- export class Config {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Config = void 0;
4
+ const State_1 = require("./State");
5
+ const Utils_1 = require("../Utils");
6
+ class Config {
4
7
  constructor() {
5
8
  this.inheritable = true;
6
9
  this.sensitive = true;
7
- this.state = State.Active;
10
+ this.state = State_1.State.Active;
8
11
  }
9
12
  static parse(rawConfig) {
10
13
  let config = new Config();
@@ -15,9 +18,10 @@ export class Config {
15
18
  config.scope = rawConfig.scope;
16
19
  config.key = rawConfig.key;
17
20
  config.value = rawConfig.value;
18
- config.inheritable = Utils.isTrue(rawConfig.inheritable);
19
- config.sensitive = Utils.isTrue(rawConfig.sensitive);
20
- config.state = State.fromString(rawConfig.state);
21
+ config.inheritable = Utils_1.Utils.isTrue(rawConfig.inheritable);
22
+ config.sensitive = Utils_1.Utils.isTrue(rawConfig.sensitive);
23
+ config.state = State_1.State.fromString(rawConfig.state);
21
24
  return config;
22
25
  }
23
26
  }
27
+ exports.Config = Config;
@@ -1,6 +1,10 @@
1
- export class DataValue {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataValue = void 0;
4
+ class DataValue {
2
5
  constructor(key, value) {
3
6
  this.key = key;
4
7
  this.value = value;
5
8
  }
6
9
  }
10
+ exports.DataValue = DataValue;
@@ -1,7 +1,10 @@
1
- import { DataValue } from './DataValue';
2
- import { Utils } from '../Utils';
3
- import { JsonSerializable } from './JsonSerializable';
4
- export class DataValueCollection extends JsonSerializable {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataValueCollection = void 0;
4
+ const DataValue_1 = require("./DataValue");
5
+ const Utils_1 = require("../Utils");
6
+ const JsonSerializable_1 = require("./JsonSerializable");
7
+ class DataValueCollection extends JsonSerializable_1.JsonSerializable {
5
8
  constructor() {
6
9
  super(...arguments);
7
10
  this._values = [];
@@ -10,7 +13,7 @@ export class DataValueCollection extends JsonSerializable {
10
13
  return this._values.length;
11
14
  }
12
15
  static fromObject(rawValues) {
13
- if (Utils.isNullOrUndefined(rawValues)) {
16
+ if (Utils_1.Utils.isNullOrUndefined(rawValues)) {
14
17
  return new DataValueCollection();
15
18
  }
16
19
  const result = new DataValueCollection();
@@ -27,7 +30,7 @@ export class DataValueCollection extends JsonSerializable {
27
30
  if (existingIndex !== -1) {
28
31
  this._values.splice(existingIndex);
29
32
  }
30
- this._values.push(new DataValue(key, value));
33
+ this._values.push(new DataValue_1.DataValue(key, value));
31
34
  }
32
35
  get(key) {
33
36
  for (const tag of this._values) {
@@ -55,3 +58,4 @@ export class DataValueCollection extends JsonSerializable {
55
58
  return this._values;
56
59
  }
57
60
  }
61
+ exports.DataValueCollection = DataValueCollection;
@@ -1,5 +1,8 @@
1
- import { HttpClient } from '../../Http/HttpClient';
2
- export class ClientError {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientError = void 0;
4
+ const HttpClient_1 = require("../../Http/HttpClient");
5
+ class ClientError {
3
6
  constructor(message, code = null) {
4
7
  this.body = null;
5
8
  this.message = message;
@@ -19,10 +22,10 @@ export class ClientError {
19
22
  else {
20
23
  if (error.code !== null && error.code !== undefined) {
21
24
  if (error.code === 'EUNAVAILABLE') {
22
- clientError.code = HttpClient.HTTP_UNAVAILABLE;
25
+ clientError.code = HttpClient_1.HttpClient.HTTP_UNAVAILABLE;
23
26
  }
24
27
  if (error.code === 'EAUTH') {
25
- clientError.code = HttpClient.HTTP_UNAUTHORIZED;
28
+ clientError.code = HttpClient_1.HttpClient.HTTP_UNAUTHORIZED;
26
29
  }
27
30
  // if (error.code === 'ESTATUS' && error.message === 'HTTP status 503') {
28
31
  // clientError.code = HttpClient.HTTP_UNAVAILABLE;
@@ -44,31 +47,31 @@ export class ClientError {
44
47
  return null;
45
48
  break;
46
49
  case 400:
47
- return new ClientError('Bad Request', HttpClient.HTTP_BAD_REQUEST);
50
+ return new ClientError('Bad Request', HttpClient_1.HttpClient.HTTP_BAD_REQUEST);
48
51
  break;
49
52
  case 401:
50
- return new ClientError('Unauthorized', HttpClient.HTTP_UNAUTHORIZED);
53
+ return new ClientError('Unauthorized', HttpClient_1.HttpClient.HTTP_UNAUTHORIZED);
51
54
  break;
52
55
  case 403:
53
- return new ClientError('Forbidden', HttpClient.HTTP_FORBIDDEN);
56
+ return new ClientError('Forbidden', HttpClient_1.HttpClient.HTTP_FORBIDDEN);
54
57
  break;
55
58
  case 404:
56
- return new ClientError('Not Found', HttpClient.HTTP_NOTFOUND);
59
+ return new ClientError('Not Found', HttpClient_1.HttpClient.HTTP_NOTFOUND);
57
60
  break;
58
61
  case 405:
59
- return new ClientError('Not allowed', HttpClient.HTTP_NOT_ALLOWED);
62
+ return new ClientError('Not allowed', HttpClient_1.HttpClient.HTTP_NOT_ALLOWED);
60
63
  break;
61
64
  case 422:
62
- return new ClientError('Unprocessable Entity', HttpClient.HTTP_UNPROCESSABLE_ENTITY);
65
+ return new ClientError('Unprocessable Entity', HttpClient_1.HttpClient.HTTP_UNPROCESSABLE_ENTITY);
63
66
  break;
64
67
  case 500:
65
- return new ClientError('Internal Server Error', HttpClient.HTTP_INTERNAL_SERVER_ERROR);
68
+ return new ClientError('Internal Server Error', HttpClient_1.HttpClient.HTTP_INTERNAL_SERVER_ERROR);
66
69
  break;
67
70
  case 502:
68
- return new ClientError('Bad gateway', HttpClient.HTTP_BAD_GATEWAY);
71
+ return new ClientError('Bad gateway', HttpClient_1.HttpClient.HTTP_BAD_GATEWAY);
69
72
  break;
70
73
  case 503:
71
- return new ClientError('Service not available', HttpClient.HTTP_UNAVAILABLE);
74
+ return new ClientError('Service not available', HttpClient_1.HttpClient.HTTP_UNAVAILABLE);
72
75
  break;
73
76
  default:
74
77
  console.error('Unknown status code "' + statusCode + '"', { code: statusCode, text: statusText });
@@ -77,3 +80,4 @@ export class ClientError {
77
80
  return null;
78
81
  }
79
82
  }
83
+ exports.ClientError = ClientError;