@hahnpro/hpc-api 6.0.0 → 2024.4.0-1
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/CHANGELOG.md +383 -0
- package/README.md +11 -0
- package/package.json +10 -27
- package/src/index.d.ts +20 -0
- package/src/index.js +20 -0
- package/{dist → src/lib}/Queue.js +2 -7
- package/src/lib/api-base.js +6 -0
- package/src/lib/api.js +60 -0
- package/src/lib/asset.interface.js +1 -0
- package/{dist → src/lib}/asset.service.js +21 -17
- package/src/lib/assettypes.service.js +24 -0
- package/{dist → src/lib}/content.interface.js +2 -5
- package/src/lib/content.service.js +49 -0
- package/src/lib/data.interface.js +3 -0
- package/{dist → src/lib}/data.service.js +18 -11
- package/src/lib/endpoint.interface.js +1 -0
- package/{dist → src/lib}/endpoint.service.d.ts +2 -2
- package/{dist → src/lib}/endpoint.service.js +2 -6
- package/src/lib/events.interface.js +1 -0
- package/src/lib/events.service.js +9 -0
- package/src/lib/flow-deployment.interface.js +1 -0
- package/src/lib/flow-deployment.service.js +68 -0
- package/src/lib/flow-function.interface.js +1 -0
- package/{dist → src/lib}/flow-function.service.js +3 -6
- package/src/lib/flow-module.interface.js +1 -0
- package/{dist → src/lib}/flow-module.service.js +8 -7
- package/src/lib/flow.interface.js +1 -0
- package/{dist → src/lib}/flow.service.js +15 -20
- package/{dist → src/lib}/http.service.d.ts +1 -1
- package/src/lib/http.service.js +184 -0
- package/src/lib/label.interface.js +1 -0
- package/{dist → src/lib}/label.service.js +2 -6
- package/src/lib/mock/api-base.mock.js +7 -0
- package/src/lib/mock/api.mock.js +199 -0
- package/{dist → src/lib}/mock/asset.mock.service.js +30 -41
- package/{dist → src/lib}/mock/assetTypes.mock.service.js +19 -27
- package/{dist → src/lib}/mock/content.mock.service.js +21 -24
- package/src/lib/mock/data.mock.service.js +93 -0
- package/{dist → src/lib}/mock/endpoint.mock.service.js +2 -6
- package/src/lib/mock/events.mock.service.js +10 -0
- package/src/lib/mock/flow-deployment.mock.service.js +118 -0
- package/{dist → src/lib}/mock/flow-functions.mock.service.js +12 -21
- package/src/lib/mock/flow-modules.mock.service.js +20 -0
- package/src/lib/mock/flow.mock.service.js +81 -0
- package/src/lib/mock/index.js +11 -0
- package/src/lib/mock/label.mock.service.js +13 -0
- package/src/lib/mock/notification.mock.service.js +7 -0
- package/src/lib/mock/secret.mock.service.js +28 -0
- package/src/lib/mock/task.mock.service.js +32 -0
- package/{dist → src/lib}/mock/timeseries.mock.service.js +40 -49
- package/{dist → src/lib}/mock/trash.mock.service.js +8 -15
- package/src/lib/mock/user.mock.service.js +10 -0
- package/{dist → src/lib}/mock/vault.mock.service.js +2 -6
- package/src/lib/notification.interface.js +1 -0
- package/src/lib/notification.service.js +6 -0
- package/{dist → src/lib}/proxy.service.js +1 -5
- package/src/lib/resource.interface.js +1 -0
- package/src/lib/schema.interface.js +1 -0
- package/src/lib/secret.interface.js +1 -0
- package/src/lib/secret.service.js +15 -0
- package/src/lib/storage.interface.js +1 -0
- package/src/lib/task.interface.js +1 -0
- package/src/lib/task.service.js +19 -0
- package/src/lib/timeseries.interface.js +1 -0
- package/src/lib/timeseries.service.js +92 -0
- package/{dist → src/lib}/token-set.js +3 -7
- package/{dist → src/lib}/trash.service.js +2 -6
- package/src/lib/user-settings.interface.js +1 -0
- package/src/lib/user.service.js +26 -0
- package/src/lib/vault.interface.js +1 -0
- package/src/lib/vault.service.js +10 -0
- package/LICENSE +0 -21
- package/dist/api-base.js +0 -10
- package/dist/api.js +0 -62
- package/dist/asset.interface.js +0 -2
- package/dist/assettypes.service.js +0 -28
- package/dist/content.service.js +0 -50
- package/dist/data.interface.js +0 -6
- package/dist/endpoint.interface.js +0 -2
- package/dist/events.interface.js +0 -2
- package/dist/events.service.js +0 -13
- package/dist/flow-deployment.interface.js +0 -2
- package/dist/flow-deployment.service.js +0 -74
- package/dist/flow-function.interface.js +0 -2
- package/dist/flow-module.interface.js +0 -2
- package/dist/flow.interface.js +0 -2
- package/dist/http.service.js +0 -182
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -23
- package/dist/label.interface.js +0 -2
- package/dist/mock/api-base.mock.js +0 -11
- package/dist/mock/api.mock.js +0 -128
- package/dist/mock/data.mock.service.js +0 -96
- package/dist/mock/events.mock.service.js +0 -14
- package/dist/mock/flow-deployment.mock.service.js +0 -142
- package/dist/mock/flow-modules.mock.service.js +0 -27
- package/dist/mock/flow.mock.service.js +0 -93
- package/dist/mock/index.js +0 -14
- package/dist/mock/label.mock.service.js +0 -17
- package/dist/mock/notification.mock.service.js +0 -11
- package/dist/mock/secret.mock.service.js +0 -31
- package/dist/mock/task.mock.service.js +0 -37
- package/dist/mock/user.mock.service.js +0 -14
- package/dist/notification.interface.js +0 -2
- package/dist/notification.service.js +0 -10
- package/dist/resource.interface.js +0 -2
- package/dist/schema.interface.js +0 -2
- package/dist/secret.interface.js +0 -2
- package/dist/secret.service.js +0 -19
- package/dist/storage.interface.js +0 -2
- package/dist/task.interface.js +0 -2
- package/dist/task.service.js +0 -22
- package/dist/timeseries.interface.js +0 -2
- package/dist/timeseries.service.js +0 -56
- package/dist/user-settings.interface.js +0 -2
- package/dist/user.service.js +0 -33
- package/dist/vault.interface.js +0 -2
- package/dist/vault.service.js +0 -14
- package/{dist → src/lib}/Queue.d.ts +0 -0
- package/{dist → src/lib}/api-base.d.ts +0 -0
- package/{dist → src/lib}/api.d.ts +6 -6
- package/{dist → src/lib}/asset.interface.d.ts +0 -0
- package/{dist → src/lib}/asset.service.d.ts +0 -0
- package/{dist → src/lib}/assettypes.service.d.ts +0 -0
- package/{dist → src/lib}/content.interface.d.ts +0 -0
- package/{dist → src/lib}/content.service.d.ts +1 -1
- package/{dist → src/lib}/data.interface.d.ts +0 -0
- package/{dist → src/lib}/data.service.d.ts +0 -0
- package/{dist → src/lib}/endpoint.interface.d.ts +0 -0
- package/{dist → src/lib}/events.interface.d.ts +0 -0
- package/{dist → src/lib}/events.service.d.ts +0 -0
- package/{dist → src/lib}/flow-deployment.interface.d.ts +1 -1
- package/{dist → src/lib}/flow-deployment.service.d.ts +0 -0
- package/{dist → src/lib}/flow-function.interface.d.ts +0 -0
- package/{dist → src/lib}/flow-function.service.d.ts +1 -1
- package/{dist → src/lib}/flow-module.interface.d.ts +0 -0
- package/{dist → src/lib}/flow-module.service.d.ts +1 -1
- package/{dist → src/lib}/flow.interface.d.ts +1 -1
- package/{dist → src/lib}/flow.service.d.ts +1 -1
- package/{dist → src/lib}/label.interface.d.ts +0 -0
- package/{dist → src/lib}/label.service.d.ts +0 -0
- package/{dist → src/lib}/mock/api-base.mock.d.ts +0 -0
- package/{dist → src/lib}/mock/api.mock.d.ts +18 -18
- package/{dist → src/lib}/mock/asset.mock.service.d.ts +1 -1
- package/{dist → src/lib}/mock/assetTypes.mock.service.d.ts +0 -0
- package/{dist → src/lib}/mock/content.mock.service.d.ts +1 -1
- package/{dist → src/lib}/mock/data.mock.service.d.ts +0 -0
- package/{dist → src/lib}/mock/endpoint.mock.service.d.ts +0 -0
- package/{dist → src/lib}/mock/events.mock.service.d.ts +0 -0
- package/{dist → src/lib}/mock/flow-deployment.mock.service.d.ts +2 -2
- package/{dist → src/lib}/mock/flow-functions.mock.service.d.ts +1 -1
- package/{dist → src/lib}/mock/flow-modules.mock.service.d.ts +2 -2
- package/{dist → src/lib}/mock/flow.mock.service.d.ts +1 -1
- package/{dist → src/lib}/mock/index.d.ts +0 -0
- package/{dist → src/lib}/mock/label.mock.service.d.ts +1 -1
- package/{dist → src/lib}/mock/notification.mock.service.d.ts +1 -1
- package/{dist → src/lib}/mock/secret.mock.service.d.ts +1 -1
- package/{dist → src/lib}/mock/task.mock.service.d.ts +0 -0
- package/{dist → src/lib}/mock/timeseries.mock.service.d.ts +0 -0
- package/{dist → src/lib}/mock/trash.mock.service.d.ts +1 -1
- package/{dist → src/lib}/mock/user.mock.service.d.ts +0 -0
- package/{dist → src/lib}/mock/vault.mock.service.d.ts +1 -1
- package/{dist → src/lib}/notification.interface.d.ts +0 -0
- package/{dist → src/lib}/notification.service.d.ts +1 -1
- package/{dist → src/lib}/proxy.service.d.ts +0 -0
- package/{dist → src/lib}/resource.interface.d.ts +0 -0
- package/{dist → src/lib}/schema.interface.d.ts +0 -0
- package/{dist → src/lib}/secret.interface.d.ts +0 -0
- package/{dist → src/lib}/secret.service.d.ts +0 -0
- package/{dist → src/lib}/storage.interface.d.ts +0 -0
- package/{dist → src/lib}/task.interface.d.ts +0 -0
- package/{dist → src/lib}/task.service.d.ts +0 -0
- package/{dist → src/lib}/timeseries.interface.d.ts +0 -0
- package/{dist → src/lib}/timeseries.service.d.ts +0 -0
- package/{dist → src/lib}/token-set.d.ts +0 -0
- package/{dist → src/lib}/trash.service.d.ts +0 -0
- package/{dist → src/lib}/user-settings.interface.d.ts +0 -0
- package/{dist → src/lib}/user.service.d.ts +0 -0
- package/{dist → src/lib}/vault.interface.d.ts +0 -0
- package/{dist → src/lib}/vault.service.d.ts +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { mix } from 'ts-mixer';
|
|
3
|
+
import { APIBase } from './api-base';
|
|
4
|
+
import { ReturnType } from './content.interface';
|
|
5
|
+
import { DataService } from './data.service';
|
|
6
|
+
import { TrashService } from './trash.service';
|
|
7
|
+
let BaseService = class BaseService extends APIBase {
|
|
8
|
+
};
|
|
9
|
+
BaseService = __decorate([
|
|
10
|
+
mix(DataService, TrashService)
|
|
11
|
+
], BaseService);
|
|
12
|
+
export class ContentService extends BaseService {
|
|
13
|
+
constructor(httpClient) {
|
|
14
|
+
super(httpClient, '/contents');
|
|
15
|
+
this.upload = (form, options = {}) => {
|
|
16
|
+
const headers = { ...form.getHeaders() };
|
|
17
|
+
return this.httpClient.post(`${this.basePath}`, form, {
|
|
18
|
+
headers,
|
|
19
|
+
maxBodyLength: Infinity,
|
|
20
|
+
maxContentLength: Infinity,
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async download(id, second, options = {}) {
|
|
26
|
+
let returnType;
|
|
27
|
+
if (typeof second === 'boolean' || second == null) {
|
|
28
|
+
returnType = second ? ReturnType.ARRAYBUFFER : ReturnType.BLOB;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
returnType = second;
|
|
32
|
+
}
|
|
33
|
+
const url = `${this.basePath}/${id}/download`;
|
|
34
|
+
switch (returnType) {
|
|
35
|
+
case ReturnType.TEXT:
|
|
36
|
+
return this.httpClient.get(url, { responseType: 'text', ...options });
|
|
37
|
+
case ReturnType.JSON:
|
|
38
|
+
return this.httpClient.get(url, { responseType: 'json', ...options });
|
|
39
|
+
case ReturnType.NODEBUFFER:
|
|
40
|
+
return Buffer.from(new Uint8Array(await this.httpClient.get(url, { responseType: 'arraybuffer', ...options })));
|
|
41
|
+
case ReturnType.BLOB:
|
|
42
|
+
return this.httpClient.get(url, { responseType: 'blob', ...options });
|
|
43
|
+
case ReturnType.ARRAYBUFFER:
|
|
44
|
+
return this.httpClient.get(url, { responseType: 'arraybuffer', ...options });
|
|
45
|
+
case ReturnType.NODESTREAM:
|
|
46
|
+
return this.httpClient.get(url, { responseType: 'stream', ...options });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const api_base_1 = require("./api-base");
|
|
5
|
-
const data_interface_1 = require("./data.interface");
|
|
6
|
-
class DataService extends api_base_1.APIBase {
|
|
1
|
+
import { APIBase } from './api-base';
|
|
2
|
+
import { instanceOfTimePeriod } from './data.interface';
|
|
3
|
+
export class DataService extends APIBase {
|
|
7
4
|
addOne(dto, options = {}) {
|
|
8
5
|
return this.httpClient.post(this.basePath, dto, options);
|
|
9
6
|
}
|
|
@@ -17,8 +14,18 @@ class DataService extends api_base_1.APIBase {
|
|
|
17
14
|
getMany(params = {}, options = {}) {
|
|
18
15
|
params.limit = params.limit || 0;
|
|
19
16
|
params.page = params.page || 1;
|
|
20
|
-
return this.httpClient.get(`${this.basePath}`,
|
|
21
|
-
}
|
|
17
|
+
return this.httpClient.get(`${this.basePath}`, { params, ...options });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Filters the elements by the passed properties. The object with these properties has to be of the form:
|
|
21
|
+
* {
|
|
22
|
+
* propertyName: string | string[] | { from: Date, to: Date },
|
|
23
|
+
* ...
|
|
24
|
+
* }.
|
|
25
|
+
* @param filter The Object with the properties to filter by.
|
|
26
|
+
* @param params Other request parameters.
|
|
27
|
+
* @param options Parameters for authentication
|
|
28
|
+
*/
|
|
22
29
|
getManyFiltered(filter, params = {}, options = {}) {
|
|
23
30
|
params.filter = this.getFilterString(filter);
|
|
24
31
|
return this.getMany(params, options);
|
|
@@ -27,13 +34,14 @@ class DataService extends api_base_1.APIBase {
|
|
|
27
34
|
return this.httpClient.put(`${this.basePath}/${id}`, dto, options);
|
|
28
35
|
}
|
|
29
36
|
deleteOne(id, force = false, options = {}) {
|
|
30
|
-
return this.httpClient.delete(`${this.basePath}/${id}`,
|
|
37
|
+
return this.httpClient.delete(`${this.basePath}/${id}`, { params: { force }, ...options });
|
|
31
38
|
}
|
|
32
39
|
getFilterString(filter) {
|
|
33
40
|
const filters = [];
|
|
34
41
|
for (const [key, value] of Object.entries(filter)) {
|
|
35
42
|
if (value != null && value !== '') {
|
|
36
|
-
|
|
43
|
+
// filter out null and undefined values and empty strings
|
|
44
|
+
if (typeof value === 'object' && instanceOfTimePeriod(value)) {
|
|
37
45
|
filters.push(`${key}>=${value.from.toISOString()};${key}<=${value.to.toISOString()}`);
|
|
38
46
|
}
|
|
39
47
|
else if (Array.isArray(value)) {
|
|
@@ -47,4 +55,3 @@ class DataService extends api_base_1.APIBase {
|
|
|
47
55
|
return filters.join(';');
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
|
-
exports.DataService = DataService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpClient, TokenOption } from './http.service';
|
|
2
1
|
import { DataService } from './data.service';
|
|
3
|
-
import { Endpoint,
|
|
2
|
+
import { Endpoint, EndpointLog, NotificationPayload } from './endpoint.interface';
|
|
3
|
+
import { HttpClient, TokenOption } from './http.service';
|
|
4
4
|
export declare class EndpointService extends DataService<Endpoint> {
|
|
5
5
|
constructor(httpClient: HttpClient);
|
|
6
6
|
sendNotification(endpointId: string, payload: NotificationPayload, options?: TokenOption): Promise<void>;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.EndpointService = void 0;
|
|
4
|
-
const data_service_1 = require("./data.service");
|
|
5
|
-
class EndpointService extends data_service_1.DataService {
|
|
1
|
+
import { DataService } from './data.service';
|
|
2
|
+
export class EndpointService extends DataService {
|
|
6
3
|
constructor(httpClient) {
|
|
7
4
|
super(httpClient, '/notification/endpoints');
|
|
8
5
|
}
|
|
@@ -13,4 +10,3 @@ class EndpointService extends data_service_1.DataService {
|
|
|
13
10
|
return this.httpClient.get(`${this.basePath}/${endpointId}/logs/${group}/last`, options);
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.EndpointService = EndpointService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DataService } from './data.service';
|
|
2
|
+
export class EventsService extends DataService {
|
|
3
|
+
constructor(httpClient) {
|
|
4
|
+
super(httpClient, '/events');
|
|
5
|
+
}
|
|
6
|
+
getLastEventByAssetAndGroup(assetId, group, options = {}) {
|
|
7
|
+
return this.httpClient.get(`${this.basePath}/last/${assetId}/${group}`, options);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { mix } from 'ts-mixer';
|
|
3
|
+
import { APIBase } from './api-base';
|
|
4
|
+
import { DataService } from './data.service';
|
|
5
|
+
import { TrashService } from './trash.service';
|
|
6
|
+
let BaseService = class BaseService extends APIBase {
|
|
7
|
+
};
|
|
8
|
+
BaseService = __decorate([
|
|
9
|
+
mix(DataService, TrashService)
|
|
10
|
+
], BaseService);
|
|
11
|
+
export class FlowDeploymentService extends BaseService {
|
|
12
|
+
constructor(httpClient) {
|
|
13
|
+
super(httpClient, '/flow/deployments');
|
|
14
|
+
}
|
|
15
|
+
// workaround as flow-deployment-service does not have a POST /many endpoint
|
|
16
|
+
addMany(dto, options = {}) {
|
|
17
|
+
const reqs = dto.map((v) => this.addOne(v, options));
|
|
18
|
+
return Promise.all(reqs);
|
|
19
|
+
}
|
|
20
|
+
updateOne(id, dto, options = { force: false }) {
|
|
21
|
+
return super.updateOne(id, dto, options);
|
|
22
|
+
}
|
|
23
|
+
getDeploymentStatistics(id, options = {}) {
|
|
24
|
+
return this.httpClient.get(`${this.basePath}/${id}/statistics`, options);
|
|
25
|
+
}
|
|
26
|
+
getDeploymentMetrics(id, range = '12h', interval = '5m', options = {}) {
|
|
27
|
+
const params = { range, interval };
|
|
28
|
+
return this.httpClient.get(`${this.basePath}/${id}/metrics`, { params, ...options });
|
|
29
|
+
}
|
|
30
|
+
getDeploymentLogs(id, options = {}) {
|
|
31
|
+
return this.httpClient.get(`${this.basePath}/${id}/logs`, options);
|
|
32
|
+
}
|
|
33
|
+
resolveReferences(id, recursive = true, types, options = {}) {
|
|
34
|
+
const params = { recursive, types: types?.join(',') ?? undefined };
|
|
35
|
+
return this.httpClient.get(`${this.basePath}/${id}/references`, { params, ...options });
|
|
36
|
+
}
|
|
37
|
+
updateStatus(id, desiredStatus, options = {}) {
|
|
38
|
+
return this.httpClient.put(`${this.basePath}/${id}/status`, { desiredStatus }, options);
|
|
39
|
+
}
|
|
40
|
+
deleteOne(id, _force, options = {}) {
|
|
41
|
+
return this.updateStatus(id, 'deleted', options);
|
|
42
|
+
}
|
|
43
|
+
async waitForRunningStatus(id, options = {}) {
|
|
44
|
+
return new Promise(async (resolve, reject) => {
|
|
45
|
+
const esId = await this.subscribeToStatus(id, (event) => {
|
|
46
|
+
if (event.type === 'message' &&
|
|
47
|
+
['running', 'deployment failed', 'deleted', 'generating failed', 'updating failed', 'upgrading failed'].includes(event.data)) {
|
|
48
|
+
this.httpClient.destroyEventSource(esId);
|
|
49
|
+
if (event.data === 'running') {
|
|
50
|
+
resolve();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
reject(`Deployment in failed status: ${event.data}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, (event) => reject(event), options);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
addOne(dto, options = {}) {
|
|
60
|
+
return super.addOne(dto, options);
|
|
61
|
+
}
|
|
62
|
+
subscribeToStatus(id, listener, errorListener, options = {}) {
|
|
63
|
+
return this.httpClient.addEventSource(`${this.basePath}/${id}/status`, listener, errorListener, options);
|
|
64
|
+
}
|
|
65
|
+
subscribeToLogs(id, listener, errorListener, options = {}) {
|
|
66
|
+
return this.httpClient.addEventSource(`${this.basePath}/${id}/logs/subscribe`, listener, errorListener, options);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FlowFunctionService = void 0;
|
|
4
|
-
const data_service_1 = require("./data.service");
|
|
5
|
-
class FlowFunctionService extends data_service_1.DataService {
|
|
1
|
+
import { DataService } from './data.service';
|
|
2
|
+
export class FlowFunctionService extends DataService {
|
|
6
3
|
constructor(httpClient) {
|
|
7
4
|
super(httpClient, '/flow/functions');
|
|
8
5
|
}
|
|
6
|
+
// workaround as flow-functions-service does not have a POST /many endpoint
|
|
9
7
|
addMany(dto, options = {}) {
|
|
10
8
|
const reqs = dto.map((v) => this.addOne(v, options));
|
|
11
9
|
return Promise.all(reqs);
|
|
@@ -20,4 +18,3 @@ class FlowFunctionService extends data_service_1.DataService {
|
|
|
20
18
|
return this.httpClient.delete(`${this.basePath}/${fqn}/revisions/${revisionId}`, options);
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
exports.FlowFunctionService = FlowFunctionService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FlowModuleService = void 0;
|
|
4
|
-
const data_service_1 = require("./data.service");
|
|
5
|
-
class FlowModuleService extends data_service_1.DataService {
|
|
1
|
+
import { DataService } from './data.service';
|
|
2
|
+
export class FlowModuleService extends DataService {
|
|
6
3
|
constructor(httpClient) {
|
|
7
4
|
super(httpClient, '/flow/modules');
|
|
8
5
|
}
|
|
@@ -10,7 +7,12 @@ class FlowModuleService extends data_service_1.DataService {
|
|
|
10
7
|
return this.httpClient.delete(`${this.basePath}/${name}/${version}`, options);
|
|
11
8
|
}
|
|
12
9
|
publish(form, options = {}) {
|
|
13
|
-
const config =
|
|
10
|
+
const config = {
|
|
11
|
+
headers: { ...form.getHeaders() },
|
|
12
|
+
maxBodyLength: Infinity,
|
|
13
|
+
maxContentLength: Infinity,
|
|
14
|
+
...options,
|
|
15
|
+
};
|
|
14
16
|
return this.httpClient.post(`${this.basePath}`, form, config);
|
|
15
17
|
}
|
|
16
18
|
addOne(_dto) {
|
|
@@ -20,4 +22,3 @@ class FlowModuleService extends data_service_1.DataService {
|
|
|
20
22
|
throw new Error('not allowed: use publish instead');
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
|
-
exports.FlowModuleService = FlowModuleService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const data_service_1 = require("./data.service");
|
|
8
|
-
const trash_service_1 = require("./trash.service");
|
|
9
|
-
let BaseService = class BaseService extends api_base_1.APIBase {
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { mix } from 'ts-mixer';
|
|
3
|
+
import { APIBase } from './api-base';
|
|
4
|
+
import { DataService } from './data.service';
|
|
5
|
+
import { TrashService } from './trash.service';
|
|
6
|
+
let BaseService = class BaseService extends APIBase {
|
|
10
7
|
};
|
|
11
|
-
BaseService =
|
|
12
|
-
|
|
8
|
+
BaseService = __decorate([
|
|
9
|
+
mix(DataService, TrashService)
|
|
13
10
|
], BaseService);
|
|
14
|
-
class FlowService extends BaseService {
|
|
11
|
+
export class FlowService extends BaseService {
|
|
15
12
|
constructor(httpClient) {
|
|
16
13
|
super(httpClient, '/flows');
|
|
17
14
|
}
|
|
15
|
+
// workaround as flow-service does not have a POST /many endpoint
|
|
18
16
|
addMany(dto, options = {}) {
|
|
19
17
|
const reqs = dto.map((v) => this.addOne(v, options));
|
|
20
18
|
return Promise.all(reqs);
|
|
@@ -33,13 +31,11 @@ class FlowService extends BaseService {
|
|
|
33
31
|
getDiagramRevisions(id, options = {}) {
|
|
34
32
|
return this.httpClient.get(`${this.basePath}/${id}/diagram/revisions`, options);
|
|
35
33
|
}
|
|
36
|
-
isDeploymentOnLatestDiagramVersion(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return revisions[revisions.length - 1].id === diagramId;
|
|
42
|
-
});
|
|
34
|
+
async isDeploymentOnLatestDiagramVersion(depl, options = {}) {
|
|
35
|
+
const flowId = typeof depl.flow === 'string' ? depl.flow : depl.flow.id;
|
|
36
|
+
const diagramId = typeof depl.diagram === 'string' ? depl.diagram : depl.diagram.id;
|
|
37
|
+
const revisions = await this.getDiagramRevisions(flowId, options);
|
|
38
|
+
return revisions[revisions.length - 1].id === diagramId;
|
|
43
39
|
}
|
|
44
40
|
getRevisions(id, options = {}) {
|
|
45
41
|
return this.httpClient.get(`${this.basePath}/${id}/revisions`, options);
|
|
@@ -51,4 +47,3 @@ class FlowService extends BaseService {
|
|
|
51
47
|
return this.httpClient.delete(`${this.basePath}/${id}/revisions/${revisionId}`, options);
|
|
52
48
|
}
|
|
53
49
|
}
|
|
54
|
-
exports.FlowService = FlowService;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { EventSource } from 'eventsource';
|
|
3
|
+
import { CompactSign, decodeJwt } from 'jose';
|
|
4
|
+
import { Queue } from './Queue';
|
|
5
|
+
import { TokenSet } from './token-set';
|
|
6
|
+
export class HttpClient {
|
|
7
|
+
constructor(baseURL, authBaseURL, realm, clientId, clientSecret, tokenSubject) {
|
|
8
|
+
this.baseURL = baseURL;
|
|
9
|
+
this.authBaseURL = authBaseURL;
|
|
10
|
+
this.realm = realm;
|
|
11
|
+
this.clientId = clientId;
|
|
12
|
+
this.clientSecret = clientSecret;
|
|
13
|
+
this.tokenSubject = tokenSubject;
|
|
14
|
+
this.discoveredIssuers = new Map();
|
|
15
|
+
this.eventSourcesMap = new Map();
|
|
16
|
+
this.getQueueStats = () => this.requestQueue?.getStats();
|
|
17
|
+
this.delete = (url, config) => this.request('DELETE', url, config);
|
|
18
|
+
this.get = (url, config) => this.request('GET', url, config);
|
|
19
|
+
this.post = (url, data, config) => this.request('POST', url, config, data);
|
|
20
|
+
this.put = (url, data, config) => this.request('PUT', url, config, data);
|
|
21
|
+
this.request = (method, url, config = {}, data) => {
|
|
22
|
+
return this.requestQueue.add(() => new Promise((resolve, reject) => {
|
|
23
|
+
const tokenP = config.token ? Promise.resolve(config.token) : this.getAccessToken();
|
|
24
|
+
tokenP
|
|
25
|
+
.then((token) => {
|
|
26
|
+
const headers = { Authorization: `Bearer ${token}`, ...config.headers };
|
|
27
|
+
return this.axiosInstance.request({ ...config, headers, method, url, data });
|
|
28
|
+
})
|
|
29
|
+
.then((response) => resolve(response.data))
|
|
30
|
+
.catch(reject);
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
this.getAccessToken = async (forceRefresh = false) => {
|
|
34
|
+
let accessToken;
|
|
35
|
+
if (forceRefresh || !this.tokenSet || this.tokenSet.isExpired()) {
|
|
36
|
+
if (this.tokenSet?.provided) {
|
|
37
|
+
throw new Error('provided token is expired and cannot be refreshed, provide a new token.');
|
|
38
|
+
}
|
|
39
|
+
this.tokenSet = await this.requestAccessToken();
|
|
40
|
+
accessToken = this.tokenSet.accessToken;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
accessToken = this.tokenSet.accessToken;
|
|
44
|
+
}
|
|
45
|
+
if (this.tokenSubject) {
|
|
46
|
+
if (forceRefresh || !this.exchangedTokenSet || this.exchangedTokenSet.isExpired()) {
|
|
47
|
+
this.exchangedTokenSet = await this.exchangeAccessToken(accessToken);
|
|
48
|
+
}
|
|
49
|
+
return this.exchangedTokenSet.accessToken;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return accessToken;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
this.axiosInstance = axios.create({ baseURL, timeout: 60000 });
|
|
56
|
+
this.authAxiosInstance = axios.create({ baseURL: authBaseURL || baseURL, timeout: 10000 });
|
|
57
|
+
this.requestQueue = new Queue({ concurrency: 1, timeout: 70000, throwOnTimeout: true });
|
|
58
|
+
}
|
|
59
|
+
async addEventSource(url, listener, errorListener, options = {}) {
|
|
60
|
+
const id = generateUUID();
|
|
61
|
+
const errListener = errorListener
|
|
62
|
+
? errorListener
|
|
63
|
+
: (event) => {
|
|
64
|
+
throw new Error(JSON.stringify(event, null, 2));
|
|
65
|
+
};
|
|
66
|
+
const token = options.token ? options.token : await this.getAccessToken();
|
|
67
|
+
const es = new EventSource(`${this.baseURL}${url}`, {
|
|
68
|
+
fetch: (input, init) => fetch(input, {
|
|
69
|
+
...init,
|
|
70
|
+
headers: {
|
|
71
|
+
...init.headers,
|
|
72
|
+
Authorization: 'Bearer ' + token,
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
es.addEventListener('message', listener);
|
|
77
|
+
es.addEventListener('error', errListener);
|
|
78
|
+
// the listeners have to be saved otherwise they cannot be removed
|
|
79
|
+
this.eventSourcesMap.set(id, { eventSource: es, listener, errListener });
|
|
80
|
+
return id;
|
|
81
|
+
}
|
|
82
|
+
destroyEventSource(id) {
|
|
83
|
+
if (!this.eventSourcesMap.has(id)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const es = this.eventSourcesMap.get(id);
|
|
87
|
+
// close and unbind listeners so that the process quits cleanly
|
|
88
|
+
es.eventSource.close();
|
|
89
|
+
es.eventSource.removeEventListener('message', es.listener);
|
|
90
|
+
es.eventSource.removeEventListener('error', es.errListener);
|
|
91
|
+
this.eventSourcesMap.delete(id);
|
|
92
|
+
}
|
|
93
|
+
destroyAllEventSources() {
|
|
94
|
+
for (const key of this.eventSourcesMap.keys()) {
|
|
95
|
+
this.destroyEventSource(key);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
validateIssuer(issuer) {
|
|
99
|
+
if (!issuer.issuer ||
|
|
100
|
+
!issuer.grant_types_supported?.includes('client_credentials') ||
|
|
101
|
+
!issuer.token_endpoint_auth_methods_supported?.includes('client_secret_jwt')) {
|
|
102
|
+
throw new Error('Issuer does not support client_secret_jwt');
|
|
103
|
+
}
|
|
104
|
+
return issuer;
|
|
105
|
+
}
|
|
106
|
+
async discoverIssuer(uri) {
|
|
107
|
+
if (this.discoveredIssuers.has(uri)) {
|
|
108
|
+
return this.discoveredIssuers.get(uri);
|
|
109
|
+
}
|
|
110
|
+
const wellKnownUri = `${uri}/.well-known/openid-configuration`;
|
|
111
|
+
const issuerResponse = await this.authAxiosInstance.get(wellKnownUri, {
|
|
112
|
+
responseType: 'json',
|
|
113
|
+
headers: { Accept: 'application/json' },
|
|
114
|
+
});
|
|
115
|
+
const validIssuer = this.validateIssuer(issuerResponse.data);
|
|
116
|
+
this.discoveredIssuers.set(uri, validIssuer);
|
|
117
|
+
return validIssuer;
|
|
118
|
+
}
|
|
119
|
+
async requestAccessToken(additionalOpts = {}) {
|
|
120
|
+
const issuer = await this.discoverIssuer(`${this.authBaseURL}/realms/${this.realm}`);
|
|
121
|
+
const timestamp = Date.now() / 1000;
|
|
122
|
+
const audience = [...new Set([issuer.issuer, issuer.token_endpoint].filter(Boolean))];
|
|
123
|
+
const assertionPayload = {
|
|
124
|
+
iat: timestamp,
|
|
125
|
+
exp: timestamp + 60,
|
|
126
|
+
jti: generateUUID(),
|
|
127
|
+
iss: this.clientId,
|
|
128
|
+
sub: this.clientId,
|
|
129
|
+
aud: audience,
|
|
130
|
+
};
|
|
131
|
+
const supportedAlgos = issuer.token_endpoint_auth_signing_alg_values_supported;
|
|
132
|
+
const alg = issuer.token_endpoint_auth_signing_alg ??
|
|
133
|
+
(Array.isArray(supportedAlgos) && supportedAlgos.find((signAlg) => /^HS(?:256|384|512)/.test(signAlg)));
|
|
134
|
+
if (!alg) {
|
|
135
|
+
throw new Error('Issuer has to support HS256, HS384 or HS512');
|
|
136
|
+
}
|
|
137
|
+
const assertion = await new CompactSign(Buffer.from(JSON.stringify(assertionPayload)))
|
|
138
|
+
.setProtectedHeader({ alg })
|
|
139
|
+
.sign(new TextEncoder().encode(this.clientSecret));
|
|
140
|
+
const opts = {
|
|
141
|
+
client_id: this.clientId,
|
|
142
|
+
client_assertion: assertion,
|
|
143
|
+
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
|
|
144
|
+
grant_type: 'client_credentials',
|
|
145
|
+
...additionalOpts,
|
|
146
|
+
};
|
|
147
|
+
const authResponse = await this.authAxiosInstance.post(issuer.token_endpoint, new URLSearchParams(opts).toString(), {
|
|
148
|
+
headers: { Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
149
|
+
});
|
|
150
|
+
if (authResponse?.data?.access_token && authResponse.data.expires_in) {
|
|
151
|
+
return new TokenSet(authResponse.data.access_token, authResponse.data.expires_in);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
throw new Error('Invalid access token received');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async exchangeAccessToken(accessToken) {
|
|
158
|
+
if (!accessToken || !this.tokenSubject) {
|
|
159
|
+
throw new Error('Could not exchange access token');
|
|
160
|
+
}
|
|
161
|
+
const opts = {
|
|
162
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
|
|
163
|
+
subject_token: accessToken,
|
|
164
|
+
audience: this.clientId,
|
|
165
|
+
requested_token_type: 'urn:ietf:params:oauth:token-type:access_token',
|
|
166
|
+
requested_subject: this.tokenSubject,
|
|
167
|
+
};
|
|
168
|
+
return this.requestAccessToken(opts);
|
|
169
|
+
}
|
|
170
|
+
async provideExternalToken(token) {
|
|
171
|
+
const issuer = await this.discoverIssuer(`${this.authBaseURL}/realms/${this.realm}`);
|
|
172
|
+
const { iss: providedIssuer, exp } = decodeJwt(token);
|
|
173
|
+
if (issuer.issuer !== providedIssuer) {
|
|
174
|
+
throw new Error(`Provided token is not issued by currently configured issuer. Provided token issued by ${providedIssuer}, but ${issuer.issuer} is configured.`);
|
|
175
|
+
}
|
|
176
|
+
this.tokenSet = new TokenSet(token, exp - Date.now() / 1000, true);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function generateUUID() {
|
|
180
|
+
if (typeof globalThis.crypto?.randomUUID === 'function') {
|
|
181
|
+
return globalThis.crypto.randomUUID();
|
|
182
|
+
}
|
|
183
|
+
throw new Error('randomUUID() not available in this environment. Please upgrade to Node 20+ or a modern browser.');
|
|
184
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.LabelService = void 0;
|
|
4
|
-
const data_service_1 = require("./data.service");
|
|
5
|
-
class LabelService extends data_service_1.DataService {
|
|
1
|
+
import { DataService } from './data.service';
|
|
2
|
+
export class LabelService extends DataService {
|
|
6
3
|
constructor(httpClient) {
|
|
7
4
|
super(httpClient, '/labels');
|
|
8
5
|
}
|
|
@@ -16,4 +13,3 @@ class LabelService extends data_service_1.DataService {
|
|
|
16
13
|
return this.httpClient.get(`${this.basePath}/count`, options);
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.LabelService = LabelService;
|