attlaz-client 1.6.11 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Client.js +55 -59
- package/dist/Http/HttpClient.d.ts +3 -1
- package/dist/Http/HttpClient.js +63 -59
- package/dist/Http/HttpClientRequest.js +5 -9
- package/dist/Http/HttpClientRequest.spec.js +3 -5
- package/dist/Http/HttpClientResponse.js +1 -5
- package/dist/Http/OAuthClient.js +19 -23
- package/dist/Http/OAuthClient.spec.js +4 -6
- package/dist/Http/OAuthClientOptions.js +1 -5
- package/dist/Http/OAuthClientToken.js +1 -5
- package/dist/Model/Adapter/Adapter.js +1 -5
- package/dist/Model/Adapter/AdapterConfiguration.js +1 -5
- package/dist/Model/Adapter/AdapterConnection.js +4 -8
- package/dist/Model/Config.js +7 -11
- package/dist/Model/DataValue.js +1 -5
- package/dist/Model/DataValueCollection.js +6 -10
- package/dist/Model/Error/ClientError.d.ts +1 -0
- package/dist/Model/Error/ClientError.js +16 -16
- package/dist/Model/Event/EventType.js +2 -5
- package/dist/Model/HealthAlert/HealthAlert.js +4 -8
- package/dist/Model/HealthAlert/HealthAlertStatus.js +5 -8
- package/dist/Model/HealthAlert/HealthTestType.js +5 -8
- package/dist/Model/JsonSerializable.js +1 -5
- package/dist/Model/Log/Log.js +11 -15
- package/dist/Model/Log/LogLevel.js +5 -8
- package/dist/Model/Log/LogQuery.js +1 -5
- package/dist/Model/Log/LogStatus.js +5 -8
- package/dist/Model/Log/LogStreamId.js +1 -5
- package/dist/Model/Messaging/Channel/Channel.js +8 -12
- package/dist/Model/Messaging/Channel/ChannelData.js +1 -5
- package/dist/Model/Messaging/Channel/ChannelType.js +5 -8
- package/dist/Model/Messaging/Channel/EmailChannelData.js +4 -8
- package/dist/Model/Messaging/Channel/PushChannelData.js +4 -8
- package/dist/Model/Messaging/Channel/SlackChannelData.js +4 -8
- package/dist/Model/Messaging/Channel/SmsChannelData.js +4 -8
- package/dist/Model/Messaging/Channel/WebhookChannelData.js +4 -8
- package/dist/Model/Messaging/ChannelHistory.js +3 -7
- package/dist/Model/Messaging/Subscriber.js +6 -10
- package/dist/Model/Notification.js +1 -5
- package/dist/Model/PagedResult.js +1 -5
- package/dist/Model/Project/PlatformLanguage.js +4 -8
- package/dist/Model/Project/Project.js +4 -8
- package/dist/Model/Project/ProjectDeploy.js +8 -12
- package/dist/Model/Project/ProjectDeployCommit.js +1 -5
- package/dist/Model/Project/ProjectDeployStatus.js +5 -8
- package/dist/Model/Project/ProjectEnvironment.js +6 -10
- package/dist/Model/Queue/QueueStatus.js +1 -5
- package/dist/Model/Result/DataResult.js +1 -5
- package/dist/Model/Result/DataResult.spec.js +2 -4
- package/dist/Model/Result/DataResultCollection.js +1 -5
- package/dist/Model/Result/ResultError.js +1 -5
- package/dist/Model/SourcesAccount.js +1 -5
- package/dist/Model/SourcesAccountRepository.js +1 -5
- package/dist/Model/State.js +5 -8
- package/dist/Model/StateAware.js +1 -2
- package/dist/Model/Storage/StorageInformation.js +1 -5
- package/dist/Model/Storage/StorageType.js +5 -8
- package/dist/Model/Task.js +4 -8
- package/dist/Model/TaskExecution/TaskExecutionStats.js +1 -5
- package/dist/Model/TaskExecution.js +1 -5
- package/dist/Model/TaskExecutionHistory.js +3 -7
- package/dist/Model/TaskExecutionResponse.js +1 -5
- package/dist/Model/TaskExecutionStatus.js +5 -8
- package/dist/Model/TaskExecutionSummary.js +7 -11
- package/dist/Model/TaskSummary.js +8 -12
- package/dist/Model/Team/Team.js +1 -5
- package/dist/Model/Team/TeamMember.js +1 -5
- package/dist/Model/Team/TeamMemberInvite.js +3 -7
- package/dist/Model/Team/TeamMemberInvite2.js +1 -5
- package/dist/Model/Team/TeamMemberInviteState.js +5 -8
- package/dist/Model/Team/TeamMemberRole.js +5 -8
- package/dist/Model/Trigger/ApiTrigger.js +4 -8
- package/dist/Model/Trigger/ApiTriggerData.js +2 -6
- package/dist/Model/Trigger/ScheduleTrigger.js +4 -8
- package/dist/Model/Trigger/ScheduleTriggerData.js +2 -6
- package/dist/Model/Trigger/Trigger.js +15 -19
- package/dist/Model/Trigger/TriggerData.js +1 -5
- package/dist/Model/Trigger/TriggerType.js +5 -8
- package/dist/Model/Trigger/WebhookTrigger.js +4 -8
- package/dist/Model/Trigger/WebhookTriggerData.js +2 -6
- package/dist/Model/User/UserAuthProvider.js +6 -10
- package/dist/Model/User.js +6 -10
- package/dist/Model/Worker/Platform.js +8 -12
- package/dist/Model/Worker/PlatformImage.js +6 -10
- package/dist/Model/Worker/Worker.js +7 -11
- package/dist/Model/Worker/WorkerConfig.js +1 -5
- package/dist/Model/Worker/WorkerInstance.js +3 -7
- package/dist/Model/Worker/WorkerInstanceState.js +5 -8
- package/dist/Model/Worker/WorkerState.js +5 -8
- package/dist/Service/AdapterEndpoint.js +15 -21
- package/dist/Service/ChannelEndpoint.js +11 -15
- package/dist/Service/ConfigEndpoint.js +8 -12
- package/dist/Service/Endpoint.js +3 -7
- package/dist/Service/HealthAlertEndpoint.js +4 -8
- package/dist/Service/LogEndpoint.js +15 -19
- package/dist/Service/NotificationsEndpoint.js +4 -8
- package/dist/Service/PlatformEndpoint.js +6 -10
- package/dist/Service/PlatformLanguageEndpoint.js +4 -8
- package/dist/Service/ProjectDeployEndpoint.js +7 -11
- package/dist/Service/ProjectEndpoint.js +9 -13
- package/dist/Service/ProjectEnvironmentEndpoint.js +2 -6
- package/dist/Service/QueueEndpoint.js +6 -10
- package/dist/Service/SourcesAccountEndpoint.js +8 -12
- package/dist/Service/StorageEndpoint.js +2 -6
- package/dist/Service/SubscriberEndpoint.js +7 -11
- package/dist/Service/TaskEndpoint.js +14 -18
- package/dist/Service/TaskExecutionEndpoint.d.ts +1 -1
- package/dist/Service/TaskExecutionEndpoint.js +16 -20
- package/dist/Service/TaskExecutionRequestEndpoint.js +2 -6
- package/dist/Service/TaskExecutionStatsEndpoint.js +4 -8
- package/dist/Service/TeamMemberEndpoint.js +14 -18
- package/dist/Service/TeamsEndpoint.js +6 -10
- package/dist/Service/TriggerEndpoint.js +9 -13
- package/dist/Service/UserEndpoint.js +10 -14
- package/dist/Service/WorkerConfigEndpoint.js +7 -11
- package/dist/Service/WorkerEndpoint.js +7 -11
- package/dist/Utils.js +1 -5
- package/dist/Utils.spec.js +32 -34
- package/dist/auth.spec.js +22 -24
- package/dist/data.spec.js +3 -5
- package/dist/index.js +105 -215
- package/dist/test.js +11 -13
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +4 -2
package/dist/Client.js
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const PlatformEndpoint_1 = require("./Service/PlatformEndpoint");
|
|
30
|
-
const TaskExecutionStatsEndpoint_1 = require("./Service/TaskExecutionStatsEndpoint");
|
|
31
|
-
class Client {
|
|
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 {
|
|
32
29
|
// private test: Map<string, any>;
|
|
33
30
|
// private socketService;
|
|
34
31
|
constructor(apiEndpoint, clientId, clientSecret) {
|
|
@@ -36,34 +33,34 @@ class Client {
|
|
|
36
33
|
this.clientId = clientId;
|
|
37
34
|
this.clientSecret = clientSecret;
|
|
38
35
|
this.Store = {
|
|
39
|
-
WorkerEndpoint
|
|
40
|
-
AdapterEndpoint
|
|
41
|
-
ProjectEndpoint
|
|
42
|
-
ProjectEnvironmentEndpoint
|
|
43
|
-
ProjectDeployEndpoint
|
|
44
|
-
QueueEndpoint
|
|
45
|
-
ChannelEndpoint
|
|
46
|
-
ConfigEndpoint
|
|
47
|
-
NotificationsEndpoint
|
|
48
|
-
SubscriberEndpoint
|
|
49
|
-
LogEndpoint
|
|
50
|
-
TaskEndpoint
|
|
51
|
-
TaskExecutionEndpoint
|
|
52
|
-
TaskExecutionRequestEndpoint
|
|
53
|
-
TeamsEndpoint
|
|
54
|
-
TriggerEndpoint
|
|
55
|
-
UserEndpoint
|
|
56
|
-
MemberEndpoint:
|
|
57
|
-
SourcesAccountEndpoint
|
|
58
|
-
LanguageEndpoint:
|
|
59
|
-
StorageEndpoint
|
|
60
|
-
WorkerConfigEndpoint
|
|
61
|
-
HealthAlertEndpoint
|
|
62
|
-
PlatformEndpoint
|
|
63
|
-
TaskExecutionStatsEndpoint
|
|
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
|
|
64
61
|
};
|
|
65
|
-
const options = new
|
|
66
|
-
this.httpClient = new
|
|
62
|
+
const options = new OAuthClientOptions(apiEndpoint, clientId, clientSecret);
|
|
63
|
+
this.httpClient = new OAuthClient(options);
|
|
67
64
|
this.endpoints = new Map();
|
|
68
65
|
// this.test = new Map<string, any>();
|
|
69
66
|
//
|
|
@@ -200,4 +197,3 @@ class Client {
|
|
|
200
197
|
return this.endpoints.get(key);
|
|
201
198
|
}
|
|
202
199
|
}
|
|
203
|
-
exports.Client = Client;
|
|
@@ -8,7 +8,9 @@ export declare class HttpClient {
|
|
|
8
8
|
static HTTP_NOT_ALLOWED: number;
|
|
9
9
|
static HTTP_UNPROCESSABLE_ENTITY: number;
|
|
10
10
|
static HTTP_INTERNAL_SERVER_ERROR: number;
|
|
11
|
+
static HTTP_BAD_GATEWAY: number;
|
|
11
12
|
static HTTP_UNAVAILABLE: number;
|
|
12
|
-
static get(url: string, requestData?: any): Promise<any>;
|
|
13
13
|
static request2(request: HttpClientRequest): Promise<HttpClientResponse>;
|
|
14
|
+
private static getContentType;
|
|
15
|
+
private static formatContentType;
|
|
14
16
|
}
|
package/dist/Http/HttpClient.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return await response.json();
|
|
22
|
-
}
|
|
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 {
|
|
6
|
+
// public static async get(url: string, requestData: any = {}): Promise<any> {
|
|
7
|
+
// if (Utils.isNullOrUndefined(requestData)) {
|
|
8
|
+
// requestData = {};
|
|
9
|
+
// }
|
|
10
|
+
// const response: Response = await fetch(url, requestData);
|
|
11
|
+
//
|
|
12
|
+
// //TODO: validate status
|
|
13
|
+
// const error: ClientError | null = ClientError.byStatus(response.status, response.statusText);
|
|
14
|
+
// if (!Utils.isNullOrUndefined(error)) {
|
|
15
|
+
// throw error;
|
|
16
|
+
// }
|
|
17
|
+
//
|
|
18
|
+
// // TODO: make it possible to do request without parsing the json
|
|
19
|
+
// return await response.json();
|
|
20
|
+
// }
|
|
23
21
|
static async request2(request) {
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
23
|
+
// Add user agent when running in Node
|
|
24
|
+
request.headers['User-Agent'] = 'Attlaz Http/' + VERSION;
|
|
25
|
+
}
|
|
24
26
|
const rawRequest = {
|
|
25
27
|
url: request.getFullUrl(),
|
|
26
28
|
method: request.method,
|
|
@@ -28,51 +30,52 @@ class HttpClient {
|
|
|
28
30
|
omitDefaultHeaders: true,
|
|
29
31
|
body: request.body
|
|
30
32
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const httpResponse = new HttpClientResponse_1.HttpClientResponse(response.status, response.statusText);
|
|
35
|
-
// httpResponse.status = response.status;
|
|
36
|
-
// httpResponse.statusText = response.statusText;
|
|
37
|
-
// TODO: should we get JSON immediately?
|
|
38
|
-
// response.json
|
|
39
|
-
// httpResponse.body = await response.text();
|
|
33
|
+
const response = await fetch(request.getFullUrl(), rawRequest);
|
|
34
|
+
const httpResponse = new HttpClientResponse(response.status, response.statusText);
|
|
35
|
+
let contentType = this.getContentType(response);
|
|
40
36
|
const rawData = await response.text();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
if (contentType.type === 'application/json') {
|
|
38
|
+
let jsonData = null;
|
|
39
|
+
try {
|
|
40
|
+
jsonData = JSON.parse(rawData);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
console.log(httpResponse.statusText);
|
|
44
|
+
console.error('Unable to parse response data to JSON');
|
|
45
|
+
}
|
|
46
|
+
httpResponse.body = jsonData;
|
|
44
47
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
console.error('Unable to parse response data to JSON');
|
|
48
|
+
else {
|
|
49
|
+
httpResponse.body = rawData;
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// const body: string = await response.text();
|
|
53
|
-
// console.log('Text' + body);
|
|
54
|
-
//
|
|
55
|
-
// console.log(response);
|
|
51
|
+
const error = ClientError.byStatus(response.status, response.statusText);
|
|
52
|
+
if (error !== null && error !== undefined) {
|
|
53
|
+
error.body = httpResponse.body;
|
|
56
54
|
throw error;
|
|
57
55
|
}
|
|
58
|
-
// //TODO: validate status
|
|
59
|
-
//
|
|
60
|
-
// const error: ClientError = ClientError.byStatus(response.status, response.statusText);
|
|
61
|
-
// if (!Utils.isNullOrUndefined(error)) {
|
|
62
|
-
//
|
|
63
|
-
// // const body: string = await response.text();
|
|
64
|
-
// // console.log('Text' + body);
|
|
65
|
-
// //
|
|
66
|
-
// // console.log(response);
|
|
67
|
-
// throw error;
|
|
68
|
-
// }
|
|
69
|
-
//
|
|
70
|
-
// // TODO: make it possible to do request without parsing the json
|
|
71
|
-
// return await response.json();
|
|
72
56
|
return httpResponse;
|
|
73
57
|
}
|
|
58
|
+
static getContentType(response) {
|
|
59
|
+
if (response.headers.has('Content-Type')) {
|
|
60
|
+
const rawContentType = response.headers.get('Content-Type');
|
|
61
|
+
if (rawContentType !== null) {
|
|
62
|
+
return this.formatContentType(rawContentType);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { type: 'application/json', options: null };
|
|
66
|
+
}
|
|
67
|
+
static formatContentType(input) {
|
|
68
|
+
const d = input.split(';');
|
|
69
|
+
if (d.length === 1) {
|
|
70
|
+
return { type: d[0], options: null };
|
|
71
|
+
}
|
|
72
|
+
else if (d.length === 2) {
|
|
73
|
+
return { type: d[0], options: d[1].trim() };
|
|
74
|
+
}
|
|
75
|
+
console.error('Unable to parse content type "' + input + '"');
|
|
76
|
+
return { type: input, options: null };
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
|
-
exports.HttpClient = HttpClient;
|
|
76
79
|
HttpClient.HTTP_BAD_REQUEST = 400;
|
|
77
80
|
HttpClient.HTTP_UNAUTHORIZED = 401;
|
|
78
81
|
HttpClient.HTTP_FORBIDDEN = 403;
|
|
@@ -80,4 +83,5 @@ HttpClient.HTTP_NOTFOUND = 404;
|
|
|
80
83
|
HttpClient.HTTP_NOT_ALLOWED = 405;
|
|
81
84
|
HttpClient.HTTP_UNPROCESSABLE_ENTITY = 422;
|
|
82
85
|
HttpClient.HTTP_INTERNAL_SERVER_ERROR = 500;
|
|
86
|
+
HttpClient.HTTP_BAD_GATEWAY = 502;
|
|
83
87
|
HttpClient.HTTP_UNAVAILABLE = 503;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Utils_1 = require("../Utils");
|
|
5
|
-
const JsonSerializable_1 = require("../Model/JsonSerializable");
|
|
6
|
-
class HttpClientRequest {
|
|
1
|
+
import { Utils } from '../Utils';
|
|
2
|
+
import { JsonSerializable } from '../Model/JsonSerializable';
|
|
3
|
+
export class HttpClientRequest {
|
|
7
4
|
constructor(url, method = HttpClientRequest.GET) {
|
|
8
5
|
this.headers = {};
|
|
9
6
|
this.body = null;
|
|
@@ -14,7 +11,7 @@ class HttpClientRequest {
|
|
|
14
11
|
this.setHeader('Content-Type', 'application/json');
|
|
15
12
|
}
|
|
16
13
|
setBasicAuth(user, password) {
|
|
17
|
-
this.setHeader('Authorization', 'Basic ' +
|
|
14
|
+
this.setHeader('Authorization', 'Basic ' + Utils.base64encode(user + ':' + password));
|
|
18
15
|
}
|
|
19
16
|
setHeader(key, value) {
|
|
20
17
|
this.headers[key] = value;
|
|
@@ -24,7 +21,7 @@ class HttpClientRequest {
|
|
|
24
21
|
}
|
|
25
22
|
setJsonBody(data) {
|
|
26
23
|
this.setJsonHeader();
|
|
27
|
-
this.body =
|
|
24
|
+
this.body = JsonSerializable.stringify(data);
|
|
28
25
|
}
|
|
29
26
|
getFullUrl() {
|
|
30
27
|
let result = this.urlObj.href;
|
|
@@ -35,7 +32,6 @@ class HttpClientRequest {
|
|
|
35
32
|
return result;
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
exports.HttpClientRequest = HttpClientRequest;
|
|
39
35
|
HttpClientRequest.GET = 'GET';
|
|
40
36
|
HttpClientRequest.POST = 'POST';
|
|
41
37
|
HttpClientRequest.PUT = 'PUT';
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const HttpClientRequest_1 = require("./HttpClientRequest");
|
|
1
|
+
import { HttpClientRequest } from './HttpClientRequest';
|
|
4
2
|
test('Test query string', async () => {
|
|
5
|
-
const request = new
|
|
3
|
+
const request = new HttpClientRequest('https://example.com');
|
|
6
4
|
expect(request.getFullUrl()).toBe('https://example.com');
|
|
7
5
|
request.addQueryParam('queryparam1', 'queryparam1value');
|
|
8
6
|
expect(request.getFullUrl()).toBe('https://example.com?queryparam1=queryparam1value');
|
|
9
7
|
});
|
|
10
8
|
test('Test query string - add to existing query string', async () => {
|
|
11
|
-
const request = new
|
|
9
|
+
const request = new HttpClientRequest('https://example.com?queryparam0=queryparam0value');
|
|
12
10
|
expect(request.getFullUrl()).toBe('https://example.com?queryparam0=queryparam0value');
|
|
13
11
|
request.addQueryParam('queryparam1', 'queryparam1value');
|
|
14
12
|
expect(request.getFullUrl()).toBe('https://example.com?queryparam0=queryparam0value&queryparam1=queryparam1value');
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpClientResponse = void 0;
|
|
4
|
-
class HttpClientResponse {
|
|
1
|
+
export class HttpClientResponse {
|
|
5
2
|
constructor(status, statusText) {
|
|
6
3
|
this.body = null;
|
|
7
4
|
this.status = status;
|
|
8
5
|
this.statusText = statusText;
|
|
9
6
|
}
|
|
10
7
|
}
|
|
11
|
-
exports.HttpClientResponse = HttpClientResponse;
|
package/dist/Http/OAuthClient.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const ClientOAuth2 = require("client-oauth2");
|
|
9
|
-
const JsonSerializable_1 = require("../Model/JsonSerializable");
|
|
10
|
-
class OAuthClient {
|
|
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 {
|
|
11
8
|
constructor(options) {
|
|
12
9
|
this.debug = false;
|
|
13
10
|
this.oauthToken = null;
|
|
@@ -42,7 +39,7 @@ class OAuthClient {
|
|
|
42
39
|
}
|
|
43
40
|
catch (e) {
|
|
44
41
|
console.log(e);
|
|
45
|
-
throw
|
|
42
|
+
throw ClientError.fromError(e);
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
async refreshToken() {
|
|
@@ -55,7 +52,7 @@ class OAuthClient {
|
|
|
55
52
|
this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
|
|
56
53
|
}
|
|
57
54
|
catch (e) {
|
|
58
|
-
const error =
|
|
55
|
+
const error = ClientError.fromError(e);
|
|
59
56
|
throw error;
|
|
60
57
|
}
|
|
61
58
|
}
|
|
@@ -71,12 +68,12 @@ class OAuthClient {
|
|
|
71
68
|
}
|
|
72
69
|
async request(action, parameters = null, method = 'GET', signWithOauthToken = true) {
|
|
73
70
|
if (signWithOauthToken && !this.isAuthenticated()) {
|
|
74
|
-
throw new
|
|
71
|
+
throw new ClientError('Unable to perform request, access token not provided');
|
|
75
72
|
}
|
|
76
73
|
else {
|
|
77
74
|
if (signWithOauthToken) {
|
|
78
75
|
if (this.oauthToken === null) {
|
|
79
|
-
throw new
|
|
76
|
+
throw new ClientError('Unable to perform request, access token not provided');
|
|
80
77
|
}
|
|
81
78
|
if (signWithOauthToken && this.oauthToken.expired()) {
|
|
82
79
|
await this.refreshToken();
|
|
@@ -84,17 +81,17 @@ class OAuthClient {
|
|
|
84
81
|
}
|
|
85
82
|
const requestData = this.createRequestData(action, parameters, method, signWithOauthToken);
|
|
86
83
|
if (this.debug) {
|
|
87
|
-
console.debug('[Client]
|
|
84
|
+
console.debug('[Client] REQ: ' + requestData.method.toUpperCase() + ' ' + requestData.getFullUrl());
|
|
88
85
|
}
|
|
89
86
|
try {
|
|
90
|
-
const response = await
|
|
87
|
+
const response = await HttpClient.request2(requestData);
|
|
91
88
|
// if (this.debug) {
|
|
92
89
|
// console.info('[Client response] ', {body: response.body});
|
|
93
90
|
// }
|
|
94
91
|
return response.body;
|
|
95
92
|
}
|
|
96
93
|
catch (error) {
|
|
97
|
-
const clientError =
|
|
94
|
+
const clientError = ClientError.fromError(error);
|
|
98
95
|
if (this.debug) {
|
|
99
96
|
console.error('[Client] Error:', { error, clientError });
|
|
100
97
|
}
|
|
@@ -146,7 +143,7 @@ class OAuthClient {
|
|
|
146
143
|
return this.oauthClient.token.getUri(options === null ? undefined : options);
|
|
147
144
|
}
|
|
148
145
|
tokenToOauthClientToken(oauthToken) {
|
|
149
|
-
const token = new
|
|
146
|
+
const token = new OAuthClientToken(oauthToken.accessToken, oauthToken.tokenType, oauthToken.refreshToken, oauthToken.data.scopes);
|
|
150
147
|
const rawTokenExpires = oauthToken.expires;
|
|
151
148
|
if (rawTokenExpires !== null && rawTokenExpires !== undefined) {
|
|
152
149
|
token.expires = rawTokenExpires;
|
|
@@ -161,10 +158,10 @@ class OAuthClient {
|
|
|
161
158
|
}
|
|
162
159
|
createRequestData(action, parameters = null, method = 'GET', signWithOauthToken = true) {
|
|
163
160
|
const url = this.getUri(action);
|
|
164
|
-
let requestData = new
|
|
161
|
+
let requestData = new HttpClientRequest(url, method);
|
|
165
162
|
if ((method === 'POST' || method === 'DELETE' || method === 'PUT') && parameters !== null && parameters !== undefined) {
|
|
166
163
|
if (typeof parameters === 'object') {
|
|
167
|
-
parameters =
|
|
164
|
+
parameters = JsonSerializable.stringify(parameters);
|
|
168
165
|
}
|
|
169
166
|
else if (typeof parameters === 'string') {
|
|
170
167
|
}
|
|
@@ -182,7 +179,7 @@ class OAuthClient {
|
|
|
182
179
|
}
|
|
183
180
|
if (signWithOauthToken) {
|
|
184
181
|
if (this.oauthToken === null) {
|
|
185
|
-
throw new
|
|
182
|
+
throw new ClientError('Unable to perform request, access token not provided');
|
|
186
183
|
}
|
|
187
184
|
if (this.oauthToken.expired()) {
|
|
188
185
|
throw new Error('Unable to sign request, token is expired');
|
|
@@ -195,7 +192,7 @@ class OAuthClient {
|
|
|
195
192
|
}
|
|
196
193
|
signRequest(requestObject) {
|
|
197
194
|
if (this.oathClientToken === null) {
|
|
198
|
-
throw new
|
|
195
|
+
throw new ClientError('Unable to sign request, access token not provided');
|
|
199
196
|
}
|
|
200
197
|
const tokenType = this.oathClientToken.token_type;
|
|
201
198
|
const accessToken = this.oathClientToken.access_token;
|
|
@@ -212,4 +209,3 @@ class OAuthClient {
|
|
|
212
209
|
return requestObject;
|
|
213
210
|
}
|
|
214
211
|
}
|
|
215
|
-
exports.OAuthClient = OAuthClient;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const OAuthClient_1 = require("./OAuthClient");
|
|
4
|
-
const OAuthClientOptions_1 = require("./OAuthClientOptions");
|
|
1
|
+
import { OAuthClient } from './OAuthClient';
|
|
2
|
+
import { OAuthClientOptions } from './OAuthClientOptions';
|
|
5
3
|
test('Test enum parsing', async () => {
|
|
6
|
-
const options = new
|
|
7
|
-
const client = new
|
|
4
|
+
const options = new OAuthClientOptions('https://github.com/login', '3b938da6f58d6bef7d59', 'da05698a6bd449de9437e11ff0b99003f511e40f');
|
|
5
|
+
const client = new OAuthClient(options);
|
|
8
6
|
// client.getClient().cod.getToken()
|
|
9
7
|
// const x: any = await client.authenticate();
|
|
10
8
|
// console.log(x);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OAuthClientOptions = void 0;
|
|
4
|
-
class OAuthClientOptions {
|
|
1
|
+
export class OAuthClientOptions {
|
|
5
2
|
constructor(apiEndpoint, clientId, clientSecret) {
|
|
6
3
|
this.accessTokenUri = 'oauth/token';
|
|
7
4
|
this.authorizationUri = 'oauth/authorize';
|
|
@@ -13,4 +10,3 @@ class OAuthClientOptions {
|
|
|
13
10
|
this.clientSecret = clientSecret;
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.OAuthClientOptions = OAuthClientOptions;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OAuthClientToken = void 0;
|
|
4
|
-
class OAuthClientToken {
|
|
1
|
+
export class OAuthClientToken {
|
|
5
2
|
constructor(access_token, token_type, refresh_token, scope) {
|
|
6
3
|
this.access_token = '';
|
|
7
4
|
this.token_type = '';
|
|
@@ -33,4 +30,3 @@ class OAuthClientToken {
|
|
|
33
30
|
return token;
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
exports.OAuthClientToken = OAuthClientToken;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Adapter = void 0;
|
|
4
|
-
class Adapter {
|
|
1
|
+
export class Adapter {
|
|
5
2
|
static parse(rawAdapter) {
|
|
6
3
|
let adapter = new Adapter();
|
|
7
4
|
adapter.id = rawAdapter.id;
|
|
@@ -17,4 +14,3 @@ class Adapter {
|
|
|
17
14
|
return adapter;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.Adapter = Adapter;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AdapterConfiguration = void 0;
|
|
4
|
-
class AdapterConfiguration {
|
|
1
|
+
export class AdapterConfiguration {
|
|
5
2
|
static parse(rawAdapter) {
|
|
6
3
|
let configuration = new AdapterConfiguration();
|
|
7
4
|
configuration.id = rawAdapter.id;
|
|
@@ -13,4 +10,3 @@ class AdapterConfiguration {
|
|
|
13
10
|
return configuration;
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.AdapterConfiguration = AdapterConfiguration;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.AdapterConnection = void 0;
|
|
4
|
-
const DataValueCollection_1 = require("../DataValueCollection");
|
|
5
|
-
class AdapterConnection {
|
|
1
|
+
import { DataValueCollection } from '../DataValueCollection';
|
|
2
|
+
export class AdapterConnection {
|
|
6
3
|
constructor() {
|
|
7
|
-
this.configuration = new
|
|
4
|
+
this.configuration = new DataValueCollection();
|
|
8
5
|
}
|
|
9
6
|
static parse(rawAdapterConnection) {
|
|
10
7
|
let adapterConnection = new AdapterConnection();
|
|
@@ -12,7 +9,7 @@ class AdapterConnection {
|
|
|
12
9
|
adapterConnection.key = rawAdapterConnection.key;
|
|
13
10
|
adapterConnection.adapter = rawAdapterConnection.adapter;
|
|
14
11
|
adapterConnection.name = rawAdapterConnection.name;
|
|
15
|
-
adapterConnection.configuration =
|
|
12
|
+
adapterConnection.configuration = DataValueCollection.fromObject(rawAdapterConnection.configuration);
|
|
16
13
|
return adapterConnection;
|
|
17
14
|
// adapter.id = rawAdapter.id;
|
|
18
15
|
// adapter.name = rawAdapter.name;
|
|
@@ -23,4 +20,3 @@ class AdapterConnection {
|
|
|
23
20
|
// return adapter;
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
exports.AdapterConnection = AdapterConnection;
|
package/dist/Model/Config.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const State_1 = require("./State");
|
|
5
|
-
const Utils_1 = require("../Utils");
|
|
6
|
-
class Config {
|
|
1
|
+
import { State } from './State';
|
|
2
|
+
import { Utils } from '../Utils';
|
|
3
|
+
export class Config {
|
|
7
4
|
constructor() {
|
|
8
5
|
this.inheritable = true;
|
|
9
6
|
this.sensitive = true;
|
|
10
|
-
this.state =
|
|
7
|
+
this.state = State.Active;
|
|
11
8
|
}
|
|
12
9
|
static parse(rawConfig) {
|
|
13
10
|
let config = new Config();
|
|
@@ -18,10 +15,9 @@ class Config {
|
|
|
18
15
|
config.scope = rawConfig.scope;
|
|
19
16
|
config.key = rawConfig.key;
|
|
20
17
|
config.value = rawConfig.value;
|
|
21
|
-
config.inheritable =
|
|
22
|
-
config.sensitive =
|
|
23
|
-
config.state =
|
|
18
|
+
config.inheritable = Utils.isTrue(rawConfig.inheritable);
|
|
19
|
+
config.sensitive = Utils.isTrue(rawConfig.sensitive);
|
|
20
|
+
config.state = State.fromString(rawConfig.state);
|
|
24
21
|
return config;
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
exports.Config = Config;
|
package/dist/Model/DataValue.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataValue = void 0;
|
|
4
|
-
class DataValue {
|
|
1
|
+
export class DataValue {
|
|
5
2
|
constructor(key, value) {
|
|
6
3
|
this.key = key;
|
|
7
4
|
this.value = value;
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.DataValue = DataValue;
|