attlaz-client 1.7.1 → 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.js +9 -13
- 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 +18 -22
- 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.js +13 -17
- 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 +11 -15
- 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.js +14 -18
- 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 -1
- package/dist/version.js +1 -4
- package/package.json +3 -2
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Trigger_1 = require("../Model/Trigger/Trigger");
|
|
6
|
-
const Utils_1 = require("../Utils");
|
|
7
|
-
class TriggerEndpoint extends Endpoint_1.Endpoint {
|
|
1
|
+
import { Endpoint } from './Endpoint';
|
|
2
|
+
import { Trigger } from '../Model/Trigger/Trigger';
|
|
3
|
+
import { Utils } from '../Utils';
|
|
4
|
+
export class TriggerEndpoint extends Endpoint {
|
|
8
5
|
async getByTask(taskId, projectEnvironmentId = null) {
|
|
9
6
|
try {
|
|
10
7
|
let parameters = null;
|
|
11
|
-
if (!
|
|
8
|
+
if (!Utils.isNullOrUndefined(projectEnvironmentId)) {
|
|
12
9
|
parameters = { environment: projectEnvironmentId };
|
|
13
10
|
}
|
|
14
11
|
const rawTriggers = await this.httpClient.request('/tasks/' + taskId + '/triggers', parameters);
|
|
15
12
|
let triggers = [];
|
|
16
13
|
for (let rawTrigger of rawTriggers) {
|
|
17
|
-
triggers.push(
|
|
14
|
+
triggers.push(Trigger.parse(rawTrigger));
|
|
18
15
|
}
|
|
19
16
|
return triggers;
|
|
20
17
|
}
|
|
@@ -28,10 +25,10 @@ class TriggerEndpoint extends Endpoint_1.Endpoint {
|
|
|
28
25
|
async getById(id) {
|
|
29
26
|
try {
|
|
30
27
|
const result = await this.httpClient.request('/triggers/' + id);
|
|
31
|
-
if (
|
|
28
|
+
if (Utils.isNullOrUndefined(result)) {
|
|
32
29
|
throw new Error('Unable to get trigger');
|
|
33
30
|
}
|
|
34
|
-
return
|
|
31
|
+
return Trigger.parse(result);
|
|
35
32
|
}
|
|
36
33
|
catch (error) {
|
|
37
34
|
if (this.httpClient.isDebugEnabled()) {
|
|
@@ -44,7 +41,7 @@ class TriggerEndpoint extends Endpoint_1.Endpoint {
|
|
|
44
41
|
try {
|
|
45
42
|
let url = '/tasks/' + trigger.task + '/triggers';
|
|
46
43
|
const result = await this.httpClient.request(url, trigger, 'POST');
|
|
47
|
-
return
|
|
44
|
+
return Trigger.parse(result);
|
|
48
45
|
}
|
|
49
46
|
catch (error) {
|
|
50
47
|
if (this.httpClient.isDebugEnabled()) {
|
|
@@ -54,4 +51,3 @@ class TriggerEndpoint extends Endpoint_1.Endpoint {
|
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
|
-
exports.TriggerEndpoint = TriggerEndpoint;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const User_1 = require("../Model/User");
|
|
7
|
-
const Utils_1 = require("../Utils");
|
|
8
|
-
class UserEndpoint extends Endpoint_1.Endpoint {
|
|
1
|
+
import { UserAuthProvider } from '../Model/User/UserAuthProvider';
|
|
2
|
+
import { Endpoint } from './Endpoint';
|
|
3
|
+
import { User } from '../Model/User';
|
|
4
|
+
import { Utils } from '../Utils';
|
|
5
|
+
export class UserEndpoint extends Endpoint {
|
|
9
6
|
async getUser() {
|
|
10
7
|
let cmd = '/user';
|
|
11
8
|
const rawUser = await this.httpClient.request(cmd);
|
|
12
|
-
if (
|
|
9
|
+
if (Utils.isNullOrUndefined(rawUser)) {
|
|
13
10
|
throw new Error('User not found');
|
|
14
11
|
}
|
|
15
|
-
return
|
|
12
|
+
return User.parse(rawUser);
|
|
16
13
|
}
|
|
17
14
|
async authenticateByAuthProvider(providerType, data) {
|
|
18
15
|
try {
|
|
@@ -56,14 +53,14 @@ class UserEndpoint extends Endpoint_1.Endpoint {
|
|
|
56
53
|
async getAuthProviders() {
|
|
57
54
|
let cmd = '/user/auth/providers';
|
|
58
55
|
const rawAuthProviders = await this.request(cmd);
|
|
59
|
-
rawAuthProviders.setData(this.parseCollection(rawAuthProviders,
|
|
56
|
+
rawAuthProviders.setData(this.parseCollection(rawAuthProviders, UserAuthProvider.parse));
|
|
60
57
|
return rawAuthProviders;
|
|
61
58
|
}
|
|
62
59
|
async update(user) {
|
|
63
60
|
try {
|
|
64
61
|
let url = '/user/' + user.id;
|
|
65
62
|
const result = await this.httpClient.request(url, { user }, 'POST');
|
|
66
|
-
return
|
|
63
|
+
return User.parse(result);
|
|
67
64
|
}
|
|
68
65
|
catch (e) {
|
|
69
66
|
if (this.httpClient.isDebugEnabled()) {
|
|
@@ -79,7 +76,7 @@ class UserEndpoint extends Endpoint_1.Endpoint {
|
|
|
79
76
|
const result = await this.request(url, data, 'PUT', false);
|
|
80
77
|
const resultData = result.getData();
|
|
81
78
|
if (resultData !== null && resultData.createdUser !== null) {
|
|
82
|
-
result.setData({ createdUser:
|
|
79
|
+
result.setData({ createdUser: User.parse(resultData.createdUser) });
|
|
83
80
|
}
|
|
84
81
|
return result;
|
|
85
82
|
}
|
|
@@ -117,4 +114,3 @@ class UserEndpoint extends Endpoint_1.Endpoint {
|
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
}
|
|
120
|
-
exports.UserEndpoint = UserEndpoint;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Utils_1 = require("../Utils");
|
|
6
|
-
const WorkerConfig_1 = require("../Model/Worker/WorkerConfig");
|
|
7
|
-
class WorkerConfigEndpoint extends Endpoint_1.Endpoint {
|
|
1
|
+
import { Endpoint } from './Endpoint';
|
|
2
|
+
import { Utils } from '../Utils';
|
|
3
|
+
import { WorkerConfig } from '../Model/Worker/WorkerConfig';
|
|
4
|
+
export class WorkerConfigEndpoint extends Endpoint {
|
|
8
5
|
async getByProjectEnvironment(projectEnvironmentId) {
|
|
9
6
|
try {
|
|
10
7
|
let url = '/projectenvironments/' + projectEnvironmentId + '/workerconfiguration';
|
|
11
8
|
const result = await this.request(url);
|
|
12
|
-
if (
|
|
9
|
+
if (Utils.isNullOrUndefined(result)) {
|
|
13
10
|
throw new Error('Unable to get project environment');
|
|
14
11
|
}
|
|
15
12
|
const resultData = result.getData();
|
|
@@ -18,7 +15,7 @@ class WorkerConfigEndpoint extends Endpoint_1.Endpoint {
|
|
|
18
15
|
}
|
|
19
16
|
let workerConfigValues = [];
|
|
20
17
|
for (let rawConfig of resultData) {
|
|
21
|
-
workerConfigValues.push(
|
|
18
|
+
workerConfigValues.push(WorkerConfig.parse(rawConfig));
|
|
22
19
|
}
|
|
23
20
|
return workerConfigValues;
|
|
24
21
|
}
|
|
@@ -34,7 +31,7 @@ class WorkerConfigEndpoint extends Endpoint_1.Endpoint {
|
|
|
34
31
|
let url = '/projectenvironments/' + workerConfig.projectEnvironment + '/workerconfiguration';
|
|
35
32
|
const result = await this.request(url, workerConfig, 'POST');
|
|
36
33
|
console.log(result);
|
|
37
|
-
return
|
|
34
|
+
return WorkerConfig.parse(result);
|
|
38
35
|
}
|
|
39
36
|
catch (error) {
|
|
40
37
|
if (this.httpClient.isDebugEnabled()) {
|
|
@@ -44,4 +41,3 @@ class WorkerConfigEndpoint extends Endpoint_1.Endpoint {
|
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
|
-
exports.WorkerConfigEndpoint = WorkerConfigEndpoint;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const Worker_1 = require("../Model/Worker/Worker");
|
|
7
|
-
const DataResult_1 = require("../Model/Result/DataResult");
|
|
8
|
-
class WorkerEndpoint extends Endpoint_1.Endpoint {
|
|
1
|
+
import { Endpoint } from './Endpoint';
|
|
2
|
+
import { Utils } from '../Utils';
|
|
3
|
+
import { Worker } from '../Model/Worker/Worker';
|
|
4
|
+
import { DataResult } from '../Model/Result/DataResult';
|
|
5
|
+
export class WorkerEndpoint extends Endpoint {
|
|
9
6
|
async getByProjectEnvironment(projectEnvironmentId) {
|
|
10
7
|
try {
|
|
11
8
|
let url = '/projectenvironments/' + projectEnvironmentId + '/workers';
|
|
12
9
|
const result = await this.httpClient.request(url);
|
|
13
|
-
if (
|
|
10
|
+
if (Utils.isNullOrUndefined(result)) {
|
|
14
11
|
throw new Error('Unable to find worker');
|
|
15
12
|
}
|
|
16
|
-
return new
|
|
13
|
+
return new DataResult(Worker.parse(result));
|
|
17
14
|
}
|
|
18
15
|
catch (error) {
|
|
19
16
|
if (this.httpClient.isDebugEnabled()) {
|
|
@@ -36,4 +33,3 @@ class WorkerEndpoint extends Endpoint_1.Endpoint {
|
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
exports.WorkerEndpoint = WorkerEndpoint;
|
package/dist/Utils.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Utils = void 0;
|
|
4
|
-
class Utils {
|
|
1
|
+
export class Utils {
|
|
5
2
|
static isNullOrUndefined(variable) {
|
|
6
3
|
return variable === null || variable === undefined;
|
|
7
4
|
}
|
|
@@ -58,4 +55,3 @@ class Utils {
|
|
|
58
55
|
// return typeof obj[Symbol.iterator] === 'function';
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
|
-
exports.Utils = Utils;
|
package/dist/Utils.spec.js
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const WorkerState_1 = require("./Model/Worker/WorkerState");
|
|
12
|
-
const Utils_1 = require("./Utils");
|
|
1
|
+
import { TriggerType } from './Model/Trigger/TriggerType';
|
|
2
|
+
import { TaskExecutionStatus } from './Model/TaskExecutionStatus';
|
|
3
|
+
import { ChannelType } from './Model/Messaging/Channel/ChannelType';
|
|
4
|
+
import { ProjectDeployStatus } from './Model/Project/ProjectDeployStatus';
|
|
5
|
+
import { State } from './Model/State';
|
|
6
|
+
import { LogLevel } from './Model/Log/LogLevel';
|
|
7
|
+
import { StorageType } from './Model/Storage/StorageType';
|
|
8
|
+
import { WorkerInstanceState } from './Model/Worker/WorkerInstanceState';
|
|
9
|
+
import { WorkerState } from './Model/Worker/WorkerState';
|
|
10
|
+
import { Utils } from './Utils';
|
|
13
11
|
test('Test enum parsing', () => {
|
|
14
|
-
expect(
|
|
15
|
-
expect(
|
|
16
|
-
expect(
|
|
17
|
-
expect(
|
|
18
|
-
expect(
|
|
19
|
-
expect(
|
|
20
|
-
expect(
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
12
|
+
expect(TriggerType.fromString('webhook')).toBe(TriggerType.Webhook);
|
|
13
|
+
expect(TaskExecutionStatus.fromString('complete')).toBe(TaskExecutionStatus.Complete);
|
|
14
|
+
expect(ChannelType.fromString('slack')).toBe(ChannelType.Slack);
|
|
15
|
+
expect(LogLevel.fromString('debug')).toBe(LogLevel.Debug);
|
|
16
|
+
expect(ProjectDeployStatus.fromString('complete')).toBe(ProjectDeployStatus.Complete);
|
|
17
|
+
expect(StorageType.fromString('cache')).toBe(StorageType.Cache);
|
|
18
|
+
expect(State.fromString('active')).toBe(State.Active);
|
|
19
|
+
expect(WorkerInstanceState.fromString('started')).toBe(WorkerInstanceState.Started);
|
|
20
|
+
expect(WorkerState.fromString('active')).toBe(WorkerState.Active);
|
|
23
21
|
});
|
|
24
22
|
test('Test base64 encode/decode', () => {
|
|
25
|
-
expect(
|
|
26
|
-
expect(
|
|
23
|
+
expect(Utils.base64encode('Lorem ipsum')).toBe('TG9yZW0gaXBzdW0=');
|
|
24
|
+
expect(Utils.base64decode('TG9yZW0gaXBzdW0=')).toBe('Lorem ipsum');
|
|
27
25
|
});
|
|
28
26
|
test('Test if iterable', async () => {
|
|
29
|
-
expect(
|
|
30
|
-
expect(
|
|
31
|
-
expect(
|
|
32
|
-
expect(
|
|
33
|
-
expect(
|
|
34
|
-
expect(
|
|
35
|
-
expect(
|
|
36
|
-
expect(
|
|
37
|
-
expect(
|
|
38
|
-
expect(
|
|
39
|
-
expect(
|
|
27
|
+
expect(Utils.isIterable(null)).toBe(false);
|
|
28
|
+
expect(Utils.isIterable('')).toBe(false);
|
|
29
|
+
expect(Utils.isIterable('Lorem')).toBe(false);
|
|
30
|
+
expect(Utils.isIterable(false)).toBe(false);
|
|
31
|
+
expect(Utils.isIterable(true)).toBe(false);
|
|
32
|
+
expect(Utils.isIterable(undefined)).toBe(false);
|
|
33
|
+
expect(Utils.isIterable(12)).toBe(false);
|
|
34
|
+
expect(Utils.isIterable([])).toBe(true);
|
|
35
|
+
expect(Utils.isIterable(['L', 'O', 'R', 'E', 'M'])).toBe(true);
|
|
36
|
+
expect(Utils.isIterable({})).toBe(false);
|
|
37
|
+
expect(Utils.isIterable({ a: 'a', b: 'b' })).toBe(false);
|
|
40
38
|
});
|
package/dist/auth.spec.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Utils_1 = require("./Utils");
|
|
6
|
-
const HttpClient_1 = require("./Http/HttpClient");
|
|
1
|
+
import { Client } from './Client';
|
|
2
|
+
import { OAuthClientToken } from './Http/OAuthClientToken';
|
|
3
|
+
import { Utils } from './Utils';
|
|
4
|
+
import { HttpClient } from './Http/HttpClient';
|
|
7
5
|
jest.setTimeout((60) * 1000);
|
|
8
6
|
// const apiEndpoint: string = 'http://localhost:5728/';
|
|
9
7
|
const apiEndpoint = 'https://api2.attlaz.com';
|
|
@@ -16,7 +14,7 @@ const passwordFlowPassword = 'koetjeboe';
|
|
|
16
14
|
const tokenExpirationInSeconds = 5;
|
|
17
15
|
test('Test client credentials flow', async () => {
|
|
18
16
|
expect.assertions(2);
|
|
19
|
-
let client = new
|
|
17
|
+
let client = new Client(apiEndpoint, clientCredentialClientId, clientCredentialClientSecret);
|
|
20
18
|
client.getHttpClient().enableDebug();
|
|
21
19
|
await client.authenticate();
|
|
22
20
|
const user = await client.getUserEndpoint().getUser();
|
|
@@ -43,14 +41,14 @@ test('Test client credentials flow', async () => {
|
|
|
43
41
|
if (token === null) {
|
|
44
42
|
throw new Error('Token is null');
|
|
45
43
|
}
|
|
46
|
-
expect(
|
|
44
|
+
expect(OAuthClientToken.isExpired(token)).toBeTruthy();
|
|
47
45
|
}
|
|
48
46
|
// const user2: User = await client.getUserEndpoint().getUser()
|
|
49
47
|
// expect(user.email).toBe('demo@attlaz.com');
|
|
50
48
|
});
|
|
51
49
|
test('Test password authentication - valid', async () => {
|
|
52
50
|
expect.assertions(3);
|
|
53
|
-
let client = new
|
|
51
|
+
let client = new Client(apiEndpoint, passwordFlowClientId, passwordFlowClientSecret);
|
|
54
52
|
client.getHttpClient().enableDebug();
|
|
55
53
|
await client.authenticate(passwordFlowUsername, passwordFlowPassword);
|
|
56
54
|
const user = await client.getUserEndpoint().getUser();
|
|
@@ -64,41 +62,41 @@ test('Test password authentication - valid', async () => {
|
|
|
64
62
|
if (token === null) {
|
|
65
63
|
throw new Error('Token is null');
|
|
66
64
|
}
|
|
67
|
-
expect(
|
|
65
|
+
expect(OAuthClientToken.isExpired(token)).toBeTruthy();
|
|
68
66
|
const user2 = await client.getUserEndpoint().getUser();
|
|
69
67
|
expect(user2.email).toBe(passwordFlowUsername);
|
|
70
68
|
});
|
|
71
69
|
test('Test password authentication - invalid', async () => {
|
|
72
70
|
expect.assertions(3);
|
|
73
|
-
let client = new
|
|
71
|
+
let client = new Client(apiEndpoint, passwordFlowClientId, passwordFlowClientSecret);
|
|
74
72
|
client.getHttpClient().enableDebug();
|
|
75
73
|
await expect(client.authenticate(passwordFlowUsername, 'wrongpassword'))
|
|
76
74
|
.rejects
|
|
77
|
-
.toHaveProperty('code',
|
|
75
|
+
.toHaveProperty('code', HttpClient.HTTP_UNAUTHORIZED);
|
|
78
76
|
await expect(client.getUserEndpoint().getUser())
|
|
79
77
|
.rejects
|
|
80
78
|
.toHaveProperty('message', 'Unable to perform request, access token not provided');
|
|
81
79
|
await expect(client.authenticate('wrongusername', 'wrongpassword'))
|
|
82
80
|
.rejects
|
|
83
|
-
.toHaveProperty('code',
|
|
81
|
+
.toHaveProperty('code', HttpClient.HTTP_UNAUTHORIZED);
|
|
84
82
|
});
|
|
85
83
|
test('Test set access token + JSON encode', async () => {
|
|
86
84
|
expect.assertions(4);
|
|
87
|
-
let client = new
|
|
85
|
+
let client = new Client(apiEndpoint, passwordFlowClientId, passwordFlowClientSecret);
|
|
88
86
|
client.getHttpClient().enableDebug();
|
|
89
87
|
await client.authenticate(passwordFlowUsername, passwordFlowPassword);
|
|
90
88
|
const token = client.getToken();
|
|
91
89
|
if (token === null) {
|
|
92
90
|
throw new Error('Token is null');
|
|
93
91
|
}
|
|
94
|
-
expect(
|
|
95
|
-
const encoded =
|
|
92
|
+
expect(OAuthClientToken.isExpired(token)).toBeFalsy();
|
|
93
|
+
const encoded = OAuthClientToken.serialize(token);
|
|
96
94
|
console.log(encoded);
|
|
97
|
-
const decodedToken =
|
|
95
|
+
const decodedToken = OAuthClientToken.deserialize(encoded);
|
|
98
96
|
client.setToken(decodedToken);
|
|
99
97
|
const user = await client.getUserEndpoint().getUser();
|
|
100
98
|
expect(user.email).toBe(passwordFlowUsername);
|
|
101
|
-
let client2 = new
|
|
99
|
+
let client2 = new Client(apiEndpoint, passwordFlowClientId, passwordFlowClientSecret);
|
|
102
100
|
client2.getHttpClient().enableDebug();
|
|
103
101
|
console.log(decodedToken);
|
|
104
102
|
client2.setToken(decodedToken);
|
|
@@ -122,19 +120,19 @@ test('Test set access token + JSON encode', async () => {
|
|
|
122
120
|
});
|
|
123
121
|
test('Test set expired tokens', async () => {
|
|
124
122
|
expect.assertions(4);
|
|
125
|
-
let client = new
|
|
123
|
+
let client = new Client(apiEndpoint, passwordFlowClientId, passwordFlowClientSecret);
|
|
126
124
|
client.getHttpClient().enableDebug();
|
|
127
|
-
const encodedToken =
|
|
128
|
-
const token =
|
|
125
|
+
const encodedToken = Utils.base64decode('eyJhY2Nlc3NfdG9rZW4iOiJvZVZpYXVhdk9wTkNpekNLRmxXUGpuaEI5aHNSdFViMFFTTVJlQWFuIiwidG9rZW5fdHlwZSI6ImJlYXJlciIsInJlZnJlc2hfdG9rZW4iOiJ4N0pINTVaR3U5OGFPN3VQaGlmS2RZME8yc3BYS0IzN296bElDUGtJIiwiZXhwaXJlcyI6IjIwMjEtMDMtMTlUMjE6MTQ6MTkuNzkyWiIsInNjb3BlIjoiYWxsIn0=');
|
|
126
|
+
const token = OAuthClientToken.deserialize(encodedToken);
|
|
129
127
|
client.setToken(token);
|
|
130
|
-
expect(
|
|
128
|
+
expect(OAuthClientToken.isExpired(token)).toBeTruthy();
|
|
131
129
|
expect(client.getHttpClient().isTokenExpires()).toBeTruthy();
|
|
132
130
|
await expect(client.getHttpClient().refreshToken())
|
|
133
131
|
.rejects
|
|
134
|
-
.toHaveProperty('code',
|
|
132
|
+
.toHaveProperty('code', HttpClient.HTTP_UNAUTHORIZED);
|
|
135
133
|
await expect(client.getUserEndpoint().getUser())
|
|
136
134
|
.rejects
|
|
137
|
-
.toHaveProperty('code',
|
|
135
|
+
.toHaveProperty('code', HttpClient.HTTP_UNAUTHORIZED);
|
|
138
136
|
// const user: User = await client.getUserEndpoint().getUser()
|
|
139
137
|
// expect(user.email).toBe(passwordFlowUsername);
|
|
140
138
|
//
|
package/dist/data.spec.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Client_1 = require("./Client");
|
|
1
|
+
import { Client } from './Client';
|
|
4
2
|
jest.setTimeout((60) * 1000);
|
|
5
3
|
// const apiEndpoint: string = 'http://localhost:5728/';
|
|
6
4
|
const apiEndpoint = 'https://api2.attlaz.com';
|
|
@@ -13,7 +11,7 @@ const passwordFlowPassword = 'koetjeboe';
|
|
|
13
11
|
const tokenExpirationInSeconds = 5;
|
|
14
12
|
test('Test get user', async () => {
|
|
15
13
|
expect.assertions(1);
|
|
16
|
-
let client = new
|
|
14
|
+
let client = new Client(apiEndpoint, clientCredentialClientId, clientCredentialClientSecret);
|
|
17
15
|
client.getHttpClient().enableDebug();
|
|
18
16
|
await client.authenticate();
|
|
19
17
|
const user = await client.getUserEndpoint().getUser();
|
|
@@ -22,7 +20,7 @@ test('Test get user', async () => {
|
|
|
22
20
|
});
|
|
23
21
|
test('Test get project', async () => {
|
|
24
22
|
expect.assertions(1);
|
|
25
|
-
let client = new
|
|
23
|
+
let client = new Client(apiEndpoint, clientCredentialClientId, clientCredentialClientSecret);
|
|
26
24
|
client.getHttpClient().enableDebug();
|
|
27
25
|
await client.authenticate();
|
|
28
26
|
const project = await client.getProjectEndpoint().getById('8B5C14EBB');
|